Example usage for javax.swing JTree JTree

List of usage examples for javax.swing JTree JTree

Introduction

In this page you can find the example usage for javax.swing JTree JTree.

Prototype

@ConstructorProperties({ "model" })
public JTree(TreeModel newModel) 

Source Link

Document

Returns an instance of JTree which displays the root node -- the tree is created using the specified data model.

Usage

From source file:org.nuclos.client.wizard.steps.NuclosEntitySQLLayoutStep.java

@Override
protected void initComponents() {

    double size[][] = { { TableLayout.FILL, 20, TableLayout.FILL },
            { TableLayout.PREFERRED, 20, 20, 20, 20, 20, 5, TableLayout.PREFERRED, 20 } };

    TableLayout layout = new TableLayout(size);
    layout.setVGap(3);//from  ww w  .  jav a2  s  .c o m
    layout.setHGap(5);
    this.setLayout(layout);

    lbRowColorScript = new JLabel(SpringLocaleDelegate.getInstance().getMessage(
            "wizard.step.entitysqllayout.rowcolor", "Hintergrundfarbe der Zeilendarstellung konfigurieren"));
    btRowColorScript = new JButton("...");
    btRowColorScript.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ScriptEditor editor = new ScriptEditor();
            if (getModel().getRowColorScript() != null) {
                editor.setScript(getModel().getRowColorScript());
            }
            editor.run();
            NuclosScript script = editor.getScript();
            if (org.nuclos.common2.StringUtils.isNullOrEmpty(script.getSource())) {
                script = null;
            }
            getModel().setRowColorScript(script);
        }
    });

    lbLayout = new JLabel(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.2",
            "M\u00f6chten Sie eine Standard-Maske generieren lassen"));
    cbLayout = new JCheckBox();
    cbLayout.setToolTipText(SpringLocaleDelegate.getInstance().getMessage(
            "wizard.step.entitysqllayout.tooltip.2", "M\u00f6chten Sie eine Standard-Maske generieren lassen"));

    lbAttributeGroup = new JLabel(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.entitysqllayout.12", "Attributegruppen werden zusammengefasst"));
    cbAttributeGroup = new JCheckBox();
    cbAttributeGroup.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.entitysqllayout.tooltip.3", "Attributegruppen werden zusammengefasst"));

    lbAttributeText = new JLabel(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.13",
            "Geben Sie die Reihenfolge an, in der die Felder in der Maske erstellt werden sollen"));

    lbSubforms = new JLabel(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.14",
            "Vorhandene Unterformular mit ins Layout aufnehmen"));
    cbSubforms = new JCheckBox();
    cbSubforms.setToolTipText(SpringLocaleDelegate.getInstance().getMessage(
            "wizard.step.entitysqllayout.tooltip.4", "Vorhandene Unterformulare mit ins Layout aufnehmen"));

    lbEditFields = new JLabel(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.15",
            "Editierungsfelder erstellen:"));
    cbEditFields = new JCheckBox();
    cbEditFields.setSelected(true);
    cbEditFields.setToolTipText(SpringLocaleDelegate.getInstance().getMessage(
            "wizard.step.entitysqllayout.tooltip.7", "Editierungsfelder mit in das Layout aufnehmen"));

    listAttributeOrder = new JList();

    treeModel = new MyTreeModel();

    treeAttributeOrder = new JTree(treeModel);
    treeAttributeOrder.setCellRenderer(new MyTreeCellRenderer());
    treeAttributeOrder.setRootVisible(false);
    treeAttributeOrder.setExpandsSelectedPaths(true);

    sPane = new JScrollPane(listAttributeOrder);

    panelAttributes = new JPanel();
    double sizePanel[][] = { { TableLayout.FILL, 3, 20 }, { 20, 3, 20, 3, TableLayout.PREFERRED } };
    panelAttributes.setLayout(new TableLayout(sizePanel));

    btUp = new JButton(Icons.getInstance().getIconSortAscending());
    btUp.setToolTipText(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.tooltip.5",
            "Attribut nach oben schieben"));
    btDown = new JButton(Icons.getInstance().getIconSortDescending());
    btDown.setToolTipText(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.tooltip.6",
            "Attribut nach unten schieben"));

    panelAttributes.add(sPane, "0,0, 0,4");
    panelAttributes.add(btUp, "2,0");
    panelAttributes.add(btDown, "2,2");

    this.add(lbRowColorScript, "0,0");
    this.add(btRowColorScript, "1,0");
    this.add(lbLayout, "0,1");
    this.add(cbLayout, "1,1");
    this.add(lbAttributeGroup, "0,2");
    this.add(cbAttributeGroup, "1,2");
    this.add(lbSubforms, "0,3");
    this.add(cbSubforms, "1,3");
    this.add(lbEditFields, "0,4");
    this.add(cbEditFields, "1,4");
    this.add(lbAttributeText, "0,5, 1,5");
    this.add(panelAttributes, "0,6, 1,7");

    enableLayoutOptions(false);

    //      cbAttributeGroup.addItemListener(new ItemListener() {
    //
    //         @Override
    //         public void itemStateChanged(ItemEvent e) {
    //            JCheckBox cb = (JCheckBox)e.getItem();
    //            if(cb.isSelected()) {
    //               sPane.setViewportView(treeAttributeOrder);
    //            }
    //            else {
    //               sPane.setViewportView(listAttributeOrder);
    //            }
    //         }
    //      });

    cbLayout.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            JCheckBox cb = (JCheckBox) e.getItem();
            NuclosEntitySQLLayoutStep.this.model.setCreateLayout(cb.isSelected());
            if (cb.isSelected() && hasEntityLayout) {
                (new Bubble(cbLayout,
                        SpringLocaleDelegate.getInstance().getMessage("wizard.step.entitysqllayout.9",
                                "Achtung! Ihr bestehendes Layout wird berschrieben!"),
                        5, Position.UPPER)).setVisible(true);
            }
            enableLayoutOptions(cb.isSelected());
        }
    });

    btUp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //            if(cbAttributeGroup.isSelected()) {
            //               buttonUpAction2();
            //            }
            //            else {
            buttonUpAttributeAction();
            //            }

        }
    });

    btDown.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //            if(cbAttributeGroup.isSelected()) {
            //               buttonDownAction2();
            //            }
            //            else {
            buttonDownAttributeAction();
        }
        //         }
    });

}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryTreeDialog.java

