Author: bobtarling
Date: 2011-04-23 07:05:31-0700
New Revision: 19270
Added:
trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigCompartment.java
Log:
A new generic compartment implementation - in preparation for stereotypes on a state
Added: trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigCompartment.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigCompartment.java?view=markup&pathrev=19270
==============================================================================
--- (empty file)
+++ trunk/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigCompartment.java 2011-04-23 07:05:31-0700
@@ -0,0 +1,122 @@
+/* $Id: $
+ *****************************************************************************
+ * Copyright (c) 2011 Contributors - see below
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Bob Tarling
+ *****************************************************************************
+ */
+
+package org.argouml.activity2.diagram;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.util.List;
+
+import org.argouml.model.InvalidElementException;
+import org.argouml.notation2.NotationType;
+import org.argouml.uml.diagram.DiagramSettings;
+import org.tigris.gef.presentation.Fig;
+import org.tigris.gef.presentation.FigGroup;
+
+/**
+ * The UML defines a Name Compartment, and a List Compartment.
+ * This class implements the latter.<p>
+ *
+ * A List Compartment is a boxed compartment,
+ * containing vertically stacked figs,
+ * which is common to e.g. a stereotypes compartment, operations
+ * compartment and an attributes compartment.<p>
+ *
+ * @author Bob Tarling
+ */
+class FigCompartment extends FigGroup {
+
+ private static final int MARGIN = 0;
+
+ private Rectangle bounds;
+
+ public FigCompartment(Object owner, Rectangle bounds,
+ DiagramSettings settings, List elements) {
+ for (Object element : elements) {
+ try {
+ int y = bounds.y + getTopMargin();
+ int x = bounds.x + getLeftMargin();
+ Rectangle childBounds = new Rectangle(x, y, 0, 0);
+ FigNotation fn =
+ new FigNotation(element, childBounds, settings, NotationType.NAME);
+ addFig(fn);
+ y += fn.getHeight();
+ } catch (InvalidElementException e) {
+ }
+ }
+ }
+
+ int getRightMargin() {
+ return MARGIN;
+ }
+
+ int getLeftMargin() {
+ return MARGIN;
+ }
+
+ int getTopMargin() {
+ return MARGIN;
+ }
+
+ int getBottomMargin() {
+ return MARGIN;
+ }
+
+ @Override
+ public Dimension getMinimumSize() {
+ int minWidth = 0;
+ int minHeight = 0;
+ for (org.tigris.gef.di.DiagramElement de : getDiagramElements()) {
+ Fig f = (Fig) de;
+ minWidth = Math.max(f.getMinimumSize().width, minWidth);
+ minHeight += f.getMinimumSize().height;
+ }
+
+ minHeight += getTopMargin() + getBottomMargin();
+ minWidth += getLeftMargin() + getRightMargin();
+
+ return new Dimension(minWidth, minHeight);
+ }
+
+ @Override
+ protected void setBoundsImpl(int x, int y, int w, int h) {
+ Rectangle oldBounds = getBounds();
+
+ Dimension minimumSize = getMinimumSize();
+
+ w = Math.max(w, minimumSize.width);
+ h = Math.max(h, minimumSize.height);
+
+ bounds = new Rectangle(x, y, w, h);
+
+ w -= getLeftMargin() + getRightMargin();
+ h -= getTopMargin() + getBottomMargin();
+
+ y += getTopMargin();
+
+ for (org.tigris.gef.di.DiagramElement de : getDiagramElements()) {
+ Fig f = (Fig) de;
+ f.setBounds(x, y, w, f.getHeight());
+ y += f.getHeight();
+ }
+ firePropChange("bounds", oldBounds, getBounds());
+ }
+
+ protected Rectangle getBoundsImpl() {
+ return bounds;
+ }
+
+ public void populate() {
+
+ }
+}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2723372
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.