Example usage for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION

List of usage examples for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION

Introduction

In this page you can find the example usage for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION.

Prototype

int SINGLE_TREE_SELECTION

To view the source code for javax.swing.tree TreeSelectionModel SINGLE_TREE_SELECTION.

Click Source Link

Document

Selection can only contain one path at a time.

Usage

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

/**
     * Creates new form FAdmin//from w  ww.  j a va  2  s . c  o  m
     */
    public FAdmin() {
        addWindowListener(new WindowListener() {

            @Override
            public void windowOpened(WindowEvent e) {
            }

            @Override
            public void windowClosing(WindowEvent e) {
                timer.stop();
            }

            @Override
            public void windowClosed(WindowEvent e) {
            }

            @Override
            public void windowIconified(WindowEvent e) {
            }

            @Override
            public void windowDeiconified(WindowEvent e) {
            }

            @Override
            public void windowActivated(WindowEvent e) {
                Uses.closeSplash();
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
            }
        });
        initComponents();

        setTitle(getTitle() + " " + Uses.getLocaleMessage("project.name" + FAbout.getCMRC_SUFF()));

        try {
            setIconImage(
                    ImageIO.read(FAdmin.class.getResource("/ru/apertum/qsystem/client/forms/resources/admin.png")));
        } catch (IOException ex) {
            System.err.println(ex);
        }

        // 
        final Toolkit kit = Toolkit.getDefaultToolkit();
        setLocation((Math.round(kit.getScreenSize().width - getWidth()) / 2),
                (Math.round(kit.getScreenSize().height - getHeight()) / 2));
        // ? ?
        final JFrame fr = this;
        tray = QTray.getInstance(fr, "/ru/apertum/qsystem/client/forms/resources/admin.png",
                getLocaleMessage("tray.caption"));
        tray.addItem(getLocaleMessage("tray.caption"), (ActionEvent e) -> {
            setVisible(true);
            setState(JFrame.NORMAL);
        });
        tray.addItem("-", (ActionEvent e) -> {
        });
        tray.addItem(getLocaleMessage("tray.exit"), (ActionEvent e) -> {
            dispose();
            System.exit(0);
        });

        int ii = 1;
        final ButtonGroup bg = new ButtonGroup();
        final String currLng = Locales.getInstance().getLangCurrName();
        for (String lng : Locales.getInstance().getAvailableLocales()) {
            final JRadioButtonMenuItem item = new JRadioButtonMenuItem(
                    org.jdesktop.application.Application.getInstance(ru.apertum.qsystem.QSystem.class).getContext()
                            .getActionMap(FAdmin.class, fr).get("setCurrentLang"));
            bg.add(item);
            item.setSelected(lng.equals(currLng));
            item.setText(lng); // NOI18N
            item.setName("QRadioButtonMenuItem" + (ii++)); // NOI18N
            menuLangs.add(item);
        }

        //  ??    ??.
        listUsers.addListSelectionListener((ListSelectionEvent e) -> {
            userListChange();
        });
        //  ??    ??.
        listResponse.addListSelectionListener((ListSelectionEvent e) -> {
            responseListChange();
        });
        listSchedule.addListSelectionListener((ListSelectionEvent e) -> {
            scheduleListChange();
        });
        listCalendar.addListSelectionListener(new ListSelectionListener() {

            private int oldSelectedValue = 0;
            private int tmp = 0;

            public int getOldSelectedValue() {
                return oldSelectedValue;
            }

            public void setOldSelectedValue(int oldSelectedValue) {
                this.oldSelectedValue = tmp;
                this.tmp = oldSelectedValue;
            }

            private boolean canceled = false;

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (canceled) {
                    canceled = false;
                } else {
                    if (tableCalendar.getModel() instanceof CalendarTableModel) {
                        final CalendarTableModel model = (CalendarTableModel) tableCalendar.getModel();
                        if (!model.isSaved()) {
                            final int res = JOptionPane.showConfirmDialog(null,
                                    getLocaleMessage("calendar.change.title"),
                                    getLocaleMessage("calendar.change.caption"), JOptionPane.YES_NO_CANCEL_OPTION,
                                    JOptionPane.QUESTION_MESSAGE);
                            switch (res) {
                            case 0: // ?  ??
                                model.save();
                                calendarListChange();
                                setOldSelectedValue(listCalendar.getSelectedIndex());
                                break;
                            case 1: // ??  ??

                                calendarListChange();
                                setOldSelectedValue(listCalendar.getSelectedIndex());

                                break;
                            case 2: //  ??  ???   
                                canceled = true;
                                listCalendar.setSelectedIndex(getOldSelectedValue());
                                break;
                            }
                        } else {
                            calendarListChange();
                            setOldSelectedValue(listCalendar.getSelectedIndex());
                        }
                    } else {
                        calendarListChange();
                        setOldSelectedValue(listCalendar.getSelectedIndex());
                    }
                }
            }
        });
        //  ??  ?  ??.
        treeServices.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        treeInfo.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        /*
         treeServices.setCellRenderer(new DefaultTreeCellRenderer() {
            
         @Override
         public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
         super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
         setText(((Element) value).attributeValue(Uses.TAG_NAME));
         return this;
         }
         });*/
        treeServices.addTreeSelectionListener((TreeSelectionEvent e) -> {
            serviceListChange();
        });
        treeInfo.addTreeSelectionListener((TreeSelectionEvent e) -> {
            infoListChange();
        });

        textFieldStartTime.setInputVerifier(DateVerifier);
        textFieldFinishTime.setInputVerifier(DateVerifier);

        // ?
        loadSettings();
        //   ? ?.
        startTimer();
        //  
        loadConfig();

        spinnerPropServerPort.getModel().addChangeListener(new ChangeNet());
        spinnerPropClientPort.getModel().addChangeListener(new ChangeNet());
        spinnerWebServerPort.getModel().addChangeListener(new ChangeNet());

        spinnerServerPort.getModel().addChangeListener(new ChangeSettings());
        spinnerClientPort.getModel().addChangeListener(new ChangeSettings());
        spinnerUserRS.getModel().addChangeListener(new ChangeUser());

        //?   .
        final Helper helper = Helper.getHelp("ru/apertum/qsystem/client/help/admin.hs");
        helper.setHelpListener(menuItemHelp);
        helper.enableHelpKey(jPanel1, "introduction");
        helper.enableHelpKey(jPanel3, "monitoring");
        helper.enableHelpKey(jPanel4, "configuring");
        helper.enableHelpKey(jPanel8, "net");

        helper.enableHelpKey(jPanel17, "schedulers");
        helper.enableHelpKey(jPanel19, "calendars");
        helper.enableHelpKey(jPanel2, "infoSystem");
        helper.enableHelpKey(jPanel13, "responses");
        helper.enableHelpKey(jPanel18, "results");

        treeServices.setTransferHandler(new TransferHandler() {

            @Override
            public boolean canImport(TransferHandler.TransferSupport info) {
                final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
                if (dl.getChildIndex() == -1) {
                    return false;
                }
                // Get the string that is being dropped.
                final Transferable t = info.getTransferable();
                final QService data;
                try {
                    data = (QService) t.getTransferData(DataFlavor.stringFlavor);
                    return (data.getParent().getId()
                            .equals(((QService) dl.getPath().getLastPathComponent()).getId()));
                } catch (UnsupportedFlavorException | IOException e) {
                    return false;
                }
            }

            @Override
            public boolean importData(TransferHandler.TransferSupport info) {
                if (!info.isDrop()) {
                    return false;
                }
                final QService data;
                try {
                    data = (QService) info.getTransferable().getTransferData(DataFlavor.stringFlavor);
                } catch (UnsupportedFlavorException | IOException e) {
                    System.err.println(e);
                    return false;
                }
                final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
                final TreePath tp = dl.getPath();
                final QService parent = (QService) tp.getLastPathComponent();
                ((QServiceTree) treeServices.getModel()).moveNode(data, parent, dl.getChildIndex());
                return true;
            }

            @Override
            public int getSourceActions(JComponent c) {
                return MOVE;
            }

            @Override
            protected Transferable createTransferable(JComponent c) {
                return (QService) ((JTree) c).getLastSelectedPathComponent();
            }
        });
        treeServices.setDropMode(DropMode.INSERT);

        //   ?
        final AnnotationSessionFactoryBean as = (AnnotationSessionFactoryBean) Spring.getInstance().getFactory()
                .getBean("conf");
        if (as.getServers().size() > 1) {
            final JMenu menu = new JMenu(getLocaleMessage("admin.servers"));
            as.getServers().stream().map((ser) -> {
                final JMenuItem mi1 = new JMenuItem(as);
                mi1.setText(ser.isCurrent() ? "<html><u><i>" + ser.getName() + "</i></u>" : ser.getName());
                return mi1;
            }).forEach((mi1) -> {
                menu.add(mi1);
            });
            jMenuBar1.add(menu, 4);
            jMenuBar1.add(new JLabel(
                    "<html><span style='font-size:13.0pt;color:red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ["
                            + as.getName() + "]"));
        }
        comboBoxVoices.setVisible(false);
    }