protected void init(final boolean addNewButtonPanel) {

    setModal(true);/*from   w  w  w .ja  v  a 2s  . co m*/
    setTitle(Messages.getInstance().getString("SolutionRepositoryTreeDialog.Title"));

    this.addNewButtonPanel = addNewButtonPanel;

    this.repositoryTreeModel = new RepositoryTreeModel();

    repositoryBrowser = new JTree(repositoryTreeModel);
    repositoryBrowser.setCellRenderer(new RepositoryTreeCellRenderer());
    repositoryBrowser.addMouseListener(new DoubleClickHandler());
    repositoryBrowser.setRootVisible(true);
    repositoryBrowser.setShowsRootHandles(true);
    repositoryBrowser.setToggleClickCount(1);

    super.init();
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

From source file:org.pentaho.reporting.engine.classic.demo.util.CompoundDemoFrame.java

protected Container createDefaultContentPane() {

    demoContent = new JPanel();
    demoContent.setLayout(new BorderLayout());
    demoContent.setMinimumSize(new Dimension(100, 100));
    demoContent.add(getNoHandlerInfoPane(), BorderLayout.CENTER);

    JPanel placeHolder = new JPanel();
    placeHolder.setMinimumSize(new Dimension(300, 0));
    placeHolder.setPreferredSize(new Dimension(300, 0));
    placeHolder.setMaximumSize(new Dimension(300, 0));

    JPanel rootContent = new JPanel();
    rootContent.setLayout(new BorderLayout());
    rootContent.add(demoContent, BorderLayout.CENTER);
    rootContent.add(placeHolder, BorderLayout.NORTH);

    final DemoSelectorTreeNode root = new DemoSelectorTreeNode(null, demoSelector);
    final DefaultTreeModel model = new DefaultTreeModel(root);
    final JTree demoTree = new JTree(model);
    demoTree.addTreeSelectionListener(new TreeSelectionHandler());

    JSplitPane rootSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(demoTree),
            rootContent);/*from  w  ww . j  a v a 2  s. c  o m*/
    rootSplitPane.setContinuousLayout(true);
    rootSplitPane.setDividerLocation(200);
    rootSplitPane.setOneTouchExpandable(true);
    return rootSplitPane;
}

From source file:org.photovault.swingui.volumetree.VolumeTreeController.java

public VolumeTreeController(AbstractController parent) {
    super(parent);
    rootNode = new DefaultMutableTreeNode();
    model = new DefaultTreeModel(rootNode);
    view = new JTree(model);
    view.setShowsRootHandles(true);//  www.  j a  v a 2 s  .  co  m
    view.setRootVisible(true);
    view.addTreeWillExpandListener(this);
    view.addTreeSelectionListener(this);
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            initVolumes();
        }
    });
}

From source file:org.rdv.ui.ChannelListPanel.java

