Author: tfmorris
Date: 2007-11-16 13:40:41-0800
New Revision: 13779
Added:
trunk/src_new/org/argouml/uml/diagram/deployment/ui/AbstractFigComponent.java (contents, props changed)
Modified:
trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponent.java
trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponentInstance.java
Log:
Refactor common code from FigComponent & FigComponentInstance.
Fix positioning of plug blades (fingers) when resized
Added: trunk/src_new/org/argouml/uml/diagram/deployment/ui/AbstractFigComponent.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/deployment/ui/AbstractFigComponent.java?view=auto&rev=13779
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/uml/diagram/deployment/ui/AbstractFigComponent.java 2007-11-16 13:40:41-0800
@@ -0,0 +1,313 @@
+// $Id$
+// Copyright (c) 2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.uml.diagram.deployment.ui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.argouml.model.AssociationChangeEvent;
+import org.argouml.model.AttributeChangeEvent;
+import org.argouml.model.Model;
+import org.argouml.uml.diagram.ui.FigEdgeModelElement;
+import org.argouml.uml.diagram.ui.FigNodeModelElement;
+import org.tigris.gef.base.Selection;
+import org.tigris.gef.graph.GraphModel;
+import org.tigris.gef.presentation.Fig;
+import org.tigris.gef.presentation.FigRect;
+import org.tigris.gef.presentation.FigText;
+
+/**
+ * Common abstract superclass for FigComponent and FigComponentInstance
+ * to encapsulate common behavior.
+ *
+ * @author 5eichler
+ * @author Tom Morris <[email protected]>
+ */
+public abstract class AbstractFigComponent extends FigNodeModelElement {
+
+ /**
+ * Size of the prong or finger that extends from the left side of the
+ * figure. It is also the distance between the left edge of the fig and the
+ * left edge of the main rectangle. Originally named BIGPORT_X (which
+ * explains what BX stands for).
+ */
+ protected static final int BX = 10;
+ protected static final int FINGER_HEIGHT = BX;
+ protected static final int FINGER_WIDTH = BX * 2;
+ private static final int OVERLAP = 0;
+ protected static final int DEFAULT_WIDTH = 120;
+ protected static final int DEFAULT_HEIGHT = 80;
+ protected FigRect cover;
+ protected FigRect upperRect;
+ protected FigRect lowerRect;
+
+ public AbstractFigComponent() {
+ super();
+ cover = new FigRect(BX, 10, DEFAULT_WIDTH, DEFAULT_HEIGHT, Color.black,
+ Color.white);
+ upperRect = new FigRect(0, 2 * FINGER_HEIGHT, FINGER_WIDTH, FINGER_HEIGHT,
+ Color.black, Color.white);
+ lowerRect = new FigRect(0, 5 * FINGER_HEIGHT, FINGER_WIDTH, FINGER_HEIGHT,
+ Color.black, Color.white);
+
+ getNameFig().setLineWidth(0);
+ getNameFig().setFilled(false);
+ getNameFig().setText(placeString());
+
+ addFig(getBigPort());
+ addFig(cover);
+ addFig(getStereotypeFig());
+ addFig(getNameFig());
+ addFig(upperRect);
+ addFig(lowerRect);
+ }
+
+ /**
+ * The constructor that hooks the Fig into an existing UML element.
+ *
+ * @param gm ignored
+ * @param node the UML element
+ */
+ public AbstractFigComponent(GraphModel gm, Object node) {
+ this();
+ setOwner(node);
+ if (Model.getFacade().isAClassifier(node)
+ && (Model.getFacade().getName(node) != null)) {
+ getNameFig().setText(Model.getFacade().getName(node));
+ }
+ updateBounds();
+ }
+
+ @Override
+ public Object clone() {
+ FigComponent figClone = (FigComponent) super.clone();
+ Iterator it = figClone.getFigs().iterator();
+ figClone.setBigPort((FigRect) it.next());
+ figClone.cover = (FigRect) it.next();
+ it.next();
+ figClone.setNameFig((FigText) it.next());
+ figClone.upperRect = (FigRect) it.next();
+ figClone.lowerRect = (FigRect) it.next();
+
+ return figClone;
+ }
+
+ @Override
+ protected void modelChanged(PropertyChangeEvent mee) {
+ super.modelChanged(mee);
+ if (mee instanceof AssociationChangeEvent
+ || mee instanceof AttributeChangeEvent) {
+ renderingChanged();
+ updateListeners(getOwner(), getOwner());
+ damage();
+ }
+ }
+
+ @Override
+ protected void updateListeners(Object oldOwner, Object newOwner) {
+ if (oldOwner != null) {
+ removeAllElementListeners();
+ }
+ if (newOwner != null) {
+ // add the listeners to the newOwner
+ addElementListener(newOwner);
+ Collection c = Model.getFacade().getStereotypes(newOwner);
+ Iterator i = c.iterator();
+ while (i.hasNext()) {
+ Object st = i.next();
+ addElementListener(st, "name");
+ }
+ }
+ }
+
+ /**
+ * @param b switch underline on or off
+ */
+ public void setUnderline(boolean b) {
+ getNameFig().setUnderline(b);
+ }
+
+ @Override
+ public void setLineColor(Color c) {
+ cover.setLineColor(c);
+ getStereotypeFig().setFilled(false);
+ getStereotypeFig().setLineWidth(0);
+ getNameFig().setFilled(false);
+ getNameFig().setLineWidth(0);
+ upperRect.setLineColor(c);
+ lowerRect.setLineColor(c);
+ }
+
+ @Override
+ public Selection makeSelection() {
+ return new SelectionComponent(this);
+ }
+
+ @Override
+ public Dimension getMinimumSize() {
+ Dimension stereoDim = getStereotypeFig().getMinimumSize();
+ Dimension nameDim = getNameFig().getMinimumSize();
+
+ int h = Math.max(stereoDim.height + nameDim.height - OVERLAP,
+ 4 * FINGER_HEIGHT);
+ int w = Math.max(stereoDim.width, nameDim.width) + FINGER_WIDTH;
+
+ return new Dimension(w, h);
+ }
+
+ @Override
+ protected void setStandardBounds(int x, int y, int w,
+ int h) {
+ if (getNameFig() == null) {
+ return;
+ }
+
+ Rectangle oldBounds = getBounds();
+ getBigPort().setBounds(x + BX, y, w - BX, h);
+ cover.setBounds(x + BX, y, w - BX, h);
+
+ Dimension stereoDim = getStereotypeFig().getMinimumSize();
+ Dimension nameDim = getNameFig().getMinimumSize();
+
+ int halfHeight = FINGER_HEIGHT / 2;
+ upperRect.setBounds(x, y + h / 3 - halfHeight, FINGER_WIDTH,
+ FINGER_HEIGHT);
+ lowerRect.setBounds(x, y + 2 * h / 3 - halfHeight, FINGER_WIDTH,
+ FINGER_HEIGHT);
+
+ getStereotypeFig().setBounds(x + FINGER_WIDTH + 1,
+ y + 1,
+ w - FINGER_WIDTH - 2,
+ stereoDim.height);
+ getNameFig().setBounds(x + FINGER_WIDTH + 1,
+ y + stereoDim.height - OVERLAP + 1,
+ w - FINGER_WIDTH - 2,
+ nameDim.height);
+ _x = x;
+ _y = y;
+ _w = w;
+ _h = h;
+ firePropChange("bounds", oldBounds, getBounds());
+ updateEdges();
+ }
+
+ @Override
+ public void setEnclosingFig(Fig encloser) {
+
+ Object comp = getOwner();
+ if (encloser != null
+ && (Model.getFacade().isANode(encloser.getOwner())
+ || Model.getFacade().isAComponent(encloser.getOwner()))
+ && getOwner() != null) {
+ if (Model.getFacade().isANode(encloser.getOwner())) {
+ Object node = encloser.getOwner();
+ if (!Model.getFacade().getDeploymentLocations(comp).contains(
+ node)) {
+ Model.getCoreHelper().addDeploymentLocation(comp, node);
+ }
+ }
+ super.setEnclosingFig(encloser);
+
+ if (getLayer() != null) {
+ // elementOrdering(figures);
+ List contents = new ArrayList(getLayer().getContents());
+ Iterator it = contents.iterator();
+ while (it.hasNext()) {
+ Object o = it.next();
+ if (o instanceof FigEdgeModelElement) {
+ FigEdgeModelElement figedge = (FigEdgeModelElement) o;
+ figedge.getLayer().bringToFront(figedge);
+ }
+ }
+ }
+ } else if (encloser == null && getEnclosingFig() != null) {
+ Object encloserOwner = getEnclosingFig().getOwner();
+ if (Model.getFacade().isANode(encloserOwner)
+ && (Model.getFacade().getDeploymentLocations(comp)
+ .contains(encloserOwner))) {
+ Model.getCoreHelper().removeDeploymentLocation(comp,
+ encloserOwner);
+ }
+ super.setEnclosingFig(encloser);
+ }
+ }
+
+ /**
+ * TODO: This is not used anywhere. Can we remove it?
+ *
+ * @param figures ?
+ * @deprecated for 0.25.4 by tfmorris. Unused in ArgoUML. Not clear it was
+ * ever intended to be part of the public API.
+ */
+ @Deprecated
+ public void setNode(Vector figures) {
+ int size = figures.size();
+ if (figures != null && (size > 0)) {
+ for (int i = 0; i < size; i++) {
+ Object o = figures.elementAt(i);
+ if (o instanceof FigComponent) {
+ FigComponent figcomp = (FigComponent) o;
+ figcomp.setEnclosingFig(this);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean getUseTrapRect() {
+ return true;
+ }
+
+ @Override
+ protected void updateStereotypeText() {
+ getStereotypeFig().setOwner(getOwner());
+ }
+
+ @Override
+ protected void textEditStarted(FigText ft) {
+ if (ft == getNameFig()) {
+ showHelp("parsing.help.fig-component");
+ }
+ }
+
+ @Override
+ public Rectangle getHandleBox() {
+ Rectangle r = getBounds();
+ return new Rectangle(r.x + BX, r.y, r.width - BX, r.height);
+ }
+
+ @Override
+ public void setHandleBox(int x, int y, int w, int h) {
+ setBounds(x - BX, y, w + BX, h);
+ }
+
+}
\ No newline at end of file
Modified: trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponent.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponent.java?view=diff&rev=13779&p1=trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponent.java&p2=trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponent.java&r1=13778&r2=13779
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponent.java (original)
+++ trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponent.java 2007-11-16 13:40:41-0800
@@ -24,67 +24,22 @@
package org.argouml.uml.diagram.deployment.ui;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Rectangle;
import java.awt.event.MouseEvent;
-import java.beans.PropertyChangeEvent;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
import java.util.Vector;
-import org.argouml.model.AssociationChangeEvent;
-import org.argouml.model.AttributeChangeEvent;
-import org.argouml.model.Model;
-import org.argouml.uml.diagram.ui.FigEdgeModelElement;
-import org.argouml.uml.diagram.ui.FigNodeModelElement;
-import org.tigris.gef.base.Selection;
import org.tigris.gef.graph.GraphModel;
-import org.tigris.gef.presentation.Fig;
-import org.tigris.gef.presentation.FigRect;
-import org.tigris.gef.presentation.FigText;
/**
* Class to display graphics for a UML Component in a diagram.
*
* @author 5eichler
*/
-public class FigComponent extends FigNodeModelElement {
- /**
- * The distance between the left edge of the fig and the left edge of the
- * main rectangle.
- * Originally named BIGPORT_X (which explains what BX stands for).
- */
- private static final int BX = 10;
-
- private static final int OVERLAP = 0;
-
- private FigRect cover;
- private FigRect upperRect;
- private FigRect lowerRect;
-
+public class FigComponent extends AbstractFigComponent {
/**
* Constructor.
*/
public FigComponent() {
- cover = new FigRect(BX, 10, 120, 80, Color.black, Color.white);
- upperRect =
- new FigRect(0, 2 * BX, 2 * BX, BX, Color.black, Color.white);
- lowerRect =
- new FigRect(0, 4 * BX, 2 * BX, BX, Color.black, Color.white);
-
- getNameFig().setLineWidth(0);
- getNameFig().setFilled(false);
- getNameFig().setText(placeString());
-
- addFig(getBigPort());
- addFig(cover);
- addFig(getStereotypeFig());
- addFig(getNameFig());
- addFig(upperRect);
- addFig(lowerRect);
+ super();
}
/**
@@ -94,73 +49,11 @@
* @param node the UML element
*/
public FigComponent(GraphModel gm, Object node) {
- this();
- setOwner(node);
- if (Model.getFacade().isAClassifier(node)
- && (Model.getFacade().getName(node) != null)) {
- getNameFig().setText(Model.getFacade().getName(node));
- }
- updateBounds();
- }
-
-
- /*
- * @see java.lang.Object#clone()
- */
- @Override
- public Object clone() {
- FigComponent figClone = (FigComponent) super.clone();
- Iterator it = figClone.getFigs().iterator();
- figClone.setBigPort((FigRect) it.next());
- figClone.cover = (FigRect) it.next();
- it.next();
- figClone.setNameFig((FigText) it.next());
- figClone.upperRect = (FigRect) it.next();
- figClone.lowerRect = (FigRect) it.next();
-
- return figClone;
+ super(gm, node);
}
- /*
- * @see org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent)
- */
- @Override
- protected void modelChanged(PropertyChangeEvent mee) {
- super.modelChanged(mee);
- if (mee instanceof AssociationChangeEvent
- || mee instanceof AttributeChangeEvent) {
- renderingChanged();
- updateListeners(getOwner(), getOwner());
- damage();
- }
- }
/*
- * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object)
- */
- @Override
- protected void updateListeners(Object oldOwner, Object newOwner) {
- if (oldOwner != null) {
- removeAllElementListeners();
- }
- if (newOwner != null) {
- // add the listeners to the newOwner
- addElementListener(newOwner);
- Collection c = Model.getFacade().getStereotypes(newOwner);
- Iterator i = c.iterator();
- while (i.hasNext()) {
- Object st = i.next();
- addElementListener(st, "name");
- }
- }
- }
-
- /**
- * Build a collection of menu items relevant for a right-click popup menu.
- *
- * @param me a mouse event
- * @return a collection of menu items
- *
* @see org.tigris.gef.ui.PopupGenerator#getPopUpActions(java.awt.event.MouseEvent)
*/
@Override
@@ -173,199 +66,4 @@
return popUpActions;
}
- /**
- * @param b switch underline on or off
- */
- public void setUnderline(boolean b) {
- getNameFig().setUnderline(b);
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
- */
- @Override
- public void setLineColor(Color c) {
- cover.setLineColor(c);
- getStereotypeFig().setFilled(false);
- getStereotypeFig().setLineWidth(0);
- getNameFig().setFilled(false);
- getNameFig().setLineWidth(0);
- upperRect.setLineColor(c);
- lowerRect.setLineColor(c);
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#makeSelection()
- */
- @Override
- public Selection makeSelection() {
- return new SelectionComponent(this);
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#getMinimumSize()
- */
- @Override
- public Dimension getMinimumSize() {
- Dimension stereoDim = getStereotypeFig().getMinimumSize();
- Dimension nameDim = getNameFig().getMinimumSize();
-
- int h = Math.max(stereoDim.height + nameDim.height - OVERLAP, 4 * BX);
- int w = Math.max(stereoDim.width, nameDim.width) + 2 * BX;
-
- return new Dimension(w, h);
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#setBounds(int, int, int, int)
- */
- @Override
- protected void setStandardBounds(int x, int y, int w, int h) {
-
- Rectangle oldBounds = getBounds();
- getBigPort().setBounds(x + BX, y, w - BX, h);
- cover.setBounds(x + BX, y, w - BX, h);
-
- Dimension stereoDim = getStereotypeFig().getMinimumSize();
- Dimension nameDim = getNameFig().getMinimumSize();
- if (h < (6 * BX)) {
- upperRect.setBounds(x, y + 2 * h / 6, 20, 10);
- lowerRect.setBounds(x, y + 4 * h / 6, 20, 10);
- } else {
- upperRect.setBounds(x, y + 2 * BX, 2 * BX, BX);
- lowerRect.setBounds(x, y + 4 * BX, 2 * BX, BX);
- }
-
- getStereotypeFig().setBounds(x + 2 * BX + 1,
- y + 1,
- w - 2 * BX - 2,
- stereoDim.height);
- getNameFig().setBounds(x + 2 * BX + 1,
- y + stereoDim.height - OVERLAP + 1,
- w - 2 * BX - 2,
- nameDim.height);
- _x = x;
- _y = y;
- _w = w;
- _h = h;
- firePropChange("bounds", oldBounds, getBounds());
- updateEdges();
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig)
- */
- @Override
- public void setEnclosingFig(Fig encloser) {
-
- Object comp = getOwner();
- if (encloser != null
- && (Model.getFacade().isANode(encloser.getOwner())
- || Model.getFacade().isAComponent(encloser.getOwner()))
- && getOwner() != null) {
- if (Model.getFacade().isANode(encloser.getOwner())) {
- Object node = encloser.getOwner();
- if (!Model.getFacade()
- .getDeploymentLocations(comp).contains(node)) {
- Model.getCoreHelper().addDeploymentLocation(comp, node);
- }
- }
- super.setEnclosingFig(encloser);
-
- if (getLayer() != null) {
- // elementOrdering(figures);
- List contents = new ArrayList(getLayer().getContents());
- Iterator it = contents.iterator();
- while (it.hasNext()) {
- Object o = it.next();
- if (o instanceof FigEdgeModelElement) {
- FigEdgeModelElement figedge = (FigEdgeModelElement) o;
- figedge.getLayer().bringToFront(figedge);
- }
- }
- }
- } else if (encloser == null && getEnclosingFig() != null) {
- Object encloserOwner = getEnclosingFig().getOwner();
- if (Model.getFacade().isANode(encloserOwner)
- && (Model.getFacade().getDeploymentLocations(comp).
- contains(encloserOwner))) {
- Model.getCoreHelper()
- .removeDeploymentLocation(comp, encloserOwner);
- }
- super.setEnclosingFig(encloser);
- }
- }
-
- /**
- * TODO: This is not used anywhere. Can we remove it?
- * @param figures ?
- * @deprecated for 0.25.4 by tfmorris. Unused in ArgoUML. Not clear it was ever
- * intended to be part of the public API.
- */
- @Deprecated
- public void setNode(Vector figures) {
- int size = figures.size();
- if (figures != null && (size > 0)) {
- for (int i = 0; i < size; i++) {
- Object o = figures.elementAt(i);
- if (o instanceof FigComponent) {
- FigComponent figcomp = (FigComponent) o;
- figcomp.setEnclosingFig(this);
- }
- }
- }
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#getUseTrapRect()
- */
- @Override
- public boolean getUseTrapRect() {
- return true;
- }
-
- /*
- * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateStereotypeText()
- */
- @Override
- protected void updateStereotypeText() {
- getStereotypeFig().setOwner(getOwner());
- }
-
- /*
- * @see org.argouml.uml.diagram.ui.FigNodeModelElement#textEditStarted(org.tigris.gef.presentation.FigText)
- */
- @Override
- protected void textEditStarted(FigText ft) {
- if (ft == getNameFig()) {
- showHelp("parsing.help.fig-component");
- }
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#getHandleBox()
- *
- * Get the rectangle on whose corners the dragging handles are to
- * be drawn. Used by Selection Resize.
- */
- @Override
- public Rectangle getHandleBox() {
- Rectangle r = getBounds();
- return new Rectangle(r.x + BX, r.y, r.width - BX,
- r.height);
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#setHandleBox(int, int, int, int)
- */
- @Override
- public void setHandleBox(int x, int y, int w, int h) {
- setBounds(x - BX, y, w + BX, h);
- }
-
- /**
- * The UID.
- */
- static final long serialVersionUID = 1647392857462847651L;
-
}
Modified: trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponentInstance.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponentInstance.java?view=diff&rev=13779&p1=trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponentInstance.java&p2=trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponentInstance.java&r1=13778&r2=13779
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponentInstance.java (original)
+++ trunk/src_new/org/argouml/uml/diagram/deployment/ui/FigComponentInstance.java 2007-11-16 13:40:41-0800
@@ -25,29 +25,22 @@
package org.argouml.uml.diagram.deployment.ui;
import java.awt.Color;
-import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
-import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import org.argouml.model.AssociationChangeEvent;
-import org.argouml.model.AttributeChangeEvent;
import org.argouml.model.Model;
import org.argouml.notation.NotationProvider;
import org.argouml.notation.NotationProviderFactory2;
import org.argouml.uml.diagram.ui.FigEdgeModelElement;
-import org.argouml.uml.diagram.ui.FigNodeModelElement;
import org.tigris.gef.base.Editor;
import org.tigris.gef.base.Globals;
import org.tigris.gef.base.Selection;
import org.tigris.gef.graph.GraphModel;
import org.tigris.gef.presentation.Fig;
-import org.tigris.gef.presentation.FigRect;
import org.tigris.gef.presentation.FigText;
/**
@@ -55,43 +48,16 @@
*
* @author 5eichler
*/
-public class FigComponentInstance extends FigNodeModelElement {
-
- /**
- * The distance between the left edge of the fig and the left edge of the
- * main rectangle.
- * Originally named BIGPORT_X (which explains what BX stands for).
- */
- private static final int BX = 10;
-
- private static final int OVERLAP = 0;
-
- private FigRect cover;
- private FigRect upperRect;
- private FigRect lowerRect;
+public class FigComponentInstance extends AbstractFigComponent {
private NotationProvider notationProvider;
/**
- * Constructor.
+ * Construct a default ComponentInstance figure.
*/
public FigComponentInstance() {
- cover = new FigRect(BX, 10, 120, 80, Color.black, Color.white);
- upperRect =
- new FigRect(0, 2 * BX, 2 * BX, BX, Color.black, Color.white);
- lowerRect =
- new FigRect(0, 4 * BX, 2 * BX, BX, Color.black, Color.white);
-
- getNameFig().setLineWidth(0);
- getNameFig().setFilled(false);
+ super();
getNameFig().setUnderline(true);
-
- addFig(getBigPort());
- addFig(cover);
- addFig(getStereotypeFig());
- addFig(getNameFig());
- addFig(upperRect);
- addFig(lowerRect);
}
/**
@@ -101,13 +67,7 @@
* @param node the UML element
*/
public FigComponentInstance(GraphModel gm, Object node) {
- this();
- setOwner(node);
- if (Model.getFacade().isAClassifier(node)
- && (Model.getFacade().getName(node) != null)) {
- getNameFig().setText(Model.getFacade().getName(node));
- }
- updateBounds();
+ super(gm, node);
}
/*
@@ -123,78 +83,31 @@
}
}
-
/*
* @see java.lang.Object#clone()
*/
@Override
public Object clone() {
FigComponentInstance figClone = (FigComponentInstance) super.clone();
- Iterator it = figClone.getFigs().iterator();
- figClone.setBigPort((FigRect) it.next());
- figClone.cover = (FigRect) it.next();
- it.next();
- figClone.setNameFig((FigText) it.next());
- figClone.upperRect = (FigRect) it.next();
- figClone.lowerRect = (FigRect) it.next();
-
+ // nothing extra to do currently
return figClone;
}
/*
- * @see org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent)
- */
- @Override
- protected void modelChanged(PropertyChangeEvent mee) {
- super.modelChanged(mee);
- if (mee instanceof AssociationChangeEvent
- || mee instanceof AttributeChangeEvent) {
- renderingChanged();
- updateListeners(getOwner(), getOwner());
- damage();
- }
- }
-
- /*
* @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object, java.lang.Object)
*/
@Override
protected void updateListeners(Object oldOwner, Object newOwner) {
- if (oldOwner != null) {
- removeAllElementListeners();
- }
+ super.updateListeners(oldOwner, newOwner);
if (newOwner != null) {
- // add the listeners to the newOwner
- addElementListener(newOwner);
- Collection c = Model.getFacade().getStereotypes(newOwner);
- Iterator i = c.iterator();
- while (i.hasNext()) {
- Object st = i.next();
- addElementListener(st, "name");
- }
- c = Model.getFacade().getClassifiers(newOwner);
- i = c.iterator();
- while (i.hasNext()) {
- Object st = i.next();
- addElementListener(st, "name");
+ for (Object classifier
+ : Model.getFacade().getClassifiers(newOwner)) {
+ addElementListener(classifier, "name");
}
}
}
- /*
- * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
- */
- @Override
- public void setLineColor(Color c) {
- cover.setLineColor(c);
- getStereotypeFig().setFilled(false);
- getStereotypeFig().setLineWidth(0);
- getNameFig().setFilled(false);
- getNameFig().setLineWidth(0);
- upperRect.setLineColor(c);
- lowerRect.setLineColor(c);
- }
-
+
/*
* @see org.tigris.gef.presentation.Fig#makeSelection()
*/
@@ -204,64 +117,12 @@
}
/*
- * @see org.tigris.gef.presentation.Fig#getMinimumSize()
- */
- @Override
- public Dimension getMinimumSize() {
- Dimension stereoDim = getStereotypeFig().getMinimumSize();
- Dimension nameDim = getNameFig().getMinimumSize();
-
- int h = Math.max(stereoDim.height + nameDim.height - OVERLAP, 4 * BX);
- int w = Math.max(stereoDim.width, nameDim.width) + 2 * BX;
-
- return new Dimension(w, h);
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#setBounds(int, int, int, int)
- */
- @Override
- protected void setStandardBounds(int x, int y, int w, int h) {
- if (getNameFig() == null) {
- return;
- }
-
- Rectangle oldBounds = getBounds();
- getBigPort().setBounds(x + BX, y, w - BX, h);
- cover.setBounds(x + BX, y, w - BX, h);
-
- Dimension stereoDim = getStereotypeFig().getMinimumSize();
- Dimension nameDim = getNameFig().getMinimumSize();
- if (h < (6 * BX)) {
- upperRect.setBounds(x, y + 2 * h / 6, 20, 10);
- lowerRect.setBounds(x, y + 4 * h / 6, 20, 10);
- } else {
- upperRect.setBounds(x, y + 2 * BX, 2 * BX, BX);
- lowerRect.setBounds(x, y + 4 * BX, 2 * BX, BX);
- }
-
- getStereotypeFig().setBounds(x + 2 * BX + 1,
- y + 1,
- w - 2 * BX - 2,
- stereoDim.height);
- getNameFig().setBounds(x + 2 * BX + 1,
- y + stereoDim.height - OVERLAP + 1,
- w - 2 * BX - 2,
- nameDim.height);
- _x = x;
- _y = y;
- _w = w;
- _h = h;
- firePropChange("bounds", oldBounds, getBounds());
- updateEdges();
- }
-
- /*
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
@Override
public void mouseClicked(MouseEvent me) {
super.mouseClicked(me);
+ // TODO: What is this needed for? - tfm
setLineColor(Color.black);
}
@@ -337,13 +198,6 @@
}
}
- /*
- * @see org.tigris.gef.presentation.Fig#getUseTrapRect()
- */
- @Override
- public boolean getUseTrapRect() {
- return true;
- }
/*
* @see org.argouml.uml.diagram.ui.FigNodeModelElement#textEdited(org.tigris.gef.presentation.FigText)
@@ -373,7 +227,7 @@
protected void updateStereotypeText() {
getStereotypeFig().setOwner(getOwner());
}
-
+
/*
* @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateNameText()
*/
@@ -386,27 +240,4 @@
setBounds(r.x, r.y, r.width, r.height);
}
- /*
- * @see org.tigris.gef.presentation.Fig#getHandleBox()
- */
- @Override
- public Rectangle getHandleBox() {
- Rectangle r = getBounds();
- return new Rectangle(r.x + BX, r.y, r.width - BX,
- r.height);
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#setHandleBox(int, int, int, int)
- */
- @Override
- public void setHandleBox(int x, int y, int w, int h) {
- setBounds(x - BX, y, w + BX, h);
- }
-
- /**
- * The UID.
- */
- static final long serialVersionUID = 1647392857462847651L;
-
}
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.