svn commit: r17317 - trunk/src/argouml-app/src/org/argouml/uml/diagram: static_structure/ui ui
Michiel van der Wulp <[email protected]>
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mvw
Date: 2009-09-14 23:24:03-0700
New Revision: 17317
Modified:
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigDataType.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigInterface.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEmptyRect.java
Log:
Fix for issue 5421: Printing causes a line to be printed between stereotype and class name.
This problem was also visible when scaling.
Solved by making the stereotype fig be drawn inside the top margin of the nameFig.
Also fixed: These figs now get drawn with the correct size when the mouse goes down, but is not yet released.
Also, D&D of a fig onto the diagram now drops the fig at the release location, not at (10,10).
Also: correct calculation of line-width for the compartment box - not yet for the compartment figs themselves.
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClass.java 2009-09-14 23:24:03-0700
@@ -39,20 +39,11 @@
/**
* Class to display graphics for a UML Class in a diagram.<p>
*
- * A Class may show compartments for stereotypes,
+ * A Class may show stereotypes, a name and compartments for
* attributes and operations.
*/
public class FigClass extends FigClassifierBoxWithAttributes {
- private void constructFigs() {
- addFig(getBigPort());
- addFig(getStereotypeFig());
- addFig(getNameFig());
- addFig(getOperationsFig());
- addFig(getAttributesFig());
- addFig(borderFig);
- }
-
/**
* Constructor for a {@link FigClass} during file load.<p>
*
@@ -64,14 +55,7 @@
*
* The properties of all these graphic elements are adjusted
* appropriately. The main boxes are all filled and have
- * outlines.<p>
- *
- * <em>Warning</em>. Much of the graphics positioning is hard
- * coded. The overall figure is placed at location (10,10).
- * The stereotype compartment is created 15 pixels
- * high in the parent, but we change it to 19 pixels, 1 more than
- * ({@link #STEREOHEIGHT} here. The attribute and operations boxes
- * are created at 19 pixels, 2 more than {@link #ROWHEIGHT}.<p>
+ * outlines. TODO: which is wrong, since the bigPort is filled, too.
*
* @param element model element to be represented by this fig.
* @param bounds rectangle describing bounds
@@ -80,9 +64,30 @@
public FigClass(Object element, Rectangle bounds,
DiagramSettings settings) {
super(element, bounds, settings);
- constructFigs();
- Rectangle r = getBounds();
- setStandardBounds(r.x, r.y, r.width, r.height);
+ constructFigs(bounds);
+ }
+
+ private void constructFigs(Rectangle bounds) {
+ enableSizeChecking(false);
+ setSuppressCalcBounds(true);
+
+ addFig(getBigPort());
+ addFig(getNameFig());
+ /* Stereotype covers NameFig: */
+ addFig(getStereotypeFig());
+ addFig(getOperationsFig());
+ addFig(getAttributesCompartment());
+ addFig(getBorderFig());
+
+
+ /* Set the drop location in the case of D&D: */
+ if (bounds != null) {
+ setLocation(bounds.x, bounds.y);
+ }
+
+ setSuppressCalcBounds(false);
+ setBounds(getBounds());
+ enableSizeChecking(true);
}
/*
@@ -96,8 +101,9 @@
while (thisIter.hasNext()) {
Fig thisFig = (Fig) thisIter.next();
Fig cloneFig = (Fig) cloneIter.next();
- if (thisFig == borderFig) {
- figClone.borderFig = thisFig;
+ if (thisFig == getBorderFig()) {
+ /* TODO: complete this */
+// figClone.setBorderFig(thisFig);
}
}
return figClone;
@@ -118,7 +124,7 @@
* @see org.tigris.gef.presentation.Fig#getLineWidth()
*/
public int getLineWidth() {
- return borderFig.getLineWidth();
+ return getBorderFig().getLineWidth();
}
/**
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBox.java 2009-09-14 23:24:03-0700
@@ -44,7 +44,6 @@
import org.argouml.uml.diagram.ui.ActionCompartmentDisplay;
import org.argouml.uml.diagram.ui.ActionEdgesDisplay;
import org.argouml.uml.diagram.ui.FigCompartmentBox;
-import org.argouml.uml.diagram.ui.FigEmptyRect;
import org.argouml.uml.diagram.ui.FigOperationsCompartment;
import org.argouml.uml.ui.foundation.core.ActionAddOperation;
import org.tigris.gef.base.Editor;
@@ -55,10 +54,7 @@
/**
* Class to display graphics for any UML Classifier in a diagram.<p>
*
- * This Fig has an Operations compartment. <p>
- *
- * Note that the upper line of the name box will be blanked out
- * if there is eventually a stereotype above.
+ * This abstract Fig adds an Operations compartment.
*/
public abstract class FigClassifierBox extends FigCompartmentBox
implements OperationsCompartmentContainer {
@@ -66,30 +62,12 @@
/**
* The Fig for the operations compartment (if any).
*/
- private FigOperationsCompartment operationsFig;
-
- // TODO: This is already defined in the superclass, can we use that?
- protected Fig borderFig;
+ private FigOperationsCompartment operationsFigCompartment;
/**
* Initialization shared by all constructors.
*/
private void constructFigs() {
- // Set properties of the stereotype box. Make it 1 pixel higher than
- // before, so it overlaps the name box, and the blanking takes out both
- // lines. Initially not set to be displayed, but this will be changed
- // when we try to render it, if we find we have a stereotype.
- getStereotypeFig().setFilled(true);
- getStereotypeFig().setLineWidth(LINE_WIDTH);
- // +1 to have 1 pixel overlap with getNameFig()
- getStereotypeFig().setHeight(STEREOHEIGHT + 1);
-
- borderFig = new FigEmptyRect(X0, Y0, 0, 0);
- borderFig.setLineWidth(LINE_WIDTH);
- borderFig.setLineColor(LINE_COLOR);
-
- getBigPort().setLineWidth(0);
- getBigPort().setFillColor(FILL_COLOR);
}
private Rectangle getDefaultBounds() {
@@ -111,7 +89,9 @@
public FigClassifierBox(Object owner, Rectangle bounds,
DiagramSettings settings) {
super(owner, bounds, settings);
- operationsFig = new FigOperationsCompartment(owner, getDefaultBounds(),
+ operationsFigCompartment = new FigOperationsCompartment(
+ owner,
+ getDefaultBounds(),
getSettings());
constructFigs();
}
@@ -124,8 +104,8 @@
Iterator thisIter = this.getFigs().iterator();
while (thisIter.hasNext()) {
Fig thisFig = (Fig) thisIter.next();
- if (thisFig == operationsFig) {
- figClone.operationsFig = (FigOperationsCompartment) thisFig;
+ if (thisFig == operationsFigCompartment) {
+ figClone.operationsFigCompartment = (FigOperationsCompartment) thisFig;
return figClone;
}
}
@@ -142,13 +122,13 @@
* have FigOperationsCompartment itself listen for add and remove events
* and make minimum change rather than entirely rebuild.
* Remark MVW: This is a bit exaggerated, since the populate()
- * method is already heavily optimised.
+ * method is already heavily optimized.
*/
protected void updateOperations() {
if (!isOperationsVisible()) {
return;
}
- operationsFig.populate();
+ operationsFigCompartment.populate();
setBounds(getBounds());
damage();
@@ -209,7 +189,7 @@
* @return The Fig for the operations compartment
*/
protected FigOperationsCompartment getOperationsFig() {
- return operationsFig;
+ return operationsFigCompartment;
}
/**
@@ -218,7 +198,7 @@
* @return the bounds of the operations compartment
*/
public Rectangle getOperationsBounds() {
- return operationsFig.getBounds();
+ return operationsFigCompartment.getBounds();
}
@@ -226,14 +206,14 @@
* @see org.argouml.uml.diagram.ui.OperationsCompartmentContainer#isOperationsVisible()
*/
public boolean isOperationsVisible() {
- return operationsFig != null && operationsFig.isVisible();
+ return operationsFigCompartment != null && operationsFigCompartment.isVisible();
}
/*
* @see org.argouml.uml.diagram.ui.OperationsCompartmentContainer#setOperationsVisible(boolean)
*/
public void setOperationsVisible(boolean isVisible) {
- setCompartmentVisible(operationsFig, isVisible);
+ setCompartmentVisible(operationsFigCompartment, isVisible);
}
/*
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java 2009-09-14 23:24:03-0700
@@ -67,20 +67,19 @@
public FigClassifierBoxWithAttributes(Object owner, Rectangle bounds,
DiagramSettings settings) {
super(owner, bounds, settings);
- attributesFigCompartment = new FigAttributesCompartment(owner,
- DEFAULT_COMPARTMENT_BOUNDS, settings);
+ getAttributesCompartment(); // this creates the compartment fig
}
/**
- * @return The vector of graphics for the uml attributes (if any).
- * First one is the rectangle for the entire operations box.
+ * @return The graphics for the UML attributes (if any).
+ * @deprecated use getAttributesCompartment
*/
protected FigAttributesCompartment getAttributesFig() {
- return attributesFigCompartment;
+ return getAttributesCompartment();
}
public Rectangle getAttributesBounds() {
- return attributesFigCompartment.getBounds();
+ return getAttributesCompartment().getBounds();
}
public boolean isAttributesVisible() {
@@ -231,17 +230,21 @@
public Dimension getMinimumSize() {
// Use "aSize" to build up the minimum size. Start with the size of the
// name compartment and build up.
-
Dimension aSize = getNameFig().getMinimumSize();
- aSize.height += NAME_V_PADDING * 2;
- aSize.height = Math.max(NAME_FIG_HEIGHT, aSize.height);
- aSize = addChildDimensions(aSize, getStereotypeFig());
- aSize = addChildDimensions(aSize, getAttributesFig());
+ /* Only take into account the stereotype width, not the height,
+ * since the height is included in the name fig: */
+ aSize = addChildWidth(aSize, getStereotypeFig());
+ aSize = addChildDimensions(aSize, getAttributesCompartment());
aSize = addChildDimensions(aSize, getOperationsFig());
+ /* We want to maintain a minimum width for the
+ * fig. Also, add the border dimensions
+ * to the minimum space required for its contents: */
aSize.width = Math.max(WIDTH, aSize.width);
-
+ aSize.width += 2 * getLineWidth();
+ aSize.height += 2 * getLineWidth();
+
return aSize;
}
@@ -250,84 +253,112 @@
* {@link #getMinimumSize()}, unless checking of size is disabled.<p>
*
* If the required height is bigger, then the additional height is
- * equally distributed among all figs (i.e. compartments), such that the
- * cumulated height of all visible figs equals the demanded height<p>.
- *
- * Some of this has "magic numbers" hardcoded in.<p>
+ * equally distributed among all compartments, such that the
+ * accumulated height of all visible figs equals the demanded height.
*
* @param x Desired X coordinate of upper left corner
*
* @param y Desired Y coordinate of upper left corner
*
- * @param width Desired width of the FigClass
+ * @param width Desired width of the Fig
*
- * @param height Desired height of the FigClass
+ * @param height Desired height of the Fig
*
* @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
*/
@Override
- protected void setStandardBounds(final int x, final int y, final int width,
- final int height) {
+ protected void setStandardBounds(final int x, final int y, final int w,
+ final int h) {
// Save our old boundaries so it can be used in property message later
Rectangle oldBounds = getBounds();
// Make sure we don't try to set things smaller than the minimum
- int w = Math.max(width, getMinimumSize().width);
- int h = Math.max(height, getMinimumSize().height);
-
- // set bounds of big box
- getBigPort().setBounds(x, y, w, h);
- if (borderFig != null) {
- borderFig.setBounds(x, y, w, h);
- }
-
- // Extra space to be distributed among compartments is the difference
- // between the actual size and the min. size
- final int whitespace = h - getMinimumSize().height;
+ Dimension minimumSize = getMinimumSize();
+ int newW = Math.max(w, minimumSize.width);
+ int newH = Math.max(h, minimumSize.height);
int currentHeight = 0;
if (getStereotypeFig().isVisible()) {
int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
+ getNameFig().setTopMargin(stereotypeHeight);
getStereotypeFig().setBounds(
- x,
- y,
- w,
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
stereotypeHeight);
- currentHeight += stereotypeHeight;
+ } else {
+ getNameFig().setTopMargin(0);
}
- int nameHeight = getNameFig().getMinimumSize().height;
- getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
- currentHeight += nameHeight;
-
- if (isAttributesVisible()) {
- int attributesHeight =
- attributesFigCompartment.getMinimumSize().height;
- if (isOperationsVisible()) {
- attributesHeight += whitespace / 2;
+ /* Now the new nameFig height will include the stereotype height: */
+ Dimension nameMin = getNameFig().getMinimumSize();
+ int minNameHeight = Math.max(nameMin.height, NAME_FIG_HEIGHT);
+
+ getNameFig().setBounds(
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
+ minNameHeight);
+
+ /* The new height can not be less than the name height: */
+ /* TODO: Is this needed/correct?
+ * For when all compartments are hidden? */
+ newH = Math.max(minNameHeight + 2 * getLineWidth(), newH);
+
+ currentHeight += minNameHeight;
+
+ int attributesHeight = 0;
+ int operationsHeight = 0;
+ int visibleCompartments = 0;
+
+ if (getAttributesCompartment().isVisible()) {
+ visibleCompartments++;
+ attributesHeight =
+ getAttributesCompartment().getMinimumSize().height;
+ }
+ if (getOperationsFig().isVisible()) {
+ visibleCompartments++;
+ operationsHeight = getOperationsFig().getMinimumSize().height;
+ }
+
+ int requestedHeight = newH - currentHeight - 2 * getLineWidth();
+ int neededHeight = attributesHeight + operationsHeight;
+
+ if (requestedHeight > neededHeight) {
+ /* Distribute the extra height over the visible compartments: */
+ if (getAttributesCompartment().isVisible()) {
+ attributesHeight += (requestedHeight - neededHeight) / visibleCompartments;
+ }
+ if (getOperationsFig().isVisible()) {
+ operationsHeight += (requestedHeight - neededHeight) / visibleCompartments;
}
- attributesFigCompartment.setBounds(
- x,
- y + currentHeight,
- w,
+ } else if (requestedHeight < neededHeight) {
+ /* Increase the height of the fig: */
+ newH += neededHeight - requestedHeight;
+ }
+
+ if (getAttributesCompartment().isVisible()) {
+ getAttributesCompartment().setBounds(
+ x + getLineWidth(),
+ y + currentHeight + getLineWidth(),
+ newW - 2 * getLineWidth(),
attributesHeight);
currentHeight += attributesHeight;
}
-
- if (isOperationsVisible()) {
- int operationsY = y + currentHeight;
- int operationsHeight = (h + y) - operationsY - LINE_WIDTH;
- if (operationsHeight < getOperationsFig().getMinimumSize().height) {
- operationsHeight = getOperationsFig().getMinimumSize().height;
- }
+
+ if (getOperationsFig().isVisible()) {
getOperationsFig().setBounds(
- x,
- operationsY,
- w,
+ x + getLineWidth(),
+ y + currentHeight + getLineWidth(),
+ newW - 2 * getLineWidth(),
operationsHeight);
}
+
+ // set bounds of big box
+ getBigPort().setBounds(x, y, newW, newH);
+ getBorderFig().setBounds(x, y, newW, newH);
// Now force calculation of the bounds of the figure, update the edges
// and trigger anyone who's listening to see if the "bounds" property
@@ -340,5 +371,19 @@
firePropChange("bounds", oldBounds, getBounds());
}
-
+ /**
+ * @return the Fig for the EnumerationLiterals compartment
+ */
+ public FigAttributesCompartment getAttributesCompartment() {
+ // Set bounds will be called from our superclass constructor before
+ // our constructor has run, so make sure this gets set up if needed.
+ if (attributesFigCompartment == null) {
+ attributesFigCompartment = new FigAttributesCompartment(
+ getOwner(),
+ DEFAULT_COMPARTMENT_BOUNDS,
+ getSettings());
+ }
+ return attributesFigCompartment;
+ }
+
}
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigDataType.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigDataType.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigDataType.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigDataType.java 2009-09-14 23:24:03-0700
@@ -32,43 +32,55 @@
import org.argouml.ui.targetmanager.TargetManager;
import org.argouml.uml.diagram.ArgoDiagram;
import org.argouml.uml.diagram.DiagramSettings;
-import org.tigris.gef.base.Editor;
-import org.tigris.gef.base.Globals;
import org.tigris.gef.base.Selection;
import org.tigris.gef.presentation.Fig;
/**
* Class to display graphics for a UML DataType in a diagram.
- * (cloned from FigInterface - perhaps they should both specialize
- * a common supertype).
+ * (much of this code is cloned from FigInterface - perhaps we need
+ * a more generic class provide this common code).
* <p>
- * A DataType may show compartments for stereotypes
- * and operations. Attributes are not supported in ArgoUML. <p>
+ * A DataType shows a keyword, a name, stereotypes and
+ * an operations compartment. Attributes are not supported
+ * in ArgoUML. <p>
*
* Every DataType shows a keyword, but it is not
- * always <<datatype>>, e.g. for an Enumeration.
+ * always <<datatype>>, e.g. for an Enumeration. <p>
+ *
+ * There is no need for a specific minimal width for this Fig,
+ * since its width will most of the time be determined by the keyword.
*/
public class FigDataType extends FigClassifierBox {
private static final Logger LOG = Logger.getLogger(FigDataType.class);
-
- private static final int MIN_WIDTH = 40;
- private void constructFigs() {
+ private void constructFigs(Rectangle bounds) {
+ enableSizeChecking(false);
+ setSuppressCalcBounds(true);
+
getStereotypeFig().setKeyword(getKeyword());
+ getStereotypeFig().setVisible(true);
+ /* The next line is needed so that we have the right dimension
+ * when drawing this Fig on the diagram by pressing down
+ * the mouse button, even before releasing the mouse button: */
+ getNameFig().setTopMargin(
+ getStereotypeFig().getMinimumSize().height);
- setSuppressCalcBounds(true);
addFig(getBigPort());
- addFig(getStereotypeFig());
addFig(getNameFig());
+ addFig(getStereotypeFig());
addFig(getOperationsFig());
- addFig(borderFig);
+ addFig(getBorderFig());
+
+ /* Set the drop location in the case of D&D: */
+ if (bounds != null) {
+ setLocation(bounds.x, bounds.y);
+ }
setSuppressCalcBounds(false);
- // Set the bounds of the figure to the total of the above
+ setBounds(getBounds());
enableSizeChecking(true);
- super.setStandardBounds(X0, Y0, WIDTH, NAME_FIG_HEIGHT + ROWHEIGHT);
}
/**
@@ -77,18 +89,11 @@
* Parent {@link org.argouml.uml.diagram.ui.FigNodeModelElement}
* will have created the main box {@link #getBigPort()} and
* its name {@link #getNameFig()} and stereotype
- * (@link #getStereotypeFig()}. This constructor
- * creates a box for the operations.<p>
+ * (@link #getStereotypeFig()}. The FigClassifierBox
+ * created a box for the operations.<p>
*
* The properties of all these graphic elements are adjusted
- * appropriately. The main boxes are all filled and have outlines.<p>
- *
- * <em>Warning</em>. Much of the graphics positioning is hard coded. The
- * overall figure is placed at location (10,10).
- * The stereotype compartment is created 15 pixels high
- * in the parent, but we change it to 19 pixels, 1 more than
- * ({@link #STEREOHEIGHT} here. The operations box is created at 19 pixels,
- * 2 more than {@link #ROWHEIGHT}.
+ * appropriately.
*
* @param owner owning UML element
* @param bounds position and size
@@ -97,7 +102,7 @@
public FigDataType(Object owner, Rectangle bounds,
DiagramSettings settings) {
super(owner, bounds, settings);
- constructFigs();
+ constructFigs(bounds);
}
/**
@@ -121,9 +126,7 @@
}
/**
- * Gets the minimum size permitted for a datatype on the diagram.<p>
- *
- * Parts of this are hardcoded with magic numbers.<p>
+ * Gets the minimum size permitted for a datatype on the diagram.
*
* @return the size of the minimum bounding box.
*/
@@ -134,31 +137,22 @@
Dimension aSize = getNameFig().getMinimumSize();
- aSize.height += NAME_V_PADDING * 2;
- aSize.height = Math.max(NAME_FIG_HEIGHT, aSize.height);
-
- // If we have a stereotype displayed, then allow some space for that
- // (width and height)
- aSize = addChildDimensions(aSize, getStereotypeFig());
+ /* Only take into account the stereotype width, not the height,
+ * since the height is included in the name fig: */
+ addChildWidth(aSize, getStereotypeFig());
+
aSize = addChildDimensions(aSize, getOperationsFig());
- // we want to maintain a minimum width for datatypes
- aSize.width = Math.max(MIN_WIDTH, aSize.width);
+ /* We want to maintain a minimum width for the
+ * interface fig. Also, add the border dimensions
+ * to the minimum space required for its contents: */
+ aSize.width = Math.max(WIDTH, aSize.width);
+ aSize.width += 2 * getLineWidth();
+ aSize.height += 2 * getLineWidth();
return aSize;
}
- /*
- * @see org.tigris.gef.presentation.Fig#getLineWidth()
- */
- @Override
- public int getLineWidth() {
- return borderFig.getLineWidth();
- }
-
- /*
- * @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig)
- */
@Override
public void setEnclosingFig(Fig encloser) {
Fig oldEncloser = getEnclosingFig();
@@ -205,18 +199,6 @@
}
/**
- * USED BY PGML.tee.
- * @return the class name and bounds together with compartment
- * visibility.
- */
- @Override
- public String classNameAndBounds() {
- return super.classNameAndBounds()
- + "operationsVisible=" + isOperationsVisible();
- }
-
-
- /**
* Sets the bounds, but the size will be at least the one returned by
* {@link #getMinimumSize()}, unless checking of size is disabled.<p>
*
@@ -236,40 +218,66 @@
@Override
protected void setStandardBounds(final int x, final int y, final int w,
final int h) {
-
- // Save our old boundaries to use in our property message later
+ /* Save our old boundaries (needed later), and get minimum size
+ * info.*/
Rectangle oldBounds = getBounds();
- // and get minimum size info.
-
- // set bounds of big box
- getBigPort().setBounds(x, y, w, h);
- borderFig.setBounds(x, y, w, h);
+ /* The new size can not be smaller than the minimum. */
+ Dimension minimumSize = getMinimumSize();
+ int newW = Math.max(w, minimumSize.width);
+ int newH = Math.max(h, minimumSize.height);
+
int currentHeight = 0;
if (getStereotypeFig().isVisible()) {
int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
+ getNameFig().setTopMargin(stereotypeHeight);
getStereotypeFig().setBounds(
- x,
- y,
- w,
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
stereotypeHeight);
- currentHeight = stereotypeHeight;
+ } else {
+ getNameFig().setTopMargin(0);
}
+
+ /* Now the new nameFig height will include the stereotype height: */
+ Dimension nameMin = getNameFig().getMinimumSize();
+ int minNameHeight = Math.max(nameMin.height, NAME_FIG_HEIGHT);
+
+ getNameFig().setBounds(
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
+ minNameHeight);
+
+ /* The new height can not be less than the name height: */
+ /* TODO: Is this needed/correct? */
+ newH = Math.max(minNameHeight, newH);
+
+ currentHeight += minNameHeight;
- int nameHeight = getNameFig().getMinimumSize().height;
- getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
- currentHeight += nameHeight;
-
+ /* And the operations compartment takes the remainder
+ * of the requested height: */
if (getOperationsFig().isVisible()) {
- int operationsY = y + currentHeight;
- int operationsHeight = (h + y) - operationsY - LINE_WIDTH;
+ int operationsHeight = newH - currentHeight - 2 * getLineWidth();
+ /* If the requested height is smaller than the minimum required, ... */
+ if ( operationsHeight < getOperationsFig().getMinimumSize().height) {
+ /* ... then we use the minimum ... */
+ operationsHeight = getOperationsFig().getMinimumSize().height;
+ /* ... and make the Fig bigger: */
+ newH += getOperationsFig().getMinimumSize().height - operationsHeight;
+ }
getOperationsFig().setBounds(
- x,
- operationsY,
- w,
+ x + getLineWidth(),
+ y + currentHeight + getLineWidth(),
+ newW - 2 * getLineWidth(),
operationsHeight);
}
+
+ // set bounds of big box
+ getBigPort().setBounds(x, y, newW, newH);
+ getBorderFig().setBounds(x, y, newW, newH);
// Now force calculation of the bounds of the figure, update the edges
// and trigger anyone who's listening to see if the "bounds" property
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java 2009-09-14 23:24:03-0700
@@ -46,22 +46,19 @@
* Class to display graphics for a UML Enumeration in a diagram.
* It depends on FigDataType for most of its behavior.<p>
*
+ * The Fig for an Enumeration has a compartment for Literals
+ * above the Operations compartment.
*/
public class FigEnumeration extends FigDataType
implements EnumLiteralsCompartmentContainer {
/**
- * Serial version (generated)
- */
- private static final long serialVersionUID = 3333154292883077250L;
-
- /**
* The Fig that represents the literals compartment.
*/
private FigEnumLiteralsCompartment literalsCompartment;
/**
- * Construct a new AbstractFigComponent.
+ * Constructor.
*
* @param owner owning UML element
* @param bounds position and size
@@ -184,80 +181,122 @@
setBounds(getBounds());
}
- /*
- * @see org.argouml.uml.diagram.static_structure.ui.FigDataType#getMinimumSize()
- */
@Override
public Dimension getMinimumSize() {
- // Start with the minimum for our parent
- Dimension aSize = super.getMinimumSize();
+ // Use "aSize" to build up the minimum size. Start with the size of the
+ // name compartment and build up.
- if (literalsCompartment != null) {
- aSize = addChildDimensions(aSize, literalsCompartment);
- }
+ Dimension aSize = getNameFig().getMinimumSize();
+
+ /* Only take into account the stereotype width, not the height,
+ * since the height is included in the name fig: */
+ addChildWidth(aSize, getStereotypeFig());
+ aSize = addChildDimensions(aSize, literalsCompartment);
+ aSize = addChildDimensions(aSize, getOperationsFig());
+
+ /* We want to maintain a minimum width for the
+ * interface fig. Also, add the border dimensions
+ * to the minimum space required for its contents: */
+ aSize.width = Math.max(WIDTH, aSize.width);
+ aSize.width += 2 * getLineWidth();
+ aSize.height += 2 * getLineWidth();
return aSize;
}
- /*
- * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
- */
@Override
- protected void setStandardBounds(final int x, final int y, final int width,
- final int height) {
-
+ protected void setStandardBounds(final int x, final int y, final int w,
+ final int h) {
// Save our old boundaries so it can be used in property message later
Rectangle oldBounds = getBounds();
-
- int w = Math.max(width, getMinimumSize().width);
- int h = Math.max(height, getMinimumSize().height);
- // set bounds of big box
- getBigPort().setBounds(x, y, w, h);
- borderFig.setBounds(x, y, w, h);
+ /* The new size can not be smaller than the minimum. */
+ Dimension minimumSize = getMinimumSize();
+ int newW = Math.max(w, minimumSize.width);
+ int newH = Math.max(h, minimumSize.height);
int currentHeight = 0;
if (getStereotypeFig().isVisible()) {
int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
+ getNameFig().setTopMargin(stereotypeHeight);
getStereotypeFig().setBounds(
- x,
- y,
- w,
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
stereotypeHeight);
- currentHeight += stereotypeHeight;
+ } else {
+ getNameFig().setTopMargin(0);
}
+
+ /* Now the new nameFig height will include the stereotype height: */
+ Dimension nameMin = getNameFig().getMinimumSize();
+ int minNameHeight = Math.max(nameMin.height, NAME_FIG_HEIGHT);
+
+ getNameFig().setBounds(
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
+ minNameHeight);
+
+ /* The new height can not be less than the name height: */
+ /* TODO: Is this needed/correct?
+ * For when all compartments are hidden? */
+ newH = Math.max(minNameHeight + 2 * getLineWidth(), newH);
+
+ currentHeight += minNameHeight;
- int nameHeight = getNameFig().getMinimumSize().height;
- getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
- currentHeight += nameHeight;
+ int literalsHeight = 0;
+ int operationsHeight = 0;
+ int visibleCompartments = 0;
- int visibleCompartments = getOperationsFig().isVisible() ? 1 : 0;
if (getLiteralsCompartment().isVisible()) {
visibleCompartments++;
- int literalsHeight =
+ literalsHeight =
getLiteralsCompartment().getMinimumSize().height;
- literalsHeight = Math.max(literalsHeight,
- (h - currentHeight) / visibleCompartments);
+ }
+ if (getOperationsFig().isVisible()) {
+ visibleCompartments++;
+ operationsHeight = getOperationsFig().getMinimumSize().height;
+ }
+
+ int requestedHeight = newH - currentHeight - 2 * getLineWidth();
+ int neededHeight = literalsHeight + operationsHeight;
+
+ if (requestedHeight > neededHeight) {
+ /* Distribute the extra height over the visible compartments: */
+ if (getLiteralsCompartment().isVisible()) {
+ literalsHeight += (requestedHeight - neededHeight) / visibleCompartments;
+ }
+ if (getOperationsFig().isVisible()) {
+ operationsHeight += (requestedHeight - neededHeight) / visibleCompartments;
+ }
+ } else if (requestedHeight < neededHeight) {
+ /* Increase the height of the fig: */
+ newH += neededHeight - requestedHeight;
+ }
+
+ if (getLiteralsCompartment().isVisible()) {
getLiteralsCompartment().setBounds(
- x + LINE_WIDTH,
- y + currentHeight,
- w - LINE_WIDTH,
+ x + getLineWidth(),
+ y + currentHeight + getLineWidth(),
+ newW - 2 * getLineWidth(),
literalsHeight);
currentHeight += literalsHeight;
}
if (getOperationsFig().isVisible()) {
- int operationsHeight = getOperationsFig().getMinimumSize().height;
- operationsHeight = Math.max(operationsHeight, h - currentHeight);
getOperationsFig().setBounds(
- x,
- y + currentHeight,
- w,
+ x + getLineWidth(),
+ y + currentHeight + getLineWidth(),
+ newW - 2 * getLineWidth(),
operationsHeight);
- currentHeight += operationsHeight;
}
-
+
+ // set bounds of big box
+ getBigPort().setBounds(x, y, newW, newH);
+ getBorderFig().setBounds(x, y, newW, newH);
+
// Now force calculation of the bounds of the figure, update the edges
// and trigger anyone who's listening to see if the "bounds" property
// has changed.
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigInterface.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigInterface.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigInterface.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigInterface.java 2009-09-14 23:24:03-0700
@@ -32,49 +32,53 @@
import org.argouml.ui.targetmanager.TargetManager;
import org.argouml.uml.diagram.ArgoDiagram;
import org.argouml.uml.diagram.DiagramSettings;
-import org.tigris.gef.base.Editor;
-import org.tigris.gef.base.Globals;
import org.tigris.gef.base.Selection;
import org.tigris.gef.presentation.Fig;
/**
* Class to display graphics for a UML Interface in a diagram.
* <p>
- * An Interface may show compartments for stereotypes
- * and operations. Attributes are not supported in ArgoUML.
+ * An Interface may show stereotypes and a compartment for
+ * operations. Attributes are not supported in ArgoUML.
*/
public class FigInterface extends FigClassifierBox {
private static final Logger LOG = Logger.getLogger(FigInterface.class);
/**
- * Initialization common to multiple constructors. This can be merged back
- * into the last constructor when the deprecated ones have been removed.
+ * Initialization common to multiple constructors.
*/
- private void initialize() {
- getStereotypeFig().setKeyword("interface");
-
+ private void initialize(Rectangle bounds) {
// Put all the bits together, suppressing bounds calculations until
// we're all done for efficiency.
enableSizeChecking(false);
setSuppressCalcBounds(true);
-
- Dimension size = new Dimension(0, 0);
+
+ getStereotypeFig().setKeyword("interface");
+ getStereotypeFig().setVisible(true);
+ /* The next line is needed so that we have the right dimension
+ * when drawing this Fig on the diagram by pressing down
+ * the mouse button, even before releasing the mouse button: */
+ getNameFig().setTopMargin(
+ getStereotypeFig().getMinimumSize().height);
addFig(getBigPort());
- addFig(getStereotypeFig());
- addChildDimensions(size, getStereotypeFig());
addFig(getNameFig());
- addChildDimensions(size, getNameFig());
+ // stereotype fig covers the name fig:
+ addFig(getStereotypeFig());
addFig(getOperationsFig());
- addChildDimensions(size, getOperationsFig());
- addFig(borderFig);
+ addFig(getBorderFig());
+
+ /* Set the drop location in the case of D&D: */
+ if (bounds != null) {
+ setLocation(bounds.x, bounds.y);
+ }
setSuppressCalcBounds(false);
// Set the bounds of the figure to the total of the above
+ setBounds(getBounds());
enableSizeChecking(true);
- setBounds(X0, Y0, size.width, size.height);
}
/**
@@ -87,7 +91,7 @@
public FigInterface(Object owner, Rectangle bounds,
DiagramSettings settings) {
super(owner, bounds, settings);
- initialize();
+ initialize(bounds);
}
/*
@@ -110,19 +114,20 @@
public Dimension getMinimumSize() {
// Use "aSize" to build up the minimum size. Start with the size of the
// name compartment and build up.
-
Dimension aSize = getNameFig().getMinimumSize();
- aSize.height += NAME_V_PADDING * 2;
- aSize.height = Math.max(NAME_FIG_HEIGHT, aSize.height);
-
- // If we have a stereotype displayed, then allow some space for that
- // (width and height)
- aSize = addChildDimensions(aSize, getStereotypeFig());
- aSize = addChildDimensions(aSize, getOperationsFig());
-
- // we want to maintain a minimum width for Interfaces
+ /* Only take into account the stereotype width, not the height,
+ * since the height is included in the name fig: */
+ addChildWidth(aSize, getStereotypeFig());
+
+ addChildDimensions(aSize, getOperationsFig());
+
+ /* We want to maintain a minimum width for the
+ * interface fig. Also, add the border dimensions
+ * to the minimum space required for its contents: */
aSize.width = Math.max(WIDTH, aSize.width);
+ aSize.width += 2 * getLineWidth();
+ aSize.height += 2 * getLineWidth();
return aSize;
}
@@ -188,6 +193,7 @@
* USED BY PGML.tee.
* @return the class name and bounds together with compartment
* visibility.
+ * TODO: Is this not duplicate with the parent?
*/
@Override
public String classNameAndBounds() {
@@ -201,9 +207,7 @@
*
* If the required height is bigger, then the additional height is
* equally distributed among all figs (i.e. compartments), such that the
- * cumulated height of all visible figs equals the demanded height<p>.
- *
- * Some of this has "magic numbers" hardcoded in.<p>
+ * accumulated height of all visible figs equals the demanded height.
*
* @param x Desired X coordinate of upper left corner
*
@@ -216,40 +220,66 @@
@Override
protected void setStandardBounds(final int x, final int y, final int w,
final int h) {
-
- // Save our old boundaries (needed later), and get minimum size
- // info.
+ /* Save our old boundaries (needed later), and get minimum size
+ * info.*/
Rectangle oldBounds = getBounds();
- // set bounds of big box
- getBigPort().setBounds(x, y, w, h);
- borderFig.setBounds(x, y, w, h);
+ /* The new size can not be smaller than the minimum. */
+ Dimension minimumSize = getMinimumSize();
+ int newW = Math.max(w, minimumSize.width);
+ int newH = Math.max(h, minimumSize.height);
int currentHeight = 0;
if (getStereotypeFig().isVisible()) {
int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
+ getNameFig().setTopMargin(stereotypeHeight);
getStereotypeFig().setBounds(
- x,
- y,
- w,
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
stereotypeHeight);
- currentHeight = stereotypeHeight;
+ } else {
+ getNameFig().setTopMargin(0);
}
+
+ /* Now the new nameFig height will include the stereotype height: */
+ Dimension nameMin = getNameFig().getMinimumSize();
+ int minNameHeight = Math.max(nameMin.height, NAME_FIG_HEIGHT);
+
+ getNameFig().setBounds(
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
+ minNameHeight);
+
+ /* The new height can not be less than the name height: */
+ /* TODO: Is this needed/correct? */
+ newH = Math.max(minNameHeight, newH);
+
+ currentHeight += minNameHeight;
- int nameHeight = getNameFig().getMinimumSize().height;
- getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
- currentHeight += nameHeight;
-
+ /* And the operations compartment takes the remainder
+ * of the requested height: */
if (getOperationsFig().isVisible()) {
- int operationsY = y + currentHeight;
- int operationsHeight = (h + y) - operationsY - 1;
+ int operationsHeight = newH - currentHeight - 2 * getLineWidth();
+ /* If the requested height is smaller than the minimum required, ... */
+ if ( operationsHeight < getOperationsFig().getMinimumSize().height) {
+ /* ... then we use the minimum ... */
+ operationsHeight = getOperationsFig().getMinimumSize().height;
+ /* ... and make the Fig bigger: */
+ newH += getOperationsFig().getMinimumSize().height - operationsHeight;
+ }
getOperationsFig().setBounds(
- x,
- operationsY,
- w,
+ x + getLineWidth(),
+ y + currentHeight + getLineWidth(),
+ newW - 2 * getLineWidth(),
operationsHeight);
}
+
+ // set bounds of big box
+ getBigPort().setBounds(x, y, newW, newH);
+ getBorderFig().setBounds(x, y, newW, newH);
// Now force calculation of the bounds of the figure, update the edges
// and trigger anyone who's listening to see if the "bounds" property
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigSignal.java 2009-09-14 23:24:03-0700
@@ -33,45 +33,63 @@
import org.argouml.model.AttributeChangeEvent;
import org.argouml.uml.diagram.DiagramSettings;
import org.tigris.gef.base.Selection;
-import org.tigris.gef.graph.GraphModel;
/**
* Class to display graphics for a UML Signal in a diagram.
* <p>
- * A Signal may have attributes - the UML standard document
+ * A Signal has a keyword "signal", possibly some stereotypes, and a name.
+ * It may also have attributes - the UML standard document
* contains an example diagram showing this.
- * <p>
* A Signal may have operations.
*
* @author Tom Morris
*/
public class FigSignal extends FigClassifierBoxWithAttributes {
- private void constructFigs() {
+ /**
+ * Construct a Fig representing a Signal.
+ *
+ * @param owner owning Signal
+ * @param bounds position and size
+ * @param settings render settings
+ */
+ public FigSignal(Object owner, Rectangle bounds, DiagramSettings settings) {
+ super(owner, bounds, settings);
+ constructFigs(bounds);
+ }
+
+ private void constructFigs(Rectangle bounds) {
+ enableSizeChecking(false);
+ setSuppressCalcBounds(true);
+
getStereotypeFig().setKeyword("signal");
+ getStereotypeFig().setVisible(true);
+ /* The next line is needed so that we have the right dimension
+ * when drawing this Fig on the diagram by pressing down
+ * the mouse button, even before releasing the mouse button: */
+ getNameFig().setTopMargin(
+ getStereotypeFig().getMinimumSize().height);
addFig(getBigPort());
- addFig(getStereotypeFig());
addFig(getNameFig());
+ /* Stereotype covers NameFig: */
+ addFig(getStereotypeFig());
addFig(getOperationsFig());
- addFig(getAttributesFig());
- addFig(borderFig);
+ addFig(getAttributesCompartment());
+ addFig(getBorderFig());
// by default, do not show operations nor attributes:
setOperationsVisible(false);
setAttributesVisible(false);
- }
- /**
- * Construct a Fig representing a Signal.
- *
- * @param owner owning Signal
- * @param bounds position and size
- * @param settings render settings
- */
- public FigSignal(Object owner, Rectangle bounds, DiagramSettings settings) {
- super(owner, bounds, settings);
- constructFigs();
+ /* Set the drop location in the case of D&D: */
+ if (bounds != null) {
+ setLocation(bounds.x, bounds.y);
+ }
+
+ setSuppressCalcBounds(false);
+ setBounds(getBounds());
+ enableSizeChecking(true);
}
/*
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigStereotypeDeclaration.java 2009-09-14 23:24:03-0700
@@ -52,21 +52,28 @@
* Classifier box notation.<p>
*
* TODO: This is just a placeholder right now! - tfm
+ * This needs to show tags and constraints.
*/
public class FigStereotypeDeclaration extends FigCompartmentBox {
- private static final long serialVersionUID = -2702539988691983863L;
-
- private void constructFigs() {
- getStereotypeFig().setKeyword("stereotype");
-
+ private void constructFigs(Rectangle bounds) {
// Put all the bits together, suppressing bounds calculations until
// we're all done for efficiency.
enableSizeChecking(false);
setSuppressCalcBounds(true);
+
+ getStereotypeFig().setKeyword("stereotype");
+ getStereotypeFig().setVisible(true);
+ /* The next line is needed so that we have the right dimension
+ * when drawing this Fig on the diagram by pressing down
+ * the mouse button, even before releasing the mouse button: */
+ getNameFig().setTopMargin(
+ getStereotypeFig().getMinimumSize().height);
+
addFig(getBigPort());
- addFig(getStereotypeFig());
addFig(getNameFig());
+ // stereotype fig covers the name fig:
+ addFig(getStereotypeFig());
// TODO: Need named Tags and Constraints compartments here
// addFig(tagsFig);
@@ -74,9 +81,13 @@
addFig(getBorderFig());
+ /* Set the drop location in the case of D&D: */
+ if (bounds != null) {
+ setLocation(bounds.x, bounds.y);
+ }
+
setSuppressCalcBounds(false);
- // Set the bounds of the figure to the total of the above (hardcoded)
- setBounds(X0, Y0, WIDTH, STEREOHEIGHT + NAME_FIG_HEIGHT);
+ setBounds(getBounds());
}
/**
@@ -89,7 +100,7 @@
public FigStereotypeDeclaration(Object owner, Rectangle bounds,
DiagramSettings settings) {
super(owner, bounds, settings);
- constructFigs();
+ constructFigs(bounds);
enableSizeChecking(true);
}
@@ -143,22 +154,29 @@
}
/**
- * Gets the minimum size permitted for a class on the diagram.<p>
+ * Gets the minimum size permitted for a class on the diagram.
*
* @return the size of the minimum bounding box.
*/
@Override
public Dimension getMinimumSize() {
+ /* Use "aSize" to build up the minimum size. Start with the size of the
+ * name compartment and build up. */
Dimension aSize = getNameFig().getMinimumSize();
-
- //TODO: Why does this differ from the other Figs?
- aSize = addChildDimensions(aSize, getStereotypeFig());
+
+ /* Only take into account the stereotype width, not the height,
+ * since the height is included in the name fig: */
+ addChildWidth(aSize, getStereotypeFig());
// TODO: Allow space for each of the Tags & Constraints we have
- // we want to maintain a minimum width for the class
+ /* We want to maintain a minimum width for the
+ * stereotypeDeclaration. Also, add the border dimensions
+ * to the minimum space required for its contents: */
aSize.width = Math.max(WIDTH, aSize.width);
-
+ aSize.width += 2 * getLineWidth();
+ aSize.height += 2 * getLineWidth();
+
return aSize;
}
@@ -179,31 +197,45 @@
@Override
protected void setStandardBounds(final int x, final int y,
final int w, final int h) {
+ /* Save our old boundaries (needed later): */
Rectangle oldBounds = getBounds();
- // set bounds of big box
- getBigPort().setBounds(x, y, w, h);
- getBorderFig().setBounds(x, y, w, h);
-
- int currentHeight = 0;
+ /* The new size can not be smaller than the minimum. */
+ Dimension minimumSize = getMinimumSize();
+ int newW = Math.max(w, minimumSize.width);
+ int newH = Math.max(h, minimumSize.height);
if (getStereotypeFig().isVisible()) {
int stereotypeHeight = getStereotypeFig().getMinimumSize().height;
+ getNameFig().setTopMargin(stereotypeHeight);
getStereotypeFig().setBounds(
- x,
- y,
- w,
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
stereotypeHeight);
- currentHeight = stereotypeHeight;
+ } else {
+ getNameFig().setTopMargin(0);
}
+
+ /* Now the new nameFig height will include the stereotype height: */
+ Dimension nameMin = getNameFig().getMinimumSize();
+ int minNameHeight = Math.max(nameMin.height, NAME_FIG_HEIGHT);
+
+ getNameFig().setBounds(
+ x + getLineWidth(),
+ y + getLineWidth(),
+ newW - 2 * getLineWidth(),
+ minNameHeight);
- int nameHeight = getNameFig().getMinimumSize().height;
- getNameFig().setBounds(x, y + currentHeight, w, nameHeight);
- currentHeight += nameHeight;
+ /* The new height can not be less than the name height: */
+ newH = Math.max(minNameHeight, newH);
// TODO: Compute size of Tags and Constraints
-
+ // set bounds of big box
+ getBigPort().setBounds(x, y, newW, newH);
+ getBorderFig().setBounds(x, y, newW, newH);
+
// Now force calculation of the bounds of the figure, update the edges
// and trigger anyone who's listening to see if the "bounds" property
// has changed.
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigCompartmentBox.java 2009-09-14 23:24:03-0700
@@ -24,6 +24,7 @@
package org.argouml.uml.diagram.ui;
+import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.InputEvent;
@@ -43,17 +44,38 @@
* Class to display graphics for a node with compartments in a diagram.<p>
*
* It adds a border around the box,
- * and deals with highlighting editable compartments. <p>
- *
- * Note that the upper line of the name box will be blanked out
- * if there is eventually a stereotype above.
+ * and deals with highlighting editable compartments.<p>
+ *
+ * All descendants of this class have the bigPort filled with the main fig
+ * fill color, without border. The borderFig has a transparent fill,
+ * and a visible border. <p>
+ *
+ * Why do we need a separate border fig: I (MVW) think because
+ * some figs may have parts protruding outside the box like a UML Package
+ * or like a UML Component.
+ *
+ * TODO: Why is the fill not drawn by the borderFig?
+ * In the current situation, the border is drawn OVER
+ * the background fill (which won't work if colors have alpha
+ * channels). But the fill should only be drawn WITHIN
+ * the border.
+ * MVW: I propose to have the borderFig show the fill color
+ * and have the bigPort be transparent and without border.
+ * Then we would need a drawing sequence change, too.
+ * Or maybe the compartments should draw the fill color instead?
+ * <p>
+ *
+ * The name, keyword and stereotype are shown in
+ * transparent figs without border, but their size is reduced so that they
+ * fit within the border of the borderFig.
*/
public abstract class FigCompartmentBox extends FigNodeModelElement {
/**
* Default bounds for a compartment.
*/
- protected static final Rectangle DEFAULT_COMPARTMENT_BOUNDS = new Rectangle(
+ protected static final Rectangle DEFAULT_COMPARTMENT_BOUNDS
+ = new Rectangle(
X0, Y0 + 20 /* 20 = height of name fig ?*/,
WIDTH, ROWHEIGHT + 2 /* 2*LINE_WIDTH? or extra padding? */ );
@@ -68,24 +90,33 @@
* Initialization shared by all constructors.
*/
private void initialize() {
- // Set properties of the stereotype box. Make it LINE_WIDTH higher than
- // before, so it overlaps the name box, and the blanking takes out both
- // lines. Initially not set to be displayed, but this will be changed
+ // Set properties of the stereotype box.
+ // Initially not set to be displayed, but this will be changed
// when we try to render it, if we find we have a stereotype.
- // TODO: Overlapping figs won't work with when the colors have alpha
- // channels
- getStereotypeFig().setFilled(true);
- getStereotypeFig().setLineWidth(LINE_WIDTH);
- // +1 to have 1 pixel overlap with getNameFig()
- getStereotypeFig().setHeight(STEREOHEIGHT + LINE_WIDTH);
+ getStereotypeFig().setVisible(false);
- // The outside border of the box around all compartments.
+ /* The nameFig is transparent, since this is a box and
+ * the fill color is drawn by the bigPort. */
+ getNameFig().setFillColor(null);
+
+ /* The borderFig shows the outside border of the box
+ * around all compartments. Its size always equals the bigPort.
+ * Its body is transparent. */
borderFig = new FigEmptyRect(X0, Y0, 0, 0);
borderFig.setLineColor(LINE_COLOR);
borderFig.setLineWidth(LINE_WIDTH);
getBigPort().setLineWidth(0);
+ /* The bigPort draws the background color: */
getBigPort().setFillColor(FILL_COLOR);
+
+ /* TODO: The above means that the border is drawn OVER
+ * the background fill (which won't work if colors have alpha
+ * channels). But the fill should only be drawn WITHIN
+ * the border.
+ * MVW: I propose to have the borderFig show the fill color
+ * and have the bigPort be transparent and without border.
+ * */
}
/**
@@ -254,23 +285,43 @@
}
/**
- * Add size of a child component to overall size. Width is maximized
- * with child's width and child's height is added to the overall height.
- * If the child figure is not visible, it's size is not added.
+ * This utility adds the size of a child component to an overall size.
+ * The width is maximized with child's width and the
+ * child's height is added to the overall height.
+ * If the child figure is not visible or not yet created, it's size is not added.
*
- * @param size current dimensions
+ * @param size current dimensions - modified with the result
* @param child child figure
* @return new Dimension with child size added
*/
- protected Dimension addChildDimensions(Dimension size, Fig child) {
- if (child.isVisible()) {
+ protected static Dimension addChildDimensions(Dimension size,
+ Fig child) {
+ if (child != null && child.isVisible()) {
Dimension childSize = child.getMinimumSize();
size.width = Math.max(size.width, childSize.width);
size.height += childSize.height;
}
return size;
}
-
+
+ /**
+ * This utility adds the width of a child component to an overall size.
+ * The width is maximized with child's width and the
+ * child's height is ignored.
+ * If the child figure is not visible, it's size is not added.
+ *
+ * @param size current dimensions - modified with the result
+ * @param child child figure
+ * @return new Dimension with child width added
+ */
+ protected static Dimension addChildWidth(Dimension size, Fig child) {
+ if (child.isVisible()) {
+ Dimension childSize = child.getMinimumSize();
+ size.width = Math.max(size.width, childSize.width);
+ }
+ return size;
+ }
+
/**
* @param compartment the compartment to be changed
* @param isVisible true if the attribute compartment is visible
@@ -305,11 +356,61 @@
}
}
- /*
- * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
- */
+ @Override
public void setLineWidth(int w) {
borderFig.setLineWidth(w);
}
+ @Override
+ public int getLineWidth() {
+ return borderFig.getLineWidth();
+ }
+
+ @Override
+ public void setLineColor(Color col) {
+ getStereotypeFig().setLineColor(null);
+ borderFig.setLineColor(col);
+ }
+
+ @Override
+ public void setFillColor(Color col) {
+ getBigPort().setFillColor(col);
+ getStereotypeFig().setFillColor(null);
+ getNameFig().setFillColor(null);
+ }
+
+ @Override
+ public Color getFillColor() {
+ return getBigPort().getFillColor();
+ }
+
+ @Override
+ public void setFilled(boolean f) {
+ getBigPort().setFilled(f);
+ getStereotypeFig().setFilled(false);
+ }
+
+ @Override
+ protected void updateStereotypeText() {
+
+ if (getOwner() == null) {
+ return;
+ }
+
+ getStereotypeFig().setVisible(
+ getStereotypeFig().getStereotypeCount() > 0);
+
+ super.updateStereotypeText();
+
+ if (getStereotypeFig().isVisible()) {
+ getNameFig().setTopMargin(
+ getStereotypeFig().getMinimumSize().height);
+ } else {
+ getNameFig().setTopMargin(0);
+ }
+
+ /* TODO: Is this needed? */
+// forceRepaintShadow();
+ }
+
}
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEmptyRect.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEmptyRect.java?view=diff&pathrev=17317&r1=17316&r2=17317
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEmptyRect.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEmptyRect.java 2009-09-14 23:24:03-0700
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2009 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
@@ -25,6 +25,8 @@
package org.argouml.uml.diagram.ui;
+import java.awt.Color;
+
import org.tigris.gef.presentation.FigRect;
/**
@@ -44,10 +46,15 @@
super.setFilled(false);
}
- /*
- * @see org.tigris.gef.presentation.Fig#setFilled(boolean)
- */
+ @Override
public void setFilled(boolean filled) {
// Do nothing, this rect will always be transparent
}
+
+ @Override
+ public void setFillColor(Color col) {
+ // Do nothing, this rect will always be transparent
+ }
+
+
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2394884
To unsubscribe from this discussion, e-mail: [[email protected]].