From source file:com.ibm.soatf.gui.SOATestingFrameworkGUI.java

/**
 * initialization stuff like models, listeners, ... for GUI components and configuration initialization
 *//*from  www  . j a  v  a2  s .com*/
private void setupGUIComponents() {
    //called asynchronuously so that the GUI shows up much sooner while the initialization is going on in background
    //why is it in the AWT invokeLater? because AsyncWorker tasks have to be called from within the EventDispatch thread
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            AsyncWorker.post(new AdditionalInitAsyncTask());
        }
    });

    //table with operation results
    jtResults.setModel(jtResultsModel);
    jtResults.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                displayResultDetails();
            }
        }
    });
    //middle panel, with the interface details (tree)
    jtInterfaceDetails.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}

From source file:edu.harvard.i2b2.previousquery.ui.QueryPreviousRunsPanel.java

/**
 * This method is called from within the constructor to initialize the form.
 *///from w  ww.j av  a 2s  . com
private void initComponents() {

    System.setProperty("PQSortByTimeCheckBox", "true");
    System.setProperty("QueryToolMaxQueryNumber", "20");
    System.setProperty("PQMaxPatientsNumber", "200");
    System.setProperty("PQSortByNameCheckBox", "false");

    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();

    setLayout(new java.awt.BorderLayout());

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("Queries by " + UserInfoBean.getInstance().getUserName());
    tmpData.tooltip("Previous query runs");
    tmpData.visualAttribute("CA");
    top = new DefaultMutableTreeNode(tmpData);
    // top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    // treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    // jTree1.getSelectionModel().setSelectionMode
    // (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    // JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.expandPath(new TreePath(top.getPath()));
    }

    ArrayList<QueryMasterData> queries = previousQueries;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(queries.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
    jTree1.addTreeWillExpandListener(this);
}

From source file:de.codesourcery.eve.skills.ui.components.impl.planning.ShoppingListComponent.java

