/** * @param lifeline the name of a lifeline that may have a non-consuming note box associated to it */ void closeNote(String lifeline) { Note note = pendingNotes.get(lifeline); if (note != null) { int diff = note.getTop() + note.getHeight() - diagram.getVerticalPosition(); if (diff > 0) { diagram.extendLifelines(diff); } pendingNotes.remove(lifeline); } }
public static void main(String[] args) throws Exception { // The path to the documents directory. String dataDir = Utils.getDataDir(ExportToSWF.class); // Call the diagram constructor to load diagram from a VSD file Diagram diagram = new Diagram(dataDir + "drawing.vsd"); // Save as SWF diagram.save(dataDir + "Output.swf", SaveFileFormat.SWF); System.out.println("Process Completed Successfully"); }
/** * Resolve the gradient reference * * @param diagram The diagram to resolve against */ public void resolve(Diagram diagram) { if (ref == null) return; Gradient other = diagram.getGradient(ref); for (int i = 0; i < other.steps.size(); i++) steps.add(other.steps.get(i)); }
private void areAllStatesReachable() { areNbInitialFinalStatesValid(); if (validationInput != null) { validationInput.reach(); } for (State s : Diagram.getInstance().getAllStates()) { if (!s.isReach()) { this.addError(new DiagramError("State unreachable : " + s.toString())); isValid = false; } } for (State s : Diagram.getInstance().getAllStates()) { s.setReach(false); s.setAlreadyTest(false); } }
private void associateEvent(Lifeline line, int descriptionNumber) { List<Pair<Lifeline, Integer>> pairs = eventAssociation.get(descriptionNumber); if (pairs == null) { pairs = new LinkedList<Pair<Lifeline, Integer>>(); eventAssociation.put(descriptionNumber, pairs); } pairs.add(new Pair<Lifeline, Integer>(line, diagram.getVerticalPosition())); }
public boolean validate(boolean displayErrors) { areStatesValid(); areAllStatesReachable(); // areCompositeValid(); if (displayErrors) Diagram.getInstance().getView().displayValidationWindow(errors); errors.clear(); return isValid; }
void calcLimits(int x1, int x2, int y1, int y2) { if (x1 < x2) { diag.maxX = Math.max(x2, diag.maxX); diag.minX = Math.min(x1, diag.minX); } else { diag.maxX = Math.max(x1, diag.maxX); diag.minX = Math.min(x2, diag.minX); } if (y1 < y2) { diag.maxY = Math.max(y2, diag.maxY); diag.minY = Math.min(y1, diag.minY); } else { diag.maxY = Math.max(y2, diag.maxY); diag.minY = Math.min(y1, diag.minY); } }
void buildArrow(HashMap<String, String> item) { String s; s = item.get("fromx").trim(); fromX = Integer.parseInt(s); s = item.get("fromy").trim(); fromY = Integer.parseInt(s); s = item.get("tox").trim(); toX = Integer.parseInt(s); s = item.get("toy").trim(); toY = Integer.parseInt(s); upStreamPort = item.get("upstreamport"); downStreamPort = item.get("downstreamport"); s = item.get("dropoldest"); if (s != null) dropOldest = true; s = item.get("fromid").trim(); fromId = Integer.parseInt(s); s = item.get("toid").trim(); toId = Integer.parseInt(s); s = item.get("id"); if (s == null) id = 0; else id = Integer.parseInt(s.trim()); if (id == 0) id = diag.maxArrowNo + 1; diag.maxArrowNo = Math.max(id, diag.maxArrowNo); endsAtBlock = true; endsAtLine = false; s = item.get("fromside"); if (s != null) { s = s.trim(); if (s.equals("L")) fromSide = Side.LEFT; else if (s.equals("R")) fromSide = Side.RIGHT; else if (s.equals("T")) fromSide = Side.TOP; else if (s.equals("B")) fromSide = Side.BOTTOM; } s = item.get("toside"); if (s != null) { s = s.trim(); if (s.equals("L")) toSide = Side.LEFT; else if (s.equals("R")) toSide = Side.RIGHT; else if (s.equals("T")) toSide = Side.TOP; else if (s.equals("B")) toSide = Side.BOTTOM; } }
/** * @see org.newdawn.slick.svg.inkscape.ElementProcessor#process(org.newdawn.slick.svg.Loader, * org.w3c.dom.Element, org.newdawn.slick.svg.Diagram, org.newdawn.slick.geom.Transform) */ public void process(Loader loader, Element element, Diagram diagram, Transform t) throws ParsingException { Transform transform = Util.getTransform(element); transform = new Transform(t, transform); String points = element.getAttribute("points"); if (element.getNodeName().equals("path")) { points = element.getAttribute("d"); } StringTokenizer tokens = new StringTokenizer(points, ", "); Polygon poly = new Polygon(); int count = processPoly(poly, element, tokens); NonGeometricData data = Util.getNonGeometricData(element); if (count > 3) { Shape shape = poly.transform(transform); diagram.addFigure(new Figure(Figure.POLYGON, shape, data, transform)); } }
private void areNbInitialFinalStatesValid() { int nbInitialState = 0; int nbFinalState = 0; for (State s : Diagram.getInstance().getDirectSons()) { if (s instanceof InitialState) { nbInitialState++; validationInput = s; } else if (s instanceof FinalState) { nbFinalState++; } } if (nbInitialState == 0 || nbInitialState > 1) { this.addError( new DiagramError("Diagram must contain one and " + "only one initial state...")); isValid = false; } if (nbFinalState > 1) { this.addError( new DiagramError("Diagram should contain one and " + "only one final state...")); isValid = false; } }
public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); diag.jpm = null; if (s.equals("Edit Upstream Port Name")) { String ans = (String) MyOptionPane.showInputDialog( driver.frame, "Enter or change text", "Edit upstream port name", JOptionPane.PLAIN_MESSAGE, null, null, upStreamPort); if (ans != null /* && ans.length() > 0 */) { Block b = diag.blocks.get(new Integer(fromId)); // upStreamPort = ans; diag.changed = true; boolean found = false; for (Arrow a : diag.arrows.values()) { if (a.fromId == fromId && a.upStreamPort != null && a.upStreamPort.equals(ans) && !(upStreamPort.equals(ans)) || a.toId == fromId && a.downStreamPort != null && a.downStreamPort.equals(ans)) found = true; } if (found) { MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans); // upStreamPort = ""; // return; } upStreamPort = ans; if (b.type.equals(Block.Types.EXTPORT_IN_BLOCK) || b instanceof IIPBlock) { MyOptionPane.showMessageDialog(driver.frame, "Upstream port must be blank"); upStreamPort = ""; } } driver.frame.repaint(); } else if (s.equals("Edit Downstream Port Name") && endsAtBlock) { String ans = (String) MyOptionPane.showInputDialog( driver.frame, "Enter or change text", "Edit downstream port name", JOptionPane.PLAIN_MESSAGE, null, null, downStreamPort); if (ans != null /* && ans.length() > 0 */) { Block b = diag.blocks.get(new Integer(toId)); diag.changed = true; boolean found = false; for (Arrow a : diag.arrows.values()) { if (a.fromId == toId && a.upStreamPort != null && a.upStreamPort.equals(ans) || a.toId == toId && a.downStreamPort != null && a.downStreamPort.equals(ans) && !(downStreamPort.equals(ans))) found = true; } if (found) { MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans); // downStreamPort = ""; // return; } downStreamPort = ans; if (b.type.equals(Block.Types.EXTPORT_OUT_BLOCK)) { MyOptionPane.showMessageDialog(driver.frame, "Downstream port must be blank"); downStreamPort = ""; } } driver.frame.repaint(); } else if (s.equals("Set Capacity")) { String capString = null; if (capacity == 0) capString = ""; else capString = Integer.toString(capacity); String ans = (String) MyOptionPane.showInputDialog( driver.frame, "Enter or change text", "Set Capacity", JOptionPane.PLAIN_MESSAGE, null, null, capString); if ((ans != null) && (ans.length() > 0)) { capacity = Integer.parseInt(ans); if (capLegend == null) { diag.xa = 2; // get around fudge in DrawFBP diag.ya = 2; // get around fudge in DrawFBP capLegend = (LegendBlock) diag.driver.createBlock(Block.Types.LEGEND_BLOCK, false); int x = toX; int y = toY; if (bends != null) { Bend bd = bends.peek(); x = bd.x; y = bd.y; } capLegend.cx = (fromX + x) / 2; capLegend.cy = (fromY + y) / 2 + 20; if (fromX == x) capLegend.cx -= 20; } capLegend.description = "(" + capacity + ")"; } driver.frame.repaint(); diag.changed = true; } else if (s.equals("Remove Capacity")) { capacity = 0; diag.delBlock(capLegend, false); capLegend = null; driver.frame.repaint(); diag.changed = true; } else if (s.equals("Toggle Upstream Port Automatic / Normal")) { if (upStreamPort == null || !upStreamPort.equals("*")) upStreamPort = "*"; else upStreamPort = null; driver.frame.repaint(); diag.changed = true; } else if (s.equals("Toggle Downstream Port Automatic / Normal")) { if (downStreamPort == null || !downStreamPort.equals("*")) downStreamPort = "*"; else downStreamPort = null; driver.frame.repaint(); diag.changed = true; } else if (s.equals("Toggle DropOldest")) { dropOldest = !dropOldest; } else if (s.equals("Drag Tail")) { tailMarked = true; driver.arrowEndForDragging = this; } else if (s.equals("Drag Head")) { headMarked = true; driver.arrowEndForDragging = this; } else if (s.equals("Drag New or Existing Bend")) { createBend(driver.curx, driver.cury); } else if (s.equals("Add Extra Arrowhead")) { Point p = new Point(driver.curx, driver.cury); int fx = fromX; int fy = fromY; int tx, ty; if (bends != null) { for (Bend bend : bends) { tx = bend.x; ty = bend.y; if (pointInLine(p, fx, fy, tx, ty)) { extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury); return; } fx = tx; fy = ty; } } tx = toX; ty = toY; if (pointInLine(p, fx, fy, tx, ty)) extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury); return; } else if (s.equals("Remove Extra Arrowhead")) { extraArrowhead = null; return; } else if (s.equals("Delete")) { if (JOptionPane.YES_OPTION == MyOptionPane.showConfirmDialog( driver.frame, "Do you want to delete this arrow?", "Delete arrow", JOptionPane.YES_NO_OPTION)) { diag.delArrow(this); diag.changed = true; diag.currentArrow = null; } driver.frame.repaint(); diag.foundArrow = null; } // if (s.equals("Exit")) { // diag.foundArrow = null; // driver.frame.repaint(); // } }
void buildArrowPopupMenu() { diag.jpm = new JPopupMenu(" Arrow-related Actions"); // driver.curPopup = jpm; diag.jpm.setVisible(true); JLabel label2 = new JLabel(); label2.setText(diag.jpm.getLabel()); label2.setFont(driver.fontg); // label2.setForeground(Color.BLUE); diag.jpm.add(label2); diag.jpm.addSeparator(); JMenuItem menuItem; Block from = diag.blocks.get(new Integer(fromId)); Block to = diag.blocks.get(new Integer(toId)); if (!(from instanceof ExtPortBlock) && !(from instanceof IIPBlock)) { menuItem = new JMenuItem("Edit Upstream Port Name"); menuItem.addActionListener(this); diag.jpm.add(menuItem); } if (!(to instanceof ExtPortBlock)) { menuItem = new JMenuItem("Edit Downstream Port Name"); menuItem.addActionListener(this); diag.jpm.add(menuItem); } diag.jpm.addSeparator(); menuItem = new JMenuItem("Set Capacity"); menuItem.addActionListener(this); diag.jpm.add(menuItem); menuItem = new JMenuItem("Remove Capacity"); menuItem.addActionListener(this); diag.jpm.add(menuItem); diag.jpm.addSeparator(); menuItem = new JMenuItem("Toggle Upstream Port Automatic / Normal"); menuItem.addActionListener(this); diag.jpm.add(menuItem); menuItem = new JMenuItem("Toggle Downstream Port Automatic / Normal"); menuItem.addActionListener(this); diag.jpm.add(menuItem); diag.jpm.addSeparator(); menuItem = new JMenuItem("Toggle DropOldest"); menuItem.addActionListener(this); diag.jpm.add(menuItem); diag.jpm.addSeparator(); menuItem = new JMenuItem("Drag Tail"); menuItem.addActionListener(this); diag.jpm.add(menuItem); menuItem = new JMenuItem("Drag Head"); menuItem.addActionListener(this); diag.jpm.add(menuItem); menuItem = new JMenuItem("Drag New or Existing Bend"); menuItem.addActionListener(this); diag.jpm.add(menuItem); diag.jpm.addSeparator(); menuItem = new JMenuItem("Add Extra Arrowhead"); menuItem.addActionListener(this); diag.jpm.add(menuItem); menuItem = new JMenuItem("Remove Extra Arrowhead"); menuItem.addActionListener(this); diag.jpm.add(menuItem); diag.jpm.addSeparator(); menuItem = new JMenuItem("Delete"); diag.jpm.add(menuItem); menuItem.addActionListener(this); // menuItem = new JMenuItem("Exit"); // jpm.add(menuItem); // menuItem.addActionListener(this); // diag.curMenuRect = new Rectangle(p.x, p.y, d.width, d.height); // return jpm; }
public boolean step() throws SyntaxError { Note note = diagram.getDataProvider().getNote(); if (note != null) { freeNoteNumber = Math.max(freeNoteNumber, note.getNumber() + 1); diagram.getPaintDevice().addSequenceElement(note); notes.add(note); closeNote(note.getLocation().getName()); diagram.getFragmentManager().openFragments(); diagram.getPaintDevice().announce(note.getHeight()); note.setTop(diagram.getVerticalPosition()); if (note.isConsuming()) { diagram.extendLifelines(note.getHeight()); } else { pendingNotes.put(note.getLocation().getName(), note); } if (diagram.getDataProvider().getState() != null) { diagram.addToStateMap(note, diagram.getDataProvider().getState()); } diagram.getFragmentManager().clearLabels(); return true; } Pair<Lifeline, Integer> eventAssoc = diagram.getDataProvider().getEventAssociation(); if (eventAssoc != null) { associateEvent(eventAssoc.getFirst(), eventAssoc.getSecond()); return true; } return false; }
private void areStatesValid() { for (State s : Diagram.getInstance().getAllStates()) { s.apply(validVisitor); } }