/**
 * Create the channel tree panel./*from   w  w  w.  j a  v a2s.co m*/
 * 
 * @return  the component containing the channel tree
 */
private JComponent createTreePanel() {
    treeModel = new ChannelTreeModel();
    treeModel.addPropertyChangeListener(new FilterPropertyChangeListener());

    tree = new JTree(treeModel);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setExpandsSelectedPaths(true);
    tree.setCellRenderer(new ChannelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addTreeSelectionListener(new ChannelTreeSelectionListener());
    tree.addMouseListener(new ChannelTreeMouseListener());
    tree.setBorder(new EmptyBorder(0, 5, 5, 5));

    JScrollPane treeView = new JScrollPane(tree);
    treeView.setBorder(null);
    treeView.setViewportBorder(null);

    tree.setDragEnabled(true);
    tree.setTransferHandler(new ChannelTransferHandler());

    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_LINK,
            new ChannelDragGestureListener());

    return treeView;
}

From source file:org.richie.codeGen.ui.CodeGenMainUI.java

public JScrollPane getTreepanel() {
    if (treePanel == null) {
        treePanel = new JScrollPane();
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("");
        tree = new JTree(root);
        treePanel.setViewportView(tree);
    }// www  .j ava 2 s  .co  m
    return treePanel;
}

From source file:org.richie.codeGen.ui.CodeGenMainUI.java

/**
 * @param list// www  .j a v a2 s  .  c om
 * @return
 */
private JTree initTreeData(List<Table> list) {
    TableTreeNode root = null;
    if (list == null || list.size() == 0) {
        root = new TableTreeNode("");
    } else {
        root = new TableTreeNode(list.get(0).getDataBaseCode() + ":" + list.get(0).getDataBaseName());
        for (Table table : list) {
            list.get(0).getDataBaseName();
            TableTreeNode node = new TableTreeNode(table);
            root.add(node);
            List<Column> columnList = table.getFields();
            for (Column column : columnList) {
                TableTreeNode columnNode = new TableTreeNode(column);
                node.add(columnNode);
            }
        }
    }
    JTree newTree = new JTree(root);
    newTree.setCellRenderer(new TableTreeRender());
    newTree.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent me) {
            doMouseClicked(me);
        }

    });
    return newTree;
}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java

private void setupTree() {
    treeModel = new DefaultTreeModel(null);
    tree = new JTree(treeModel);

    tree.setCellRenderer(new ComponentTreeCellRenderer());

    // popup menu
    tree.addMouseListener(new PopupListener() {
        @Override//from w w  w  . j av a  2 s  .c o  m
        public void showPopup(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            DefaultMutableTreeNode node = (path == null) ? null
                    : (DefaultMutableTreeNode) path.getLastPathComponent();

            if (node == null)
                return;

            // ensure we select the node...
            tree.setSelectionPath(path);

            // get the element
            Element element = (Element) node.getUserObject();

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this);
            popup.show(tree, e.getX(), e.getY());
        }
    });
    ToolTipManager.sharedInstance().setInitialDelay(0);

    tree.setToolTipText("");

}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java

private void setupTree() {
    treeModel = new DefaultTreeModel(null);
    tree = new JTree(treeModel);

    tree.setCellRenderer(new ComponentTreeCellRenderer());

    // popup menu
    tree.addMouseListener(new PopupListener() {
        @Override//  w w w .  j ava 2s .c om
        public void showPopup(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            DefaultMutableTreeNode node = (path == null) ? null
                    : (DefaultMutableTreeNode) path.getLastPathComponent();

            if (node == null)
                return;

            // ensure we select the node...
            tree.setSelectionPath(path);

            // get the element
            Element element = (Element) node.getUserObject();

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this);
            popup.show(tree, e.getX(), e.getY());
        }
    });
    ToolTipManager.sharedInstance().setInitialDelay(0);

    tree.setToolTipText("");

}

From source file:org.trianacode.gui.hci.ApplicationFrame.java

/**
 * Initialises the panels in the main window
 *///  w ww  .  j av a 2  s  .co  m