@Override
protected JPanel createPanel() {

    table.setFillsViewportHeight(true);// ww  w  . j  a  va2 s  .  com
    table.setRowSorter(tableModel.getRowSorter());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {

            final int[] selectedViewRows = table.getSelectedRows();
            final int[] selectedModelRows = new int[selectedViewRows.length];

            int i = 0;
            for (int viewRow : selectedViewRows) {
                selectedModelRows[i++] = viewRow;
            }

            List<TableRow> selection = new ArrayList<TableRow>();
            for (int modelRow : selectedModelRows) {
                selection.add(tableModel.getRow(modelRow));
            }
            totalValue.setItems(selection);
            totalVolume.setItems(selection);
        }
    });

    FixedBooleanTableCellRenderer.attach(table);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    final JPanel controlsPanel = new JPanel();
    controlsPanel.setLayout(new GridBagLayout());
    controlsPanel.add(this.tableViewModePanel, constraints(0, 0).useRemainingWidth().end());

    final JPanel totalsPanel = new JPanel();
    totalsPanel.setLayout(new GridBagLayout());

    totalsPanel.add(totalValue.getPanel(),
            constraints(0, 0).weightX(0.2).width(1).weightY(0).anchorWest().end());
    totalsPanel.add(totalVolume.getPanel(),
            constraints(1, 0).weightX(0.2).width(1).weightY(0).anchorWest().end());

    final JPanel rest = new JPanel();
    rest.setLayout(new GridBagLayout());

    rest.add(componentPanel, constraints(0, 0).weightX(0.2).width(1).weightY(0.3).anchorWest().end());
    rest.add(totalsPanel,
            constraints(0, 1).weightX(0.2).width(1).weightY(0).resizeHorizontally().anchorWest().end());
    rest.add(controlsPanel,
            constraints(0, 2).weightX(0.2).width(1).weightY(0).resizeHorizontally().anchorWest().end());
    rest.add(new JScrollPane(table),
            constraints(0, 3).weightX(0.2).width(1).weightY(0.7).resizeBoth().anchorWest().end());

    //        new GridLayoutBuilder().add(
    //            new VerticalGroup( new Cell( componentPanel ),
    //                    new FixedCell( controlsPanel ),
    //                    new FixedCell( totalsPanel ),
    //                    new Cell( new JScrollPane( table ) ) ) ).addTo( rest );

    final ImprovedSplitPane splitPane = new ImprovedSplitPane(JSplitPane.HORIZONTAL_SPLIT,
            new JScrollPane(tree), rest);

    panel.add(splitPane, constraints(0, 0).resizeBoth().end());

    tree.setRootVisible(false);
    tree.setCellRenderer(cellRenderer);

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            final TreePath selection = e.getPath();
            selectedNodeChanged((ITreeNode) (selection != null ? selection.getLastPathComponent() : null));
        }
    });

    final PopupMenuBuilder menuBuilder = new PopupMenuBuilder();

    menuBuilder.addItem("New shopping list...", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final ShoppingListEditorComponent comp = new ShoppingListEditorComponent("New list", "",
                    new ArrayList<ItemWithQuantity>());

            comp.setModal(true);
            ComponentWrapper.wrapComponent("Create new shopping list", comp).setVisible(true);
            if (!comp.wasCancelled()) {
                manager.addShoppingList(comp.getShoppingList());
            }
        }
    });

    menuBuilder.addItem("Edit list...", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            final ITreeNode node = getSelectedTreeNode();
            if (node == null) {
                return;
            }

            final ShoppingList list = (ShoppingList) node.getValue();
            final ShoppingListEditorComponent comp = new ShoppingListEditorComponent(list);
            comp.setModal(true);
            ComponentWrapper.wrapComponent(list.getTitle(), comp).setVisible(true);
            if (!comp.wasCancelled() && comp.isExistingEntryEdited()) {
                manager.shoppingListChanged(comp.getShoppingList());
            }
        }

        @Override
        public boolean isEnabled() {
            final ITreeNode node = getSelectedTreeNode();
            return node != null && node.getValue() instanceof ShoppingList;
        }
    });

    menuBuilder.addItem("Delete item", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            final ITreeNode node = getSelectedTreeNode();
            if (node != null && node.getValue() instanceof ShoppingListEntry) {
                final ShoppingListEntry entry = (ShoppingListEntry) node.getValue();
                final ShoppingList list = entry.getShoppingList();

                manager.removeEntry(list, entry);
                selectedNodeChanged(null);
            }
        }

        @Override
        public boolean isEnabled() {
            final ITreeNode node = getSelectedTreeNode();
            return node != null && node.getValue() instanceof ShoppingListEntry;
        }
    });

    menuBuilder.addItem("Delete list", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final ShoppingList list = getSelectedShoppingList();
            if (list != null) {
                manager.removeShoppingList(list);
                selectedNodeChanged(null);
            }
        }

        @Override
        public boolean isEnabled() {
            final ITreeNode node = getSelectedTreeNode();
            return node.getValue() instanceof ShoppingList;
        }
    });

    menuBuilder.addItem("Copy this list to clipboard (text)", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            putSelectedShoppingListOnClipboard();
        }

        @Override
        public boolean isEnabled() {
            return getSelectedShoppingList() != null;
        }
    });

    menuBuilder.attach(tree);
    return panel;
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

/**
 * This method is called from within the constructor to initialize the form.
 *//* w  w w  . ja v a 2 s.c  o  m*/
