alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

// $Id: UMLActivityDiagram.java,v 1.59 2004/10/03 17:57:09 mvw Exp $
// Copyright (c) 1996-2004 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.

// File: UMLActivityDiagram.java
// Classes: UMLActivityDiagram

package org.argouml.uml.diagram.activity.ui;

import java.beans.PropertyVetoException;

import javax.swing.Action;

import org.apache.log4j.Logger;

import org.argouml.kernel.ProjectManager;
import org.argouml.model.ModelFacade;
import org.argouml.ui.CmdCreateNode;
import org.argouml.ui.CmdSetMode;
import org.argouml.uml.diagram.activity.ActivityDiagramGraphModel;
import org.argouml.uml.diagram.state.ui.ActionCreatePseudostate;
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;

/**
 * Enabling an activity diagram connected to an actor has been
 * requested as a feature.

* * As well enabling swim lanes in the activity diagram is considered * valuable as well.

*/ public class UMLActivityDiagram extends UMLDiagram { private static final Logger LOG = Logger. getLogger(UMLActivityDiagram.class); //////////////// // actions for toolbar private Action actionState; private Action actionStartPseudoState; private Action actionFinalPseudoState; private Action actionJunctionPseudoState; private Action actionBranchPseudoState; private Action actionForkPseudoState; private Action actionJoinPseudoState; private Action actionTransition; // private Action actionNewSwimlane; private Action actionCallState; private Action actionObjectFlowState; private Action actionSubactivityState; //////////////////////////////////////////////////////////////// // contructors /** * The serial number for new activity diagrams. * Used to create an unique number for the name of the diagram. */ private static int activityDiagramSerial = 1; /** * Constructor */ public UMLActivityDiagram() { try { setName(getNewDiagramName()); } catch (PropertyVetoException pve) { } actionState = new RadioAction( new CmdCreateNode(ModelFacade.ACTION_STATE, "ActionState")); // start state, end state, forks, joins, etc. actionStartPseudoState = new RadioAction( new ActionCreatePseudostate(ModelFacade.INITIAL_PSEUDOSTATEKIND, "Initial")); actionFinalPseudoState = new RadioAction( new CmdCreateNode(ModelFacade.FINALSTATE, "FinalState")); actionJunctionPseudoState = new RadioAction( new ActionCreatePseudostate(ModelFacade.JUNCTION_PSEUDOSTATEKIND, "Junction")); actionForkPseudoState = new RadioAction( new ActionCreatePseudostate(ModelFacade.FORK_PSEUDOSTATEKIND, "Fork")); actionJoinPseudoState = new RadioAction( new ActionCreatePseudostate(ModelFacade.JOIN_PSEUDOSTATEKIND, "Join")); actionTransition = new RadioAction( new CmdSetMode( ModeCreatePolyEdge.class, "edgeClass", ModelFacade.TRANSITION, "Transition")); // actionNewSwimlane = new CmdCreateNode(ModelFacade.PARTITION, // "Create a new swimlane"); actionCallState = new RadioAction( new CmdCreateNode(ModelFacade.CALLSTATE, "CallState")); actionObjectFlowState = new RadioAction( new CmdCreateNode(ModelFacade.OBJECTFLOWSTATE, "ObjectFlowState")); actionSubactivityState = new RadioAction( new CmdCreateNode(ModelFacade.SUBACTIVITYSTATE, "SubactivityState")); } /** * @param m the namespace for the diagram */ public UMLActivityDiagram(Object m) { this(); setNamespace(m); Object context = ModelFacade.getContext(getStateMachine()); String name = null; if (context != null && ModelFacade.getName(context) != null && ModelFacade.getName(context).length() > 0) { name = ModelFacade.getName(context); try { setName(name); } catch (PropertyVetoException pve) { } } } /** * Constructor * @param namespace the namespace for the diagram * @param agraph the ActivityGraph for the diagram */ public UMLActivityDiagram(Object namespace, Object agraph) { this(); if (!ModelFacade.isANamespace(namespace) || !ModelFacade.isAActivityGraph(agraph)) throw new IllegalArgumentException(); if (namespace != null && ModelFacade.getName(namespace) != null) { String name = ModelFacade.getName(namespace) + " activity " + (ModelFacade.getBehaviors(namespace).size()); try { setName(name); } catch (PropertyVetoException pve) { } } if (namespace != null) setup(namespace, agraph); else throw new NullPointerException("Namespace may not be null"); } /** * @see org.tigris.gef.base.Diagram#initialize(java.lang.Object) */ public void initialize(Object o) { if (!(org.argouml.model.ModelFacade.isAActivityGraph(o))) return; Object context = ModelFacade.getContext(o); if (context != null && org.argouml.model.ModelFacade.isANamespace(context)) setup(context, o); else LOG.debug("ActivityGraph without context not yet possible :-("); } /** * Method to perform a number of important initializations of an * Activity Diagram.

* * Each diagram type has a similar UMLxxxDiagram class.

* * Changed lay from LayerPerspective to * LayerPerspectiveMutable. This class is a child of * LayerPerspective and was implemented to correct some * difficulties in changing the model. lay is used mainly * in LayerManager(GEF) to control the adding, changing and * deleting layers on the diagram... psager@tigris.org Jan. 24, * 2002 * @param m Namespace from the model * @param agraph ActivityGraph from the model */ public void setup(Object m, Object agraph) { if (!ModelFacade.isANamespace(m) || !ModelFacade.isAActivityGraph(agraph)) throw new IllegalArgumentException(); super.setNamespace(m); ActivityDiagramGraphModel gm = new ActivityDiagramGraphModel(); gm.setNamespace(m); if (agraph != null) { gm.setMachine(agraph); } LayerPerspective lay = new LayerPerspectiveMutable(ModelFacade.getName(m), gm); ActivityDiagramRenderer rend = new ActivityDiagramRenderer(); lay.setGraphNodeRenderer(rend); lay.setGraphEdgeRenderer(rend); setLayer(lay); } /** * @see org.argouml.uml.diagram.ui.UMLDiagram#getOwner() */ public Object getOwner() { ActivityDiagramGraphModel gm = (ActivityDiagramGraphModel) getGraphModel(); Object sm = gm.getMachine(); if (sm != null) return sm; return gm.getNamespace(); } /** * @return the statemachine */ public Object getStateMachine() { return ((ActivityDiagramGraphModel) getGraphModel()).getMachine(); } /** * @param sm set the statemachine for this diagram */ public void setStateMachine(Object sm) { if (!ModelFacade.isAStateMachine(sm)) throw new IllegalArgumentException(); ((ActivityDiagramGraphModel) getGraphModel()).setMachine(sm); } /** * Get the actions from which to create a toolbar or equivalent * graphic triggers. * * @see org.argouml.uml.diagram.ui.UMLDiagram#getUmlActions() */ protected Object[] getUmlActions() { Object actions[] = { actionState, actionTransition, null, actionStartPseudoState, actionFinalPseudoState, actionJunctionPseudoState, actionForkPseudoState, actionJoinPseudoState, //actionNewSwimlane, null, /*actionCallState,*/ // uncomment these ... actionObjectFlowState, /*actionSubactivityState,*/ /*getExtendedActions(),*/ }; return actions; } /*private Object[] getExtendedActions() { Object actions[] = { actionCallState, actionObjectFlowState, actionSubactivityState }; return actions; }*/ /** * Creates a new diagram name.

* * @return String */ protected static String getNewDiagramName() { String name = null; name = "Activity Diagram " + activityDiagramSerial; activityDiagramSerial++; if (!ProjectManager.getManager().getCurrentProject() .isValidDiagramName(name)) { name = getNewDiagramName(); } return name; } } /* end class UMLActivityDiagram */

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.