summaryrefslogtreecommitdiff
path: root/propertysheet/src/org/eclipse/wb/internal
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-04-19 15:05:27 -0700
committerandroid code review <noreply-gerritcodereview@google.com>2012-04-19 15:05:28 -0700
commit7d5e809721ca0f3460afcd8ae32fa366c86ec978 (patch)
treef456b9a3b7e64bee9a8f9980f58c641aa6dc3a7e /propertysheet/src/org/eclipse/wb/internal
parent710a161c9c528b5e5cb5cd6d0d41736881c9697f (diff)
parent4b1a9d7baa71df312585022c22e8025fafaba95a (diff)
downloadeclipse-windowbuilder-7d5e809721ca0f3460afcd8ae32fa366c86ec978.tar.gz
Diffstat (limited to 'propertysheet/src/org/eclipse/wb/internal')
-rw-r--r--propertysheet/src/org/eclipse/wb/internal/core/editor/structure/IPage.java56
-rw-r--r--propertysheet/src/org/eclipse/wb/internal/core/editor/structure/PageSiteComposite.java101
-rw-r--r--propertysheet/src/org/eclipse/wb/internal/core/utils/ui/DrawUtils.java67
3 files changed, 224 insertions, 0 deletions
diff --git a/propertysheet/src/org/eclipse/wb/internal/core/editor/structure/IPage.java b/propertysheet/src/org/eclipse/wb/internal/core/editor/structure/IPage.java
new file mode 100644
index 0000000..a86522d
--- /dev/null
+++ b/propertysheet/src/org/eclipse/wb/internal/core/editor/structure/IPage.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Google, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Google, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wb.internal.core.editor.structure;
+
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * View-like page.
+ *
+ * @author scheglov_ke
+ * @coverage core.editor.structure
+ */
+public interface IPage {
+ /**
+ * Creates the {@link Control} for this page.
+ */
+ void createControl(Composite parent);
+
+ /**
+ * Disposes this page.
+ * <p>
+ * This is the last method called on the {@link IPage}. Implementors should clean up any resources
+ * associated with the page.
+ * <p>
+ * Note that there is no guarantee that {@link #createControl(Composite)} has been called, so the
+ * control may never have been created.
+ */
+ void dispose();
+
+ /**
+ * @return the {@link Control} of this page, may be <code>null</code>.
+ */
+ Control getControl();
+
+ /**
+ * Allows the page to make contributions to the given {@link IToolBarManager}. The contributions
+ * will be visible when the page is visible. This method is automatically called shortly after
+ * {@link #createControl(Composite)} is called.
+ */
+ void setToolBar(IToolBarManager toolBarManager);
+
+ /**
+ * Asks this page to take focus.
+ */
+ void setFocus();
+}
diff --git a/propertysheet/src/org/eclipse/wb/internal/core/editor/structure/PageSiteComposite.java b/propertysheet/src/org/eclipse/wb/internal/core/editor/structure/PageSiteComposite.java
new file mode 100644
index 0000000..bc57360
--- /dev/null
+++ b/propertysheet/src/org/eclipse/wb/internal/core/editor/structure/PageSiteComposite.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Google, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Google, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wb.internal.core.editor.structure;
+
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.wb.core.controls.CImageLabel;
+import org.eclipse.wb.internal.core.utils.check.Assert;
+import org.eclipse.wb.internal.core.utils.ui.GridDataFactory;
+import org.eclipse.wb.internal.core.utils.ui.GridLayoutFactory;
+
+/**
+ * The site {@link Composite} for {@link IPage}.
+ *
+ * @author scheglov_ke
+ * @coverage core.editor.structure
+ */
+public final class PageSiteComposite extends Composite {
+ private final CImageLabel m_title;
+ private final ToolBarManager m_toolBarManager;
+ private final ToolBar m_toolBar;
+ private IPage m_page;
+
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Constructor
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ public PageSiteComposite(Composite parent, int style) {
+ super(parent, style);
+ GridLayoutFactory.create(this).noMargins().spacingV(0).columns(2);
+ // title
+ {
+ m_title = new CImageLabel(this, SWT.NONE);
+ GridDataFactory.create(m_title).grabH().fill();
+ }
+ // toolbar
+ {
+ m_toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
+ GridDataFactory.create(m_toolBar).fill();
+ m_toolBarManager = new ToolBarManager(m_toolBar);
+ }
+ // separator
+ {
+ Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridDataFactory.create(separator).spanH(2).grabH().fillH();
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Access
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Sets the {@link Image} for title;
+ */
+ public void setTitleImage(Image image) {
+ m_title.setImage(image);
+ }
+
+ /**
+ * Sets the text for title.
+ */
+ public void setTitleText(String title) {
+ m_title.setText(title);
+ }
+
+ /**
+ * Sets the {@link IPage} to display.
+ */
+ public void setPage(IPage page) {
+ Assert.isNull(m_page);
+ Assert.isNotNull(page);
+ m_page = page;
+ // create Control
+ m_page.createControl(this);
+ GridDataFactory.create(m_page.getControl()).spanH(2).grab().fill();
+ // set toolbar
+ m_page.setToolBar(m_toolBarManager);
+ }
+
+ // BEGIN ADT MODIFICATIONS
+ public ToolBar getToolBar() {
+ return m_toolBar;
+ }
+ // END ADT MODIFICATIONS
+
+}
diff --git a/propertysheet/src/org/eclipse/wb/internal/core/utils/ui/DrawUtils.java b/propertysheet/src/org/eclipse/wb/internal/core/utils/ui/DrawUtils.java
index f7cc09d..c22256e 100644
--- a/propertysheet/src/org/eclipse/wb/internal/core/utils/ui/DrawUtils.java
+++ b/propertysheet/src/org/eclipse/wb/internal/core/utils/ui/DrawUtils.java
@@ -262,6 +262,73 @@ public class DrawUtils {
////////////////////////////////////////////////////////////////////////////
//
+ // Rotated images
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Returns a new Image that is the given Image rotated left by 90 degrees. The client is
+ * responsible for disposing the returned Image. This method MUST be invoked from the
+ * user-interface (Display) thread.
+ *
+ * @param srcImage
+ * the Image that is to be rotated left
+ * @return the rotated Image (the client is responsible for disposing it)
+ */
+ public static Image createRotatedImage(Image srcImage) {
+ // prepare Display
+ Display display = Display.getCurrent();
+ if (display == null) {
+ SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ }
+ // rotate ImageData
+ ImageData destData;
+ {
+ ImageData srcData = srcImage.getImageData();
+ if (srcData.depth < 8) {
+ destData = rotatePixelByPixel(srcData);
+ } else {
+ destData = rotateOptimized(srcData);
+ }
+ }
+ // create new image
+ return new Image(display, destData);
+ }
+
+ private static ImageData rotatePixelByPixel(ImageData srcData) {
+ ImageData destData =
+ new ImageData(srcData.height, srcData.width, srcData.depth, srcData.palette);
+ for (int y = 0; y < srcData.height; y++) {
+ for (int x = 0; x < srcData.width; x++) {
+ destData.setPixel(y, srcData.width - x - 1, srcData.getPixel(x, y));
+ }
+ }
+ return destData;
+ }
+
+ private static ImageData rotateOptimized(ImageData srcData) {
+ int bytesPerPixel = Math.max(1, srcData.depth / 8);
+ int destBytesPerLine =
+ ((srcData.height * bytesPerPixel - 1) / srcData.scanlinePad + 1) * srcData.scanlinePad;
+ byte[] newData = new byte[destBytesPerLine * srcData.width];
+ for (int srcY = 0; srcY < srcData.height; srcY++) {
+ for (int srcX = 0; srcX < srcData.width; srcX++) {
+ int destX = srcY;
+ int destY = srcData.width - srcX - 1;
+ int destIndex = destY * destBytesPerLine + destX * bytesPerPixel;
+ int srcIndex = srcY * srcData.bytesPerLine + srcX * bytesPerPixel;
+ System.arraycopy(srcData.data, srcIndex, newData, destIndex, bytesPerPixel);
+ }
+ }
+ return new ImageData(srcData.height,
+ srcData.width,
+ srcData.depth,
+ srcData.palette,
+ srcData.scanlinePad,
+ newData);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ //
// Colors
//
////////////////////////////////////////////////////////////////////////////