private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;
    System.setProperty("PQSortByTimeCheckBox", "true");
    System.setProperty("QueryToolMaxQueryNumber", "20");
    System.setProperty("PQMaxPatientsNumber", "200");
    System.setProperty("PQSortByNameCheckBox", "false");

    jPanel1 = new javax.swing.JPanel();
    jContainComboBox = new javax.swing.JComboBox();
    jCategoryComboBox = new javax.swing.JComboBox();
    jSearchStringTextField = new javax.swing.JTextField();
    jFindButton = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jPanel2 = new javax.swing.JPanel();
    jStartTimeTextField = new javax.swing.JTextField();
    jBackwardButton = new javax.swing.JButton();
    jForwardButton = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();

    //setLayout(new java.awt.BorderLayout());
    setLayout(new java.awt.BorderLayout(20, 4));

    jPanel1.setLayout(new java.awt.GridBagLayout());

    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Search By Name"));
    jPanel1.setMinimumSize(new java.awt.Dimension(0, 50));
    jPanel1.setPreferredSize(new java.awt.Dimension(400, 80));
    jContainComboBox.setModel(new javax.swing.DefaultComboBoxModel(
            new String[] { "Containing", "Start With", "End With", "Exact" }));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.ipadx = 32;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 2);
    jPanel1.add(jContainComboBox, gridBagConstraints);

    jCategoryComboBox.setModel(new javax.swing.DefaultComboBoxModel(
            new String[] { "Any Category", "Previous Query", "Previous Query Result", "Patient" }));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.ipadx = 14;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.6;
    gridBagConstraints.insets = new java.awt.Insets(4, 2, 0, 2);
    jPanel1.add(jCategoryComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 11;
    gridBagConstraints.ipady = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.9;
    gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
    jPanel1.add(jSearchStringTextField, gridBagConstraints);

    jFindButton.setText("Find");
    jFindButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jFindButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.ipadx = 19;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 2);
    jPanel1.add(jFindButton, gridBagConstraints);

    add(jPanel1, java.awt.BorderLayout.NORTH);

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("Queries by " + UserInfoBean.getInstance().getUserName());
    tmpData.tooltip("Previous query runs");
    tmpData.visualAttribute("CA");
    top = new DefaultMutableTreeNode(tmpData);
    // top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    // treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    // jTree1.getSelectionModel().setSelectionMode
    // (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    // JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.expandPath(new TreePath(top.getPath()));
    }

    ArrayList<QueryMasterData> queries = previousQueries;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(queries.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
    jTree1.addTreeWillExpandListener(this);

    jPanel2.setLayout(new java.awt.GridBagLayout());

    jPanel2.setMinimumSize(new java.awt.Dimension(92, 20));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 244;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.9;
    gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0);
    jPanel2.add(jStartTimeTextField, gridBagConstraints);

    jBackwardButton.setText("<");
    jBackwardButton.setMaximumSize(new java.awt.Dimension(43, 22));
    jBackwardButton.setMinimumSize(new java.awt.Dimension(43, 22));
    jBackwardButton.setPreferredSize(new java.awt.Dimension(43, 22));
    jBackwardButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jBackwardButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2);
    jPanel2.add(jBackwardButton, gridBagConstraints);

    jForwardButton.setText(">");
    jForwardButton.setMaximumSize(new java.awt.Dimension(43, 22));
    jForwardButton.setMinimumSize(new java.awt.Dimension(43, 22));
    jForwardButton.setPreferredSize(new java.awt.Dimension(43, 22));
    jForwardButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jForwardButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 43, 0, 3);
    jPanel2.add(jForwardButton, gridBagConstraints);

    jLabel2.setText("Begin:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(3, 7, 0, 2);
    jPanel2.add(jLabel2, gridBagConstraints);

    add(jPanel2, java.awt.BorderLayout.SOUTH);
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private JPanel createAParameterBox(final boolean first) {

    final JLabel runLabel = new JLabel("<html><b>Number of runs:</b> 0</html>");
    final JLabel warningLabel = new JLabel();

    final JButton closeButton = new JButton();
    closeButton.setOpaque(false);//  ww  w.  j  a va 2s  .c  om
    closeButton.setBorder(null);
    closeButton.setFocusable(false);

    if (!first) {
        closeButton.setRolloverIcon(PARAMETER_BOX_REMOVE);
        closeButton.setRolloverEnabled(true);
        closeButton.setIcon(RGBGrayFilter.getDisabledIcon(closeButton, PARAMETER_BOX_REMOVE));
        closeButton.setActionCommand(ACTIONCOMMAND_REMOVE_BOX);
    }

    final JScrollPane treeScrPane = new JScrollPane();
    final DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode();
    final JTree tree = new JTree(treeRoot);
    ToolTipManager.sharedInstance().registerComponent(tree);

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(new ParameterBoxTreeRenderer());
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(final TreeSelectionEvent e) {
            final TreePath selectionPath = tree.getSelectionPath();
            boolean success = true;
            if (editedNode != null
                    && (selectionPath == null || !editedNode.equals(selectionPath.getLastPathComponent())))
                success = modify();

            if (success) {
                if (selectionPath != null) {
                    cancelAllSelectionBut(tree);
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    if (!node.equals(editedNode)) {
                        ParameterInATree userObj = null;
                        final DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
                        if (!node.isRoot()
                                && selectionPath.getPathCount() == model.getPathToRoot(node).length) {
                            userObj = (ParameterInATree) node.getUserObject();
                            final ParameterInfo info = userObj.info;
                            editedNode = node;
                            editedTree = tree;
                            edit(info);
                        } else {
                            tree.setSelectionPath(null);
                            if (cancelButton.isEnabled())
                                cancelButton.doClick();
                            resetSettings();
                            enableDisableSettings(false);
                            editedNode = null;
                            editedTree = null;
                        }

                        updateDescriptionField(userObj);
                    } else
                        updateDescriptionField();

                } else
                    updateDescriptionField();

                enableDisableParameterCombinationButtons();
            } else {
                final DefaultTreeModel model = (DefaultTreeModel) editedTree.getModel();
                final DefaultMutableTreeNode storedEditedNode = editedNode;
                editedNode = null;
                tree.setSelectionPath(null);
                editedNode = storedEditedNode;
                editedTree.setSelectionPath(new TreePath(model.getPathToRoot(editedNode)));
            }
        }
    });

    treeScrPane.setViewportView(tree);
    treeScrPane.setBorder(null);
    treeScrPane.setViewportBorder(null);
    treeScrPane.setPreferredSize(new Dimension(450, 250));

    final JButton upButton = new JButton();
    upButton.setOpaque(false);
    upButton.setRolloverEnabled(true);
    upButton.setIcon(PARAMETER_UP_ICON);
    upButton.setRolloverIcon(PARAMETER_UP_ICON_RO);
    upButton.setDisabledIcon(PARAMETER_UP_ICON_DIS);
    upButton.setBorder(null);
    upButton.setToolTipText("Move up the selected parameter");
    upButton.setActionCommand(ACTIONCOMMAND_MOVE_UP);

    final JButton downButton = new JButton();
    downButton.setOpaque(false);
    downButton.setRolloverEnabled(true);
    downButton.setIcon(PARAMETER_DOWN_ICON);
    downButton.setRolloverIcon(PARAMETER_DOWN_ICON_RO);
    downButton.setDisabledIcon(PARAMETER_DOWN_ICON_DIS);
    downButton.setBorder(null);
    downButton.setToolTipText("Move down the selected parameter");
    downButton.setActionCommand(ACTIONCOMMAND_MOVE_DOWN);

    final JPanel mainPanel = FormsUtils.build("~ f:p:g ~ p ~ r:p",
            "012||" + "333||" + "44_||" + "445||" + "446||" + "44_ f:p:g", runLabel, first ? "" : warningLabel,
            first ? warningLabel : closeButton, new FormsUtils.Separator(""), treeScrPane, upButton, downButton)
            .getPanel();

    mainPanel.setBorder(BorderFactory.createTitledBorder(""));

    final JButton addButton = new JButton();
    addButton.setOpaque(false);
    addButton.setRolloverEnabled(true);
    addButton.setIcon(PARAMETER_ADD_ICON);
    addButton.setRolloverIcon(PARAMETER_ADD_ICON_RO);
    addButton.setDisabledIcon(PARAMETER_ADD_ICON_DIS);
    addButton.setBorder(null);
    addButton.setToolTipText("Add selected parameter");
    addButton.setActionCommand(ACTIONCOMMAND_ADD_PARAM);

    final JButton removeButton = new JButton();
    removeButton.setOpaque(false);
    removeButton.setRolloverEnabled(true);
    removeButton.setIcon(PARAMETER_REMOVE_ICON);
    removeButton.setRolloverIcon(PARAMETER_REMOVE_ICON_RO);
    removeButton.setDisabledIcon(PARAMETER_REMOVE_ICON_DIS);
    removeButton.setBorder(null);
    removeButton.setToolTipText("Remove selected parameter");
    removeButton.setActionCommand(ACTIONCOMMAND_REMOVE_PARAM);

    final JPanel result = FormsUtils.build("p ~ f:p:g", "_0 f:p:g||" + "10 p ||" + "20 p||" + "_0 f:p:g",
            mainPanel, addButton, removeButton).getPanel();

    Style.registerCssClasses(result, Dashboard.CSS_CLASS_COMMON_PANEL);

    final ParameterCombinationGUI pcGUI = new ParameterCombinationGUI(tree, treeRoot, runLabel, warningLabel,
            addButton, removeButton, upButton, downButton);
    parameterTreeBranches.add(pcGUI);

    final ActionListener boxActionListener = new ActionListener() {

        //====================================================================================================
        // methods

        //----------------------------------------------------------------------------------------------------
        public void actionPerformed(final ActionEvent e) {
            final String cmd = e.getActionCommand();

            if (ACTIONCOMMAND_ADD_PARAM.equals(cmd))
                handleAddParameter(pcGUI);
            else if (ACTIONCOMMAND_REMOVE_PARAM.equals(cmd))
                handleRemoveParameter(tree);
            else if (ACTIONCOMMAND_REMOVE_BOX.equals(cmd))
                handleRemoveBox(tree);
            else if (ACTIONCOMMAND_MOVE_UP.equals(cmd))
                handleMoveUp();
            else if (ACTIONCOMMAND_MOVE_DOWN.equals(cmd))
                handleMoveDown();
        }

        //----------------------------------------------------------------------------------------------------
        private void handleAddParameter(final ParameterCombinationGUI pcGUI) {
            final Object[] selectedValues = parameterList.getSelectedValues();
            if (selectedValues != null && selectedValues.length > 0) {
                final AvailableParameter[] params = new AvailableParameter[selectedValues.length];
                System.arraycopy(selectedValues, 0, params, 0, selectedValues.length);
                addParameterToTree(params, pcGUI);
                enableDisableParameterCombinationButtons();
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleRemoveParameter(final JTree tree) {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                cancelButton.doClick();

                final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                        .getLastPathComponent();
                if (!node.isRoot()) {
                    final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                    if (parentNode.isRoot()) {
                        removeParameter(tree, node, parentNode);
                        enableDisableParameterCombinationButtons();
                    }
                }
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleRemoveBox(final JTree tree) {
            final int answer = Utilities.askUser(dashboard, false, "Comfirmation",
                    "This operation deletes the combination.",
                    "All related parameter returns back to the list on the left side.", "Are you sure?");
            if (answer == 1) {
                final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();

                if (tree.getSelectionCount() > 0) {
                    editedNode = null;
                    tree.setSelectionPath(null);
                    if (cancelButton.isEnabled())
                        cancelButton.doClick();
                }

                final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
                for (int i = 0; i < root.getChildCount(); ++i) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
                    removeParameter(tree, node, root);
                }

                enableDisableParameterCombinationButtons();

                parameterTreeBranches.remove(pcGUI);
                combinationsPanel.remove(result);
                combinationsPanel.revalidate();

                updateNumberOfRuns();
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void removeParameter(final JTree tree, final DefaultMutableTreeNode node,
                final DefaultMutableTreeNode parentNode) {
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            final ParameterInfo originalInfo = findOriginalInfo(userObj.info);
            if (originalInfo != null) {
                final DefaultListModel model = (DefaultListModel) parameterList.getModel();
                model.addElement(new AvailableParameter(originalInfo, currentModelHandler.getModelClass()));
                final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
                treeModel.removeNodeFromParent(node);
                updateNumberOfRuns();
                tree.expandPath(new TreePath(treeModel.getPathToRoot(parentNode)));
            } else
                throw new IllegalStateException(
                        "Parameter " + userObj.info.getName() + " is not found in the model.");
        }

        //----------------------------------------------------------------------------------------------------
        private void handleMoveUp() {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                boolean success = true;
                if (editedNode != null)
                    success = modify();

                if (success) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

                    if (parent == null || parent.getFirstChild().equals(node)) {
                        tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel
                        tree.setSelectionPath(new TreePath(node.getPath()));
                        return;
                    }

                    final int index = parent.getIndex(node);
                    final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel();
                    treemodel.removeNodeFromParent(node);
                    treemodel.insertNodeInto(node, parent, index - 1);
                    tree.setSelectionPath(new TreePath(node.getPath()));
                }

            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleMoveDown() {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                boolean success = true;
                if (editedNode != null)
                    success = modify();

                if (success) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

                    if (parent == null || parent.getLastChild().equals(node)) {
                        tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel
                        tree.setSelectionPath(new TreePath(node.getPath()));
                        return;
                    }

                    final int index = parent.getIndex(node);
                    final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel();
                    treemodel.removeNodeFromParent(node);
                    treemodel.insertNodeInto(node, parent, index + 1);
                    tree.setSelectionPath(new TreePath(node.getPath()));
                }
            }
        }
    };

    GUIUtils.addActionListener(boxActionListener, closeButton, upButton, downButton, addButton, removeButton);

    result.setPreferredSize(new Dimension(500, 250));
    enableDisableParameterCombinationButtons();

    Style.apply(result, dashboard.getCssStyle());

    return result;
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

/**
 * This method is called from within the constructor to initialize the form.
 *//*from  www  .j  a  va 2 s  . c  o  m*/
private void initComponents() {

    java.awt.GridBagConstraints gridBagConstraints;
    System.setProperty("PQSortByTimeCheckBox", "true");
    System.setProperty("PatientSetMaxQueryNumber", "20");
    System.setProperty("PatientSetMaxPatientsNumber", "200");
    System.setProperty("PQSortByNameCheckBox", "false");

    jPanel1 = new javax.swing.JPanel();
    jContainComboBox = new javax.swing.JComboBox();
    jCategoryComboBox = new javax.swing.JComboBox();
    jSearchStringTextField = new javax.swing.JTextField();
    jFindButton = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jPanel2 = new javax.swing.JPanel();
    jStartTimeTextField = new javax.swing.JTextField();
    jBackwardButton = new javax.swing.JButton();
    jForwardButton = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();

    setLayout(new java.awt.BorderLayout(20, 10));

    jPanel1.setLayout(new java.awt.GridBagLayout());

    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Search By Name"));
    jPanel1.setMinimumSize(new java.awt.Dimension(0, 50));
    jPanel1.setPreferredSize(new java.awt.Dimension(400, 80));
    jContainComboBox.setModel(new javax.swing.DefaultComboBoxModel(
            new String[] { "Containing", "Start With", "End With", "Exact" }));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.ipadx = 32;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 2);
    jPanel1.add(jContainComboBox, gridBagConstraints);

    jCategoryComboBox.setModel(
            new javax.swing.DefaultComboBoxModel(new String[] { "Any Category", "Patient Set", "Patient" }));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.ipadx = 14;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.6;
    gridBagConstraints.insets = new java.awt.Insets(4, 2, 0, 2);
    jPanel1.add(jCategoryComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 11;
    gridBagConstraints.ipady = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.9;
    gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
    jPanel1.add(jSearchStringTextField, gridBagConstraints);

    jFindButton.setText("Find");
    jFindButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jFindButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.ipadx = 19;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 2);
    jPanel1.add(jFindButton, gridBagConstraints);

    add(jPanel1, java.awt.BorderLayout.NORTH);

    QueryResultData tmpData = new QueryResultData();
    tmpData.name("Pateint Sets by " + UserInfoBean.getInstance().getUserName());
    tmpData.tooltip("Patient Sets");
    tmpData.visualAttribute("CA");
    tmpData.type("PATIENTSET");
    top = new DefaultMutableTreeNode(tmpData);
    // top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    // treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    // jTree1.getSelectionModel().setSelectionMode
    // (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    // JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.expandPath(new TreePath(top.getPath()));
    }

    ArrayList<QueryResultData> queries = patientSets;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(patientSets.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
    jTree1.addTreeWillExpandListener(this);

    jPanel2.setLayout(new java.awt.GridBagLayout());

    jPanel2.setMinimumSize(new java.awt.Dimension(92, 20));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 244;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.9;
    gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0);
    jPanel2.add(jStartTimeTextField, gridBagConstraints);

    jBackwardButton.setText("<");
    jBackwardButton.setMaximumSize(new java.awt.Dimension(43, 22));
    jBackwardButton.setMinimumSize(new java.awt.Dimension(43, 22));
    jBackwardButton.setPreferredSize(new java.awt.Dimension(43, 22));
    jBackwardButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jBackwardButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2);
    jPanel2.add(jBackwardButton, gridBagConstraints);

    jForwardButton.setText(">");
    jForwardButton.setMaximumSize(new java.awt.Dimension(43, 22));
    jForwardButton.setMinimumSize(new java.awt.Dimension(43, 22));
    jForwardButton.setPreferredSize(new java.awt.Dimension(43, 22));
    jForwardButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jForwardButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 43, 0, 3);
    jPanel2.add(jForwardButton, gridBagConstraints);

    jLabel2.setText("Begin:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(3, 7, 0, 2);
    jPanel2.add(jLabel2, gridBagConstraints);

    add(jPanel2, java.awt.BorderLayout.SOUTH);
}

