Author: bobtarling
Date: 2011-04-21 06:25:57-0700
New Revision: 19266
Modified:
trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/BaseDisplayState.java
trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigBaseNode.java
trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigNotation.java
trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/RRectDisplayState.java
Log:
Trying to get parent Fig to grow when a notation fig grows beyond its bounds.
Not complete as yet.
Modified: trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/BaseDisplayState.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/BaseDisplayState.java?view=diff&pathrev=19266&r1=19265&r2=19266
==============================================================================
--- trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/BaseDisplayState.java (original)
+++ trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/BaseDisplayState.java 2011-04-21 06:25:57-0700
@@ -19,6 +19,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import org.apache.log4j.Logger;
import org.argouml.notation2.NotationType;
import org.argouml.uml.diagram.DiagramSettings;
import org.tigris.gef.presentation.Fig;
@@ -26,9 +27,12 @@
abstract class BaseDisplayState extends FigGroup
implements StereotypeDisplayer, NameDisplayer, PropertyChangeListener {
+
+ private static final Logger LOG = Logger.getLogger(BaseDisplayState.class);
private final DiagramElement bigPort;
private final DiagramElement nameDisplay;
+ private Rectangle bounds;
public BaseDisplayState(
final Rectangle rect,
@@ -45,6 +49,7 @@
addFig((Fig) bigPort);
addFig((Fig) getNameDisplay());
((Fig) nameDisplay).addPropertyChangeListener(this);
+ setBounds(rect);
}
public DiagramElement getStereotypeDisplay() {
@@ -64,11 +69,46 @@
return bigPort;
}
- /**
- * Default implementation makes sure the model element name is
- * displayed in the centre of the node.
- * TODO: We need stereotypes displayed above this.
- */
+ public void propertyChange(PropertyChangeEvent pce) {
+ if (pce.getSource() == getNameDisplay() && pce.getPropertyName().equals("bounds")) {
+ // The size of the name has changed. Check if we need to make the
+ // node bigger so that it contains all its children.
+ Rectangle textBounds = (Rectangle) pce.getNewValue();
+ int notationEndX = textBounds.x + textBounds.width;
+ int thisEndX = getBounds().x + getBounds().width;
+ LOG.debug("Got the event notation right = " + notationEndX + " container right = " + thisEndX);
+ if (notationEndX > thisEndX) {
+ // TODO: Why do we not get here?
+ // The container seems to be growing by itself but we don't see that visibly.
+ LOG.info("text has grown too wide so redrawing parent");
+ // TODO: layout our children and calculate our bounds.
+ calcBounds();
+ }
+ }
+ super.propertyChange(pce);
+ }
+
+ // TODO: Move an empty implementation to FigGroup in GEF
+ protected void positionChildren() {
+ Rectangle myBounds = getBounds();
+ getPort().setBounds(myBounds);
+
+ final Dimension nameDim = getNameDisplay().getMinimumSize();
+ final int nameWidth = nameDim.width;
+ final int nameHeight = nameDim.height;
+
+ final int nx = bounds.x + (bounds.width - nameWidth) /2;
+ final int ny = bounds.y + (bounds.height - nameHeight) /2;
+ getNameDisplay().setLocation(nx, ny);
+ }
+
+
+ //
+ // !! TODO: All code below here is duplicated in FigBaseNode. The reason
+ // is the GEF defect - http://gef.tigris.org/issues/show_bug.cgi?id=358
+ // Once we have taken a release of GEF with that fix we can remove this
+ // code.
+ //
@Override
protected void setBoundsImpl(
final int x,
@@ -78,25 +118,41 @@
final Rectangle oldBounds = getBounds();
- getPort().setBounds(new Rectangle(x, y, w, h));
+ bounds = new Rectangle(x, y, w, h);
+ _x = x;
+ _y = y;
+ _w = w;
+ _h = h;
- final Dimension nameDim = getNameDisplay().getMinimumSize();
- final int nameWidth = nameDim.width;
- final int nameHeight = nameDim.height;
+ positionChildren();
- final int nx = x + (w - nameWidth) /2;
- final int ny = y + (h - nameHeight) /2;
- getNameDisplay().setLocation(nx, ny);
- calcBounds();
- firePropChange("bounds", oldBounds, getBounds());
- }
-
- public void propertyChange(PropertyChangeEvent pce) {
- if (pce.getSource() == getNameDisplay() && pce.getPropertyName().equals("bounds")) {
- calcBounds();
+ if (!oldBounds.equals(getBounds())) {
+ firePropChange("bounds", oldBounds, bounds);
}
- super.propertyChange(pce);
+ }
+
+ protected Rectangle getBoundsImpl() {
+ return bounds;
}
+ /**
+ * Change the position of the object from where it is to where it is plus dx
+ * and dy. Often called when an object is dragged. This could be very useful
+ * if local-coordinate systems are used because deltas need less
+ * transforming... maybe. Fires property "bounds".
+ */
+ protected void translateImpl(int dx, int dy) {
+ if (dx ==0 || dy == 0) {
+ return;
+ }
+ Rectangle oldBounds = getBounds();
+ Rectangle newBounds = new Rectangle(
+ oldBounds.x + dx,
+ oldBounds.y + dy,
+ oldBounds.width,
+ oldBounds.height);
+ setBounds(newBounds);
+ }
}
+
Modified: trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigBaseNode.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigBaseNode.java?view=diff&pathrev=19266&r1=19265&r2=19266
==============================================================================
--- trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigBaseNode.java (original)
+++ trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigBaseNode.java 2011-04-21 06:25:57-0700
@@ -17,7 +17,6 @@
import java.awt.Rectangle;
import org.argouml.uml.diagram.DiagramSettings;
-import org.tigris.gef.presentation.Fig;
import org.tigris.gef.presentation.FigNode;
/**
@@ -31,6 +30,8 @@
private final DiagramSettings settings;
private DiagramElement nameDiagramElement;
+ private Rectangle bounds;
+
/**
* Constructor a new FigBaseNode
*
@@ -41,6 +42,7 @@
FigBaseNode(final Object owner, final Rectangle bounds,
final DiagramSettings settings) {
super(owner);
+ this.bounds = bounds;
this.settings = settings;
}
@@ -62,4 +64,57 @@
public void setNameDiagramElement(DiagramElement name) {
}
+
+ // TODO: Move an empty implementation to FigGroup in GEF
+ protected void positionChildren() {
+ Rectangle myBounds = getBounds();
+ displayState.setBounds(myBounds);
+// calcBounds();
+ updateEdges();
+ }
+
+ @Override
+ protected void setBoundsImpl(
+ final int x,
+ final int y,
+ final int w,
+ final int h) {
+
+ final Rectangle oldBounds = getBounds();
+
+ bounds = new Rectangle(x, y, w, h);
+ _x = x;
+ _y = y;
+ _w = w;
+ _h = h;
+
+ positionChildren();
+
+ if (!oldBounds.equals(getBounds())) {
+ firePropChange("bounds", oldBounds, bounds);
+ }
+ }
+
+ protected Rectangle getBoundsImpl() {
+ return bounds;
+ }
+
+ /**
+ * Change the position of the object from where it is to where it is plus dx
+ * and dy. Often called when an object is dragged. This could be very useful
+ * if local-coordinate systems are used because deltas need less
+ * transforming... maybe. Fires property "bounds".
+ */
+ protected void translateImpl(int dx, int dy) {
+ if (dx ==0 || dy == 0) {
+ return;
+ }
+ Rectangle oldBounds = getBounds();
+ Rectangle newBounds = new Rectangle(
+ oldBounds.x + dx,
+ oldBounds.y + dy,
+ oldBounds.width,
+ oldBounds.height);
+ setBounds(newBounds);
+ }
}
Modified: trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigNotation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigNotation.java?view=diff&pathrev=19266&r1=19265&r2=19266
==============================================================================
--- trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigNotation.java (original)
+++ trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigNotation.java 2011-04-21 06:25:57-0700
@@ -16,6 +16,7 @@
import java.awt.Dimension;
import java.awt.Rectangle;
+import org.apache.log4j.Logger;
import org.argouml.notation2.NotatedItem;
import org.argouml.notation2.NotationLanguage;
import org.argouml.notation2.NotationManager;
@@ -29,6 +30,8 @@
*/
class FigNotation extends FigText implements NotatedItem, DiagramElement {
+ private static final Logger LOG = Logger.getLogger(FigNotation.class);
+
private final NotationType notationType;
/**
@@ -68,9 +71,6 @@
@Override
public Dimension getMinimumSize() {
-// int w = getFontMetrics().stringWidth(getText());
-// int h = getFontMetrics().getHeight();
-
int w = getFontMetrics().stringWidth(getText());
int h = getFontMetrics().getHeight();
@@ -109,4 +109,57 @@
}
this.damage();
}
+
+ public void setText(String s) {
+ final String oldText = getText();
+ if (s.equals(oldText)) {
+ return;
+ }
+ final Rectangle oldBounds = getBounds();
+ super.setText(s);
+ // TODO: This should happen in GEF
+ firePropChange("text", oldText, s);
+ // TODO: setText in GEF should call setBounds instead of directly
+ // changing x, y, w, h - then we will have an event generated
+ // correctly in GEF
+ firePropChange("bounds", oldBounds, getBounds());
+ if (!oldBounds.equals(getBounds())) {
+ LOG.info("notation Fig firing bounds changed");
+ firePropChange("bounds changed", oldBounds, getBounds());
+ }
+ }
+
+ /**
+ * Prevent underline events if underline does not change.
+ * TODO: GEF should manage this after GEF 0.13.4 is included.
+ */
+ public void setUnderline(boolean u) {
+ if (getUnderline() == u) {
+ return;
+ }
+ super.setUnderline(u);
+ }
+
+
+ /**
+ * Prevent bold events if bold does not change.
+ * TODO: GEF should manage this after GEF 0.13.4 is included.
+ */
+ public void setBold(boolean b) {
+ if (getBold() == b) {
+ return;
+ }
+ super.setBold(b);
+ }
+
+ /**
+ * Prevent italic events if italic does not change.
+ * TODO: GEF should manage this after GEF 0.13.4 is included.
+ */
+ public void setItalic(boolean i) {
+ if (getItalic() == i) {
+ return;
+ }
+ super.setItalic(i);
+ }
}
Modified: trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/RRectDisplayState.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/RRectDisplayState.java?view=diff&pathrev=19266&r1=19265&r2=19266
==============================================================================
--- trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/RRectDisplayState.java (original)
+++ trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/RRectDisplayState.java 2011-04-21 06:25:57-0700
@@ -17,7 +17,6 @@
import java.awt.Dimension;
import java.awt.Rectangle;
-import org.argouml.uml.diagram.DiagramAppearance;
import org.argouml.uml.diagram.DiagramSettings;
import org.tigris.gef.presentation.FigRRect;
@@ -77,5 +76,6 @@
super(x, y, w, h, lineColor, fillColor);
this.setCornerRadius(RADIUS);
}
- }
+ }
+
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2722138
To unsubscribe from this discussion, e-mail: [[email protected]].
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.