/** Opens the diagram which contains the last selected element in the diagram viewer. */ private void openDiagram() { Object object = null; DocumentTreeNode documentTreeNode; for (int i = documentTreeNodes.size() - 1; i >= 0; --i) { documentTreeNode = documentTreeNodes.get(i); if (documentTreeNode.getType() != DocumentTreeNodeType.DIAGRAM_CATEGORY) { if (!(documentTreeNode.getNodeObject() instanceof Collaboration) && !(documentTreeNode.getNodeObject() instanceof ActivityGraph)) { object = documentTreeNode.getNodeObject(); if ((object instanceof GraphElement) || (DeployHelper.getGraphElement((ModelElement) object) != null)) { break; } object = null; } } } if (object == null) { return; } Diagram diagram = null; DiagramView view = DeployHelper.getDiagramView(mainFrame); if (object instanceof Diagram) { diagram = (Diagram) object; } else { if (object instanceof ModelElement) { List<Diagram> diagrams = DeployHelper.getDiagram((ModelElement) object); if ((view != null) && (diagrams.contains(view.getDiagram()))) { diagram = view.getDiagram(); } else { if (diagrams.size() > 0) { diagram = diagrams.get(0); } } } else { diagram = DeployHelper.getDiagram((GraphElement) object); } } if (diagram != null) { if (view == null || view.getDiagram() != diagram) { DiagramView openedView = mainFrame.getDiagramViewer().openDiagramView(diagram); DeployHelper.updateZoomPane(openedView); } } }
/** Prepare the test environment. */ protected void setUp() throws Exception { ConfigManager.getInstance().add(StressHelper.CONFIG_FILE); Constructor ctor = DiagramView.class.getDeclaredConstructor(Diagram.class, DiagramViewer.class); ctor.setAccessible(true); DiagramView diagramView = (DiagramView) ctor.newInstance(new Object[] {StressHelper.createDiagram(), new DiagramViewer()}); // insert 100 nodes into diagramView for (int i = 0; i < 100; i++) { diagramView.add( new MockNode( new GraphNode(), new Point(i * 10, i * 10), new Rectangle(0, 0, 100, 100), new ArrayList<SelectionCornerType>())); } handler = new SelectionHandler(); event = new SelectionEvent(diagramView, new Rectangle(0, 0, 1000, 1000)); }
public void exportAllImages(String extension, String filePath, boolean showProcess) { /* * BUGR-108: The aim is to export all the diagrams (along with the * hidden ones) and preview them in a separate JFrame, that will have * JLabels describing the current action. * * To fix that, I will create a JFrame and have its contentPane as a * JPanel that will have 2 JLabels, 1 JProgressBar and the * DiagramViewer. Then, create all the diagrams inside the DiagramViewer * as tabs. Next, export each diagram in it and update the JPanel's * JLabels and JProgressBar. Finally close the frame. */ UMLModelManager modelManager = UMLModelManager.getInstance(); JFrame exportingFrame = null; JProgressBar bar = null; JPanel panel = null; JLabel export_num = null; JLabel export_name = null; exportingFrame = new JFrame("Exporting All Diagrams"); if (showProcess) { exportingFrame.setBounds(100, 100, 500, 500); exportingFrame.setAlwaysOnTop(true); } else { exportingFrame.setBounds(0, 0, 0, 0); exportingFrame.setUndecorated(true); exportingFrame.setAlwaysOnTop(false); } exportingFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); exportingFrame.setResizable(false); exportingFrame.setEnabled(false); panel = new JPanel(); panel.setLayout(null); panel.setVisible(true); if (showProcess) { export_num = new JLabel("Exporting:"); export_num.setBounds(10, 10, 200, 20); export_num.setVisible(true); panel.add(export_num); export_name = new JLabel("Current Diagram:"); export_name.setBounds(10, 30, 480, 20); export_name.setVisible(true); panel.add(export_name); bar = new JProgressBar(0, 0); bar.setStringPainted(true); bar.setBounds(250, 10, 240, 20); bar.setVisible(true); panel.add(bar); } DiagramViewer viewer = null; try { viewer = new DiagramViewer(); viewer.setBackgroundGridVisible(false); List<Diagram> diagrams = modelManager.getDiagrams(); int length = diagrams.size(); for (int i = 0; i < length; i++) { Diagram diagram = diagrams.get(i); DiagramView view = viewer.openDiagramView(diagram); mainFrame.recoverDiagramView(diagram, view, mainFrame.isConverted); } if (showProcess) { bar.setMaximum(length); } viewer.setBounds(0, 50, 500, 450); panel.add(viewer); exportingFrame.setContentPane(panel); exportingFrame.setVisible(true); DiagramView[] views = viewer.getCachedDiagramViews(); for (int i = 0; i < length; i++) { DiagramView view = views[i]; Diagram diagram = view.getDiagram(); if (showProcess) { export_num.setText("Exporting: " + (i + 1) + " of " + length); export_name.setText("Current Diagram: " + diagram.getName()); bar.setValue(i + 1); } viewer.getTabbedPane().setSelectedIndex(i); panel.paintImmediately(0, 0, 500, 500); if (diagram.isVisible()) { DeployHelper.exportToFile( mainFrame, view, filePath, DeployHelper.generateOutputFileName(diagram.getName()) + "." + extension, extension); } } exportingFrame.dispose(); mainFrame.setLastImageExportPath(filePath); } catch (ConfigurationException e) { } }