From source file:edu.harvard.i2b2.query.ui.QueryConceptTreePanel.java

/** This method is called from within the constructor to
 * initialize the form.//  w w w  .  j  a  v a2  s.  c o m
 */
private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jClearButton = new javax.swing.JButton();
    jConstrainButton = new javax.swing.JButton();
    jExcludeButton = new javax.swing.JButton();
    jOccurrenceButton = new javax.swing.JButton();
    jNameLabel = new javax.swing.JLabel();
    jHintLabel = new javax.swing.JLabel();

    setLayout(null);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A root node");
    tmpData.visualAttribute("FAO");
    top = new DefaultMutableTreeNode(tmpData);
    //top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    //treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);

    jTree1.setDragEnabled(true);
    jTree1.setEditable(true);
    //jTree1.getSelectionModel().setSelectionMode
    //        (TreeSelectionModel.SINGLE_TREE_SELECTION);
    //jTree1.setShowsRootHandles(true);
    //JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    setBorder(javax.swing.BorderFactory.createEtchedBorder());
    add(jScrollPane1);
    //jScrollPane1.setBounds(0, 40, 180, 200);

    jClearButton.setFont(new java.awt.Font("Tahoma", 1, 10));
    jClearButton.setText("X");
    jClearButton.setToolTipText("Clear all items from panel");
    jClearButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jClearButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
    jClearButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jClearButton.setMargin(new java.awt.Insets(-10, -15, -10, -20));
    }
    jClearButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jClearButtonActionPerformed(evt);
        }
    });

    add(jClearButton);
    jClearButton.setBounds(160, 0, 18, 20);

    jConstrainButton.setText("Dates");
    jConstrainButton.setToolTipText("Constrain group by dates");
    jConstrainButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
    jConstrainButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    //jConstrainButton.setMargin(new java.awt.Insets(-10, -15, -10,-20));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jConstrainButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        //jConstrainButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jConstrainButton.setMargin(new java.awt.Insets(-10, -15, -10, -20));
    }

    jConstrainButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jConstrainButtonActionPerformed(evt);
        }
    });

    add(jConstrainButton);
    jConstrainButton.setBounds(0, 20, 40, 21);

    jOccurrenceButton.setText("Occurs > 0x");
    jOccurrenceButton.setToolTipText("Set occurrence times");
    jOccurrenceButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jOccurrenceButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jOccurrenceButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jOccurrenceButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jOccurrenceButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jOccurrenceButton.setMargin(new java.awt.Insets(-10, -10, -10, -10));
    }
    jOccurrenceButton.setIconTextGap(0);
    jOccurrenceButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jOccurrenceButtonActionPerformed(evt);
        }
    });
    jOccurrenceButton.setBounds(40, 20, 90, 21);
    add(jOccurrenceButton);

    //jExcludeButton.setMnemonic('E');
    jExcludeButton.setText("Exclude");
    jExcludeButton.setToolTipText("Exclude all items in group");
    jExcludeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jExcludeButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jExcludeButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jExcludeButton.setMargin(new java.awt.Insets(-10, -15, -10, -20));
        jExcludeButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    }
    jExcludeButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jExcludeButtonActionPerformed(evt);
        }
    });
    add(jExcludeButton);
    jExcludeButton.setBounds(130, 20, 48, 21);

    jNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jNameLabel.setText("Group 1");
    jNameLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    jNameLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    add(jNameLabel);
    jNameLabel.setBounds(0, 0, 160, 20);
    jNameLabel.setTransferHandler(new GroupLabelTextHandler());
    jNameLabel.addMouseListener(new DragMouseAdapter());
    jNameLabel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
        public void mouseMoved(java.awt.event.MouseEvent evt) {
            jNameLabelMouseMoved(evt);
            //System.out.println("mouse x: "+evt.getX()+" y: "+evt.getY());
            //System.out.println("name label x: "+jNameLabel.getX()+" width: "+
            //   jNameLabel.getWidth()+" y: "            
            //   +jNameLabel.getY()+" height "+jNameLabel.getHeight());
        }

    });
    jNameLabel.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseExited(java.awt.event.MouseEvent evt) {
            jNameLabelMouseExited(evt);
        }

    });

    jTree1.addTreeExpansionListener(this);
    jTree1.setTransferHandler(new TextHandler());
    add(jScrollPane1);
    jScrollPane1.setViewportView(jTree1);
    //jTree1.setToolTipText("Double click on a folder to view the items inside");
    //jScrollPane1.getViewport().setToolTipText("Double click on a folder to view the items inside");
    jScrollPane1.setBounds(0, 40, 180, 120);
    //jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    //jTree1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
    //   public void mouseMoved(java.awt.event.MouseEvent evt) {
    //       jScrollPane1MouseMoved(evt);
    //   }

    //@Override
    //public void mouseDragged(MouseEvent e) {
    //    jScrollPane1MouseMoved(e);
    //}

    //});
    //jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
    //   public void mouseExited(java.awt.event.MouseEvent evt) {
    //       jScrollPane1MouseExited(evt);
    //   }

    //@Override
    //public void mouseEntered(MouseEvent e) {

    //    jScrollPane1MouseEntered(e);
    //}

    //});

    jHintLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jHintLabel.setText(
            "<html><center>Drag terms from Navigate, <br>" + "<left>Find and Workplace into this group");
    //jHintLabel.getFont();
    jHintLabel.setFont(new Font("SansSerif", Font.PLAIN, 9));
    //jHintLabel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    jHintLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jHintLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
    //jHintLabel.setBackground(Color.WHITE);
    //jHintLabel.setForeground(Color.WHITE);
    add(jHintLabel);
    jHintLabel.setBounds(0, 120, 180, 30);
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

