/** * Selection handler * * @param tree The source event * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent) */ @Override public void valueChanged(TreeSelectionEvent tree) { JTree component = (JTree) tree.getSource(); JSplitPane splitPanel = (JSplitPane) component.getParent().getParent().getParent(); PaletteNode node = (PaletteNode) component.getLastSelectedPathComponent(); if (node == null) { // Nothing is selected. return; } JScrollPane nodeView = null; final Dimension dimension = splitPanel.getRightComponent().getPreferredSize(); if (node instanceof Category) { final PaletteListModel model = new PaletteListModel((Category) node); final JComponent list = new PaletteConfiguratorListView(model); nodeView = new JScrollPane(list); } else if (node instanceof PreLoaded) { final PreLoaded palette = (PreLoaded) node; final PaletteView view = new PaletteView(); for (PaletteBlock b : palette.getBlock()) { view.add(new PaletteBlockCtrl(b).getView()); } panel.setViewportView(view); nodeView = panel; } else if (node instanceof Custom) { final Custom desc = (Custom) node; JavaController controller = new JavaController(); PaletteDiagram diagram = new PaletteDiagram(controller.createObject(Kind.DIAGRAM)); diagram.openDiagramAsPal(desc.getPath().getEvaluatedPath()); nodeView = diagram.getAsComponent(); } else { Logger.getLogger(PaletteManagerTreeSelectionListener.class.getName()) .severe("tree selection is not handled"); return; } // update nodeView.setPreferredSize(dimension); splitPanel.setRightComponent(nodeView); nodeView.validate(); }
/** * Change the label of the port according to the integer parameters property. * * @param source the source of the block */ public void updateLabel(final BasicBlock source) { /** Get the input port children */ final List<InputPort> ports = new ArrayList<InputPort>(); for (int i = 0; i < source.getChildCount(); i++) { final mxICell port = source.getChildAt(i); if (port instanceof InputPort) { ports.add((InputPort) port); } } /** Set the ports labels */ JavaController controller = new JavaController(); VectorOfInt ipar = new VectorOfInt(); controller.getObjectProperty(source.getUID(), Kind.BLOCK, ObjectProperties.IPAR, ipar); for (int i = 0; i < ports.size(); i++) { final int gain; if (i < ipar.size()) { gain = ipar.get(i); } else { gain = 1; } ports.get(i).setValue(getLabel(gain)); } /** Check if all the values are equal to the default one. */ if (!hasDefaultValue(ports)) { return; } /** When all values are equal to the default one, set it to the block and hide the children. */ source.setValue(NOT_PRINTED_LABEL); for (InputPort port : ports) { port.setValue(""); } }