/**
  * Updates the diagram viewer when selecting a diagram.
  *
  * @param diagram the diagram
  * @param isSelected whether the diagram is selected
  */
 private void selectDiagram(Diagram diagram, boolean isSelected) {
   DiagramViewer diagramViewer = mainFrame.getDiagramViewer();
   DiagramView diagramView = diagramViewer.createDiagramView(diagram);
   if (isSelected) {
     styleObjects.add(new GraphNodeStyleObjectAdapter(diagram));
     diagramViewer.addSelectedElement(diagramView);
   } else {
     removeStyleObject(diagram);
     diagramViewer.removeSelectedElement(diagramView);
   }
 }
Exemplo n.º 2
0
 /**
  * Set the edge as the active component in diagram viewer.
  *
  * @param edge the Edge instance to active
  */
 static void setEdgeActive(Edge edge) {
   DiagramViewer diagramViewer = edge.getDiagramViewer();
   if (diagramViewer != null) {
     diagramViewer.addSelectedElement(edge);
   }
 }
  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) {
    }
  }