/**
 * This method is called from within the constructor to initialize the form.
 *//*from   ww  w. ja  va 2  s.co  m*/
private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jClearButton = new javax.swing.JButton();
    jConstrainButton = new javax.swing.JButton();
    jExcludeButton = new javax.swing.JButton();
    jOccurrenceButton = new javax.swing.JButton();
    jNameLabel = new javax.swing.JLabel();
    jHintLabel = new javax.swing.JLabel();

    setLayout(null);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A root node");
    tmpData.visualAttribute("FAO");
    top = new DefaultMutableTreeNode(tmpData);
    // top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    // treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);

    jTree1.setDragEnabled(true);
    jTree1.setEditable(true);
    // jTree1.getSelectionModel().setSelectionMode
    // (TreeSelectionModel.SINGLE_TREE_SELECTION);
    // jTree1.setShowsRootHandles(true);
    // JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    setBorder(javax.swing.BorderFactory.createEtchedBorder());
    add(jScrollPane1);
    // jScrollPane1.setBounds(0, 40, 180, 200);

    jClearButton.setFont(new java.awt.Font("Tahoma", 1, 10));
    jClearButton.setText("X");
    jClearButton.setToolTipText("Clear all items from panel");
    jClearButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jClearButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
    jClearButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jClearButton.setMargin(new java.awt.Insets(-10, -15, -10, -20));
    }
    jClearButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jClearButtonActionPerformed(evt);
        }
    });

    add(jClearButton);
    jClearButton.setBounds(160, 0, 18, 20);

    jConstrainButton.setText("Dates");
    jConstrainButton.setToolTipText("Constrain group by dates");
    jConstrainButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
    jConstrainButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    // jConstrainButton.setMargin(new java.awt.Insets(-10, -15, -10,-20));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jConstrainButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        // jConstrainButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jConstrainButton.setMargin(new java.awt.Insets(-10, -15, -10, -20));
    }

    jConstrainButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jConstrainButtonActionPerformed(evt);
        }
    });

    add(jConstrainButton);
    jConstrainButton.setBounds(0, 20, 40, 21);

    jOccurrenceButton.setText("Occurs > 0x");
    jOccurrenceButton.setToolTipText("Set occurrence times");
    jOccurrenceButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jOccurrenceButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jOccurrenceButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jOccurrenceButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jOccurrenceButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jOccurrenceButton.setMargin(new java.awt.Insets(-10, -10, -10, -10));
    }
    jOccurrenceButton.setIconTextGap(0);
    jOccurrenceButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jOccurrenceButtonActionPerformed(evt);
        }
    });
    jOccurrenceButton.setBounds(40, 20, 90, 21);
    add(jOccurrenceButton);

    // jExcludeButton.setMnemonic('E');
    jExcludeButton.setText("Exclude");
    jExcludeButton.setToolTipText("Exclude all items in group");
    jExcludeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jExcludeButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jExcludeButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
        jExcludeButton.setMargin(new java.awt.Insets(-10, -15, -10, -20));
        jExcludeButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    }
    jExcludeButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jExcludeButtonActionPerformed(evt);
        }
    });
    add(jExcludeButton);
    jExcludeButton.setBounds(130, 20, 48, 21);

    jNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jNameLabel.setText("Group 1");
    jNameLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    jNameLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    add(jNameLabel);
    jNameLabel.setBounds(0, 0, 160, 20);
    jNameLabel.setTransferHandler(new GroupLabelTextHandler());
    jNameLabel.addMouseListener(new DragMouseAdapter());
    jNameLabel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
        public void mouseMoved(java.awt.event.MouseEvent evt) {
            jNameLabelMouseMoved(evt);
            // System.out.println("mouse x: "+evt.getX()+" y: "+evt.
            // getY());
            // System.out.println("name label x: "+jNameLabel.getX()+
            // " width: "+
            // jNameLabel.getWidth()+" y: "
            // +jNameLabel.getY()+" height "+jNameLabel.getHeight());
        }

    });
    jNameLabel.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseExited(java.awt.event.MouseEvent evt) {
            jNameLabelMouseExited(evt);
        }

    });

    jTree1.addTreeExpansionListener(this);
    jTree1.setTransferHandler(new TextHandler());
    add(jScrollPane1);
    jScrollPane1.setViewportView(jTree1);
    // jTree1.setToolTipText(
    // "Double click on a folder to view the items inside");
    // jScrollPane1.getViewport().setToolTipText(
    // "Double click on a folder to view the items inside");
    jScrollPane1.setBounds(0, 40, 180, 120);
    // jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new
    // java.awt.Color(0, 0, 0)));
    // jTree1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
    // {
    // public void mouseMoved(java.awt.event.MouseEvent evt) {
    // jScrollPane1MouseMoved(evt);
    // }

    // @Override
    // public void mouseDragged(MouseEvent e) {
    // jScrollPane1MouseMoved(e);
    // }

    // });
    // jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
    // public void mouseExited(java.awt.event.MouseEvent evt) {
    // jScrollPane1MouseExited(evt);
    // }

    // @Override
    // public void mouseEntered(MouseEvent e) {

    // jScrollPane1MouseEntered(e);
    // }

    // });

    jHintLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jHintLabel.setText(
            "<html><center>Drag terms from Navigate, <br>" + "<left>Find and Workplace into this group");
    // jHintLabel.getFont();
    jHintLabel.setFont(new Font("SansSerif", Font.PLAIN, 9));
    // jHintLabel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    jHintLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jHintLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
    // jHintLabel.setBackground(Color.WHITE);
    // jHintLabel.setForeground(Color.WHITE);
    add(jHintLabel);
    jHintLabel.setBounds(0, 120, 180, 30);
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Aggiunge il pannello delle classificazioni all'interfaccia dei metadati
 *
 * @param innerPanel Pannello sul quale aggiungere i metadati
 * @param kv Valori dei metadati/*from w ww. j  av  a 2s  . co  m*/
 */
