Source Code Cross Referenced for ProcessApplet.java in  » Web-Framework » argun » biz » hammurapi » web » process » 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 » Web Framework » argun » biz.hammurapi.web.process 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Process editor applet. 
0003:         * Based on GraphEd from JGraph.
0004:         * 
0005:         * @(#)GraphEd.java 3.3 23-APR-04
0006:         * 
0007:         * Copyright (c) 2001-2004, Gaudenz Alder All rights reserved.
0008:         * 
0009:         * This library is free software; you can redistribute it and/or
0010:         * modify it under the terms of the GNU Lesser General Public
0011:         * License as published by the Free Software Foundation; either
0012:         * version 2.1 of the License, or (at your option) any later version.
0013:         *
0014:         * This library is distributed in the hope that it will be useful,
0015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017:         * Lesser General Public License for more details.
0018:         *
0019:         * You should have received a copy of the GNU Lesser General Public
0020:         * License along with this library; if not, write to the Free Software
0021:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0022:         *  
0023:         */
0024:        package biz.hammurapi.web.process;
0025:
0026:        import java.awt.BorderLayout;
0027:        import java.awt.Color;
0028:        import java.awt.Container;
0029:        import java.awt.Cursor;
0030:        import java.awt.Font;
0031:        import java.awt.Graphics;
0032:        import java.awt.Point;
0033:        import java.awt.event.ActionEvent;
0034:        import java.awt.event.KeyEvent;
0035:        import java.awt.event.KeyListener;
0036:        import java.awt.event.MouseEvent;
0037:        import java.awt.geom.Point2D;
0038:        import java.awt.geom.Rectangle2D;
0039:        import java.awt.image.BufferedImage;
0040:        import java.io.ByteArrayInputStream;
0041:        import java.io.ByteArrayOutputStream;
0042:        import java.io.ObjectInputStream;
0043:        import java.io.ObjectOutputStream;
0044:        import java.net.MalformedURLException;
0045:        import java.net.URL;
0046:        import java.util.ArrayList;
0047:        import java.util.Date;
0048:        import java.util.Hashtable;
0049:        import java.util.List;
0050:        import java.util.Map;
0051:        import java.util.zip.GZIPOutputStream;
0052:
0053:        import javax.imageio.ImageIO;
0054:        import javax.swing.AbstractAction;
0055:        import javax.swing.Action;
0056:        import javax.swing.BorderFactory;
0057:        import javax.swing.ImageIcon;
0058:        import javax.swing.JApplet;
0059:        import javax.swing.JFrame;
0060:        import javax.swing.JLabel;
0061:        import javax.swing.JOptionPane;
0062:        import javax.swing.JPanel;
0063:        import javax.swing.JPopupMenu;
0064:        import javax.swing.JScrollPane;
0065:        import javax.swing.JToolBar;
0066:        import javax.swing.SwingConstants;
0067:        import javax.swing.SwingUtilities;
0068:        import javax.swing.event.UndoableEditEvent;
0069:
0070:        import org.apache.commons.httpclient.HttpClient;
0071:        import org.apache.commons.httpclient.HttpMethod;
0072:        import org.apache.commons.httpclient.HttpStatus;
0073:        import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
0074:        import org.apache.commons.httpclient.methods.GetMethod;
0075:        import org.apache.commons.httpclient.methods.PostMethod;
0076:        import org.jgraph.JGraph;
0077:        import org.jgraph.event.GraphModelEvent;
0078:        import org.jgraph.event.GraphModelListener;
0079:        import org.jgraph.event.GraphSelectionEvent;
0080:        import org.jgraph.event.GraphSelectionListener;
0081:        import org.jgraph.graph.BasicMarqueeHandler;
0082:        import org.jgraph.graph.CellHandle;
0083:        import org.jgraph.graph.CellView;
0084:        import org.jgraph.graph.EdgeView;
0085:        import org.jgraph.graph.GraphConstants;
0086:        import org.jgraph.graph.GraphContext;
0087:        import org.jgraph.graph.GraphLayoutCache;
0088:        import org.jgraph.graph.GraphModel;
0089:        import org.jgraph.graph.GraphUndoManager;
0090:        import org.jgraph.graph.Port;
0091:        import org.jgraph.graph.PortView;
0092:
0093:        import biz.hammurapi.util.Attributable;
0094:
0095:        public class ProcessApplet extends JApplet implements 
0096:                GraphSelectionListener, KeyListener {
0097:
0098:            private String processDownloadUrl;
0099:            private String processUploadUrl = "bred sobachii";
0100:            private String exitUrl;
0101:            private String cookie;
0102:
0103:            // JGraph instance
0104:            protected JGraph graph;
0105:
0106:            // Undo Manager
0107:            protected GraphUndoManager undoManager;
0108:
0109:            // Actions which Change State
0110:            //	protected Action undo;
0111:            //	protected Action redo; 
0112:            protected Action delete;
0113:            //	protected Action group; 
0114:            //	protected Action ungroup; 
0115:            //	protected Action tofront; 
0116:            //	protected Action toback;
0117:            //	protected Action cut;
0118:            //	protected Action copy; 
0119:            //	protected Action paste;
0120:            private Action saveAction;
0121:            private Action saveAndCloseAction;
0122:
0123:            // Status Bar
0124:            protected EdStatusBar statusBar;
0125:
0126:            private Process process;
0127:
0128:            //
0129:            // Main
0130:            //
0131:
0132:            // Main Method
0133:            public static void main(String[] args) {
0134:                // Construct Frame
0135:                JFrame frame = new JFrame("Process editor");
0136:                ProcessApplet processApplet = new ProcessApplet();
0137:                processApplet.start();
0138:                // Set Close Operation to Exit
0139:                // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
0140:                // Add an Editor Panel
0141:                frame.getContentPane().add(processApplet);
0142:                // Fetch URL to Icon Resource
0143:                URL jgraphUrl = ProcessApplet.class
0144:                        .getClassLoader()
0145:                        .getResource(
0146:                                "biz/hammurapi/web/interaction/resources/jgraph.gif");
0147:                // If Valid URL
0148:                if (jgraphUrl != null) {
0149:                    // Load Icon
0150:                    ImageIcon jgraphIcon = new ImageIcon(jgraphUrl);
0151:                    // Use in Window
0152:                    frame.setIconImage(jgraphIcon.getImage());
0153:                }
0154:                // Set Default Size
0155:                frame.setSize(520, 390);
0156:                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
0157:                // Show Frame
0158:                frame.setVisible(true);
0159:            }
0160:
0161:            //
0162:            // Editor Panel
0163:            //
0164:
0165:            // Construct an Editor Panel
0166:            public ProcessApplet() {
0167:                // Construct the Graph
0168:                ProcessModel theModel = new ProcessModel();
0169:                graph = new MyGraph(theModel);
0170:                graph
0171:                        .getGraphLayoutCache()
0172:                        .setFactory(
0173:                                new biz.hammurapi.web.interaction.ArgunCellViewFactory() {
0174:
0175:                                    // Override Superclass Method to Return Custom EdgeView
0176:                                    protected EdgeView createEdgeView(
0177:                                            Object cell) {
0178:
0179:                                        // Return Custom EdgeView
0180:                                        return new EdgeView(cell) {
0181:
0182:                                            /**
0183:                                             * Returns a cell handle for the view.
0184:                                             */
0185:                                            public CellHandle getHandle(
0186:                                                    GraphContext context) {
0187:                                                return new MyEdgeHandle(this ,
0188:                                                        context);
0189:                                            }
0190:
0191:                                        };
0192:                                    }
0193:                                });
0194:
0195:                // Use a Custom Marquee Handler
0196:                graph.setMarqueeHandler(new MyMarqueeHandler());
0197:                // Construct Command History
0198:                //
0199:                // Create a GraphUndoManager which also Updates the ToolBar
0200:                undoManager = new GraphUndoManager() {
0201:                    // Override Superclass
0202:                    public void undoableEditHappened(UndoableEditEvent e) {
0203:                        // First Invoke Superclass
0204:                        super .undoableEditHappened(e);
0205:                        // Then Update Undo/Redo Buttons
0206:                        updateHistoryButtons();
0207:                    }
0208:                };
0209:                // Use Border Layout
0210:                getContentPane().setLayout(new BorderLayout());
0211:                // Add a ToolBar
0212:                getContentPane().add(createToolBar(), BorderLayout.NORTH);
0213:                // Add the Graph as Center Component
0214:                getContentPane().add(new JScrollPane(graph),
0215:                        BorderLayout.CENTER);
0216:                statusBar = new EdStatusBar();
0217:                getContentPane().add(statusBar, BorderLayout.SOUTH);
0218:
0219:                /**********************************************************************
0220:                 * GraphModelChange explaination
0221:                 *********************************************************************/
0222:                // Uncomment out the code below if you want to see the model change outputs
0223:                // the new attributes are obtained from getPreviousAttributes(). The 
0224:                // mode change is the undo edit of the change. That is, if you undo, 
0225:                // that change edit is executed directly. So the previous attributes 
0226:                // are the attributes before the undo and the attributes are the 
0227:                // attributes after the undo. But when listening to a change,
0228:                // getPreviousAttributes() returns the new attributes and
0229:                // getAttributes() the old attributes.
0230:                //        graph.getModel().addGraphModelListener(new GraphModelListener() {
0231:                //            public void graphChanged(GraphModelEvent e) {
0232:                //                GraphModelEvent.GraphModelChange c = e.getChange();
0233:                //                if (c.getRemoved() == null && c.getInserted() == null) {
0234:                //                	Map previousAttributes = c.getPreviousAttributes();
0235:                //                	Set keySet = previousAttributes.keySet();
0236:                //                	Iterator iter = keySet.iterator();
0237:                //                    while (iter.hasNext()) {
0238:                //                    	Object attribute = iter.next();
0239:                //                        System.out.println("Prev Key " + String.valueOf(attribute));
0240:                //                        Object value = c.getPreviousAttributes().get(attribute);
0241:                //                        System.out.println("\t" + String.valueOf(value));
0242:                //                    }
0243:                //                    Map attributes = c.getAttributes();
0244:                //                    keySet = attributes.keySet();
0245:                //                    iter = keySet.iterator();
0246:                //                    while (iter.hasNext()) {
0247:                //                    	Object attribute = iter.next();
0248:                //                        System.out.println("Curr Key " + String.valueOf(attribute));
0249:                //                        Object value = c.getAttributes().get(attribute);
0250:                //                        System.out.println("\t" + String.valueOf(value));
0251:                //                    }
0252:                //                    System.out.println("\n\n");
0253:                //                }     
0254:                //            }
0255:                //        });
0256:                // Add Listeners to Graph
0257:                //
0258:                // Register UndoManager with the Model
0259:                graph.getModel().addUndoableEditListener(undoManager);
0260:                // Update ToolBar based on Selection Changes
0261:                graph.getSelectionModel().addGraphSelectionListener(this );
0262:                // Listen for Delete Keystroke when the Graph has Focus
0263:                graph.addKeyListener(this );
0264:                graph.getModel().addGraphModelListener(statusBar);
0265:
0266:                graph.setAntiAliased(true);
0267:            }
0268:
0269:            // Hook for subclassers
0270:            protected void uninstallListeners(JGraph graph) {
0271:                graph.getModel().removeUndoableEditListener(undoManager);
0272:                graph.getSelectionModel().removeGraphSelectionListener(this );
0273:                graph.removeKeyListener(this );
0274:                graph.getModel().removeGraphModelListener(statusBar);
0275:            }
0276:
0277:            // Insert a new Vertex at point
0278:            public void insert(Point2D point) {
0279:                insert(point, process.createTask());
0280:            }
0281:
0282:            public void insert(Point2D point, Task task) {
0283:                // Add input and output ports
0284:                task.addPort(process.getIsVertical() ? new Point2D.Double(
0285:                        GraphConstants.PERMILLE / 2, 0) : new Point2D.Double(0,
0286:                        GraphConstants.PERMILLE / 2));
0287:                task.addPort(process.getIsVertical() ? new Point2D.Double(
0288:                        GraphConstants.PERMILLE / 2, GraphConstants.PERMILLE)
0289:                        : new Point2D.Double(GraphConstants.PERMILLE,
0290:                                GraphConstants.PERMILLE / 2));
0291:
0292:                // Create a Map that holds the attributes for the Vertex
0293:                Map cellAttributes = new Hashtable();
0294:                // Snap the Point to the Grid
0295:                point = graph.snap((Point2D) point.clone());
0296:
0297:                // Add a Bounds Attribute to the Map
0298:                GraphConstants.setBounds(cellAttributes,
0299:                        new Rectangle2D.Double(point.getX(), point.getY(), 40,
0300:                                20));
0301:
0302:                // Make sure the cell is resized on insert
0303:                // Add a nice looking gradient background
0304:                GraphConstants.setGradientColor(cellAttributes, new Color(200,
0305:                        200, 225));
0306:                // Add a Border Color Attribute to the Map
0307:                GraphConstants.setBorderColor(cellAttributes, Color.BLACK);
0308:                //GraphConstants.setBorder(cellAttributes, BorderFactory.createLineBorder(Color.RED, 3));
0309:
0310:                // Add a White Background
0311:                GraphConstants.setBackground(cellAttributes, new Color(220,
0312:                        220, 255));
0313:                // Make Vertex Opaque
0314:                GraphConstants.setOpaque(cellAttributes, true);
0315:
0316:                //GraphConstants.setConstrained(map, true);
0317:                GraphConstants.setAutoSize(cellAttributes, true);
0318:                //GraphConstants.setResize(cellAttributes, true);
0319:
0320:                GraphConstants.setInset(cellAttributes, 5);
0321:                GraphConstants.setHorizontalAlignment(cellAttributes,
0322:                        SwingConstants.CENTER);
0323:
0324:                Font font = GraphConstants.DEFAULTFONT;
0325:                GraphConstants.setFont(cellAttributes, font.deriveFont(
0326:                        Font.PLAIN, 10));
0327:
0328:                //GraphConstants.setBeginSize(cellAttributes, 5);
0329:
0330:                task.getAttributes().applyMap(cellAttributes);
0331:                // Insert the Vertex (including child port and attributes)
0332:                graph.getGraphLayoutCache().insert(task);
0333:            }
0334:
0335:            // Insert a new Edge between source and target
0336:            public void connect(Port source, Port target) {
0337:                connect(process.createTransition(), source, target, null);
0338:            }
0339:
0340:            public void connect(Transition edge, Port source, Port target,
0341:                    List points) {
0342:                if (graph.getModel().acceptsSource(edge, source)
0343:                        && graph.getModel().acceptsTarget(edge, target)) {
0344:                    // Create a Map thath holds the attributes for the edge
0345:                    Map edgeAttributes = new Hashtable();
0346:                    // Add a Line End Attribute
0347:                    GraphConstants.setLineEnd(edgeAttributes,
0348:                            GraphConstants.ARROW_SIMPLE);
0349:                    // Add a label along edge attribute
0350:                    GraphConstants.setLabelAlongEdge(edgeAttributes, true);
0351:                    GraphConstants.setBendable(edgeAttributes, true);
0352:                    GraphConstants.setLineWidth(edgeAttributes, 2);
0353:                    //GraphConstants.setLineStyle(edgeAttributes, GraphConstants.STYLE_SPLINE);
0354:                    GraphConstants.setDisconnectable(edgeAttributes, true);
0355:
0356:                    edge.getAttributes().applyMap(edgeAttributes);
0357:                    // Insert the Edge and its Attributes			
0358:                    graph.getGraphLayoutCache()
0359:                            .insertEdge(edge, source, target);
0360:
0361:                    if (points != null) {
0362:                        List allPoints = new ArrayList();
0363:                        allPoints.add(source);
0364:                        allPoints.addAll(points);
0365:                        allPoints.add(target);
0366:                        Map newAttributes = new Hashtable();
0367:                        GraphConstants.setPoints(newAttributes, allPoints);
0368:                        //				edge.getAttributes().applyMap(newAttributes);
0369:                        //				graph.getGraphLayoutCache().reload();
0370:                        graph.getGraphLayoutCache().editCell(edge,
0371:                                newAttributes);
0372:                    }
0373:                } else {
0374:                    process.removeTransition(edge);
0375:                }
0376:                graph.repaint();
0377:            }
0378:
0379:            //	// Ungroup the Groups in Cells and Select the Children
0380:            //	public void ungroup(Object[] cells) {
0381:            //		graph.getGraphLayoutCache().ungroup(cells);
0382:            //	}
0383:
0384:            // Determines if a Cell is a Group
0385:            public boolean isGroup(Object cell) {
0386:                // Map the Cell to its View
0387:                CellView view = graph.getGraphLayoutCache().getMapping(cell,
0388:                        false);
0389:                if (view != null)
0390:                    return !view.isLeaf();
0391:                return false;
0392:            }
0393:
0394:            // Brings the Specified Cells to Front
0395:            public void toFront(Object[] c) {
0396:                graph.getGraphLayoutCache().toFront(c);
0397:            }
0398:
0399:            // Sends the Specified Cells to Back
0400:            public void toBack(Object[] c) {
0401:                graph.getGraphLayoutCache().toBack(c);
0402:            }
0403:
0404:            // Undo the last Change to the Model or the View
0405:            public void undo() {
0406:                try {
0407:                    undoManager.undo(graph.getGraphLayoutCache());
0408:                } catch (Exception ex) {
0409:                    System.err.println(ex);
0410:                } finally {
0411:                    updateHistoryButtons();
0412:                }
0413:            }
0414:
0415:            // Redo the last Change to the Model or the View
0416:            public void redo() {
0417:                try {
0418:                    undoManager.redo(graph.getGraphLayoutCache());
0419:                } catch (Exception ex) {
0420:                    System.err.println(ex);
0421:                } finally {
0422:                    updateHistoryButtons();
0423:                }
0424:            }
0425:
0426:            // Update Undo/Redo Button State based on Undo Manager
0427:            protected void updateHistoryButtons() {
0428:                // The View Argument Defines the Context
0429:                //		undo.setEnabled(undoManager.canUndo(graph.getGraphLayoutCache()));
0430:                //		redo.setEnabled(undoManager.canRedo(graph.getGraphLayoutCache()));
0431:            }
0432:
0433:            //
0434:            // Listeners
0435:            //
0436:
0437:            // From GraphSelectionListener Interface
0438:            public void valueChanged(GraphSelectionEvent e) {
0439:                // Group Button only Enabled if more than One Cell Selected
0440:                //		group.setEnabled(graph.getSelectionCount() > 1);
0441:                // Update Button States based on Current Selection
0442:                boolean enabled = !graph.isSelectionEmpty();
0443:                delete.setEnabled(enabled);
0444:                //		ungroup.setEnabled(enabled);
0445:                //		tofront.setEnabled(enabled);
0446:                //		toback.setEnabled(enabled);
0447:                //		copy.setEnabled(enabled);
0448:                //		cut.setEnabled(enabled);
0449:            }
0450:
0451:            //
0452:            // KeyListener for Delete KeyStroke
0453:            //
0454:            public void keyReleased(KeyEvent e) {
0455:            }
0456:
0457:            public void keyTyped(KeyEvent e) {
0458:            }
0459:
0460:            public void keyPressed(KeyEvent e) {
0461:                // Listen for Delete Key Press
0462:                if (e.getKeyCode() == KeyEvent.VK_DELETE)
0463:                    // Execute Remove Action on Delete Key Press
0464:                    delete.actionPerformed(null);
0465:            }
0466:
0467:            //
0468:            // Custom Graph
0469:            //
0470:
0471:            // Defines a Graph that uses the Shift-Button (Instead of the Right
0472:            // Mouse Button, which is Default) to add/remove point to/from an edge.
0473:            public static class MyGraph extends JGraph {
0474:
0475:                // Construct the Graph using the Model as its Data Source
0476:                public MyGraph(GraphModel model) {
0477:                    this (model, null);
0478:                }
0479:
0480:                // Construct the Graph using the Model as its Data Source
0481:                public MyGraph(GraphModel model, GraphLayoutCache cache) {
0482:                    super (model, cache);
0483:                    // Make Ports Visible by Default
0484:                    setPortsVisible(true);
0485:                    // Use the Grid (but don't make it Visible)
0486:                    setGridEnabled(true);
0487:                    // Set the Grid Size to 10 Pixel
0488:                    setGridSize(6);
0489:                    // Set the Tolerance to 2 Pixel
0490:                    setTolerance(2);
0491:                    // Accept edits if click on background
0492:                    setInvokesStopCellEditing(true);
0493:                    // Allows control-drag
0494:                    setCloneable(false);
0495:                    // Jump to default port on connect
0496:                    setJumpToDefaultPort(true);
0497:                }
0498:
0499:            }
0500:
0501:            //
0502:            // Custom Edge Handle
0503:            //
0504:
0505:            // Defines a EdgeHandle that uses the Shift-Button (Instead of the Right
0506:            // Mouse Button, which is Default) to add/remove point to/from an edge.
0507:            public static class MyEdgeHandle extends EdgeView.EdgeHandle {
0508:
0509:                /**
0510:                 * @param edge
0511:                 * @param ctx
0512:                 */
0513:                public MyEdgeHandle(EdgeView edge, GraphContext ctx) {
0514:                    super (edge, ctx);
0515:                }
0516:
0517:                // Override Superclass Method
0518:                public boolean isAddPointEvent(MouseEvent event) {
0519:                    // Points are Added using Shift-Click
0520:                    return event.isShiftDown();
0521:                }
0522:
0523:                // Override Superclass Method
0524:                public boolean isRemovePointEvent(MouseEvent event) {
0525:                    // Points are Removed using Shift-Click
0526:                    return event.isShiftDown();
0527:                }
0528:
0529:            }
0530:
0531:            //
0532:            // Custom Model
0533:            //
0534:
0535:            // MarqueeHandler that Connects Vertices and Displays PopupMenus
0536:            public class MyMarqueeHandler extends BasicMarqueeHandler {
0537:
0538:                // Holds the Start and the Current Point
0539:                protected Point2D start, current;
0540:
0541:                // Holds the First and the Current Port
0542:                protected PortView port, firstPort;
0543:
0544:                // Override to Gain Control (for PopupMenu and ConnectMode)
0545:                public boolean isForceMarqueeEvent(MouseEvent e) {
0546:                    if (e.isShiftDown())
0547:                        return false;
0548:                    // If Right Mouse Button we want to Display the PopupMenu
0549:                    if (SwingUtilities.isRightMouseButton(e))
0550:                        // Return Immediately
0551:                        return true;
0552:                    // Find and Remember Port
0553:                    port = getSourcePortAt(e.getPoint());
0554:                    // If Port Found and in ConnectMode (=Ports Visible)
0555:                    if (port != null && graph.isPortsVisible())
0556:                        return true;
0557:                    // Else Call Superclass
0558:                    return super .isForceMarqueeEvent(e);
0559:                }
0560:
0561:                // Display PopupMenu or Remember Start Location and First Port
0562:                public void mousePressed(final MouseEvent e) {
0563:                    // If Right Mouse Button
0564:                    if (SwingUtilities.isRightMouseButton(e)) {
0565:                        // Find Cell in Model Coordinates
0566:                        Object cell = graph.getFirstCellForLocation(e.getX(), e
0567:                                .getY());
0568:                        // Create PopupMenu for the Cell
0569:                        JPopupMenu menu = createPopupMenu(e.getPoint(), cell);
0570:                        // Display PopupMenu
0571:                        menu.show(graph, e.getX(), e.getY());
0572:                        // Else if in ConnectMode and Remembered Port is Valid
0573:                    } else if (port != null && graph.isPortsVisible()) {
0574:                        // Remember Start Location
0575:                        start = graph.toScreen(port.getLocation());
0576:                        // Remember First Port
0577:                        firstPort = port;
0578:                    } else {
0579:                        // Call Superclass
0580:                        super .mousePressed(e);
0581:                    }
0582:                }
0583:
0584:                // Find Port under Mouse and Repaint Connector
0585:                public void mouseDragged(MouseEvent e) {
0586:                    // If remembered Start Point is Valid
0587:                    if (start != null) {
0588:                        // Fetch Graphics from Graph
0589:                        Graphics g = graph.getGraphics();
0590:                        // Reset Remembered Port
0591:                        PortView newPort = getTargetPortAt(e.getPoint());
0592:                        // Do not flicker (repaint only on real changes)
0593:                        if (newPort == null || newPort != port) {
0594:                            // Xor-Paint the old Connector (Hide old Connector)
0595:                            paintConnector(Color.black, graph.getBackground(),
0596:                                    g);
0597:                            // If Port was found then Point to Port Location
0598:                            port = newPort;
0599:                            if (port != null)
0600:                                current = graph.toScreen(port.getLocation());
0601:                            // Else If no Port was found then Point to Mouse Location
0602:                            else
0603:                                current = graph.snap(e.getPoint());
0604:                            // Xor-Paint the new Connector
0605:                            paintConnector(graph.getBackground(), Color.black,
0606:                                    g);
0607:                        }
0608:                    }
0609:                    // Call Superclass
0610:                    super .mouseDragged(e);
0611:                }
0612:
0613:                public PortView getSourcePortAt(Point2D point) {
0614:                    // Disable jumping
0615:                    graph.setJumpToDefaultPort(false);
0616:                    PortView result;
0617:                    try {
0618:                        // Find a Port View in Model Coordinates and Remember
0619:                        result = graph
0620:                                .getPortViewAt(point.getX(), point.getY());
0621:                    } finally {
0622:                        graph.setJumpToDefaultPort(true);
0623:                    }
0624:                    return result;
0625:                }
0626:
0627:                // Find a Cell at point and Return its first Port as a PortView
0628:                protected PortView getTargetPortAt(Point2D point) {
0629:                    // Find a Port View in Model Coordinates and Remember
0630:                    return graph.getPortViewAt(point.getX(), point.getY());
0631:                }
0632:
0633:                // Connect the First Port and the Current Port in the Graph or Repaint
0634:                public void mouseReleased(MouseEvent e) {
0635:                    // If Valid Event, Current and First Port
0636:                    if (e != null && port != null && firstPort != null
0637:                            && firstPort != port) {
0638:                        // Then Establish Connection
0639:                        connect((Port) firstPort.getCell(), (Port) port
0640:                                .getCell());
0641:                        e.consume();
0642:                        // Else Repaint the Graph
0643:                    } else
0644:                        graph.repaint();
0645:                    // Reset Global Vars
0646:                    firstPort = port = null;
0647:                    start = current = null;
0648:                    // Call Superclass
0649:                    super .mouseReleased(e);
0650:                }
0651:
0652:                // Show Special Cursor if Over Port
0653:                public void mouseMoved(MouseEvent e) {
0654:                    // Check Mode and Find Port
0655:                    if (e != null && getSourcePortAt(e.getPoint()) != null
0656:                            && graph.isPortsVisible()) {
0657:                        // Set Cusor on Graph (Automatically Reset)
0658:                        graph.setCursor(new Cursor(Cursor.HAND_CURSOR));
0659:                        // Consume Event
0660:                        // Note: This is to signal the BasicGraphUI's
0661:                        // MouseHandle to stop further event processing.
0662:                        e.consume();
0663:                    } else
0664:                        // Call Superclass
0665:                        super .mouseMoved(e);
0666:                }
0667:
0668:                // Use Xor-Mode on Graphics to Paint Connector
0669:                protected void paintConnector(Color fg, Color bg, Graphics g) {
0670:                    // Set Foreground
0671:                    g.setColor(fg);
0672:                    // Set Xor-Mode Color
0673:                    g.setXORMode(bg);
0674:                    // Highlight the Current Port
0675:                    paintPort(graph.getGraphics());
0676:                    // If Valid First Port, Start and Current Point
0677:                    if (firstPort != null && start != null && current != null)
0678:                        // Then Draw A Line From Start to Current Point
0679:                        g.drawLine((int) start.getX(), (int) start.getY(),
0680:                                (int) current.getX(), (int) current.getY());
0681:                }
0682:
0683:                // Use the Preview Flag to Draw a Highlighted Port
0684:                protected void paintPort(Graphics g) {
0685:                    // If Current Port is Valid
0686:                    if (port != null) {
0687:                        // If Not Floating Port...
0688:                        boolean o = (GraphConstants.getOffset(port
0689:                                .getAllAttributes()) != null);
0690:                        // ...Then use Parent's Bounds
0691:                        Rectangle2D r = (o) ? port.getBounds() : port
0692:                                .getParentView().getBounds();
0693:                        // Scale from Model to Screen
0694:                        r = graph.toScreen((Rectangle2D) r.clone());
0695:                        // Add Space For the Highlight Border
0696:                        r.setFrame(r.getX() - 3, r.getY() - 3,
0697:                                r.getWidth() + 6, r.getHeight() + 6);
0698:                        // Paint Port in Preview (=Highlight) Mode
0699:                        graph.getUI().paintCell(g, port, r, true);
0700:                    }
0701:                }
0702:
0703:            } // End of Editor.MyMarqueeHandler
0704:
0705:            //
0706:            //
0707:            //
0708:
0709:            //
0710:            // PopupMenu and ToolBar
0711:            //
0712:
0713:            //
0714:            //
0715:            //
0716:
0717:            //
0718:            // PopupMenu
0719:            //
0720:            public JPopupMenu createPopupMenu(final Point pt, final Object cell) {
0721:                JPopupMenu menu = new JPopupMenu();
0722:                if (cell != null) {
0723:                    // Edit
0724:                    menu.add(new AbstractAction("Edit") {
0725:                        public void actionPerformed(ActionEvent e) {
0726:                            Container owner = graph;
0727:                            while (owner != null && !(owner instanceof  JFrame)) {
0728:                                owner = owner.getParent();
0729:                            }
0730:                            ProcessElementPropertiesDialog pd = new ProcessElementPropertiesDialog(
0731:                                    owner instanceof  JFrame ? (JFrame) owner
0732:                                            : null, (ProcessElement) cell);
0733:                            pd.setVisible(true);
0734:                            GraphLayoutCache graphLayoutCache = graph
0735:                                    .getGraphLayoutCache();
0736:                            CellView cellView = graphLayoutCache.getMapping(
0737:                                    cell, false);
0738:                            cellView.update(graphLayoutCache);
0739:                            //					Map attributes = cellView.getAllAttributes();
0740:                            //					Iterator it=attributes.entrySet().iterator();
0741:                            //					while (it.hasNext()) {
0742:                            //						System.out.println(it.next());
0743:                            //					}
0744:                            graph.updateAutoSize(cellView);
0745:                        }
0746:                    });
0747:                }
0748:                // Remove
0749:                if (!graph.isSelectionEmpty()) {
0750:                    menu.addSeparator();
0751:                    menu.add(new AbstractAction("Delete") {
0752:                        public void actionPerformed(ActionEvent e) {
0753:                            delete.actionPerformed(e);
0754:                        }
0755:                    });
0756:                }
0757:                menu.addSeparator();
0758:                // Insert
0759:                menu.add(new AbstractAction("Insert") {
0760:                    public void actionPerformed(ActionEvent ev) {
0761:                        insert(pt);
0762:                    }
0763:                });
0764:                return menu;
0765:            }
0766:
0767:            // Time when applet was loaded to generate unique id.
0768:            private long loadTime = System.currentTimeMillis();
0769:            // Applet ID.
0770:            private String aid;
0771:
0772:            //
0773:            // ToolBar
0774:            //
0775:            public JToolBar createToolBar() {
0776:                JToolBar toolbar = new JToolBar();
0777:                toolbar.setFloatable(false);
0778:
0779:                // Insert
0780:                URL insertUrl = getClass().getClassLoader().getResource(
0781:                        "biz/hammurapi/web/interaction/resources/insert.gif");
0782:                ImageIcon insertIcon = new ImageIcon(insertUrl);
0783:                toolbar.add(new AbstractAction("Insert task", insertIcon) {
0784:                    public void actionPerformed(ActionEvent e) {
0785:                        insert(new Point(20, 20)); // TODO - iterate over cells to avoid inserting task over other tasks.
0786:                    }
0787:                });
0788:
0789:                // Toggle Connect Mode
0790:                URL connectUrl = getClass()
0791:                        .getClassLoader()
0792:                        .getResource(
0793:                                "biz/hammurapi/web/interaction/resources/connecton.gif");
0794:                ImageIcon connectIcon = new ImageIcon(connectUrl);
0795:                toolbar.add(new AbstractAction("Toggle connect mode",
0796:                        connectIcon) {
0797:                    public void actionPerformed(ActionEvent e) {
0798:                        graph.setPortsVisible(!graph.isPortsVisible());
0799:                        URL connectUrl;
0800:                        if (graph.isPortsVisible())
0801:                            connectUrl = getClass()
0802:                                    .getClassLoader()
0803:                                    .getResource(
0804:                                            "biz/hammurapi/web/interaction/resources/connectoff.gif");
0805:                        else
0806:                            connectUrl = getClass()
0807:                                    .getClassLoader()
0808:                                    .getResource(
0809:                                            "biz/hammurapi/web/interaction/resources/connecton.gif");
0810:                        ImageIcon connectIcon = new ImageIcon(connectUrl);
0811:                        putValue(SMALL_ICON, connectIcon);
0812:                    }
0813:                });
0814:
0815:                toolbar.addSeparator();
0816:
0817:                URL propertiesUrl = getClass()
0818:                        .getClassLoader()
0819:                        .getResource(
0820:                                "biz/hammurapi/web/interaction/resources/properties.gif");
0821:                ImageIcon propertiesIcon = new ImageIcon(propertiesUrl);
0822:                toolbar.add(new AbstractAction("Properties", propertiesIcon) {
0823:                    public void actionPerformed(ActionEvent e) {
0824:                        showProperties();
0825:                    }
0826:                });
0827:
0828:                URL saveUrl = getClass().getClassLoader().getResource(
0829:                        "biz/hammurapi/web/interaction/resources/save.gif");
0830:                ImageIcon saveIcon = new ImageIcon(saveUrl);
0831:                saveAction = new AbstractAction("Save", saveIcon) {
0832:                    public void actionPerformed(ActionEvent e) {
0833:                        if (aid == null) {
0834:                            aid = Long.toHexString(loadTime)
0835:                                    + ":"
0836:                                    + Long.toHexString(System
0837:                                            .currentTimeMillis());
0838:                        }
0839:                        if (process.getData().getName() == null
0840:                                || process.getData().getName().trim().length() == 0) {
0841:                            JOptionPane.showMessageDialog(ProcessApplet.this ,
0842:                                    "Process name shall not be blank",
0843:                                    "Warning", JOptionPane.WARNING_MESSAGE);
0844:                            showProperties();
0845:                            return;
0846:                        }
0847:                        setEnabled(false);
0848:                        statusBar.getLeftSideStatus().setText(
0849:                                "Process editor. Saving...");
0850:                        process.storeGeometry();
0851:                        try {
0852:                            ByteArrayOutputStream out = new ByteArrayOutputStream();
0853:                            Color bg = graph.getBackground();
0854:                            BufferedImage img = graph.getImage(bg, 5);
0855:                            if (img != null) {
0856:                                ImageIO.write(img, "PNG", out);
0857:                                out.flush();
0858:                                out.close();
0859:                                process.getData().setProcessImage(
0860:                                        out.toByteArray());
0861:                                process.getData().setImageType("image/png");
0862:                            }
0863:
0864:                            ((Attributable) process.getData()).setAttribute(
0865:                                    "create-id", aid);
0866:
0867:                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
0868:                            GZIPOutputStream gzos = new GZIPOutputStream(baos);
0869:                            ObjectOutputStream oos = new ObjectOutputStream(
0870:                                    gzos);
0871:                            if (processDownloadUrl == null) {
0872:                                ((Attributable) process.getData())
0873:                                        .setAttribute("new", Boolean.TRUE);
0874:                            }
0875:                            oos.writeObject(process.getData());
0876:                            oos.close();
0877:                            gzos.close();
0878:                            baos.close();
0879:                            HttpClient client = new HttpClient();
0880:                            PostMethod method = new PostMethod(processUploadUrl);
0881:                            method.setRequestEntity(new ByteArrayRequestEntity(
0882:                                    baos.toByteArray()));
0883:                            if (cookie != null) {
0884:                                method.setRequestHeader("Cookie", cookie);
0885:                            }
0886:                            int status = client.executeMethod(method);
0887:                            if (status != HttpStatus.SC_OK) {
0888:                                String errorMessage = "HTTP Error: " + status
0889:                                        + "\n"
0890:                                        + method.getResponseBodyAsString();
0891:                                JOptionPane.showMessageDialog(
0892:                                        ProcessApplet.this ,
0893:                                        "Could not save process:\n"
0894:                                                + errorMessage, "Error",
0895:                                        JOptionPane.ERROR_MESSAGE);
0896:                                statusBar.getLeftSideStatus().setText(
0897:                                        "Process editor. Save failed: "
0898:                                                + errorMessage);
0899:                                setEnabled(true);
0900:                            }
0901:                            statusBar.getLeftSideStatus().setText(
0902:                                    "Process editor. Last saved on "
0903:                                            + new Date());
0904:                        } catch (Exception ex) {
0905:                            JOptionPane.showMessageDialog(ProcessApplet.this ,
0906:                                    "Could not save process:\n" + ex, "Error",
0907:                                    JOptionPane.ERROR_MESSAGE);
0908:                            ex.printStackTrace();
0909:                            statusBar.getLeftSideStatus().setText(
0910:                                    "Process editor. Save failed: " + ex);
0911:                            setEnabled(true);
0912:                        } catch (Error er) {
0913:                            JOptionPane.showMessageDialog(ProcessApplet.this ,
0914:                                    "Could not save process:\n" + er, "Error",
0915:                                    JOptionPane.ERROR_MESSAGE);
0916:                            statusBar.getLeftSideStatus().setText(
0917:                                    "Process editor. Save failed: " + er);
0918:                            setEnabled(true);
0919:                            throw er;
0920:                        }
0921:                    }
0922:                };
0923:                // Save
0924:                saveAction.setEnabled(false);
0925:                toolbar.add(saveAction);
0926:
0927:                saveAndCloseAction = new AbstractAction("Save And Close") {
0928:                    public void actionPerformed(ActionEvent e) {
0929:                        saveAction.actionPerformed(e);
0930:                        if (exitUrl == null) {
0931:                            this .setEnabled(false);
0932:                        } else {
0933:                            try {
0934:                                getAppletContext().showDocument(
0935:                                        new URL(exitUrl));
0936:                            } catch (MalformedURLException ex) {
0937:                                ex.printStackTrace();
0938:                                JOptionPane.showMessageDialog(
0939:                                        ProcessApplet.this ,
0940:                                        "Could not close editor:\n" + ex,
0941:                                        "Error", JOptionPane.ERROR_MESSAGE);
0942:                                this .setEnabled(false);
0943:                            }
0944:                        }
0945:                    }
0946:                };
0947:                saveAndCloseAction.setEnabled(false);
0948:                toolbar.add(saveAndCloseAction);
0949:
0950:                toolbar.addSeparator();
0951:
0952:                // Undo
0953:                //		URL undoUrl = getClass().getClassLoader().getResource("biz/hammurapi/web/interaction/resources/undo.gif");
0954:                //		ImageIcon undoIcon = new ImageIcon(undoUrl);
0955:                //		undo = new AbstractAction("Undo", undoIcon) {
0956:                //			public void actionPerformed(ActionEvent e) {
0957:                //				undo();
0958:                //			}
0959:                //		};
0960:                //		undo.setEnabled(false);
0961:                //		toolbar.add(undo);
0962:                //
0963:                //		// Redo
0964:                //		URL redoUrl = getClass().getClassLoader().getResource("biz/hammurapi/web/interaction/resources/redo.gif");
0965:                //		ImageIcon redoIcon = new ImageIcon(redoUrl);
0966:                //		redo = new AbstractAction("Redo", redoIcon) {
0967:                //			public void actionPerformed(ActionEvent e) {
0968:                //				redo();
0969:                //			}
0970:                //		};
0971:                //		redo.setEnabled(false);
0972:                //		toolbar.add(redo);
0973:                //
0974:                //		//
0975:                //		// Edit Block
0976:                //		//
0977:                //		toolbar.addSeparator();
0978:                //		Action action;
0979:                //		URL url;
0980:                //
0981:                //		// Copy
0982:                //		action = javax.swing.TransferHandler // JAVA13:
0983:                //				// org.jgraph.plaf.basic.TransferHandler
0984:                //				.getCopyAction();
0985:                //		url = getClass().getClassLoader().getResource("biz/hammurapi/web/interaction/resources/copy.gif");
0986:                //		action.putValue(Action.SMALL_ICON, new ImageIcon(url));
0987:                //		toolbar.add(copy = new EventRedirector(action));
0988:                //
0989:                //		// Paste
0990:                //		action = javax.swing.TransferHandler // JAVA13:
0991:                //				// org.jgraph.plaf.basic.TransferHandler
0992:                //				.getPasteAction();
0993:                //		url = getClass().getClassLoader().getResource("biz/hammurapi/web/interaction/resources/paste.gif");
0994:                //		action.putValue(Action.SMALL_ICON, new ImageIcon(url));
0995:                //		toolbar.add(paste = new EventRedirector(action));
0996:                //
0997:                //		// Cut
0998:                //		action = javax.swing.TransferHandler // JAVA13:
0999:                //				// org.jgraph.plaf.basic.TransferHandler
1000:                //				.getCutAction();
1001:                //		url = getClass().getClassLoader().getResource(
1002:                //				"biz/hammurapi/web/interaction/resources/cut.gif");
1003:                //		action.putValue(Action.SMALL_ICON, new ImageIcon(url));
1004:                //		toolbar.add(cut = new EventRedirector(action));
1005:
1006:                // Remove
1007:                URL removeUrl = getClass().getClassLoader().getResource(
1008:                        "biz/hammurapi/web/interaction/resources/delete.gif");
1009:                ImageIcon removeIcon = new ImageIcon(removeUrl);
1010:                delete = new AbstractAction("Deletes selected object(s)",
1011:                        removeIcon) {
1012:                    public void actionPerformed(ActionEvent e) {
1013:                        if (!graph.isSelectionEmpty()
1014:                                && JOptionPane.showConfirmDialog(
1015:                                        ProcessApplet.this ,
1016:                                        "Delete object(s)?", "Confirm delete",
1017:                                        JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
1018:                            Object[] cells = graph.getSelectionCells();
1019:                            cells = graph.getDescendants(cells);
1020:                            graph.getModel().remove(cells);
1021:                        }
1022:                    }
1023:                };
1024:                delete.setEnabled(false);
1025:                toolbar.add(delete);
1026:
1027:                //		// To Front
1028:                //		toolbar.addSeparator();
1029:                //		URL toFrontUrl = getClass().getClassLoader().getResource(
1030:                //				"biz/hammurapi/web/interaction/resources/tofront.gif");
1031:                //		ImageIcon toFrontIcon = new ImageIcon(toFrontUrl);
1032:                //		tofront = new AbstractAction("", toFrontIcon) {
1033:                //			public void actionPerformed(ActionEvent e) {
1034:                //				if (!graph.isSelectionEmpty())
1035:                //					toFront(graph.getSelectionCells());
1036:                //			}
1037:                //		};
1038:                //		tofront.setEnabled(false);
1039:                //		toolbar.add(tofront);
1040:                //
1041:                //		// To Back
1042:                //		URL toBackUrl = getClass().getClassLoader().getResource(
1043:                //				"biz/hammurapi/web/interaction/resources/toback.gif");
1044:                //		ImageIcon toBackIcon = new ImageIcon(toBackUrl);
1045:                //		toback = new AbstractAction("", toBackIcon) {
1046:                //			public void actionPerformed(ActionEvent e) {
1047:                //				if (!graph.isSelectionEmpty())
1048:                //					toBack(graph.getSelectionCells());
1049:                //			}
1050:                //		};
1051:                //		toback.setEnabled(false);
1052:                //		toolbar.add(toback);
1053:
1054:                // Zoom Std
1055:                toolbar.addSeparator();
1056:                URL zoomUrl = getClass().getClassLoader().getResource(
1057:                        "biz/hammurapi/web/interaction/resources/zoom.gif");
1058:                ImageIcon zoomIcon = new ImageIcon(zoomUrl);
1059:                toolbar.add(new AbstractAction("Zoom", zoomIcon) {
1060:                    public void actionPerformed(ActionEvent e) {
1061:                        graph.setScale(1.0);
1062:                    }
1063:                });
1064:                // Zoom In
1065:                URL zoomInUrl = getClass().getClassLoader().getResource(
1066:                        "biz/hammurapi/web/interaction/resources/zoomin.gif");
1067:                ImageIcon zoomInIcon = new ImageIcon(zoomInUrl);
1068:                toolbar.add(new AbstractAction("Zoom in", zoomInIcon) {
1069:                    public void actionPerformed(ActionEvent e) {
1070:                        graph.setScale(1.5 * graph.getScale());
1071:                    }
1072:                });
1073:                // Zoom Out
1074:                URL zoomOutUrl = getClass().getClassLoader().getResource(
1075:                        "biz/hammurapi/web/interaction/resources/zoomout.gif");
1076:                ImageIcon zoomOutIcon = new ImageIcon(zoomOutUrl);
1077:                toolbar.add(new AbstractAction("Zoom out", zoomOutIcon) {
1078:                    public void actionPerformed(ActionEvent e) {
1079:                        graph.setScale(graph.getScale() / 1.5);
1080:                    }
1081:                });
1082:
1083:                //		// Group
1084:                //		toolbar.addSeparator();
1085:                //		URL groupUrl = getClass().getClassLoader().getResource("biz/hammurapi/web/interaction/resources/group.gif");
1086:                //		ImageIcon groupIcon = new ImageIcon(groupUrl);
1087:                //		group = new AbstractAction("Group", groupIcon) {
1088:                //			public void actionPerformed(ActionEvent e) {
1089:                //				group(graph.getSelectionCells());
1090:                //			}
1091:                //		};
1092:                //		group.setEnabled(false);
1093:                //		toolbar.add(group);
1094:                //
1095:                //		// Ungroup
1096:                //		URL ungroupUrl = getClass().getClassLoader().getResource("biz/hammurapi/web/interaction/resources/ungroup.gif");
1097:                //		ImageIcon ungroupIcon = new ImageIcon(ungroupUrl);
1098:                //		ungroup = new AbstractAction("Ungroup", ungroupIcon) {
1099:                //			public void actionPerformed(ActionEvent e) {
1100:                //				ungroup(graph.getSelectionCells());
1101:                //			}
1102:                //		};
1103:                //		ungroup.setEnabled(false);
1104:                //		toolbar.add(ungroup);
1105:
1106:                return toolbar;
1107:            }
1108:
1109:            /**
1110:             * @return Returns the graph.
1111:             */
1112:            public JGraph getGraph() {
1113:                return graph;
1114:            }
1115:
1116:            /**
1117:             * @param graph
1118:             *            The graph to set.
1119:             */
1120:            public void setGraph(JGraph graph) {
1121:                this .graph = graph;
1122:            }
1123:
1124:            // This will change the source of the actionevent to graph.
1125:            public class EventRedirector extends AbstractAction {
1126:
1127:                protected Action action;
1128:
1129:                // Construct the "Wrapper" Action
1130:                public EventRedirector(Action a) {
1131:                    super ("", (ImageIcon) a.getValue(Action.SMALL_ICON));
1132:                    this .action = a;
1133:                }
1134:
1135:                // Redirect the Actionevent
1136:                public void actionPerformed(ActionEvent e) {
1137:                    e = new ActionEvent(graph, e.getID(), e.getActionCommand(),
1138:                            e.getModifiers());
1139:                    action.actionPerformed(e);
1140:                }
1141:            }
1142:
1143:            public class EdStatusBar extends JPanel implements 
1144:                    GraphModelListener {
1145:                /**
1146:                 * 
1147:                 */
1148:                protected JLabel leftSideStatus;
1149:
1150:                /**
1151:                 * contains the scale for the current graph
1152:                 */
1153:                protected JLabel rightSideStatus;
1154:
1155:                /**
1156:                 * Constructor for GPStatusBar.
1157:                 * 
1158:                 */
1159:                public EdStatusBar() {
1160:                    super ();
1161:                    // Add this as graph model change listener
1162:                    setLayout(new BorderLayout());
1163:                    leftSideStatus = new JLabel("Process editor");
1164:                    rightSideStatus = new JLabel("0/0Mb");
1165:                    leftSideStatus.setBorder(BorderFactory
1166:                            .createLoweredBevelBorder());
1167:                    rightSideStatus.setBorder(BorderFactory
1168:                            .createLoweredBevelBorder());
1169:                    add(leftSideStatus, BorderLayout.CENTER);
1170:                    add(rightSideStatus, BorderLayout.EAST);
1171:                }
1172:
1173:                protected void updateStatusBar() {
1174:                    Runtime runtime = Runtime.getRuntime();
1175:                    int freeMemory = (int) (runtime.freeMemory() / 1024);
1176:                    int totalMemory = (int) (runtime.totalMemory() / 1024);
1177:                    int usedMemory = (totalMemory - freeMemory);
1178:                    String str = (usedMemory / 1024) + "/"
1179:                            + (totalMemory / 1024) + "Mb";
1180:                    rightSideStatus.setText(str);
1181:                }
1182:
1183:                /**
1184:                 * @return Returns the leftSideStatus.
1185:                 */
1186:                public JLabel getLeftSideStatus() {
1187:                    return leftSideStatus;
1188:                }
1189:
1190:                /**
1191:                 * @param leftSideStatus
1192:                 *            The leftSideStatus to set.
1193:                 */
1194:                public void setLeftSideStatus(JLabel leftSideStatus) {
1195:                    this .leftSideStatus = leftSideStatus;
1196:                }
1197:
1198:                /**
1199:                 * @return Returns the rightSideStatus.
1200:                 */
1201:                public JLabel getRightSideStatus() {
1202:                    return rightSideStatus;
1203:                }
1204:
1205:                /**
1206:                 * @param rightSideStatus
1207:                 *            The rightSideStatus to set.
1208:                 */
1209:                public void setRightSideStatus(JLabel rightSideStatus) {
1210:                    this .rightSideStatus = rightSideStatus;
1211:                }
1212:
1213:                public void graphChanged(GraphModelEvent changeEvent) {
1214:                    modelChanged();
1215:                }
1216:            }
1217:
1218:            /**
1219:             * Notification that model has changed.
1220:             *
1221:             */
1222:            public void modelChanged() {
1223:                saveAction.setEnabled(true);
1224:                saveAndCloseAction.setEnabled(exitUrl != null);
1225:            }
1226:
1227:            //	/**
1228:            //	 * @return Returns the copy.
1229:            //	 */
1230:            //	public Action getCopy() {
1231:            //		return copy;
1232:            //	}
1233:            //
1234:            //	/**
1235:            //	 * @param copy
1236:            //	 *            The copy to set.
1237:            //	 */
1238:            //	public void setCopy(Action copy) {
1239:            //		this.copy = copy;
1240:            //	}
1241:            //
1242:            //	/**
1243:            //	 * @return Returns the cut.
1244:            //	 */
1245:            //	public Action getCut() {
1246:            //		return cut;
1247:            //	}
1248:            //
1249:            //	/**
1250:            //	 * @param cut
1251:            //	 *            The cut to set.
1252:            //	 */
1253:            //	public void setCut(Action cut) {
1254:            //		this.cut = cut;
1255:            //	}
1256:            //
1257:            //	/**
1258:            //	 * @return Returns the paste.
1259:            //	 */
1260:            //	public Action getPaste() {
1261:            //		return paste;
1262:            //	}
1263:            //
1264:            //	/**
1265:            //	 * @param paste
1266:            //	 *            The paste to set.
1267:            //	 */
1268:            //	public void setPaste(Action paste) {
1269:            //		this.paste = paste;
1270:            //	}
1271:            //
1272:            //	/**
1273:            //	 * @return Returns the toback.
1274:            //	 */
1275:            //	public Action getToback() {
1276:            //		return toback;
1277:            //	}
1278:            //
1279:            //	/**
1280:            //	 * @param toback
1281:            //	 *            The toback to set.
1282:            //	 */
1283:            //	public void setToback(Action toback) {
1284:            //		this.toback = toback;
1285:            //	}
1286:            //
1287:            //	/**
1288:            //	 * @return Returns the tofront.
1289:            //	 */
1290:            //	public Action getTofront() {
1291:            //		return tofront;
1292:            //	}
1293:            //
1294:            //	/**
1295:            //	 * @param tofront
1296:            //	 *            The tofront to set.
1297:            //	 */
1298:            //	public void setTofront(Action tofront) {
1299:            //		this.tofront = tofront;
1300:            //	}
1301:
1302:            /**
1303:             * @return Returns the remove.
1304:             */
1305:            public Action getDelete() {
1306:                return delete;
1307:            }
1308:
1309:            /**
1310:             * @param delete
1311:             *            The remove to set.
1312:             */
1313:            public void setDelete(Action delete) {
1314:                this .delete = delete;
1315:            }
1316:
1317:            public void start() {
1318:                super .init();
1319:                try {
1320:                    //			File inFile = new File("process.bin");
1321:                    //			if (inFile.exists()) {
1322:                    //				FileInputStream fis = new FileInputStream(inFile);
1323:                    //				GZIPInputStream gzis = new GZIPInputStream(fis);
1324:                    //				ObjectInputStream ois = new ObjectInputStream(gzis);
1325:                    //				biz.hammurapi.web.process.sql.Process data = (biz.hammurapi.web.process.sql.Process) ois.readObject();
1326:                    //				ois.close();
1327:                    //				gzis.close();
1328:                    //				fis.close();
1329:                    //				
1330:                    //				process = new Process(data);
1331:                    //			} else {
1332:                    //				process = new Process();
1333:                    //			}
1334:
1335:                    if (processDownloadUrl != null) {
1336:                        HttpClient httpClient = new HttpClient();
1337:                        HttpMethod method = new GetMethod(processDownloadUrl);
1338:                        if (cookie != null) {
1339:                            method.setRequestHeader("Cookie", cookie);
1340:                        }
1341:                        int statusCode = httpClient.executeMethod(method);
1342:                        if (statusCode != HttpStatus.SC_OK) {
1343:                            JOptionPane.showMessageDialog(ProcessApplet.this ,
1344:                                    "Could not load process from "
1345:                                            + processDownloadUrl
1346:                                            + ".\nHttp error code: "
1347:                                            + statusCode + "\n"
1348:                                            + method.getResponseBodyAsString(),
1349:                                    "Error", JOptionPane.ERROR_MESSAGE);
1350:                            process = new Process();
1351:                            statusBar.getLeftSideStatus().setText(
1352:                                    "Process editor: Disabled");
1353:                            setEnabled(false);
1354:                        } else {
1355:                            ByteArrayInputStream bis = new ByteArrayInputStream(
1356:                                    method.getResponseBody());
1357:                            method.releaseConnection();
1358:                            //GZIPInputStream gzis = new GZIPInputStream(bis);
1359:                            ObjectInputStream ois = new ObjectInputStream(bis /* gzis */);
1360:                            biz.hammurapi.web.process.sql.Process data = (biz.hammurapi.web.process.sql.Process) ois
1361:                                    .readObject();
1362:                            ois.close();
1363:                            //gzis.close();
1364:                            bis.close();
1365:
1366:                            process = new Process(data);
1367:                        }
1368:                    } else {
1369:                        process = new Process();
1370:                    }
1371:
1372:                    process.setApplet(this );
1373:                    ((ProcessModel) graph.getModel()).setProcess(process);
1374:                    if (processUploadUrl == null) {
1375:                        statusBar.getLeftSideStatus().setText("Process viewer");
1376:                        setEnabled(false);
1377:                    }
1378:                    saveAction.setEnabled(false);
1379:                } catch (Exception e) {
1380:                    e.printStackTrace();
1381:                    JOptionPane.showMessageDialog(ProcessApplet.this ,
1382:                            "Could not load process:\n" + e, "Error",
1383:                            JOptionPane.ERROR_MESSAGE);
1384:                    statusBar.getLeftSideStatus().setText(
1385:                            "Process editor: Disabled");
1386:                    setEnabled(false);
1387:                } catch (Error er) {
1388:                    JOptionPane.showMessageDialog(ProcessApplet.this ,
1389:                            "Could not save process:\n" + er, "Error",
1390:                            JOptionPane.ERROR_MESSAGE);
1391:                    statusBar.getLeftSideStatus().setText(
1392:                            "Process editor: Disabled");
1393:                    setEnabled(false);
1394:                    throw er;
1395:                }
1396:            }
1397:
1398:            /**
1399:             * Reads download URL, upload URL and Cookie string.
1400:             */
1401:            public void init() {
1402:                super .init();
1403:                cookie = getParameter("Cookie");
1404:                processDownloadUrl = getParameter("DownloadURL");
1405:                processUploadUrl = getParameter("UploadURL");
1406:                exitUrl = getParameter("ExitURL");
1407:            }
1408:
1409:            private void showProperties() {
1410:                Container owner = graph;
1411:                while (owner != null && !(owner instanceof  JFrame)) {
1412:                    owner = owner.getParent();
1413:                }
1414:                ProcessPropertiesDialog ipd = new ProcessPropertiesDialog(
1415:                        owner instanceof  JFrame ? (JFrame) owner : null,
1416:                        process);
1417:                ipd.setVisible(true);
1418:            }
1419:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.