Source Code Cross Referenced for BaseGraphPanel.java in  » UML » MetaBoss » com » metaboss » applications » designstudio » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » MetaBoss » com.metaboss.applications.designstudio 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012:        // POSSIBILITY OF SUCH DAMAGE.
0013:        //
0014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015:        package com.metaboss.applications.designstudio;
0016:
0017:        import java.awt.BorderLayout;
0018:        import java.awt.Color;
0019:        import java.awt.Point;
0020:        import java.awt.Rectangle;
0021:        import java.awt.event.ActionEvent;
0022:        import java.awt.event.InputEvent;
0023:        import java.awt.event.KeyEvent;
0024:        import java.awt.event.MouseAdapter;
0025:        import java.awt.event.MouseEvent;
0026:        import java.awt.geom.Point2D;
0027:        import java.awt.geom.Rectangle2D;
0028:        import java.util.ArrayList;
0029:        import java.util.Hashtable;
0030:        import java.util.Map;
0031:
0032:        import javax.swing.AbstractButton;
0033:        import javax.swing.Action;
0034:        import javax.swing.ActionMap;
0035:        import javax.swing.ButtonGroup;
0036:        import javax.swing.ImageIcon;
0037:        import javax.swing.InputMap;
0038:        import javax.swing.JColorChooser;
0039:        import javax.swing.JComponent;
0040:        import javax.swing.JMenuItem;
0041:        import javax.swing.JOptionPane;
0042:        import javax.swing.JPopupMenu;
0043:        import javax.swing.JScrollPane;
0044:        import javax.swing.JTabbedPane;
0045:        import javax.swing.JToolBar;
0046:        import javax.swing.KeyStroke;
0047:        import javax.swing.ToolTipManager;
0048:
0049:        import org.jgraph.event.GraphModelEvent;
0050:        import org.jgraph.event.GraphModelListener;
0051:        import org.jgraph.event.GraphSelectionEvent;
0052:        import org.jgraph.event.GraphSelectionListener;
0053:        import org.jgraph.graph.CellHandle;
0054:        import org.jgraph.graph.CellView;
0055:        import org.jgraph.graph.DefaultEdge;
0056:        import org.jgraph.graph.DefaultGraphCell;
0057:        import org.jgraph.graph.DefaultGraphModel;
0058:        import org.jgraph.graph.DefaultGraphSelectionModel;
0059:        import org.jgraph.graph.EdgeView;
0060:        import org.jgraph.graph.GraphConstants;
0061:        import org.jgraph.graph.GraphContext;
0062:        import org.jgraph.graph.Port;
0063:
0064:        import com.metaboss.applications.designstudio.Application.ObjectChangedEvent;
0065:        import com.metaboss.applications.designstudio.Application.OnContainerChangedEvent;
0066:        import com.metaboss.applications.designstudio.Application.RefreshDiagramsEvent;
0067:        import com.metaboss.applications.designstudio.Application.RefreshEvent;
0068:        import com.metaboss.applications.designstudio.components.ContainerAction;
0069:        import com.metaboss.applications.designstudio.components.DesignEdgeView;
0070:        import com.metaboss.applications.designstudio.components.DesignGraph;
0071:        import com.metaboss.applications.designstudio.components.DockLayout;
0072:        import com.metaboss.applications.designstudio.components.EtchedToolBarBorder;
0073:        import com.metaboss.applications.designstudio.components.MarqueeHandler;
0074:        import com.metaboss.applications.designstudio.components.Rule;
0075:        import com.metaboss.applications.designstudio.components.SeparatorAction;
0076:        import com.metaboss.applications.designstudio.components.VertexCell;
0077:        import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
0078:        import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
0079:        import com.metaboss.sdlctools.models.metabossmodel.visualmodel.Diagram;
0080:        import com.metaboss.sdlctools.models.metabossmodel.visualmodel.DiagramModelElement;
0081:
0082:        /*		Base class for graph panels		*/
0083:
0084:        public class BaseGraphPanel extends BaseChildPanel {
0085:            public final static int NO_SELECTION = 0;
0086:            private static Object[] sCopyObjectsArray = null;
0087:
0088:            protected int mState = NO_SELECTION;
0089:            protected boolean mOldPortsVisible = false;
0090:            protected boolean mLoading = true;
0091:            //events lesteners
0092:            protected Application.RefreshListener mRefreshListener = null;
0093:            protected Application.ObjectChangedListener mObjectChangedListener = null;
0094:            protected Application.RefreshDiagramsEventListener mRefreshDiagramsEventListener = null;
0095:            protected Application.OnContainerChangedListener mOnContainerChangedListener = null;
0096:            protected SelectionListener mSelectionListener = new SelectionListener();
0097:            //UI
0098:            protected Diagram mDiagram = null;
0099:            protected DesignGraph mGraph = null;
0100:            protected BaseGraphModel mModel = null;
0101:            protected BorderLayout mLayout = null;
0102:            protected JScrollPane mPane = null;
0103:            protected Rule mColumnRule = null;
0104:            protected Rule mRowRule = null;
0105:            protected JToolBar mToolBar = new JToolBar();
0106:            protected ButtonGroup mButtonGroup = null;
0107:            protected BaseGraphDropTarget mDropTarget = null;
0108:            // actions
0109:            protected UnselectAction mUnselectAction = new UnselectAction();
0110:            protected BringToFrontAction mBringToFrontAction = new BringToFrontAction();
0111:            protected BringToBackAction mBringToBackAction = new BringToBackAction();
0112:            protected ActualSizeAction mActualSizeAction = new ActualSizeAction();
0113:            protected ZoomInAction mZoomInAction = new ZoomInAction();
0114:            protected ZoomOutAction mZoomOutAction = new ZoomOutAction();
0115:            protected ZoomToPageAction mZoomToPageAction = new ZoomToPageAction();
0116:            protected AlignToGridAction mAlignToGridAction = new AlignToGridAction();
0117:            protected AlignAllToGridAction mAlignAllToGridAction = new AlignAllToGridAction();
0118:            protected ViewEdgesCaptionsAction mViewEdgesCaptionsAction = new ViewEdgesCaptionsAction();
0119:            protected ViewEdgesCardinalityAction mViewEdgesCardinalityAction = new ViewEdgesCardinalityAction();
0120:            protected ViewEdgesEndsNamesAction mViewEdgesEndsNamesAction = new ViewEdgesEndsNamesAction();
0121:            protected ViewFieldsAction mViewFieldsAction = new ViewFieldsAction();
0122:            protected EditCellAction mEditCellAction = new EditCellAction();
0123:            protected DeleteCellAction mDeleteCellAction = new DeleteCellAction();
0124:            protected AddEdgePointAction mAddEdgePointAction = new AddEdgePointAction();
0125:            protected SetColorAction mSetColorAction = new SetColorAction();
0126:            protected CopyElementAction mCopyElementAction = new CopyElementAction();
0127:            protected PasteElementAction mPasteElementAction = new PasteElementAction();
0128:
0129:            public BaseGraphPanel(ModelElement pObject, Diagram pDiagram)
0130:                    throws Exception {
0131:                super (pObject);
0132:
0133:                setLayout(mLayout = new BorderLayout());
0134:
0135:                mDiagram = pDiagram;
0136:                mModel = createModel();
0137:                mGraph = createGraph();
0138:                mGraph.addMouseListener(new MouseHandler());
0139:                mGraph.setMarqueeHandler(new MarqueeHandler(this ));
0140:                mModel.mGraph = mGraph;
0141:
0142:                mPane = new JScrollPane(mGraph);
0143:                mPane.setBorder(null);
0144:
0145:                mColumnRule = new Rule(Rule.HORIZONTAL, true, mGraph);
0146:                mColumnRule.setFont(Application.DEFAULT_FONT_SMALL);
0147:                mRowRule = new Rule(Rule.VERTICAL, true, mGraph);
0148:                mRowRule.setFont(Application.DEFAULT_FONT_SMALL);
0149:
0150:                //mToolBar.setOrientation(JToolBar.VERTICAL);
0151:                mToolBar.setBorder(new EtchedToolBarBorder());
0152:                mToolBar.setRollover(true);
0153:
0154:                setLayout(new DockLayout());
0155:                add(mPane, BorderLayout.CENTER);
0156:                //add(mToolBar, BorderLayout.WEST);
0157:                add(mToolBar, BorderLayout.SOUTH);
0158:
0159:                ToolTipManager.sharedInstance().registerComponent(mGraph);
0160:                arrangeActions((DefaultGraphCell) mGraph.getSelectionCell());
0161:                mGraph.addGraphSelectionListener(mSelectionListener);
0162:
0163:                loadToolBar();
0164:                updateComponents();
0165:                addEventsListeners();
0166:
0167:                InputMap lMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0168:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "edit");
0169:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
0170:                        "delete");
0171:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
0172:                        "cancel");
0173:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C,
0174:                        InputEvent.CTRL_MASK), "copy");
0175:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V,
0176:                        InputEvent.CTRL_MASK), "paste");
0177:
0178:                ActionMap lActionMap = getActionMap();
0179:                lActionMap.put("cancel", mUnselectAction);
0180:                lActionMap.put("edit", mEditCellAction);
0181:                lActionMap.put("delete", mDeleteCellAction);
0182:                lActionMap.put("copy", mCopyElementAction);
0183:                lActionMap.put("paste", mPasteElementAction);
0184:
0185:                if (mModel != null) {
0186:                    mModel.setLoading(false);
0187:                    addModelListeners();
0188:                }
0189:
0190:                mDropTarget = new BaseGraphDropTarget(this );
0191:                mLoading = false;
0192:            }
0193:
0194:            // create graph
0195:            public DesignGraph createGraph() throws Exception {
0196:                return new DesignGraph(mModel);
0197:            }
0198:
0199:            public BaseGraphModel createModel() throws Exception {
0200:                return null;
0201:            }
0202:
0203:            public void reLoadModel() throws Exception {
0204:                mGraph.setSelectionModel(null);
0205:                try {
0206:                    mModel = createModel();
0207:                    mGraph.setModel(mModel);
0208:                    if (mModel != null) {
0209:                        mModel.setLoading(false);
0210:                        addModelListeners();
0211:                    }
0212:                } finally {
0213:                    mGraph.setSelectionModel(new DefaultGraphSelectionModel(
0214:                            mGraph));
0215:                }
0216:            }
0217:
0218:            public DesignGraph getGraph() {
0219:                return mGraph;
0220:            }
0221:
0222:            public DefaultGraphModel getModel() {
0223:                return mModel;
0224:            }
0225:
0226:            public int getState() {
0227:                return mState;
0228:            }
0229:
0230:            public boolean edgePending() {
0231:                return (mState > NO_SELECTION);
0232:            }
0233:
0234:            // connect Edges
0235:            public void connectEdges(Port pFrom, Port pTo) {
0236:                //??? 
0237:            }
0238:
0239:            // view PopUp menu
0240:            public void showPopUpMenuForCell(DefaultGraphCell pCell, int X,
0241:                    int Y) {
0242:                JPopupMenu lMenu = new JPopupMenu();
0243:                JMenuItem lItem = null;
0244:                Object[] lDiagramActions = getActions();
0245:
0246:                if (pCell == null)
0247:                    Application.fillActions(lDiagramActions, null, null, lMenu);
0248:                else if (pCell.getUserObject() instanceof  BaseUserObject) {
0249:                    ArrayList lActions = new ArrayList();
0250:                    SelectionUserObject lUserObject = new SelectionUserObject(
0251:                            (BaseUserObject) pCell.getUserObject());
0252:                    ContainerAction lActionContainer = new ContainerAction(
0253:                            "Action", lUserObject.getActions());
0254:
0255:                    for (int i = 0; i < lDiagramActions.length; i++)
0256:                        lActions.add(lDiagramActions[i]);
0257:                    lActions.add(lActionContainer);
0258:                    Application.fillActions(lActions.toArray(), null, null,
0259:                            lMenu);
0260:                }
0261:                lMenu.show(mGraph, X, Y);
0262:            }
0263:
0264:            // get Actions
0265:            /*public Object[] getActions()
0266:            {
0267:            	ArrayList lActionsList = new ArrayList();
0268:            	fillActions(lActionsList);
0269:            	return lActionsList.toArray();
0270:            }*/
0271:
0272:            // get ToolBar Actions
0273:            public Object[] getToolBarActions() {
0274:                ArrayList lActionsList = new ArrayList();
0275:                fillToolBarActions(lActionsList);
0276:                return lActionsList.toArray();
0277:            }
0278:
0279:            public void setVisible(boolean aFlag) {
0280:                if (!aFlag && aFlag != isVisible()) {
0281:                    //if (mModel!=null) mModel.savePositions();
0282:                    Application.fireOnContainerClose(this );
0283:                    //removeEventsListeners();	    
0284:                }
0285:                super .setVisible(aFlag);
0286:            }
0287:
0288:            // save content
0289:            public void saveContent() {
0290:                if (mModel != null)
0291:                    mModel.savePositions();
0292:                super .saveContent();
0293:            }
0294:
0295:            protected void fillToolBarActions(ArrayList pActionsList) {
0296:                mButtonGroup = new ButtonGroup();
0297:                pActionsList.add(mUnselectAction);
0298:                pActionsList.add(new SeparatorAction());
0299:            }
0300:
0301:            // arrange actions
0302:            protected void arrangeActions(DefaultGraphCell pCell) {
0303:                boolean lEnabled = false;
0304:                boolean lVertex = false;
0305:                boolean lEdge = false;
0306:                boolean lAddPoint = true;
0307:                boolean lPaste = false;
0308:
0309:                if (pCell != null && mGraph.isCellSelected(pCell)) {
0310:                    Object lObject = pCell.getUserObject();
0311:                    lEnabled = (lObject instanceof  BaseUserObject);
0312:                    lVertex = !(pCell instanceof  DefaultEdge);
0313:                    lEdge = (pCell instanceof  DefaultEdge);
0314:                    if (lEdge)
0315:                        lAddPoint = isAddPointEvent(pCell);
0316:                }
0317:                lPaste = isCopyElementExpected();
0318:
0319:                mAddEdgePointAction.setEnabled(lEdge);
0320:                mAddEdgePointAction.checkCaption(lAddPoint);
0321:
0322:                mBringToFrontAction.setEnabled(lEnabled);
0323:                mBringToBackAction.setEnabled(lEnabled);
0324:
0325:                mAlignToGridAction.setEnabled(lVertex);
0326:
0327:                mAlignAllToGridAction.setEnabled(true);
0328:                mActualSizeAction.setEnabled(true);
0329:                mZoomInAction.setEnabled(true);
0330:                mZoomOutAction.setEnabled(true);
0331:
0332:                mCopyElementAction.setEnabled(lEnabled);
0333:                mPasteElementAction.setEnabled(lPaste);
0334:
0335:                //???mViewFieldsAction.setEnabled(mHaveFields && ((DesignGraph)getGraph()).getShowClassVertex());
0336:                mViewEdgesCaptionsAction.setEnabled(true);
0337:                mSetColorAction.setEnabled(lVertex);
0338:            }
0339:
0340:            // fill actions list
0341:            protected void fillActions(ArrayList pActionList) {
0342:                if (pActionList == null)
0343:                    return;
0344:
0345:                ContainerAction lZoom = new ContainerAction("Zoom");
0346:                lZoom.addChildAction(mActualSizeAction);
0347:                lZoom.addChildAction(mZoomInAction);
0348:                lZoom.addChildAction(mZoomOutAction);
0349:                lZoom.addChildAction(mZoomToPageAction);
0350:
0351:                pActionList.add(mAddEdgePointAction);
0352:                pActionList.add(new SeparatorAction());
0353:                pActionList.add(mBringToFrontAction);
0354:                pActionList.add(mBringToBackAction);
0355:                pActionList.add(new SeparatorAction());
0356:                pActionList.add(mAlignToGridAction);
0357:                pActionList.add(mAlignAllToGridAction);
0358:                pActionList.add(new SeparatorAction());
0359:                pActionList.add(mCopyElementAction);
0360:                pActionList.add(mPasteElementAction);
0361:                pActionList.add(new SeparatorAction());
0362:                pActionList.add(lZoom);
0363:                pActionList.add(mSetColorAction);
0364:                pActionList.add(mViewEdgesCaptionsAction);
0365:                if (((DesignGraph) getGraph()).getVertexHaveFields()
0366:                        && ((DesignGraph) getGraph()).getShowClassVertex())
0367:                    pActionList.add(mViewFieldsAction);
0368:            }
0369:
0370:            // load toolbar
0371:            protected void loadToolBar() {
0372:                Object[] lActions = getToolBarActions();
0373:                Application.fillActions(lActions, mToolBar, null, null);
0374:            }
0375:
0376:            // called when properties were changed
0377:            protected void updateComponents() {
0378:                if (Application.properties.mShowRuler) {
0379:                    mPane.setColumnHeaderView(mColumnRule);
0380:                    mPane.setRowHeaderView(mRowRule);
0381:                } else {
0382:                    mPane.setColumnHeaderView(null);
0383:                    mPane.setRowHeaderView(null);
0384:                }
0385:                mGraph.loadGraphProperties();
0386:                mColumnRule.setGridStep(Application.properties.mGridSize);
0387:                mColumnRule.setMode(Application.properties.mRulerMode);
0388:                mRowRule.setGridStep(Application.properties.mGridSize);
0389:                mRowRule.setMode(Application.properties.mRulerMode);
0390:                mGraph.setGridSize((int) mColumnRule.getIncrement());
0391:
0392:                super .updateComponents();
0393:            }
0394:
0395:            // add application events listeners
0396:            protected void addEventsListeners() {
0397:                mRefreshListener = new Application.RefreshListener() {
0398:                    public void refresh(RefreshEvent event) {
0399:                        try {
0400:                            reLoadModel();
0401:                        } catch (Throwable t) {
0402:                            t.printStackTrace();
0403:                        }
0404:                    }
0405:                };
0406:                Application.addRefreshListener(mRefreshListener);
0407:
0408:                mObjectChangedListener = new Application.ObjectChangedListener() {
0409:                    public void onObjectChanged(ObjectChangedEvent event) {
0410:                        try {
0411:                            switch (event.getEventSource()) {
0412:                            //case ObjectChangedEvent.ET_INSERTED:
0413:                            //	if (isRightUserObject(event.getUserObject()))
0414:                            //		processObjectInserted(event.getUserObject());
0415:                            //	break;
0416:
0417:                            case ObjectChangedEvent.ET_EDITED:
0418:                                if (isRightUserObject(event.getUserObject()))
0419:                                    processObjectEdited(event.getUserObject());
0420:                                break;
0421:
0422:                            case ObjectChangedEvent.ET_DELETED:
0423:                                String lID = event.getObjectID();
0424:                                if (lID != null && getBOObject() != null
0425:                                        && getBOObject().refMofId().equals(lID))
0426:                                    break;
0427:                                processObjectDeleted(event);
0428:                                break;
0429:                            }
0430:                        } catch (Exception e) {
0431:                            e.printStackTrace();
0432:                        }
0433:                    }
0434:                };
0435:                Application.addObjectChanged(mObjectChangedListener);
0436:
0437:                mRefreshDiagramsEventListener = new Application.RefreshDiagramsEventListener() {
0438:                    public void refreshDiagram(RefreshDiagramsEvent event) {
0439:                        try {
0440:                            if (isRightUserObject(event.getUserObject()))
0441:                                processRefreshDiagramElement(
0442:                                        event.getDiagram(), event
0443:                                                .getUserObject());
0444:                        } catch (Exception e) {
0445:                            e.printStackTrace();
0446:                        }
0447:                    }
0448:                };
0449:                Application
0450:                        .addRefreshDiagramsListener(mRefreshDiagramsEventListener);
0451:
0452:                mOnContainerChangedListener = new Application.OnContainerChangedListener() {
0453:                    public void containerChanged(OnContainerChangedEvent event) {
0454:                        if (mGraph != null)
0455:                            arrangeActions((DefaultGraphCell) mGraph
0456:                                    .getSelectionCell());
0457:                    }
0458:                };
0459:                Application
0460:                        .addOnContainerChangedListener(mOnContainerChangedListener);
0461:            }
0462:
0463:            public boolean isRightUserObject(BaseUserObject pObject) {
0464:                return (pObject != null && mState == NO_SELECTION
0465:                        && pObject.getPackage() != null && pObject.getPackage()
0466:                        .equals(getPackage()));
0467:            }
0468:
0469:            // remove events listeners
0470:            public void removeEventsListeners() {
0471:                super .removeEventsListeners();
0472:
0473:                if (mRefreshListener != null)
0474:                    Application.removeRefreshListener(mRefreshListener);
0475:                if (mObjectChangedListener != null)
0476:                    Application.removeObjectChanged(mObjectChangedListener);
0477:                if (mRefreshDiagramsEventListener != null)
0478:                    Application
0479:                            .removeRefreshDiagramsListener(mRefreshDiagramsEventListener);
0480:                if (mOnContainerChangedListener != null)
0481:                    Application
0482:                            .removeOnContainerChangedListener(mOnContainerChangedListener);
0483:            }
0484:
0485:            // update all graph cells
0486:            public void updateAll() {
0487:                Object[] lCells = mGraph.getRoots();
0488:                Map lViewMap = new Hashtable();
0489:
0490:                for (int i = 0; i < lCells.length; i++) {
0491:                    DefaultGraphCell lCell = (DefaultGraphCell) lCells[i];
0492:                    lViewMap.put(lCell, lCell.getAttributes());
0493:                }
0494:                mGraph.getGraphLayoutCache().edit(lViewMap, null, null, null);
0495:            }
0496:
0497:            public void updateObject(BaseUserObject pObject) {
0498:                updateObject(pObject.getBOObject());
0499:            }
0500:
0501:            public void updateObject(ModelElement pElement) {
0502:                DefaultGraphCell lCell = mModel.findElementCell(pElement);
0503:                updateObject(lCell);
0504:            }
0505:
0506:            public void updateObject(DefaultGraphCell pCell) {
0507:                if (pCell != null) {
0508:                    Map lViewMap = new Hashtable();
0509:                    lViewMap.put(pCell, pCell.getAttributes());
0510:                    //mGraph.getGraphLayoutCache().edit(lViewMap, null, null, null);
0511:                    updateModel(lViewMap);
0512:                }
0513:            }
0514:
0515:            protected void addModelListeners() {
0516:                if (mModel == null)
0517:                    return;
0518:
0519:                mModel.addGraphModelListener(new GraphModelListener() {
0520:                    public void graphChanged(GraphModelEvent e) {
0521:                        if (mModel != null && !mLoading && !mModel.mLoading) {
0522:                            setChanged(true);
0523:                            Object[] pChanged = e.getChange().getChanged();
0524:                            for (int i = 0; i < pChanged.length; i++) {
0525:                                DefaultGraphCell lChangedObject = (DefaultGraphCell) pChanged[i];
0526:                                processCellChange(lChangedObject);
0527:                            }
0528:                        }
0529:                    }
0530:                });
0531:            }
0532:
0533:            // process cell change	
0534:            protected void processCellChange(DefaultGraphCell pCell) {
0535:                if (pCell != null && pCell instanceof  DefaultEdge) {
0536:                    mModel.removeTempVertexes();
0537:                }
0538:            }
0539:
0540:            protected void processObjectInserted(BaseUserObject pObject)
0541:                    throws Exception {
0542:                //???
0543:            }
0544:
0545:            protected void processObjectEdited(BaseUserObject pObject)
0546:                    throws Exception {
0547:                //updateAll();
0548:                updateObject(pObject);
0549:            }
0550:
0551:            protected void processObjectDeleted(ObjectChangedEvent event)
0552:                    throws Exception {
0553:                if (event == null)
0554:                    return;
0555:
0556:                BaseUserObject lObject = event.getUserObject();
0557:                String lID = event.getObjectID();
0558:
0559:                deleteObjectFormTheModel(lObject, lID);
0560:            }
0561:
0562:            protected void processRefreshDiagramElement(Diagram pDiagram,
0563:                    BaseUserObject pUserObject) throws Exception {
0564:                if (mDiagram != null && !mDiagram.equals(pDiagram))
0565:                    processObjectEdited(pUserObject);
0566:            }
0567:
0568:            // delete object from the model
0569:            protected void deleteObjectFormTheModel(BaseUserObject pObject,
0570:                    String pID) {
0571:                Object[] cells = null;
0572:                if (pObject != null) {
0573:                    if (isRightUserObject(pObject))
0574:                        cells = mModel.getUserObjectCells(pObject);
0575:                } else
0576:                    cells = mModel.getUserObjectCells(pID);
0577:
0578:                if (cells != null && cells.length > 0) {
0579:                    cells = mGraph.getDescendants(cells);
0580:                    if (cells != null && cells.length > 0)
0581:                        mGraph.getModel().remove(cells);
0582:                }
0583:
0584:                if (pObject != null) {
0585:                    ModelElement lBOObject = pObject.getBOObject();
0586:                    if (lBOObject != null) {
0587:                        DiagramModelElement lElement = mDiagram
0588:                                .findDiagramModelElement(lBOObject);
0589:                        if (lElement != null) {
0590:                            BaseUserObject lUserObject = new BaseUserObject(
0591:                                    lElement);
0592:                            if (lUserObject != null) {
0593:                                try {
0594:                                    lUserObject.deleteObject();
0595:                                } catch (Exception e) {
0596:                                    e.printStackTrace();
0597:                                }
0598:                            }
0599:                        }
0600:                    }
0601:                }
0602:                mModel.removeTempVertexes();
0603:            }
0604:
0605:            // Brings the Specified Cells to Front
0606:            protected void toFront(Object[] c) {
0607:                if (c != null && c.length > 0)
0608:                    if (mModel != null)
0609:                        mModel.toFront(c);
0610:            }
0611:
0612:            // Sends the Specified Cells to Back
0613:            protected void toBack(Object[] c) {
0614:                if (c != null && c.length > 0)
0615:                    if (mModel != null)
0616:                        mModel.toBack(c);
0617:            }
0618:
0619:            // zoom to Page
0620:            protected void zoomToPage() {
0621:                if (mModel == null)
0622:                    return;
0623:
0624:                Rectangle lGraphBounds = mPane.getBounds();
0625:                int lMaxX = 0;
0626:                int lMaxY = 0;
0627:
0628:                for (int i = 0; i < mModel.getRootCount(); i++) {
0629:                    DefaultGraphCell lCell = (DefaultGraphCell) mModel
0630:                            .getRootAt(i);
0631:                    Map lAttributes = lCell.getAttributes();
0632:                    Rectangle2D lBounds = GraphConstants.getBounds(lAttributes);
0633:                    if (lBounds.getX() + lBounds.getWidth() > lMaxX)
0634:                        lMaxX = (int) Math.round(lBounds.getX()
0635:                                + lBounds.getWidth());
0636:                    if (lBounds.getY() + lBounds.getHeight() > lMaxY)
0637:                        lMaxY = (int) Math.round(lBounds.getY()
0638:                                + lBounds.getHeight());
0639:                }
0640:                if (Application.properties.mShowRuler) {
0641:                    lGraphBounds.width -= 20;
0642:                    lGraphBounds.height -= 20;
0643:                }
0644:                lMaxX += 80;
0645:                lMaxY += 80;
0646:
0647:                double lXScale = lGraphBounds.getWidth() / lMaxX;
0648:                double lYScale = lGraphBounds.getHeight() / lMaxY;
0649:                double lScale = (lXScale < lYScale) ? lXScale : lYScale;
0650:                mGraph.setScale(lScale);
0651:            }
0652:
0653:            // align vertex to grid
0654:            protected void alignToGrid() {
0655:                boolean lGridEnabled = mGraph.isGridEnabled();
0656:                try {
0657:                    mGraph.setGridEnabled(true);
0658:
0659:                    Object[] lCells = mGraph.getSelectionCells();
0660:                    Map lViewMap = new Hashtable();
0661:
0662:                    for (int i = 0; i < lCells.length; i++) {
0663:                        alignCellToGrid((DefaultGraphCell) lCells[i], lViewMap);
0664:                    }
0665:                    mGraph.getGraphLayoutCache().edit(lViewMap, null, null,
0666:                            null);
0667:                } finally {
0668:                    mGraph.setGridEnabled(lGridEnabled);
0669:                }
0670:            }
0671:
0672:            // align all vertexes to the grid
0673:            protected void alignAllToGrid() {
0674:                boolean lGridEnabled = mGraph.isGridEnabled();
0675:                try {
0676:                    mGraph.setGridEnabled(true);
0677:
0678:                    Object[] lCells = mGraph.getRoots();
0679:                    Map lViewMap = new Hashtable();
0680:
0681:                    for (int i = 0; i < lCells.length; i++) {
0682:                        alignCellToGrid((DefaultGraphCell) lCells[i], lViewMap);
0683:                    }
0684:                    mGraph.getGraphLayoutCache().edit(lViewMap, null, null,
0685:                            null);
0686:                } finally {
0687:                    mGraph.setGridEnabled(lGridEnabled);
0688:                }
0689:            }
0690:
0691:            // align single cell to grid
0692:            protected void alignCellToGrid(DefaultGraphCell pCell, Map pVewMap) {
0693:                if (pCell == null || pVewMap == null)
0694:                    return;
0695:
0696:                if (!(pCell instanceof  DefaultEdge)) {
0697:                    Rectangle2D lRect = GraphConstants.getBounds(pCell
0698:                            .getAttributes());
0699:                    Point2D lPoint = mGraph.snap(GraphConstants.createPoint(
0700:                            lRect.getX(), lRect.getY()));
0701:                    Map lAttributes = GraphConstants.createMap();
0702:                    GraphConstants.setBounds(lAttributes, GraphConstants
0703:                            .createRect(lPoint));
0704:                    pVewMap.put(pCell, lAttributes);
0705:                }
0706:            }
0707:
0708:            // specify current model (if any) element selection
0709:            protected void setSelection(int pSelection) {
0710:                if (mState != pSelection) {
0711:                    mState = pSelection;
0712:                    AbstractButton lButton = (AbstractButton) mToolBar
0713:                            .getComponentAtIndex(0);
0714:                    if (mState == NO_SELECTION && lButton != null)
0715:                        lButton.doClick();
0716:
0717:                    if (edgePending()) {
0718:                        mOldPortsVisible = mGraph.isPortsVisible();
0719:                        mGraph.setPortsVisible(true);
0720:                    } else
0721:                        mGraph.setPortsVisible(mOldPortsVisible);
0722:                }
0723:            }
0724:
0725:            // process selection
0726:            protected boolean processSelection(int pSelection, int X, int Y) {
0727:                return false;
0728:            }
0729:
0730:            // get current user object
0731:            protected BaseUserObject getCurrentUserObject() {
0732:                DefaultGraphCell lCell = (DefaultGraphCell) mGraph
0733:                        .getSelectionCell();
0734:                if (lCell != null
0735:                        && lCell.getUserObject() instanceof  BaseUserObject)
0736:                    return (BaseUserObject) lCell.getUserObject();
0737:                else
0738:                    return null;
0739:            }
0740:
0741:            // edit current cell
0742:            protected void editCurrentCell() {
0743:                BaseUserObject lObject = getCurrentUserObject();
0744:                if (lObject != null && lObject.getEditAction() != null)
0745:                    lObject.getEditAction().run();
0746:            }
0747:
0748:            // delete current cell
0749:            protected void deleteCurrentCell() {
0750:                Object[] lSelectionCells = mGraph.getSelectionCells();
0751:                if (lSelectionCells != null && lSelectionCells.length > 0) {
0752:                    String lQuery = (lSelectionCells.length > 1) ? Application
0753:                            .getString("deletesetfromdiagram_query")
0754:                            : Application.getString("deletefromdiagram_query");
0755:                    int n = JOptionPane.showConfirmDialog(null, lQuery,
0756:                            "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
0757:                    switch (n) {
0758:                    case 0:
0759:                        deleteSelectionCells(lSelectionCells);
0760:                        break;
0761:                    case 1:
0762:                        removeSelectionCells(lSelectionCells);
0763:                        break;
0764:                    }
0765:                }
0766:
0767:                /*BaseUserObject lObject = getCurrentUserObject();
0768:                if (lObject!=null)
0769:                {
0770:                    int n = JOptionPane.showConfirmDialog(null,
0771:                            Application.getString("deletefromdiagram_query"), 
0772:                            "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
0773:                    switch (n)
0774:                    {
0775:                        case 0:
0776:                            if (lObject.getDeleteAction()!=null)
0777:                            {
0778:                                lObject.mConfirmDelete = false;
0779:                                try
0780:                                {
0781:                                    lObject.getDeleteAction().run();
0782:                                }
0783:                                finally
0784:                                {
0785:                                    lObject.mConfirmDelete = true;
0786:                                }
0787:                            }
0788:                            break;
0789:                        case 1:
0790:                            deleteObjectFormTheModel(lObject, null);
0791:                            break;
0792:                    }
0793:                }*/
0794:            }
0795:
0796:            // delete current cell from model
0797:            protected void deleteCurrentCellFromModel() {
0798:                Object[] lSelectionCells = mGraph.getSelectionCells();
0799:                if (lSelectionCells != null && lSelectionCells.length > 0) {
0800:                    String lQuery = (lSelectionCells.length > 1) ? Application
0801:                            .getString("deleteelements_query") : Application
0802:                            .getString("deleteelement_query");
0803:                    int n = JOptionPane.showConfirmDialog(null, lQuery,
0804:                            "Confirm", JOptionPane.YES_NO_OPTION);
0805:                    if (n == 0)
0806:                        removeSelectionCells(lSelectionCells);
0807:                }
0808:            }
0809:
0810:            // delete selection cells
0811:            protected void deleteSelectionCells(Object[] pSelectionsCells) {
0812:                if (pSelectionsCells == null)
0813:                    return;
0814:
0815:                mGraph.removeGraphSelectionListener(mSelectionListener);
0816:                try {
0817:                    mGraph.clearSelection();
0818:                    for (int i = 0; i < pSelectionsCells.length; i++) {
0819:                        Object lObject = pSelectionsCells[i];
0820:                        if (lObject != null
0821:                                && lObject instanceof  DefaultGraphCell) {
0822:                            DefaultGraphCell lCell = (DefaultGraphCell) lObject;
0823:                            Object lUserObject = lCell.getUserObject();
0824:                            if (lUserObject != null
0825:                                    && lUserObject instanceof  BaseUserObject) {
0826:                                BaseUserObject lBaseUserObject = (BaseUserObject) lUserObject;
0827:                                if (lBaseUserObject.getDeleteAction() != null) {
0828:                                    lBaseUserObject.mConfirmDelete = false;
0829:                                    try {
0830:                                        lBaseUserObject.getDeleteAction().run();
0831:                                    } finally {
0832:                                        lBaseUserObject.mConfirmDelete = true;
0833:                                    }
0834:                                }
0835:                            }
0836:                        }
0837:                    }
0838:                } finally {
0839:                    mGraph.addGraphSelectionListener(mSelectionListener);
0840:                }
0841:            }
0842:
0843:            // remove selection cells from diagram
0844:            protected void removeSelectionCells(Object[] pSelectionsCells) {
0845:                if (pSelectionsCells == null)
0846:                    return;
0847:
0848:                for (int i = 0; i < pSelectionsCells.length; i++) {
0849:                    Object lObject = pSelectionsCells[i];
0850:                    if (lObject != null && lObject instanceof  DefaultGraphCell) {
0851:                        DefaultGraphCell lCell = (DefaultGraphCell) lObject;
0852:                        Object lUserObject = lCell.getUserObject();
0853:                        if (lUserObject != null
0854:                                && lUserObject instanceof  BaseUserObject)
0855:                            deleteObjectFormTheModel(
0856:                                    (BaseUserObject) lUserObject, null);
0857:                    }
0858:                }
0859:            }
0860:
0861:            // add new point to the curretn adge
0862:            public void addNewPoint() {
0863:                DefaultGraphCell lCell = (DefaultGraphCell) mGraph
0864:                        .getSelectionCell();
0865:                if (lCell instanceof  DefaultEdge) {
0866:                    CellView lView = mGraph.getGraphLayoutCache().getMapping(
0867:                            lCell, false);
0868:                    if (lView != null && lView instanceof  DesignEdgeView) {
0869:                        CellHandle lHandle = lView.getHandle(new GraphContext(
0870:                                mGraph, mGraph.getSelectionCells()));
0871:                        if (lHandle != null
0872:                                && lHandle instanceof  EdgeView.EdgeHandle) {
0873:                            MarqueeHandler lMarqueeHandler = (MarqueeHandler) mGraph
0874:                                    .getMarqueeHandler();
0875:                            if (lMarqueeHandler != null
0876:                                    && lMarqueeHandler.getOldMouseEvent() != null) {
0877:                                ((EdgeView.EdgeHandle) lHandle)
0878:                                        .mousePressed(lMarqueeHandler
0879:                                                .getOldMouseEvent());
0880:                                ((EdgeView.EdgeHandle) lHandle)
0881:                                        .mouseReleased(lMarqueeHandler
0882:                                                .getOldMouseEvent());
0883:                                //???mGraph.getGraphLayoutCache().refresh(lView, false);
0884:                            }
0885:                        }
0886:                    }
0887:                }
0888:            }
0889:
0890:            protected boolean isAddPointEvent(DefaultGraphCell pCell) {
0891:                MarqueeHandler lMarqueeHandler = (MarqueeHandler) mGraph
0892:                        .getMarqueeHandler();
0893:                MouseEvent lEvent = lMarqueeHandler.getOldMouseEvent();
0894:                java.util.List lPoints = GraphConstants.getPoints(pCell
0895:                        .getAttributes());
0896:
0897:                if (lEvent != null) {
0898:                    int lHandleSize = mGraph.getHandleSize();
0899:                    for (int i = 0; i < lPoints.size(); i++) {
0900:                        Point2D lPoint = mGraph.toScreen(GraphConstants
0901:                                .createPoint((Point2D) lPoints.get(i)));
0902:                        Rectangle lRect = new Rectangle((int) lPoint.getX()
0903:                                - lHandleSize, (int) lPoint.getY()
0904:                                - lHandleSize, 2 * lHandleSize, 2 * lHandleSize);
0905:
0906:                        if (lRect.contains(lEvent.getX(), lEvent.getY()))
0907:                            return false;
0908:                    }
0909:                }
0910:                return true;
0911:            }
0912:
0913:            // specify vertex color
0914:            protected void setVertexColor() {
0915:                DefaultGraphCell lCell = (DefaultGraphCell) mGraph
0916:                        .getSelectionCell();
0917:                if (lCell != null) {
0918:                    Map lAttributes = lCell.getAttributes();
0919:                    Color lColor = GraphConstants.getBackground(lAttributes);
0920:                    Color lNewColor = JColorChooser.showDialog(this ,
0921:                            "Vertex Color", lColor);
0922:                    if (lNewColor != lColor && lNewColor != null) {
0923:                        GraphConstants.setBackground(lAttributes, lNewColor);
0924:                        Map lViewMap = new Hashtable();
0925:                        lViewMap.put(lCell, lAttributes);
0926:                        mGraph.getGraphLayoutCache().edit(lViewMap, null, null,
0927:                                null);
0928:                    }
0929:                }
0930:            }
0931:
0932:            // copy diagram element
0933:            public synchronized void copyElement() {
0934:                sCopyObjectsArray = null;
0935:                Object[] lSelectionCells = mGraph.getSelectionCells();
0936:                if (lSelectionCells != null && lSelectionCells.length > 0) {
0937:                    ArrayList lList = new ArrayList();
0938:                    for (int i = 0; i < lSelectionCells.length; i++) {
0939:                        Object lObject = lSelectionCells[i];
0940:                        if (lObject != null
0941:                                && lObject instanceof  DefaultGraphCell) {
0942:                            DefaultGraphCell lCell = (DefaultGraphCell) lObject;
0943:                            Object lUserObject = lCell.getUserObject();
0944:                            if (lUserObject != null
0945:                                    && lUserObject instanceof  BaseUserObject) {
0946:                                Point lCellPoint = null;
0947:                                if (lCell instanceof  VertexCell) {
0948:                                    Rectangle2D lBounds = (Rectangle2D) GraphConstants
0949:                                            .getBounds(lCell.getAttributes());
0950:                                    lCellPoint = new Point(
0951:                                            (int) lBounds.getX(), (int) lBounds
0952:                                                    .getY());
0953:                                }
0954:                                lList.add(new GraphElementCopyContainer(
0955:                                        (BaseUserObject) lUserObject,
0956:                                        lCellPoint));
0957:                            }
0958:                        }
0959:                    }
0960:                    if (lList.size() > 0) {
0961:                        sCopyObjectsArray = lList.toArray();
0962:                        arrangeActions((DefaultGraphCell) mGraph
0963:                                .getSelectionCell());
0964:                    }
0965:                }
0966:            }
0967:
0968:            // paste elements into the diagram
0969:            public synchronized void pasteElement() {
0970:                if (sCopyObjectsArray != null && sCopyObjectsArray.length > 0) {
0971:                    int lCount = pasteIteration();
0972:                    while (lCount > 0 && lCount < sCopyObjectsArray.length)
0973:                        lCount = pasteIteration();
0974:                }
0975:            }
0976:
0977:            // paste elements
0978:            public synchronized int pasteIteration() {
0979:                int lCount = 0;
0980:                if (sCopyObjectsArray != null && sCopyObjectsArray.length > 0) {
0981:                    for (int i = 0; i < sCopyObjectsArray.length; i++) {
0982:                        Object lObject = sCopyObjectsArray[i];
0983:                        if (lObject != null
0984:                                && lObject instanceof  GraphElementCopyContainer) {
0985:                            GraphElementCopyContainer lContainer = (GraphElementCopyContainer) lObject;
0986:                            if (isObjectExcepted(lContainer.mUserObject)) {
0987:                                dropObject(lContainer.mUserObject,
0988:                                        lContainer.mCellPosition);
0989:                                lCount++;
0990:                            }
0991:                        }
0992:                    }
0993:                }
0994:                return lCount;
0995:            }
0996:
0997:            // check is a object that could be copied in the copy array
0998:            public synchronized boolean isCopyElementExpected() {
0999:                if (sCopyObjectsArray != null && sCopyObjectsArray.length > 0) {
1000:                    for (int i = 0; i < sCopyObjectsArray.length; i++) {
1001:                        Object lObject = sCopyObjectsArray[i];
1002:                        if (lObject != null
1003:                                && lObject instanceof  GraphElementCopyContainer) {
1004:                            GraphElementCopyContainer lContainer = (GraphElementCopyContainer) lObject;
1005:                            if (isObjectExcepted(lContainer.mUserObject))
1006:                                return true;
1007:                        }
1008:                    }
1009:                }
1010:                return false;
1011:            }
1012:
1013:            // check object excepted by current diagram
1014:            public boolean isObjectExcepted(BaseUserObject pObject) {
1015:                return false;
1016:            }
1017:
1018:            // insert new object into the diagram
1019:            public void dropObject(BaseUserObject pObject, Point aLocation) {
1020:                //???
1021:            }
1022:
1023:            // update graph model
1024:            public void updateModel(Map pViewMap) {
1025:                if (mModel != null) {
1026:                    mModel.removeModelListener();
1027:                    try {
1028:                        getGraph().getGraphLayoutCache().edit(pViewMap, null,
1029:                                null, null);
1030:                    } finally {
1031:                        mModel.setModelListener();
1032:                    }
1033:                }
1034:            }
1035:
1036:            // method called when panel activated in the container window
1037:            public void containerActivate() {
1038:                if (mGraph != null)
1039:                    arrangeActions((DefaultGraphCell) mGraph.getSelectionCell());
1040:            }
1041:
1042:            /*		       Auxilary classes		              */
1043:
1044:            /*	        Define a Selection Listener           */
1045:
1046:            public class SelectionListener implements  GraphSelectionListener {
1047:                public void valueChanged(GraphSelectionEvent e) {
1048:                    //???System.out.println("Selection changed: " + e);
1049:                    //???DefaultGraphCell lCell = (DefaultGraphCell) e.getCell();
1050:                    DefaultGraphCell lCell = (DefaultGraphCell) mGraph
1051:                            .getSelectionCell();
1052:                    if (lCell != null) {
1053:                        Object lObject = lCell.getUserObject();
1054:                        if (lObject instanceof  BaseUserObject)
1055:                            //Application.fireObjectSelected((BaseUserObject)lObject);
1056:                            Application
1057:                                    .fireObjectSelected(new SelectionUserObject(
1058:                                            (BaseUserObject) lObject));
1059:                    }
1060:                    arrangeActions(lCell);
1061:                }
1062:            }
1063:
1064:            /*      Selection User Object        */
1065:
1066:            public class SelectionUserObject extends BaseUserObject {
1067:                protected BaseUserObject mUserObject = null;
1068:                protected DeleteElementFromDiagramAction mModelDeleteAction = new DeleteElementFromDiagramAction();
1069:
1070:                public SelectionUserObject(BaseUserObject pObject) {
1071:                    super (pObject.getBOObject());
1072:                    mUserObject = pObject;
1073:                }
1074:
1075:                // get object editor
1076:                public BasePropertiesDialog getObjectEditor() {
1077:                    return mUserObject.getObjectEditor();
1078:                }
1079:
1080:                // load object properties into grid control
1081:                public void loadObjectProperties(PropertiesTableModel pModel)
1082:                        throws Exception {
1083:                    mUserObject.loadObjectProperties(pModel);
1084:                }
1085:
1086:                // add extra properties tabs
1087:                public void addExtraPropertiesTabs(JTabbedPane pTabbedPane) {
1088:                    mUserObject.addExtraPropertiesTabs(pTabbedPane);
1089:                }
1090:
1091:                // fill actions list
1092:                public void fillActionsList(ArrayList pList) {
1093:                    mUserObject.fillActionsList(pList);
1094:                    int lIndex = pList.indexOf(mUserObject.getDeleteAction());
1095:                    if (lIndex > -1)
1096:                        pList.add(lIndex + 1, mModelDeleteAction);
1097:                    else
1098:                        pList.add(mModelDeleteAction);
1099:                }
1100:            }
1101:
1102:            /*		Graph Mouse Evemts Handler		*/
1103:
1104:            public class MouseHandler extends MouseAdapter {
1105:                public void mouseClicked(MouseEvent e) {
1106:                    if (mState != NO_SELECTION) {
1107:                        if (!processSelection(mState, e.getX(), e.getY()))
1108:                            Application
1109:                                    .showError("Operation wasn't yet implemented!");
1110:                        setSelection(NO_SELECTION);
1111:                    }
1112:                    super .mouseClicked(e);
1113:                }
1114:            }
1115:
1116:            /*      Graph Element Copy Container     */
1117:
1118:            public class GraphElementCopyContainer {
1119:                public BaseUserObject mUserObject = null;
1120:                public Point mCellPosition = null;
1121:
1122:                public GraphElementCopyContainer(BaseUserObject pUserObject,
1123:                        Point pCellPosition) {
1124:                    mUserObject = pUserObject;
1125:                    mCellPosition = pCellPosition;
1126:                }
1127:            }
1128:
1129:            /*		Actions		*/
1130:
1131:            /*		Bring To Front Action			*/
1132:
1133:            public class BringToFrontAction extends BaseAction {
1134:                public BringToFrontAction() {
1135:                    super ("To Front", Application.BRINGTOFRONT_ICON);
1136:                }
1137:
1138:                public void actionPerformed(ActionEvent e) {
1139:                    if (!mGraph.isSelectionEmpty())
1140:                        toFront(mGraph.getSelectionCells());
1141:                }
1142:            }
1143:
1144:            /*		Bring Back	Action	*/
1145:
1146:            public class BringToBackAction extends BaseAction {
1147:                public BringToBackAction() {
1148:                    super ("To Back", Application.BRINGTOBACK_ICON);
1149:                }
1150:
1151:                public void actionPerformed(ActionEvent e) {
1152:                    if (!mGraph.isSelectionEmpty())
1153:                        toBack(mGraph.getSelectionCells());
1154:                }
1155:            }
1156:
1157:            /*		Actual Size Action		*/
1158:
1159:            public class ActualSizeAction extends BaseAction {
1160:                public ActualSizeAction() {
1161:                    super ("Actual Size", Application.NORMALSIZE_ICON);
1162:                    mAddToToolBar = false;
1163:                }
1164:
1165:                public void actionPerformed(ActionEvent e) {
1166:                    mGraph.setScale(1.0);
1167:                }
1168:            }
1169:
1170:            /*		Zoom In Action		*/
1171:
1172:            public class ZoomInAction extends BaseAction {
1173:                public ZoomInAction() {
1174:                    super ("Zoom In", Application.ZOOMIN_ICON);
1175:                }
1176:
1177:                public void actionPerformed(ActionEvent e) {
1178:                    mGraph.setScale(2 * mGraph.getScale());
1179:                }
1180:            }
1181:
1182:            /*		Zoom Out Action		*/
1183:
1184:            public class ZoomOutAction extends BaseAction {
1185:                public ZoomOutAction() {
1186:                    super ("Zoom Out", Application.ZOOMOUT_ICON);
1187:                }
1188:
1189:                public void actionPerformed(ActionEvent e) {
1190:                    mGraph.setScale(mGraph.getScale() / 2);
1191:                }
1192:            }
1193:
1194:            /*		Zoom to Page Action				*/
1195:
1196:            public class ZoomToPageAction extends BaseAction {
1197:                public ZoomToPageAction() {
1198:                    super ("Zoom To Page", Application.FITTOSIZE_ICON);
1199:                    mAddToToolBar = false;
1200:                }
1201:
1202:                public void actionPerformed(ActionEvent arg0) {
1203:                    zoomToPage();
1204:                }
1205:            }
1206:
1207:            /*		Align To Grid Action				*/
1208:
1209:            public class AlignToGridAction extends BaseAction {
1210:                public AlignToGridAction() {
1211:                    super ("Align To Grid", Application.ALIGNTOGRID_ICON);
1212:                }
1213:
1214:                public void actionPerformed(ActionEvent arg0) {
1215:                    alignToGrid();
1216:                }
1217:            }
1218:
1219:            /*		Align All To Grid Action		*/
1220:
1221:            public class AlignAllToGridAction extends BaseAction {
1222:                public AlignAllToGridAction() {
1223:                    super ("Align All To Grid", null);
1224:                    mAddToToolBar = false;
1225:                }
1226:
1227:                public void actionPerformed(ActionEvent arg0) {
1228:                    alignAllToGrid();
1229:                }
1230:            }
1231:
1232:            /*      View Edges Captions Action     */
1233:
1234:            public class ViewEdgesCaptionsAction extends BaseAction {
1235:                public ViewEdgesCaptionsAction() {
1236:                    super ("View Edges Captions", null);
1237:                    mAddToToolBar = false;
1238:                    mIsCheck = true;
1239:                    mIsChecked = Application.properties.mShowEdgesLabels;
1240:                }
1241:
1242:                public void actionPerformed(ActionEvent arg0) {
1243:                    super .actionPerformed(arg0);
1244:                    mGraph.setShowEdgesLabels(isChecked());
1245:                }
1246:            }
1247:
1248:            /*      View Edges Cardinality Action     */
1249:
1250:            public class ViewEdgesCardinalityAction extends BaseAction {
1251:                public ViewEdgesCardinalityAction() {
1252:                    super ("View Edges Cardinality", null);
1253:                    mAddToToolBar = false;
1254:                    mIsCheck = true;
1255:                    mIsChecked = Application.properties.mShowEdgesCardinality;
1256:                }
1257:
1258:                public void actionPerformed(ActionEvent arg0) {
1259:                    super .actionPerformed(arg0);
1260:                    mGraph.setShowEdgesCardinalities(isChecked());
1261:                }
1262:            }
1263:
1264:            /*      View Ends Names Action     */
1265:
1266:            public class ViewEdgesEndsNamesAction extends BaseAction {
1267:                public ViewEdgesEndsNamesAction() {
1268:                    super ("View Edges Ends Names", null);
1269:                    mAddToToolBar = false;
1270:                    mIsCheck = true;
1271:                    mIsChecked = Application.properties.mShowEdgesEndsNames;
1272:                }
1273:
1274:                public void actionPerformed(ActionEvent arg0) {
1275:                    super .actionPerformed(arg0);
1276:                    mGraph.setShowEdgesEndsNames(isChecked());
1277:                }
1278:            }
1279:
1280:            /*      	View Vertex Fields Action     		*/
1281:
1282:            public class ViewFieldsAction extends BaseAction {
1283:                public ViewFieldsAction() {
1284:                    super ("View Fields", null);
1285:                    mAddToToolBar = false;
1286:                    mIsCheck = true;
1287:                    mIsChecked = true;
1288:                }
1289:
1290:                public void actionPerformed(ActionEvent arg0) {
1291:                    super .actionPerformed(arg0);
1292:                    mGraph.setShowVertexFields(isChecked());
1293:                }
1294:            }
1295:
1296:            /*		Add Edge Point		*/
1297:
1298:            public class AddEdgePointAction extends BaseAction {
1299:                public AddEdgePointAction() {
1300:                    super ("Add Point", null);
1301:                    mAddToToolBar = false;
1302:                    mAddToMenu = false;
1303:                }
1304:
1305:                public void actionPerformed(ActionEvent arg0) {
1306:                    addNewPoint();
1307:                }
1308:
1309:                public void checkCaption(boolean pAddPoint) {
1310:                    String lCaption = (pAddPoint) ? "Add Point"
1311:                            : "Remove Point";
1312:                    putValue(Action.NAME, lCaption);
1313:                    putValue(Action.SHORT_DESCRIPTION, lCaption);
1314:                }
1315:            }
1316:
1317:            /*		Edit Cell Action Class		*/
1318:
1319:            public class EditCellAction extends BaseAction {
1320:                public EditCellAction() {
1321:                    super ("Edit current cell", null);
1322:                }
1323:
1324:                public void actionPerformed(ActionEvent arg0) {
1325:                    editCurrentCell();
1326:                }
1327:            }
1328:
1329:            /*		Delete Cell Action Class	*/
1330:
1331:            public class DeleteCellAction extends BaseAction {
1332:                public DeleteCellAction() {
1333:                    super ("Delete current cell", null);
1334:                }
1335:
1336:                public void actionPerformed(ActionEvent arg0) {
1337:                    deleteCurrentCell();
1338:                }
1339:            }
1340:
1341:            /*      Delte element form diagram action        */
1342:
1343:            public class DeleteElementFromDiagramAction extends BaseAction {
1344:                public DeleteElementFromDiagramAction() {
1345:                    super (Application.getString("deletefromdigram_action"),
1346:                            Application.DELETEFROMMODEL_ICON);
1347:                }
1348:
1349:                public void actionPerformed(ActionEvent arg0) {
1350:                    deleteCurrentCellFromModel();
1351:                }
1352:            }
1353:
1354:            /*		Set Color		*/
1355:
1356:            public class SetColorAction extends BaseAction {
1357:                public SetColorAction() {
1358:                    super ("Color", null);
1359:                }
1360:
1361:                public void actionPerformed(ActionEvent arg0) {
1362:                    setVertexColor();
1363:                }
1364:            }
1365:
1366:            /*      Copy Element Action     */
1367:
1368:            public class CopyElementAction extends BaseAction {
1369:                public CopyElementAction() {
1370:                    super ("Copy", Application.COPYTOCLIP_ICON);
1371:                }
1372:
1373:                public void actionPerformed(ActionEvent arg0) {
1374:                    copyElement();
1375:                }
1376:            }
1377:
1378:            /*      Paste Element Action     */
1379:
1380:            public class PasteElementAction extends BaseAction {
1381:                public PasteElementAction() {
1382:                    super ("Paste", Application.PASTE_ICON);
1383:                }
1384:
1385:                public void actionPerformed(ActionEvent arg0) {
1386:                    pasteElement();
1387:                }
1388:            }
1389:
1390:            /*		Base selecion Action class		*/
1391:
1392:            public class BaseSelectionAction extends BaseAction {
1393:                int mActionCode = NO_SELECTION;
1394:
1395:                public BaseSelectionAction(int pActionCode, String pCaption,
1396:                        ImageIcon pIcon) {
1397:                    super (pCaption, pIcon);
1398:                    mActionCode = pActionCode;
1399:                    mIsCheck = true;
1400:                }
1401:
1402:                public void actionPerformed(ActionEvent e) {
1403:                    setSelection(mActionCode);
1404:                }
1405:
1406:                public ButtonGroup getButtonGroup() {
1407:                    return mButtonGroup;
1408:                }
1409:            }
1410:
1411:            /*		Unselect Action		*/
1412:
1413:            public class UnselectAction extends BaseSelectionAction {
1414:                public UnselectAction() {
1415:                    super (NO_SELECTION, "Unselect", Application.UNSELECT_ICON);
1416:                }
1417:            }
1418:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.