private void addClassification(JPanel innerPanel, Integer kv, final String sequence, final String panelname)
        throws Exception {
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                Globals.loader);

        DefaultMutableTreeNode hierarchy = new DefaultMutableTreeNode("root");
        selected = null;
        String selectedPath = "";

        String link = selectedClassificationList.get(panelname + "---" + sequence);

        recursiveOefosTreeviewBuild(hierarchy, oefos.get(link), sequence, panelname);
        DefaultTreeModel model = new DefaultTreeModel(hierarchy);

        final JTree tree = new JTree(model);
        tree.setRootVisible(false);

        if (selected != null) {
            TreePath selpath = new TreePath(selected.getPath());
            tree.setSelectionPath(selpath);

            Object[] nodes = selpath.getPath();

            for (int i = 1; i < nodes.length; i++) {
                selectedPath += nodes[i].toString();
                selectedPath += (i != nodes.length - 1) ? "/" : "";
            }
        }

        tree.setName("MID_" + Integer.toString(kv) + "---" + sequence);
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

        tree.addTreeSelectionListener(new TreeSelectionListener() {

            public void valueChanged(TreeSelectionEvent e) {
                try {
                    setOEFOS(tree, sequence, panelname);
                } catch (Exception ex) {
                    logger.error(ex.getMessage());
                }
            }
        });

        javax.swing.JScrollPane tree_scroller = new javax.swing.JScrollPane();
        tree_scroller
                .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        tree_scroller.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        tree_scroller.setViewportView(tree);
        tree_scroller.setBorder(null);

        innerPanel.add(tree_scroller, "wrap, width 100:800:800");

        JPanel iPanel = new JPanel(new MigLayout());
        iPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                Utility.getBundleString("choose2", bundle), TitledBorder.LEFT, TitledBorder.TOP));
        JLabel label = new JLabel();
        label.setName("classification_path" + "---" + sequence);
        label.setText(selectedPath);
        iPanel.add(label, "wrap, growx, height 30:30:30");

        innerPanel.add(iPanel, "wrap, width 100:800:800");

        findLastClassification(panelname);

    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw new Exception("Exception in addClassification: " + ex.getStackTrace() + "\n");
    }
}