/** 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); } } }
/** * Performing the action. * * <p> * * @param actionEvent the action event */ public void actionPerformed(ActionEvent actionEvent) { // initializes file chooser JFileChooser f = DeployHelper.createExportFileChooser(); f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); f.setCurrentDirectory(new File(mainFrame.getLastImageExportPath())); int returnVal = f.showSaveDialog(mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = f.getSelectedFile(); // gets file path and file extension String filePath = selectedFile.getPath(); if (!(new File(filePath)).exists()) { DeployHelper.handleException(mainFrame, null, "Directory not exists."); return; } exportAllImages(DeployHelper.getExtension(f), filePath, true); } }
/** * Updates the node corresponding to the document tree node in the diagram viewer and the model * elements list. * * @param documentTreeNode the document tree node * @param isSelected the flag whether selecting or unselecting the node */ private void selectNode(DocumentTreeNode documentTreeNode, boolean isSelected) { DocumentTreeNodeType type = documentTreeNode.getType(); if (type != DocumentTreeNodeType.DIAGRAM_CATEGORY) { Object object = documentTreeNode.getNodeObject(); if (object instanceof Diagram) { selectDiagram((Diagram) object, isSelected); } else { List<JComponent> jComponents = new ArrayList<JComponent>(); ModelElement modelElement; if (type == DocumentTreeNodeType.MODEL_ELEMENT) { modelElement = (ModelElement) object; jComponents = DeployHelper.getComponent((ModelElement) object, mainFrame); } else { modelElement = DeployHelper.getElement((GraphElement) object); JComponent component = DeployHelper.getComponent((GraphElement) object, mainFrame); if (component != null) { jComponents.add(component); } } if (jComponents.size() > 0) { for (JComponent jComponent : jComponents) { if (isSelected) { mainFrame.getDiagramViewer().addSelectedElement(jComponent); } else { mainFrame.getDiagramViewer().removeSelectedElement(jComponent); } updateDiagramViewAndStyle(jComponent, isSelected); } } if (isSelected) { modelElements.add(modelElement); } else { remove(modelElement); } } } }
/** * The selected document tree node is changed. * * @param event the selection changed event * @throws IllegalArgumentException if event is null */ public void treeNodeSelectionChanged(SelectionChangedEvent event) { DeployHelper.checkNotNull(event, "event"); updateNodes(event); updatePanels(); openDiagram(); DocumentTreeTabbedPane documentTreePanel = mainFrame.getDocumentTree(); DocumentTreeView documentTreeView = documentTreePanel.getCurrentPanel().getCurrentView(); JTree tree = documentTreeView.getTree(); tree.scrollPathToVisible(tree.getSelectionPath()); // BugFix: BUGR-419 // This bug is caused by the JTree get the focus from the Document Editor. // So, it is better not request the focus here. // tree.requestFocus(); }
/** Creates the graph node for new node. */ protected void createGraphNode() { graphNode = DeployHelper.createGraphNodeForClass(element, position, size); NodeContainer nodeContainer = getNodeContainer(); if (nodeContainer != null) { GraphNode container = nodeContainer.getGraphNode(); GraphNode bodyCompartment = (GraphNode) container.getContaineds().get(1); setAddDiagramElementAction( new AddDiagramElementAction( bodyCompartment, graphNode, modelManager.getProjectConfigurationManager())); } else { setAddDiagramElementAction( new AddDiagramElementAction( getDiagramView().getDiagram(), graphNode, modelManager.getProjectConfigurationManager())); } }
/** * The documenttreenode's name is changed. Updates the element and panels. * * @param event the NameChangedEvent * @throws IllegalArgumentException if event is null */ public void treeNodeNameChanged(NameChangedEvent event) { DeployHelper.checkNotNull(event, "event"); DocumentTreeNode treeNode = event.getTreeNode(); DocumentTreeNodeType nodeType = treeNode.getType(); Object object = treeNode.getNodeObject(); List<JComponent> jComponents = new ArrayList<JComponent>(); ModelElement modelElement = null; if (nodeType == DocumentTreeNodeType.MODEL_ELEMENT) { // when the changed node is a model element. modelElement = (ModelElement) object; if (modelElement instanceof AssociationEnd) { jComponents = DeployHelper.getComponent(((AssociationEnd) modelElement).getAssociation(), mainFrame); } else { jComponents = DeployHelper.getComponent(modelElement, mainFrame); } } else if (nodeType == DocumentTreeNodeType.GRAPH_ELEMENT) { if (object instanceof Diagram) { // when the changed node is a diagram. ((Diagram) object).setName(event.getNewName()); /* * BugFix: BUGR-65 Sorting diagrams */ mainFrame.getDocumentTree().updateTree(); mainFrame.getDiagramViewer().openDiagramView((Diagram) object); mainFrame .getDocumentTree() .getCurrentPanel() .getCurrentView() .setSelectedTreeNodes(new DocumentTreeNode[] {treeNode}); } else { // When the changed node is a graph element. modelElement = DeployHelper.getElement((GraphElement) object); jComponents.add(DeployHelper.getComponent((GraphElement) object, mainFrame)); } } else { mainFrame.getDocumentTree().getCurrentPanel().getCurrentView().updateTreeNode(treeNode); } if (modelElement != null) { if (modelElement instanceof ClassImpl) { DeployHelper.changeConstructors( mainFrame, (ClassImpl) modelElement, event.getNewName(), jComponents); } else { ChangeEntityNameAction changeEntityNameAction = new ChangeEntityNameAction( modelElement, event.getNewName(), mainFrame.isAutoGenerateMethods()); mainFrame.handleActionEvent(changeEntityNameAction, jComponents, "change name"); } } }
/** Creates the model element for new node. */ protected void createModelElement() { element = new ClassImpl(); element.setName(name); // Obtain the stereotypes from project configuration manager Set<Stereotype> newStereotypes = new HashSet<Stereotype>(); newStereotypes.add(getStandardStereotype("Enum")); getMainFrame().getPropertiesPanel().addStereotypes(newStereotypes, element.getClass()); for (Stereotype stereotype : newStereotypes) { element.addStereotype(stereotype); } NodeContainer nodeContainer = getNodeContainer(); if (nodeContainer != null) { setAddModelElementAction( new AddClassAction( element, modelManager, (Namespace) DeployHelper.getElement(nodeContainer))); } else { setAddModelElementAction(new AddClassAction(element, modelManager)); } }
/** Updates the style panel, property panel and documentation panel. */ private void updatePanels() { mainFrame.getStylePanel().setVisible(true); mainFrame.getPropertiesPanel().setVisible(true); mainFrame.getDocumentationPanel().setVisible(true); if (styleObjects.size() == 0) { mainFrame.getStylePanel().clearStyleObjects(); mainFrame.getStylePanel().setVisible(false); } else { mainFrame.getStylePanel().setStyleObjectList(styleObjects); } if (modelElements.size() == 0) { mainFrame.getPropertiesPanel().setVisible(false); mainFrame.getDocumentationPanel().setVisible(false); } else { if (modelElements.size() == 1) { DeployHelper.notifyDocumentationPanel(mainFrame); mainFrame.getDocumentationPanel().setTarget(modelElements.get(0)); } else { mainFrame.getDocumentationPanel().setVisible(false); } mainFrame.getPropertiesPanel().configurePanel(modelElements); } }
/** * Creates an instance of RemoveAbstractionAction. * * @param edge edge to remove * @return an an instance of RemoveAbstractionAction */ private static RemoveAbstractionAction createRemoveAbstractionAction(AbstractionEdge edge) { Abstraction abstraction = (Abstraction) DeployHelper.getElement(edge.getGraphEdge()); return new RemoveAbstractionAction(abstraction); }
/** * Performing the action. * * <p> * * @param actionEvent the action event */ public void actionPerformed(ActionEvent actionEvent) { CopyPasteCutUtil.copyComplete( mainFrame, new HashSet<Object>(DeployHelper.getFilteredSelectedNodes(mainFrame))); }
/** * Creates an instance of RemoveUseCaseAction. * * @param node node to remove * @return an an instance of RemoveUseCaseAction */ private static RemoveUseCaseAction createRemoveUseCaseAction(UseCaseNode node) { UseCase usecase = (UseCase) DeployHelper.getElement(node.getGraphNode()); return new RemoveUseCaseAction(usecase); }
/** Creates a new ExceptionNode node. */ protected void createNode() { EnumClassNode node = DeployHelper.createEnumClassNode(getMainFrame(), graphNode); setNode(node); }
/** * Creates an instance of document tree event handler with the mainframe. * * @param mainFrame the mainframe */ public DocumentTreeEventHandler(MainFrame mainFrame) { DeployHelper.checkNotNull(mainFrame, "mainFrame"); this.mainFrame = mainFrame; }
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) { } }