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