@Override public void valueChanged(TreeSelectionEvent e) { if (e.getSource() == colors && !locked) { TreeSelectionModel tsm = colors.getSelectionModel(); TreePath tp[] = tsm.getSelectionPaths(); if (tp == null) return; Vector<ClassedItem> tmp = new Vector<ClassedItem>(); for (TreePath element : tp) { try { Object[] path = element.getPath(); ClassedItem ci = new ClassedItem(path[1].toString(), path[2].toString()); tmp.add(ci); } catch (Exception exp) { // User did not select a leafnode } } if (sceneElement instanceof NenyaImageSceneElement) { ((NenyaImageSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0])); } if (sceneElement instanceof NenyaTileSceneElement) { ((NenyaTileSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0])); } if (sceneElement instanceof NenyaComponentSceneElement) { ((NenyaComponentSceneElement) sceneElement) .getComponents()[itemList.getSelectedIndex()].setColorList( tmp.toArray(new ClassedItem[0])); } submitElement(sceneElement, null); } else { super.valueChanged(e); } }
public ReplicatedTreeView(ReplicatedTree tree, Object title) throws Exception { this.tree = tree; tree.addReplicatedTreeListener(this); addNotify(); setTitle("ReplicatedTreeDemo: mbr=" + title); tree_model = new DefaultTreeModel(root); jtree = new JTree(tree_model); jtree.setDoubleBuffered(true); jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); JScrollPane scroll_pane = new JScrollPane(jtree); populateTree(); getContentPane().add(scroll_pane, BorderLayout.CENTER); addWindowListener(this); table_model.setColumnIdentifiers(new String[] {"Name", "Value"}); table_model.addTableModelListener(this); setTableColumnWidths(); tablePanel = new JPanel(); tablePanel.setLayout(new BorderLayout()); tablePanel.add(table.getTableHeader(), BorderLayout.NORTH); tablePanel.add(table, BorderLayout.CENTER); getContentPane().add(tablePanel, BorderLayout.SOUTH); jtree.addTreeSelectionListener(this); // REVISIT MouseListener ml = new MouseAdapter() { public void mouseClicked(MouseEvent e) { int selRow = jtree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = jtree.getPathForLocation(e.getX(), e.getY()); if (selRow != -1) { selected_node = makeFQN(selPath.getPath()); jtree.setSelectionPath(selPath); if (e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK) { operationsPopup.show(e.getComponent(), e.getX(), e.getY()); } } } }; jtree.addMouseListener(ml); createMenus(); setLocation(50, 50); setSize( getInsets().left + getInsets().right + 485, getInsets().top + getInsets().bottom + 367); init(); setVisible(true); }
@Override public void adoptElement(SceneElement elem) { if (!(elem instanceof NenyaImageSceneElement || elem instanceof NenyaTileSceneElement || elem instanceof NenyaComponentSceneElement)) { enableEditor(false); return; } DefaultComboBoxModel dcm = (DefaultComboBoxModel) itemList.getModel(); // Important: Work on a copy, not on the original. Otherwise we mess up the undomanager sceneElement = elem.copy(); if ((sceneElement instanceof NenyaImageSceneElement) && !locked) { dcm.removeAllElements(); String[] tmp = ((NenyaImageSceneElement) sceneElement).getPath(); dcm.addElement(tmp[tmp.length - 1]); } if ((sceneElement instanceof NenyaTileSceneElement) && !locked) { dcm.removeAllElements(); dcm.addElement(((NenyaTileSceneElement) sceneElement).getTileName()); } if ((sceneElement instanceof NenyaComponentSceneElement) && !locked) { dcm.removeAllElements(); NenyaComponentItem[] ni = ((NenyaComponentSceneElement) sceneElement).getComponents(); for (NenyaComponentItem element : ni) { dcm.addElement(element); } } try { ClassedItem[] cols = null; if (elem instanceof NenyaTileSceneElement) cols = ((NenyaTileSceneElement) elem).getColorList(); if (elem instanceof NenyaImageSceneElement) cols = ((NenyaImageSceneElement) elem).getColorList(); if (elem instanceof NenyaComponentSceneElement) { NenyaComponentItem nci = (NenyaComponentItem) dcm.getSelectedItem(); cols = nci.getColorList(); } Vector<TreePath> collect = new Vector<TreePath>(); TreeNode root = (TreeNode) colors.getModel().getRoot(); for (ClassedItem col : cols) { String[] tmp = {root.toString(), col.getClassName(), col.getItemName()}; collect.add(TreeUtil.findPath(root, tmp)); } TreePath[] path = collect.toArray(new TreePath[0]); colors.getSelectionModel().setSelectionPaths(path); } catch (Exception e) { // Either the tree is filtered away or the selected item is not colorized. } enableEditor(true); itemList.setEnabled(elem instanceof NenyaComponentSceneElement); }
public void uninstallUI(JComponent c) { HelpModel helpmodel = searchnav.getModel(); searchnav.removeComponentListener(this); searchnav.removePropertyChangeListener(this); TreeSelectionModel tsm = tree.getSelectionModel(); tsm.removeTreeSelectionListener(this); searchnav.setLayout(null); searchnav.removeAll(); if (helpmodel != null) { helpmodel.removeHelpModelListener(this); } searchnav = null; }
private void restoreUsageExpandState(final Collection<UsageState> states) { // always expand the last level group final DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot(); for (int i = root.getChildCount() - 1; i >= 0; i--) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i); if (child instanceof GroupNode) { final TreePath treePath = new TreePath(child.getPath()); myTree.expandPath(treePath); } } myTree.getSelectionModel().clearSelection(); for (final UsageState usageState : states) { usageState.restore(); } }
/** * Initialize the common user interface components. * * <p> */ protected JButton[] initUI( String title, JComponent extraComps, String confirm, String[][] extra, String cancel) { JButton[] extraBtns = null; /* create dialog body components */ { JPanel body = new JPanel(); body.setName("MainDialogPanel"); body.setLayout(new BoxLayout(body, BoxLayout.Y_AXIS)); body.add(UIFactory.createPanelLabel("Existing Layouts:")); body.add(Box.createRigidArea(new Dimension(0, 4))); { DefaultMutableTreeNode root = new DefaultMutableTreeNode(new TreeData(), true); DefaultTreeModel model = new DefaultTreeModel(root, true); JTree tree = new JFancyTree(model); pTree = tree; tree.setName("DarkTree"); tree.setCellRenderer(new JLayoutTreeCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); { JScrollPane scroll = UIFactory.createScrollPane( pTree, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, new Dimension(230, 120), new Dimension(230, 150), null); body.add(scroll); } } if (extraComps != null) body.add(extraComps); extraBtns = super.initUI(title, body, confirm, null, extra, cancel); } return extraBtns; }
private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) { if (!myTree.isExpanded(pathFrom)) { return; } final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent(); final int childCount = node.getChildCount(); for (int idx = 0; idx < childCount; idx++) { final TreeNode child = node.getChildAt(idx); if (child instanceof UsageNode) { final Usage usage = ((UsageNode) child).getUsage(); states.add( new UsageState( usage, myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child)))); } else { captureUsagesExpandState(pathFrom.pathByAddingChild(child), states); } } }
public void installUI(JComponent c) { searchnav = (JHelpSearchNavigator) c; HelpModel helpmodel = searchnav.getModel(); searchnav.setLayout(new BorderLayout()); searchnav.addPropertyChangeListener(this); searchnav.addComponentListener(this); if (helpmodel != null) { helpmodel.addHelpModelListener(this); } JLabel search = new JLabel(HelpUtilities.getString(HelpUtilities.getLocale(c), "search.findLabel")); searchparams = new JTextField("", 20); search.setLabelFor(searchparams); searchparams.addActionListener(searchAction); JPanel box = new JPanel(); box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS)); box.add(search); box.add(searchparams); searchnav.add("North", box); topNode = new DefaultMutableTreeNode(); lastTOCnode = null; tree = new JTree(topNode); // public String convertValueToText(Object val TreeSelectionModel tsm = tree.getSelectionModel(); tsm.addTreeSelectionListener(this); tree.setShowsRootHandles(false); tree.setRootVisible(false); sp = new JScrollPane(); sp.getViewport().add(tree); searchnav.add("Center", sp); reloadData(); }
public JComponent buildLeft() { String colSpec = FormLayoutUtil.getColSpec(LEFT_COL_SPEC, orientation); FormLayout layout = new FormLayout(colSpec, LEFT_ROW_SPEC); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.EMPTY_BORDER); builder.setOpaque(false); CellConstraints cc = new CellConstraints(); JButton but = new JButton(LooksFrame.readImageIcon("kdevelop_down-32.png")); but.setToolTipText(Messages.getString("TrTab2.6")); but.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { TreePath path = tree.getSelectionModel().getSelectionPath(); if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) { TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent()); if (node.getPlayer() != null) { DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); // get the tree model // now get the index of the selected node in the DefaultTreeModel int index = dtm.getIndexOfChild(node.getParent(), node); // if selected node is first, return (can't move it up) if (index < node.getParent().getChildCount() - 1) { dtm.insertNodeInto( node, (DefaultMutableTreeNode) node.getParent(), index + 1); // move the node dtm.reload(); for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); } tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath())); updateEngineModel(); } } } } }); builder.add(but, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation)); JButton but2 = new JButton(LooksFrame.readImageIcon("up-32.png")); but2.setToolTipText(Messages.getString("TrTab2.6")); but2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { TreePath path = tree.getSelectionModel().getSelectionPath(); if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings) { TreeNodeSettings node = ((TreeNodeSettings) path.getLastPathComponent()); if (node.getPlayer() != null) { DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); // get the tree model // now get the index of the selected node in the DefaultTreeModel int index = dtm.getIndexOfChild(node.getParent(), node); // if selected node is first, return (can't move it up) if (index != 0) { dtm.insertNodeInto( node, (DefaultMutableTreeNode) node.getParent(), index - 1); // move the node dtm.reload(); for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); } tree.getSelectionModel().setSelectionPath(new TreePath(node.getPath())); updateEngineModel(); } } } } }); builder.add(but2, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation)); JButton but3 = new JButton(LooksFrame.readImageIcon("connect_no-32.png")); but3.setToolTipText(Messages.getString("TrTab2.0")); but3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { TreePath path = tree.getSelectionModel().getSelectionPath(); if (path != null && path.getLastPathComponent() instanceof TreeNodeSettings && ((TreeNodeSettings) path.getLastPathComponent()).getPlayer() != null) { ((TreeNodeSettings) path.getLastPathComponent()) .setEnable(!((TreeNodeSettings) path.getLastPathComponent()).isEnable()); updateEngineModel(); tree.updateUI(); } } }); builder.add(but3, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation)); DefaultMutableTreeNode root = new DefaultMutableTreeNode(Messages.getString("TrTab2.11")); TreeNodeSettings commonEnc = new TreeNodeSettings(Messages.getString("TrTab2.5"), null, buildCommon()); commonEnc .getConfigPanel() .addComponentListener( new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { handleCardComponentChange(e.getComponent()); } }); tabbedPane.add(commonEnc.id(), commonEnc.getConfigPanel()); root.add(commonEnc); parent = new DefaultMutableTreeNode[5]; parent[0] = new DefaultMutableTreeNode(Messages.getString("TrTab2.14")); parent[1] = new DefaultMutableTreeNode(Messages.getString("TrTab2.15")); parent[2] = new DefaultMutableTreeNode(Messages.getString("TrTab2.16")); parent[3] = new DefaultMutableTreeNode(Messages.getString("TrTab2.17")); parent[4] = new DefaultMutableTreeNode(Messages.getString("TrTab2.18")); root.add(parent[0]); root.add(parent[1]); root.add(parent[2]); root.add(parent[3]); root.add(parent[4]); tree = new JTree(new DefaultTreeModel(root)) { private static final long serialVersionUID = -6703434752606636290L; }; tree.setRootVisible(false); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (e.getNewLeadSelectionPath() != null && e.getNewLeadSelectionPath().getLastPathComponent() instanceof TreeNodeSettings) { TreeNodeSettings tns = (TreeNodeSettings) e.getNewLeadSelectionPath().getLastPathComponent(); cl.show(tabbedPane, tns.id()); } } }); tree.setCellRenderer(new TreeRenderer()); JScrollPane pane = new JScrollPane( tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); builder.add(pane, FormLayoutUtil.flip(cc.xyw(2, 1, 4), colSpec, orientation)); builder.addLabel( Messages.getString("TrTab2.19"), FormLayoutUtil.flip(cc.xyw(2, 5, 4), colSpec, orientation)); builder.addLabel( Messages.getString("TrTab2.20"), FormLayoutUtil.flip(cc.xyw(2, 7, 4), colSpec, orientation)); JPanel panel = builder.getPanel(); // Apply the orientation to the panel and all components in it panel.applyComponentOrientation(orientation); return panel; }