private void initLayout() {

    GUIEnv.setApplicationFrame(this);
    ColorManager.setDefaultColorModel(new TrianaColorModel());
    ColorManager.registerColorModel(ScriptConstants.SCRIPT_RENDERING_HINT, new ScriptColorModel());

    // do this after all other color loading
    ColorTable.instance().loadUserPrefs();

    TaskGraphView defaultview = new TaskGraphView("Default View");
    TrianaComponentModel compmodel = new TrianaComponentModel(tools, this, this);

    defaultview.setDefaultToolModel(compmodel);
    defaultview.setDefaultOpenGroupModel(compmodel);
    defaultview.registerToolModel(ScriptConstants.SCRIPT_RENDERING_HINT, new ScriptComponentModel());
    defaultview.registerToolModel(TextToolConstants.TEXT_TOOL_RENDERING_HINT, new TextToolComponentModel());
    defaultview.registerToolModel(HiddenToolConstants.HIDDEN_RENDERING_HINT, new HiddenComponentModel());

    TaskGraphView mapview = new TaskGraphView("Map View", defaultview);
    mapview.registerOpenGroupModel(MapConstants.MAP_RENDERING_HINT, new MapComponentModel());
    mapview.registerToolModel(MapConstants.MAP_LOCATION_RENDERING_HINT, new MapLocationComponentModel());

    TaskGraphViewManager.setDefaultTaskGraphView(defaultview);
    TaskGraphViewManager.registerTaskGraphView(MapConstants.MAP_RENDERING_HINT, mapview);

    taskGraphFileHandler = new TaskGraphFileHandler();

    trianaMenuBar = new TrianaMainMenu(this, tools);
    this.setJMenuBar(trianaMenuBar);

    TrianaShutdownHook shutDownHook = new TrianaShutdownHook();
    Runtime.getRuntime().addShutdownHook(shutDownHook);
    getDesktopViewManager().addDesktopViewListener(this);
    this.workspace.add(getDesktopViewManager().getWorkspace(), BorderLayout.CENTER);

    ((TrianaMainMenu) trianaMenuBar).addHelp();

    ToolTreeModel treemodel = new ToolTreeModel(tools);
    toolboxTree = new JTree(treemodel);
    toolboxTree.addFocusListener(this);
    toolboxTree.setCellRenderer(new TrianaTreeRenderer());
    toolmonitor.setTree(toolboxTree);

    treemodel.addTreeModelListener(this);

    ToolTipManager.sharedInstance().registerComponent(toolboxTree);
    ToolTipManager.sharedInstance().setInitialDelay(TOOL_TIP_SHOW_DELAY);
    ToolTipManager.sharedInstance().setDismissDelay(TOOL_TIP_HIDE_DELAY);

    //set up key maps
    MainTrianaKeyMapFactory keymaps = new MainTrianaKeyMapFactory(this, ActionDisplayOptions.DISPLAY_NAME);
    InputMap inputMap = keymaps.getInputMap();
    inputMap.setParent(this.getRootPane().getInputMap());
    this.getRootPane().setInputMap(JComponent.WHEN_FOCUSED, inputMap);
    ActionMap actMap = keymaps.getActionMap();
    actMap.setParent(this.getRootPane().getActionMap());
    this.getRootPane().setActionMap(actMap);

    leaflistener = new LeafListener(toolboxTree, this, tools);

    keymaps = new MainTrianaKeyMapFactory(leaflistener, ActionDisplayOptions.DISPLAY_NAME);
    inputMap = keymaps.getInputMap();
    inputMap.setParent(toolboxTree.getInputMap());
    toolboxTree.setInputMap(JComponent.WHEN_FOCUSED, inputMap);
    actMap = keymaps.getActionMap();
    actMap.setParent(toolboxTree.getActionMap());
    toolboxTree.setActionMap(actMap);

    toolboxTree.addMouseListener(leaflistener);
    toolboxTree.addMouseMotionListener(leaflistener);
    //toolboxTree.setRootVisible(false);
    JPanel toolPanel = new JPanel(new BorderLayout());

    SearchToolBar searchtoolbar = new SearchToolBar("Search", toolboxTree, treemodel);
    searchtoolbar.setFloatable(false);

    toolPanel.add(searchtoolbar, BorderLayout.NORTH);
    JScrollPane scroll = new JScrollPane(toolboxTree);

    toolPanel.add(scroll, BorderLayout.CENTER);

    JSplitPane verticalSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, toolPanel, workspace);

    TrianaToolBar toolbar = new TrianaToolBar("Main ToolBar", this);
    TrianaUnitToolBar unitToolbar = new TrianaUnitToolBar("Unit ToolBar");
    toolbar.setRollover(true);
    unitToolbar.setRollover(true);

    JPanel innerpanel = new JPanel();
    innerpanel.setLayout(new BoxLayout(innerpanel, BoxLayout.X_AXIS));
    innerpanel.add(toolbar);
    innerpanel.add(Box.createHorizontalStrut(10));
    innerpanel.add(unitToolbar);
    innerpanel.add(Box.createHorizontalGlue());

    JPanel outerpanel = new JPanel(new BorderLayout());

    outerpanel.add(innerpanel, BorderLayout.NORTH);
    outerpanel.add(verticalSplit, BorderLayout.CENTER);
    getContentPane().add(outerpanel);
}