Author: bobtarling
Date: 2011-05-20 03:51:10-0700
New Revision: 19471
Added:
trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigRegion.java
trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigVertex.java
Removed:
trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/BaseDiagram.java
trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramRenderer.java
Modified:
trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramFactory.java
trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramGraphModel.java
trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/UMLStateDiagram.java
Log:
Move UML2 state diagram code into module
Removed: trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/BaseDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/BaseDiagram.java?view=markup&pathrev=19470
Added: trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigRegion.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigRegion.java?view=markup&pathrev=19471
==============================================================================
--- (empty file)
+++ trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigRegion.java 2011-05-20 03:51:10-0700
@@ -0,0 +1,44 @@
+/* $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.state2.diagram;
+
+import java.awt.Dimension;
+import org.tigris.gef.presentation.FigRect;
+
+/**
+ * Displays a region within a composite state
+ */
+public class FigRegion extends FigRect {
+
+ /**
+ * Construct a fig representing a region.
+ *
+ * @param region owning UML element
+ * @param bounds position and size
+ */
+ public FigRegion(
+ final Object region) {
+ super(0,0,0,0);
+ setLineWidth(0);
+ setOwner(region);
+ }
+
+ /*
+ * @see org.tigris.gef.presentation.Fig#getMinimumSize()
+ */
+ @Override
+ public Dimension getMinimumSize() {
+ return new Dimension(180, 80);
+ }
+}
Added: trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigVertex.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigVertex.java?view=markup&pathrev=19471
==============================================================================
--- (empty file)
+++ trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/FigVertex.java 2011-05-20 03:51:10-0700
@@ -0,0 +1,502 @@
+/* $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.state2.diagram;
+
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.event.MouseEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyVetoException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+import org.argouml.model.AddAssociationEvent;
+import org.argouml.model.Model;
+import org.argouml.model.RemoveAssociationEvent;
+import org.argouml.notation.Notation;
+import org.argouml.notation.NotationName;
+import org.argouml.notation.NotationProvider;
+import org.argouml.notation.NotationProviderFactory2;
+import org.argouml.notation.NotationSettings;
+import org.argouml.ui.ActionCreateContainedModelElement;
+import org.argouml.ui.targetmanager.TargetManager;
+import org.argouml.uml.diagram.ArgoDiagram;
+import org.argouml.uml.diagram.DiagramSettings;
+import org.argouml.uml.diagram.ui.FigNodeModelElement;
+import org.tigris.gef.base.LayerPerspective;
+import org.tigris.gef.base.Selection;
+import org.tigris.gef.di.DiagramElement;
+import org.tigris.gef.presentation.Fig;
+import org.tigris.gef.presentation.FigGroup;
+import org.tigris.gef.presentation.FigRRect;
+import org.tigris.gef.presentation.FigText;
+
+/**
+ * A Fig that can represent a UML2 vertex. The current implementation
+ * is limited to just handling States. Other vertices are currently handled
+ * by different Figs but they will most likely all be handled here in future.
+ */
+public class FigVertex extends FigNodeModelElement {
+
+ private static final Logger LOG = Logger.getLogger(FigVertex.class);
+
+ private static final int MARGIN = 2;
+
+ private NotationProvider notationProviderBody;
+
+ /**
+ * The body for entry/exit/do actions
+ */
+ private FigBody bodyText;
+
+ private FigGroup regionCompartment;
+
+ /**
+ * Create a new instance of FigVertex
+ * @param owner the vertex that own this dagram element
+ * @param bounds the bounds of the diagram element
+ * @param settings the display settings for this diagram element
+ */
+ public FigVertex(Object owner, Rectangle bounds, DiagramSettings settings) {
+ super(owner, bounds, settings);
+ this.allowRemoveFromDiagram(false);
+
+ initialize();
+
+ NotationName notation = Notation.findNotation(getNotationSettings()
+ .getNotationLanguage());
+ notationProviderBody = NotationProviderFactory2.getInstance()
+ .getNotationProvider(NotationProviderFactory2.TYPE_STATEBODY,
+ getOwner(), this, notation);
+ updateNameText();
+
+ LOG.info("Registering as listener");
+ Model.getPump().addModelEventListener(this, getOwner(), "region");
+ }
+
+ @Override
+ public void setEnclosingFig(Fig encloser) {
+ LayerPerspective lp = (LayerPerspective) getLayer();
+ if (lp == null) {
+ return;
+ }
+
+ super.setEnclosingFig(encloser);
+
+ Object region = null;
+ if (encloser != null) {
+ // Get the region as the first Region in the State.
+ // If there is no region in the StateMachine then create one.
+ List regions = Model.getStateMachinesHelper().getRegions(
+ encloser.getOwner());
+ if (regions.isEmpty()) {
+ // There are no regions so create one and place the vertex there.
+ region = Model.getUmlFactory().buildNode(
+ Model.getMetaTypes().getRegion(), encloser.getOwner());
+ } else {
+ // There are one or more regions so find the one that the
+ //vertex was dropped in
+ FigVertex compositeState = (FigVertex) encloser;
+ for (DiagramElement de :
+ compositeState.regionCompartment.getDiagramElements()) {
+ if (((Fig) de).getBounds().contains(getBounds())) {
+ region = de.getOwner();
+ break;
+ }
+ }
+ }
+ } else {
+ // The vertex was dropped onto the diagram.
+ // Get the region as the first Region in the StateMachine.
+ // If there is no region in the StateMachine then create one.
+ ArgoDiagram diagram = (ArgoDiagram) lp.getDiagram();
+ Object stateMachine = diagram.getOwner();
+ List regions =
+ Model.getStateMachinesHelper().getRegions(stateMachine);
+ if (regions.isEmpty()) {
+ region = Model.getUmlFactory().buildNode(
+ Model.getMetaTypes().getRegion(), stateMachine);
+ } else {
+ region = regions.get(0);
+ }
+ }
+ if (region != null
+ && Model.getFacade().getContainer(getOwner()) != region) {
+ Model.getStateMachinesHelper().setContainer(getOwner(), region);
+ }
+ }
+
+ @Override
+ protected Fig createBigPortFig() {
+ return new FigRRect(0, 0, 0, 0, LINE_COLOR, FILL_COLOR);
+ }
+
+ private void initialize() {
+ getNameFig().setLineWidth(0);
+ getNameFig().setFilled(false);
+
+ bodyText = new FigBody(0,0,0,0);
+ regionCompartment = new FigRegionCompartment(0,0,0,0);
+
+ addFig(getBigPort());
+ addFig(getNameFig());
+ addFig(getBodyText());
+ addFig(regionCompartment);
+
+ setBounds(getBounds());
+ }
+
+ /*
+ * @see
+ * org.argouml.uml.diagram.state.ui.FigStateVertex#initNotationProviders
+ * (java.lang.Object)
+ */
+ @Override
+ protected void initNotationProviders(Object own) {
+ if (notationProviderBody != null) {
+ notationProviderBody.cleanListener();
+ }
+ super.initNotationProviders(own);
+ NotationName notation = Notation.findNotation(getNotationSettings()
+ .getNotationLanguage());
+ if (Model.getFacade().isAState(own)) {
+ notationProviderBody = NotationProviderFactory2.getInstance()
+ .getNotationProvider(
+ NotationProviderFactory2.TYPE_STATEBODY, own, this,
+ notation);
+ }
+ }
+
+ // Temporary start
+// private static final Color[] COLOR_ARRAY = {
+// Color.RED, Color.BLUE, Color.CYAN, Color.YELLOW, Color.GREEN};
+// private int nextColor = 0;
+ // Temporary end
+
+ @Override
+ protected void modelChanged(PropertyChangeEvent mee) {
+ super.modelChanged(mee);
+
+ assert(mee.getPropertyName().equals("region"));
+
+ if (mee instanceof AddAssociationEvent) {
+ // TODO: Before adding a new region make the last region
+ // its minimum size (smallest size that will still
+ // contain all enclosed)
+
+ Object newRegion = mee.getNewValue();
+ FigRegion rg = new FigRegion(newRegion);
+ rg.setBounds(
+ regionCompartment.getX(), regionCompartment.getY(),
+ rg.getMinimumSize().width, rg.getMinimumSize().height);
+
+ // Temporary start - colour the regions so that we can see them for now
+// rg.setFillColor(COLOR_ARRAY[nextColor++]);
+// if (nextColor >= COLOR_ARRAY.length) {
+// nextColor = 0;
+// }
+ // Temporary end
+
+ regionCompartment.addFig(rg);
+ setSize(getMinimumSize());
+ }
+ if (mee instanceof RemoveAssociationEvent) {
+ Object oldRegion = mee.getNewValue();
+ for (DiagramElement de : regionCompartment.getDiagramElements()) {
+ if (de.getOwner() == oldRegion) {
+ regionCompartment.removeFig((Fig) de);
+ // TODO: After removing a region reset the overall
+ // size of the node.
+ renderingChanged();
+ damage();
+ }
+ }
+ LOG.debug("Removing region " + oldRegion);
+ }
+ }
+
+ /*
+ * @see
+ * org.argouml.uml.diagram.ui.FigNodeModelElement#removeFromDiagramImpl()
+ */
+ @Override
+ public void removeFromDiagramImpl() {
+ if (notationProviderBody != null) {
+ notationProviderBody.cleanListener();
+ }
+ super.removeFromDiagramImpl();
+ }
+
+ /*
+ * @see org.argouml.uml.diagram.ui.FigNodeModelElement#renderingChanged()
+ */
+ @Override
+ public void renderingChanged() {
+ super.renderingChanged();
+ if (notationProviderBody != null) {
+ bodyText.setText(notationProviderBody.toString(getOwner(),
+ getNotationSettings()));
+ }
+ calcBounds();
+ setBounds(getBounds());
+ }
+
+ private FigText getBodyText() {
+ return bodyText;
+ }
+
+ @Override
+ protected void textEditStarted(FigText ft) {
+ super.textEditStarted(ft);
+ if (ft == bodyText) {
+ showHelp(notationProviderBody.getParsingHelp());
+ }
+ }
+
+ @Override
+ public void textEdited(FigText ft) throws PropertyVetoException {
+ super.textEdited(ft);
+ if (ft == getBodyText()) {
+ notationProviderBody.parse(getOwner(), ft.getText());
+ ft.setText(notationProviderBody.toString(getOwner(),
+ getNotationSettings()));
+ }
+ }
+
+ public void notationRenderingChanged(NotationProvider np, String rendering) {
+ super.notationRenderingChanged(np, rendering);
+ if (notationProviderBody == np) {
+ bodyText.setText(rendering);
+ updateBounds();
+ damage();
+ }
+ }
+
+ public NotationSettings getNotationSettings(NotationProvider np) {
+ return getNotationSettings();
+ }
+
+ public Object getOwner(NotationProvider np) {
+ return getOwner();
+ }
+
+ public Dimension getMinimumSize() {
+ final Dimension nameSize = getNameFig().getMinimumSize();
+ final Dimension bodySize = getBodyText().getMinimumSize();
+
+ int h = getTopMargin()
+ + nameSize.height
+ + getBottomMargin();
+
+ h += regionCompartment.getMinimumSize().height;
+
+ if (getBodyText().getText().length() > 0) {
+ h += bodySize.height;
+ }
+
+ int w = getLeftMargin()
+ + Math.max(nameSize.width, bodySize.width)
+ + getRightMargin();
+
+ if (Model.getFacade().isACompositeState(getOwner())) {
+ w = Math.max(180, w);
+ h = Math.max(150, h);
+ } else {
+ w = Math.max(80, w);
+ h = Math.max(40, h);
+ }
+
+ return new Dimension(w, h);
+ }
+
+ public boolean getUseTrapRect() {
+ return true;
+ }
+
+ public List<Rectangle> getTrapRects() {
+ List regions = Model.getStateMachinesHelper().getRegions(getOwner());
+
+ ArrayList<Rectangle> rects = new ArrayList<Rectangle>(regions.size());
+ if (regions.isEmpty()) {
+ rects.add(regionCompartment.getBounds());
+ } else {
+ for (DiagramElement f : regionCompartment.getDiagramElements()) {
+ rects.add(((Fig) f).getBounds());
+ }
+ }
+ return rects;
+ }
+
+ protected void setStandardBounds(int x, int y, int w, int h) {
+ Dimension nameSize = getNameFig().getMinimumSize();
+ Dimension bodySize = getBodyText().getMinimumSize();
+
+ getNameFig().setBounds(
+ x + getLeftMargin(), y + getTopMargin(),
+ w - getLeftMargin() - getRightMargin(), nameSize.height);
+
+
+
+ if (getBodyText().getText().length() > 0) {
+ getBodyText().setBounds(
+ x + getLeftMargin(), y + getTopMargin() + nameSize.height,
+ bodySize.width,
+ bodySize.height);
+ } else {
+ getBodyText().setBounds(
+ x + getLeftMargin(), y + getTopMargin() + nameSize.height,
+ bodySize.width,
+ 1);
+ }
+
+ regionCompartment.setBounds(
+ x + getLeftMargin(),
+ getBodyText().getY() + getBodyText().getHeight(),
+ w - getLeftMargin() - getRightMargin(),
+ h - getTopMargin() - getBottomMargin()
+ - getNameFig().getHeight() - getBodyText().getHeight());
+
+ getBigPort().setBounds(x, y, w, h);
+
+ calcBounds(); // _x = x; _y = y; _w = w; _h = h;
+ }
+
+
+
+ int getRightMargin() {
+ return MARGIN;
+ }
+
+ int getLeftMargin() {
+ return MARGIN;
+ }
+
+ int getTopMargin() {
+ return MARGIN;
+ }
+
+ int getBottomMargin() {
+ return MARGIN;
+ }
+
+ /*
+ * @see org.tigris.gef.ui.PopupGenerator#getPopUpActions(java.awt.event.MouseEvent)
+ */
+ public Vector getPopUpActions(MouseEvent me) {
+ Vector popUpActions = super.getPopUpActions(me);
+ if (TargetManager.getInstance().getTargets().size() == 1) {
+ popUpActions.add(
+ popUpActions.size() - getPopupAddOffset(),
+ new ActionCreateContainedModelElement(
+ Model.getMetaTypes().getRegion(), getOwner()));
+ }
+ return popUpActions;
+ }
+
+ /**
+ * The text Fig that displays the body of the actions on the state
+ *
+ * @author Bob Tarling
+ */
+ private class FigBody extends FigText {
+ public FigBody(int x, int y, int width, int height) {
+ super (x, y, width, height);
+ setFont(getSettings().getFont(Font.PLAIN));
+ setTextColor(TEXT_COLOR);
+ setLineWidth(0);
+ setFilled(false);
+ setExpandOnly(true);
+ setReturnAction(FigText.INSERT);
+ setJustification(FigText.JUSTIFY_LEFT);
+ }
+ }
+
+ /**
+ * The text Fig that displays the body of the actions on the state
+ *
+ * @author Bob Tarling
+ */
+ private class FigRegionCompartment extends FigGroup {
+ public FigRegionCompartment(int x, int y, int width, int height) {
+ super();
+ }
+
+ @Override
+ protected void setBoundsImpl(
+ final int x,
+ int y,
+ final int w,
+ int h) {
+
+ _x = x;
+ _y = y;
+ _w = w;
+ _h = h;
+
+ for (Iterator it = getFigs().iterator(); it.hasNext(); ) {
+ Fig fig = (Fig) it.next();
+ if (it.hasNext()) {
+ fig.setBounds(x, y, w, fig.getMinimumSize().height);
+ h -= fig.getMinimumSize().height;
+ } else {
+ fig.setBounds(x, y, w, h);
+ }
+ y += fig.getHeight();
+ }
+ }
+
+
+ @Override
+ public Dimension getMinimumSize() {
+ int minWidth = 0;
+ int minHeight = 0;
+ for (Iterator it = getFigs().iterator(); it.hasNext(); ) {
+ Fig fig = (Fig) it.next();
+ minWidth = Math.max(fig.getMinimumSize().width, minWidth);
+ if (it.hasNext()) {
+ minHeight += fig.getHeight();
+ } else {
+ minHeight += fig.getMinimumSize().height;
+ }
+ }
+
+ return new Dimension(minWidth, minHeight);
+ }
+
+ public void paint(Graphics g) {
+ super.paint(g);
+
+ for (Iterator it = getFigs().iterator(); it.hasNext(); ) {
+ Fig fig = (Fig) it.next();
+ if (it.hasNext()) {
+ g.setColor(getLineColor());
+
+ drawDashedLine(
+ g, 1,
+ fig.getX(),
+ fig.getY() + fig.getHeight(),
+ fig.getX() + fig.getWidth(),
+ fig.getY() + fig.getHeight(),
+ 0, new float [] { 5.0f, 5.0f }, 10);
+ }
+ }
+
+ }
+ }
+}
Modified: trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramFactory.java?view=diff&pathrev=19471&r1=19470&r2=19471
==============================================================================
--- trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramFactory.java (original)
+++ trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramFactory.java 2011-05-20 03:51:10-0700
@@ -13,9 +13,6 @@
package org.argouml.state2.diagram;
-import java.beans.PropertyVetoException;
-
-import org.apache.log4j.Logger;
import org.argouml.uml.diagram.ArgoDiagram;
import org.argouml.uml.diagram.DiagramFactoryInterface2;
import org.argouml.uml.diagram.DiagramSettings;
@@ -23,23 +20,8 @@
public class StateDiagramFactory
implements DiagramFactoryInterface2{
- /**
- * Logger.
- */
- private static final Logger LOG =
- Logger.getLogger(StateDiagramFactory.class);
-
public ArgoDiagram createDiagram(Object owner, String name,
DiagramSettings settings) {
- final ArgoDiagram diagram = new UMLStateDiagram(owner);
- if (name != null) {
- try {
- diagram.setName(name);
- } catch (PropertyVetoException e) {
- LOG.error("Cannot set the name " + name +
- " to the diagram just created: "+ diagram.getName(), e);
- }
- }
- return diagram;
+ return new UMLStateDiagram(name, owner);
}
}
Modified: trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramGraphModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramGraphModel.java?view=diff&pathrev=19471&r1=19470&r2=19471
==============================================================================
--- trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramGraphModel.java (original)
+++ trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramGraphModel.java 2011-05-20 03:51:10-0700
@@ -1,4 +1,4 @@
-/* $Id:$
+/* $Id: StateDiagramGraphModel.java 19385 2011-05-09 19:41:39Z bobtarling $
*****************************************************************************
* Copyright (c) 2009 Contributors - see below
* All rights reserved. This program and the accompanying materials
@@ -7,52 +7,43 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Bob Tarling
+ * bobtarling
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
*/
-package org.argouml.state2.diagram;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.argouml.model.Model;
-import org.argouml.uml.diagram.UMLMutableGraphSupport;
-
-class StateDiagramGraphModel extends UMLMutableGraphSupport {
-
- /**
- * Logger.
- */
- private static final Logger LOG = Logger
- .getLogger(StateDiagramGraphModel.class);
-
- public StateDiagramGraphModel() {
- super();
- }
-
- /*
- * @see org.tigris.gef.graph.GraphModel#getPorts(java.lang.Object)
- */
- public List getPorts(Object nodeOrEdge) {
- List res = new ArrayList();
- return res;
- }
+// Copyright (c) 1996-2006 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.
- public List getInEdges(Object port) {
- // TODO: Auto-generated method stub
- return null;
- }
+package org.argouml.state2.diagram;
- public List getOutEdges(Object port) {
- // TODO: Auto-generated method stub
- return null;
- }
+public class StateDiagramGraphModel extends org.argouml.uml.diagram.state.StateDiagramGraphModel {
- public Object getOwner(Object port) {
- return port;
+
+ public void setHomeModel(Object ns) {
+ super.setHomeModel(ns);
+ setMachine(ns);
}
+
}
Removed: trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramRenderer.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/StateDiagramRenderer.java?view=markup&pathrev=19470
Modified: trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/UMLStateDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/UMLStateDiagram.java?view=diff&pathrev=19471&r1=19470&r2=19471
==============================================================================
--- trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/UMLStateDiagram.java (original)
+++ trunk/src/argouml-core-diagrams-state2/src/org/argouml/state2/diagram/UMLStateDiagram.java 2011-05-20 03:51:10-0700
@@ -1,6 +1,6 @@
/* $Id: $
*****************************************************************************
- * Copyright (c) 2010 Contributors - see below
+ * Copyright (c) 2009-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
@@ -14,70 +14,186 @@
package org.argouml.state2.diagram;
import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyVetoException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.swing.Action;
-import org.apache.log4j.Logger;
import org.argouml.i18n.Translator;
+import org.argouml.model.DeleteInstanceEvent;
import org.argouml.model.Model;
-import org.argouml.model.StateDiagram;
+import org.argouml.ui.CmdCreateNode;
import org.argouml.uml.diagram.DiagramElement;
+import org.argouml.uml.diagram.DiagramFactory;
import org.argouml.uml.diagram.DiagramSettings;
-import org.argouml.uml.diagram.UMLMutableGraphSupport;
-import org.argouml.uml.diagram.UmlDiagramRenderer;
+import org.argouml.uml.diagram.state.ui.FigBranchState;
+import org.argouml.uml.diagram.state.ui.FigDeepHistoryState;
+import org.argouml.uml.diagram.state.ui.FigFinalState;
+import org.argouml.uml.diagram.state.ui.FigForkState;
+import org.argouml.uml.diagram.state.ui.FigInitialState;
+import org.argouml.uml.diagram.state.ui.FigJoinState;
+import org.argouml.uml.diagram.state.ui.FigJunctionState;
+import org.argouml.uml.diagram.state.ui.FigShallowHistoryState;
+import org.argouml.uml.diagram.state.ui.StateDiagramRenderer;
import org.argouml.uml.diagram.static_structure.ui.FigComment;
+import org.argouml.uml.diagram.ui.ActionSetMode;
import org.argouml.uml.diagram.ui.FigNodeModelElement;
+import org.argouml.uml.diagram.ui.RadioAction;
+import org.argouml.uml.diagram.ui.UMLDiagram;
+import org.tigris.gef.base.LayerPerspective;
+import org.tigris.gef.base.LayerPerspectiveMutable;
+import org.tigris.gef.base.ModeCreatePolyEdge;
+import org.tigris.gef.presentation.FigNode;
-public class UMLStateDiagram extends BaseDiagram implements StateDiagram {
-
- private static final Logger LOG = Logger
- .getLogger(UMLStateDiagram.class);
-
- public UMLStateDiagram(Object stateMachine) {
- super(stateMachine);
- }
-
- @Override
- UmlDiagramRenderer createDiagramRenderer() {
- return new StateDiagramRenderer();
+/**
+ * Diagram for UML2 State Machine diagram
+ * @author Bob Tarling
+ */
+public class UMLStateDiagram extends UMLDiagram {
+
+ /**
+ * Construct a new State Machine diagram.
+ *
+ * @param name the name of the new diagram
+ * @param machine the owner of the diagram which will be a state machine
+ */
+ public UMLStateDiagram(String name, Object machine) {
+ super(name, machine, new StateDiagramGraphModel());
+ if (name == null || name.trim().length() == 0) {
+ name = getLabelName() + Model.getFacade().getName(machine);
+ try {
+ setName(name);
+ } catch (PropertyVetoException pve) {
+ // nothing we can do about veto, so just ignore it
+ }
+ }
+ initialize(machine);
}
@Override
- UMLMutableGraphSupport createGraphModel() {
- return new StateDiagramGraphModel();
+ public void initialize(Object o) {
+
+ setNamespace(o);
+
+ StateDiagramGraphModel gm = createGraphModel();
+ gm.setHomeModel(namespace);
+ StateDiagramRenderer rend = new StateDiagramRenderer();
+
+ LayerPerspective lay = new LayerPerspectiveMutable(
+ Model.getFacade().getName(namespace), gm);
+ lay.setGraphNodeRenderer(rend);
+ lay.setGraphEdgeRenderer(rend);
+ setLayer(lay);
+
+ Model.getPump().addModelEventListener(this, namespace,
+ new String[] {"remove"});
}
- @Override
- Object[] getNewEdgeTypes() {
- return new Object[] {
- };
+ private StateDiagramGraphModel createGraphModel() {
+ if ((getGraphModel() instanceof StateDiagramGraphModel)) {
+ return (StateDiagramGraphModel) getGraphModel();
+ } else {
+ return new StateDiagramGraphModel();
+ }
}
+ /*
+ * @see org.argouml.uml.diagram.ui.UMLDiagram#propertyChange(java.beans.PropertyChangeEvent)
+ */
@Override
- Object[] getNewNodeTypes() {
- return new Object[] {
- };
+ public void propertyChange(PropertyChangeEvent evt) {
+ if ((evt.getSource() == namespace)
+ && (evt instanceof DeleteInstanceEvent)) {
+ Model.getPump().removeModelEventListener(this,
+ namespace, new String[] {"remove"});
+ if (getProject() != null) {
+ getProject().moveToTrash(this);
+ } else {
+ DiagramFactory.getInstance().removeDiagram(this);
+ }
+ }
}
- @Override
- public void initialize(Object owner) {
- super.initialize(owner);
- StateDiagramGraphModel gm =
- (StateDiagramGraphModel) getGraphModel();
+ protected Object[] getUmlActions() {
+
+ ArrayList actions = new ArrayList();
+
+ actions.add(getNodeAction(Model.getMetaTypes().getState()));
+ actions.add(getEdgeAction(Model.getMetaTypes().getTransition()));
+ actions.add(null);
+ actions.add(getPseudoAction(Model.getPseudostateKind().getInitial()));
+ actions.add(getNodeAction(Model.getMetaTypes().getFinalState()));
+ actions.add(getPseudoAction(
+ Model.getPseudostateKind().getEntryPoint()));
+ actions.add(getPseudoAction(Model.getPseudostateKind().getExitPoint()));
+ actions.add(getPseudoAction(Model.getPseudostateKind().getJunction()));
+ actions.add(getPseudoAction(Model.getPseudostateKind().getChoice()));
+ actions.add(getPseudoAction(Model.getPseudostateKind().getFork()));
+ actions.add(getPseudoAction(Model.getPseudostateKind().getJoin()));
+ actions.add(getPseudoAction(
+ Model.getPseudostateKind().getShallowHistory()));
+ actions.add(getPseudoAction(
+ Model.getPseudostateKind().getDeepHistory()));
+
+ return actions.toArray();
}
- @Override
public String getLabelName() {
- return Translator.localize("label.state-diagram");
+ return Translator.localize("label.statemachine-diagram");
+ }
+
+ private Action getNodeAction(Object metaType) {
+ String label = getLabel(metaType);
+ return new RadioAction(new CmdCreateNode(metaType, label));
+ }
+
+ private Action getPseudoAction(Object kind) {
+ String label =
+ "button.new-" + Model.getFacade().getName(kind).toLowerCase();
+ return new RadioAction(new CreatePseudostateAction(kind, label));
}
+
+ private Action getEdgeAction(Object metaType) {
+ String label = getLabel(metaType);
+ return new RadioAction(
+ new ActionSetMode(
+ ModeCreatePolyEdge.class,
+ "edgeClass",
+ metaType,
+ label));
+ }
+
+ private String getLabel(Object metaType) {
+ return "button.new-"
+ + Model.getMetaTypes().getName(metaType).toLowerCase();
+ }
+
+ /*
+ * @see org.argouml.uml.diagram.ui.UMLDiagram#relocate(java.lang.Object)
+ */
+ public boolean relocate(Object base) {
+ return false;
+ }
+
+ public void encloserChanged(FigNode enclosed,
+ FigNode oldEncloser, FigNode newEncloser) {
+ }
+
@Override
public boolean doesAccept(Object objectToAccept) {
- if (Model.getFacade().isAComment(objectToAccept) ) {
+ if (Model.getFacade().isAVertex(objectToAccept)) {
return true;
- }
+ } else if (Model.getFacade().isAComment(objectToAccept)) {
+ return true;
+ }
return false;
}
+
public DiagramElement createDiagramElement(
final Object modelElement,
final Rectangle bounds) {
@@ -86,6 +202,66 @@
DiagramSettings settings = getDiagramSettings();
+ if (Model.getFacade().isAFinalState(modelElement)) {
+ figNode = new FigFinalState(modelElement, bounds, settings);
+ } else if (Model.getFacade().isAState(modelElement)) {
+ figNode = new FigVertex(modelElement, bounds, settings);
+ } else if (Model.getFacade().isAComment(modelElement)) {
+ figNode = new FigComment(modelElement, bounds, settings);
+ } else if (Model.getFacade().isAPseudostate(modelElement)) {
+ Object kind = Model.getFacade().getKind(modelElement);
+ if (kind == null) {
+ return null;
+ }
+ if (kind.equals(Model.getPseudostateKind().getInitial())) {
+ figNode = new FigInitialState(modelElement, bounds, settings);
+ } else if (kind.equals(
+ Model.getPseudostateKind().getChoice())) {
+ figNode = new FigBranchState(modelElement, bounds, settings);
+ } else if (kind.equals(
+ Model.getPseudostateKind().getJunction())) {
+ figNode = new FigJunctionState(modelElement, bounds, settings);
+ } else if (kind.equals(
+ Model.getPseudostateKind().getFork())) {
+ figNode = new FigForkState(modelElement, bounds, settings);
+ } else if (kind.equals(
+ Model.getPseudostateKind().getJoin())) {
+ figNode = new FigJoinState(modelElement, bounds, settings);
+ } else if (kind.equals(
+ Model.getPseudostateKind().getShallowHistory())) {
+ figNode = new FigShallowHistoryState(modelElement, bounds,
+ settings);
+ } else if (kind.equals(
+ Model.getPseudostateKind().getDeepHistory())) {
+ figNode = new FigDeepHistoryState(modelElement, bounds,
+ settings);
+ }
+ }
return figNode;
}
-}
+
+ @Override
+ public boolean isRelocationAllowed(Object base) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Collection getRelocationCandidates(Object root) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ private class CreatePseudostateAction extends CmdCreateNode {
+ public CreatePseudostateAction(Object kind, String name) {
+ super(Model.getMetaTypes().getPseudostate(), name);
+ setArg("kind", kind);
+ }
+
+ public Object makeNode() {
+ Object newNode = super.makeNode();
+ Object kind = getArg("kind");
+ Model.getCoreHelper().setKind(newNode, kind);
+ return newNode;
+ }
+ }
+}
\ No newline at end of file
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2742258
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.