Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorashatalin2009-07-02 09:29:40 -0400
committerashatalin2009-07-02 09:29:40 -0400
commit91fb7bc8671b3efad865bc5856ebccada3dd882b (patch)
tree8c346993d6063c1dba9b4e94e56850d194ab7d90
parentf87b3209ddfa94719f64becbe0354d67447feb5a (diff)
downloadorg.eclipse.gmf-tooling-91fb7bc8671b3efad865bc5856ebccada3dd882b.tar.gz
org.eclipse.gmf-tooling-91fb7bc8671b3efad865bc5856ebccada3dd882b.tar.xz
org.eclipse.gmf-tooling-91fb7bc8671b3efad865bc5856ebccada3dd882b.zip
Using Ctrl+L to switch between BubbleItem figure representation modes.v20090702-1925
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Ellipse.pngbin0 -> 409 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Label.pngbin0 -> 150 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Point.pngbin0 -> 201 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polygon.pngbin0 -> 178 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polyline.pngbin0 -> 172 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Rectangle.pngbin0 -> 200 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/RoundedRectangle.pngbin0 -> 314 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Unknown.pngbin0 -> 192 bytes
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/ChildFigureSelectionEditPolicy.java32
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/AssistantFigureKeyListener.java14
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/BubbleFigure.java20
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/PreviewFigure.java16
-rw-r--r--plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/SelectableBubbleItemFigure.java20
13 files changed, 97 insertions, 5 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Ellipse.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Ellipse.png
new file mode 100644
index 000000000..1d35c88c0
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Ellipse.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Label.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Label.png
new file mode 100644
index 000000000..38e7fbb56
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Label.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Point.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Point.png
new file mode 100644
index 000000000..04b032d6e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Point.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polygon.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polygon.png
new file mode 100644
index 000000000..81cb6b51b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polygon.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polyline.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polyline.png
new file mode 100644
index 000000000..66330d4ef
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Polyline.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Rectangle.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Rectangle.png
new file mode 100644
index 000000000..8e737cb5e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Rectangle.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/RoundedRectangle.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/RoundedRectangle.png
new file mode 100644
index 000000000..82fcb8ff9
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/RoundedRectangle.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Unknown.png b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Unknown.png
new file mode 100644
index 000000000..2362f4143
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.editor/icons/handles/Unknown.png
Binary files differ
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/ChildFigureSelectionEditPolicy.java b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/ChildFigureSelectionEditPolicy.java
index 55a07b4af..0983a57aa 100644
--- a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/ChildFigureSelectionEditPolicy.java
+++ b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/ChildFigureSelectionEditPolicy.java
@@ -15,6 +15,7 @@ import java.util.Iterator;
import org.eclipse.draw2d.FocusEvent;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.MouseMotionListener;
import org.eclipse.draw2d.geometry.Point;
@@ -23,6 +24,7 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartListener;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gmf.gmfgraph.Figure;
+import org.eclipse.gmf.gmfgraph.GMFGraphPackage;
import org.eclipse.gmf.gmfgraph.RealFigure;
import org.eclipse.gmf.graphdef.editor.edit.parts.AbstractFigureEditPart;
import org.eclipse.gmf.graphdef.editor.edit.policies.assistant.AssistantFigureKeyListener;
@@ -33,6 +35,7 @@ import org.eclipse.gmf.graphdef.editor.edit.policies.assistant.SelectEditPartDra
import org.eclipse.gmf.graphdef.editor.edit.policies.assistant.SelectableBubbleItemFigure;
import org.eclipse.gmf.graphdef.editor.edit.policies.keyhandler.KeyHandler;
import org.eclipse.gmf.graphdef.editor.edit.policies.keyhandler.KeyPressedRequest;
+import org.eclipse.gmf.graphdef.editor.part.GMFGraphDiagramEditorPlugin;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DiagramAssistantEditPolicy;
import org.eclipse.gmf.runtime.notation.View;
@@ -40,6 +43,12 @@ import org.eclipse.swt.widgets.Display;
public class ChildFigureSelectionEditPolicy extends DiagramAssistantEditPolicy implements KeyHandlerEditPolicy {
+ private static final String PNG_EXTENSION = ".png";
+
+ private static final String ICONS_FOLDER = "icons/handles/";
+
+ private static final String UNKNOWN_FIGURE_ICON = ICONS_FOLDER + "Unknown" + PNG_EXTENSION;
+
private BubbleFigure myFeedbackFigure;
private static Figure getFigure(EditPart editPart) {
@@ -132,16 +141,18 @@ public class ChildFigureSelectionEditPolicy extends DiagramAssistantEditPolicy i
// TODO: Better check for figure instance here.
if (previewFigure.isPreviewValid()) {
previewFigure.setPreferredSize(15, 15);
- itemFigure.add(previewFigure);
+ itemFigure.setItemRepresentation(BubbleFigure.Mode.PREVIEW, previewFigure);
} else {
- // TODO: add image figure to visualize invalid preview.
+ itemFigure.setItemRepresentation(BubbleFigure.Mode.PREVIEW, new ImageFigure(GMFGraphDiagramEditorPlugin.getInstance().getBundledImage(UNKNOWN_FIGURE_ICON)));
}
+ itemFigure.setItemRepresentation(BubbleFigure.Mode.ICON, getImageFigure(figure));
if (myFeedbackFigure.getChildren().size() == 1) {
- itemFigure.setSelected(true);
+ myFeedbackFigure.selectChild(itemFigure);
}
}
}
+ myFeedbackFigure.setMode(BubbleFigure.Mode.PREVIEW);
myFeedbackFigure.setSize(myFeedbackFigure.getPreferredSize());
layer.add(myFeedbackFigure);
myFeedbackFigure.addKeyListener(new AssistantFigureKeyListener(myFeedbackFigure) {
@@ -166,6 +177,21 @@ public class ChildFigureSelectionEditPolicy extends DiagramAssistantEditPolicy i
myFeedbackFigure.requestFocus();
}
+ private IFigure getImageFigure(Figure figure) {
+ switch (figure.eClass().getClassifierID()) {
+ case GMFGraphPackage.ELLIPSE:
+ case GMFGraphPackage.LABEL:
+ case GMFGraphPackage.POINT:
+ case GMFGraphPackage.POLYGON:
+ case GMFGraphPackage.POLYLINE:
+ case GMFGraphPackage.RECTANGLE:
+ case GMFGraphPackage.ROUNDED_RECTANGLE:
+ return new ImageFigure(GMFGraphDiagramEditorPlugin.getInstance().getBundledImage(ICONS_FOLDER + figure.eClass().getName() + PNG_EXTENSION));
+ default:
+ return new ImageFigure(GMFGraphDiagramEditorPlugin.getInstance().getBundledImage(UNKNOWN_FIGURE_ICON));
+ }
+ }
+
private void disposeFeedbackFigure() {
IFigure layer = getLayer(LayerConstants.HANDLE_LAYER);
layer.remove(getFeedbackFigure());
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/AssistantFigureKeyListener.java b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/AssistantFigureKeyListener.java
index 189510733..23bd724f2 100644
--- a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/AssistantFigureKeyListener.java
+++ b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/AssistantFigureKeyListener.java
@@ -29,6 +29,10 @@ public abstract class AssistantFigureKeyListener extends KeyListener.Stub {
hideAssistant();
return;
case ' ':
+ if (ke.getState() != 0) {
+ // ignoring any key events with state masks
+ return;
+ }
case SWT.CR:
for (Object nextFigure : myFeedbackFigure.getChildren()) {
if (nextFigure instanceof SelectableBubbleItemFigure) {
@@ -40,6 +44,16 @@ public abstract class AssistantFigureKeyListener extends KeyListener.Stub {
}
}
return;
+ case 12:
+ switch (myFeedbackFigure.getMode()) {
+ case ICON:
+ myFeedbackFigure.setMode(BubbleFigure.Mode.PREVIEW);
+ break;
+ case PREVIEW:
+ myFeedbackFigure.setMode(BubbleFigure.Mode.ICON);
+ break;
+ }
+ myFeedbackFigure.setSize(myFeedbackFigure.getPreferredSize());
}
switch (ke.keycode) {
case SWT.ARROW_UP:
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/BubbleFigure.java b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/BubbleFigure.java
index 1e25affc7..8769ad807 100644
--- a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/BubbleFigure.java
+++ b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/BubbleFigure.java
@@ -33,6 +33,8 @@ public class BubbleFigure extends Shape {
private static final int HORIZONTAL_CHILDREN_INSET = 2;
+ private Mode myMode;
+
public BubbleFigure() {
setRequestFocusEnabled(true);
setLineStyle(SWT.LINE_DASH);
@@ -120,4 +122,22 @@ public class BubbleFigure extends Shape {
}
}
+ // TODO: move to EditPolicy?
+ public void setMode(Mode mode) {
+ myMode = mode;
+ for (Object childFigure : getChildren()) {
+ if (childFigure instanceof SelectableBubbleItemFigure) {
+ ((SelectableBubbleItemFigure) childFigure).setMode(mode);
+ }
+ }
+ }
+
+ public Mode getMode() {
+ return myMode;
+ }
+
+ public enum Mode {
+ PREVIEW, ICON;
+ }
+
}
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/PreviewFigure.java b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/PreviewFigure.java
index bc4603824..4b89fd473 100644
--- a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/PreviewFigure.java
+++ b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/PreviewFigure.java
@@ -29,6 +29,10 @@ public class PreviewFigure extends Figure {
private double myScale;
+ private int myHorizontalShift;
+
+ private int myVerticalShift;
+
public PreviewFigure(View view, HeadlessDiagramGraphicalViewer viewer) {
myActualFigure = viewer.addChild(view);
myValid = myActualFigure != null;
@@ -63,10 +67,18 @@ public class PreviewFigure extends Figure {
@Override
public void setPreferredSize(Dimension size) {
Dimension figurePreferredSize = myActualFigure.getPreferredSize();
- myActualFigure.getPreferredSize(figurePreferredSize.width, figurePreferredSize.height);
+ if (figurePreferredSize.width == 0 && figurePreferredSize.height == 0) {
+ figurePreferredSize.width = figurePreferredSize.height = 15;
+ } else if (figurePreferredSize.width == 0) {
+ figurePreferredSize.width = figurePreferredSize.height;
+ } else if (figurePreferredSize.height == 0) {
+ figurePreferredSize.height = figurePreferredSize.width;
+ }
myActualFigure.setSize(figurePreferredSize);
myActualFigure.setLocation(new Point(0, 0));
myScale = Math.min(size.width / (double) figurePreferredSize.width, size.height / (double) figurePreferredSize.height);
+ myHorizontalShift = (int) ((size.width - figurePreferredSize.width * myScale) / 2);
+ myVerticalShift = (int) ((size.height - figurePreferredSize.height * myScale) / 2);
super.setPreferredSize(size);
}
@@ -84,7 +96,7 @@ public class PreviewFigure extends Figure {
protected void paintClientArea(Graphics graphics) {
graphics.pushState();
boolean optimizeClip = getBorder() == null || getBorder().isOpaque();
- graphics.translate(getBounds().x + getInsets().left, getBounds().y + getInsets().top);
+ graphics.translate(getBounds().x + getInsets().left + myHorizontalShift, getBounds().y + getInsets().top + myVerticalShift);
if (!optimizeClip) {
graphics.clipRect(getClientArea(Rectangle.SINGLETON));
}
diff --git a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/SelectableBubbleItemFigure.java b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/SelectableBubbleItemFigure.java
index 35953c498..8454d2a30 100644
--- a/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/SelectableBubbleItemFigure.java
+++ b/plugins/org.eclipse.gmf.graphdef.editor/src-extra/org/eclipse/gmf/graphdef/editor/edit/policies/assistant/SelectableBubbleItemFigure.java
@@ -11,6 +11,9 @@
*/
package org.eclipse.gmf.graphdef.editor.edit.policies.assistant;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
@@ -34,6 +37,10 @@ public class SelectableBubbleItemFigure extends Shape implements Handle {
private boolean mySelected;
+ private Map<BubbleFigure.Mode, IFigure> myModeToFigureMap = new HashMap<BubbleFigure.Mode, IFigure>();
+
+ private IFigure myVisibleChild;
+
public SelectableBubbleItemFigure(DragTracker dragTracker) {
myDragTracker = dragTracker;
setBorder(border);
@@ -80,4 +87,17 @@ public class SelectableBubbleItemFigure extends Shape implements Handle {
return null;
}
+ public void setItemRepresentation(BubbleFigure.Mode mode, IFigure figure) {
+ myModeToFigureMap.put(mode, figure);
+ }
+
+ void setMode(BubbleFigure.Mode mode) {
+ assert myModeToFigureMap.containsKey(mode);
+ if (myVisibleChild != null) {
+ remove(myVisibleChild);
+ }
+ myVisibleChild = myModeToFigureMap.get(mode);
+ add(myVisibleChild);
+ }
+
}

Back to the top