Example usage for javax.swing.event ListSelectionListener ListSelectionListener

List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener

Introduction

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

Prototype

ListSelectionListener

Source Link

Usage

From source file:au.org.ala.delta.intkey.ui.CharacterSelectionDialog.java

private void init(List<Character> characters, boolean displayNumbering) {
    ResourceMap resourceMap = Application.getInstance().getContext()
            .getResourceMap(CharacterSelectionDialog.class);
    resourceMap.injectFields(this);
    ActionMap actionMap = Application.getInstance().getContext().getActionMap(CharacterSelectionDialog.class,
            this);

    setTitle(MessageFormat.format(title, _directiveName));

    _panelButtons.setBorder(new EmptyBorder(0, 20, 10, 20));
    _panelButtons.setLayout(new GridLayout(0, 5, 5, 5));

    _btnOk = new JButton();
    _btnOk.setAction(actionMap.get("characterSelectionDialog_OK"));
    _panelButtons.add(_btnOk);//  w  ww  .ja v  a  2  s .co m

    _btnSelectAll = new JButton();
    _btnSelectAll.setAction(actionMap.get("characterSelectionDialog_SelectAll"));
    _panelButtons.add(_btnSelectAll);

    _btnKeywords = new JButton();
    _btnKeywords.setAction(actionMap.get("characterSelectionDialog_Keywords"));
    _panelButtons.add(_btnKeywords);

    _btnImages = new JButton();
    _btnImages.setAction(actionMap.get("characterSelectionDialog_Images"));
    _btnImages.setEnabled(false);
    _panelButtons.add(_btnImages);

    _btnSearch = new JButton();
    _btnSearch.setAction(actionMap.get("characterSelectionDialog_Search"));
    _panelButtons.add(_btnSearch);

    _btnCancel = new JButton();
    _btnCancel.setAction(actionMap.get("characterSelectionDialog_Cancel"));
    _panelButtons.add(_btnCancel);

    _btnDeselectAll = new JButton();
    _btnDeselectAll.setAction(actionMap.get("characterSelectionDialog_DeselectAll"));
    _panelButtons.add(_btnDeselectAll);

    _btnFullText = new JButton();
    _btnFullText.setAction(actionMap.get("characterSelectionDialog_FullText"));
    _panelButtons.add(_btnFullText);

    _btnNotes = new JButton();
    _btnNotes.setAction(actionMap.get("characterSelectionDialog_Notes"));
    _btnNotes.setEnabled(false);
    _panelButtons.add(_btnNotes);

    _btnHelp = new JButton();
    _btnHelp.setAction(actionMap.get("characterSelectionDialog_Help"));
    _panelButtons.add(_btnHelp);

    // Some of the buttons should not be displayed if not in advanced mode
    if (_context.getUI().isAdvancedMode()) {
        _panelButtons.add(_btnOk);
        _panelButtons.add(_btnSelectAll);
        _panelButtons.add(_btnKeywords);
        _panelButtons.add(_btnImages);
        _panelButtons.add(_btnSearch);
        _panelButtons.add(_btnCancel);
        _panelButtons.add(_btnDeselectAll);
        _panelButtons.add(_btnFullText);
        _panelButtons.add(_btnNotes);
        _panelButtons.add(_btnHelp);
    } else {
        _panelButtons.setLayout(new GridLayout(0, 4, 5, 0));
        _panelButtons.add(_btnOk);
        _panelButtons.add(_btnCancel);
        _panelButtons.add(_btnSelectAll);
        _panelButtons.add(_btnDeselectAll);
    }

    _selectedCharacters = null;

    if (characters != null) {
        _listModel = new DefaultListModel();
        for (Character ch : characters) {
            _listModel.addElement(ch);
        }
        _list.setCellRenderer(new CharacterCellRenderer(displayNumbering));
        _list.setModel(_listModel);
    }

    _list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (_list.getSelectedIndices().length == 1) {
                Character ch = (Character) _list.getSelectedValue();
                _btnImages.setEnabled(ch.getImages().size() > 0);
                _btnFullText.setEnabled(true);
                _btnNotes.setEnabled(StringUtils.isNotBlank(ch.getNotes()));
            } else {
                _btnImages.setEnabled(false);
                _btnFullText.setEnabled(false);
                _btnNotes.setEnabled(false);
            }
        }
    });

    _list.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                // Treat double click on a list item as the ok button being
                // pressed.
                characterSelectionDialog_OK();
            }
        }

    });

    _selectedKeywords = new ArrayList<String>();
}

From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java

/**
 * /*from w  w w  .  j a v a 2  s  .c  o m*/
 */
protected void createUI() {
    dbList = new JList(new DefaultListModel());
    otherDBList = new JList(new DefaultListModel());

    userModel = new UserTableModel(null);
    userTable = new JTable(userModel);

    CellConstraints cc = new CellConstraints();

    saveBtn = UIHelper.createButton("Save");
    mkKeysBtn = UIHelper.createButton("Make Keys");
    copyKeyBtn = UIHelper.createButton("Copy Master Key");
    sendKeysBtn = UIHelper.createButton("Send Keys");
    showKeysBtn = UIHelper.createButton("Show Summary");
    printKeysBtn = UIHelper.createButton("Print");
    btns = new JButton[] { saveBtn, sendKeysBtn, copyKeyBtn, showKeysBtn, printKeysBtn };

    String colDef = UIHelper.createDuplicateJGoodiesDef("p", "8px", btns.length);
    PanelBuilder btnPB = new PanelBuilder(new FormLayout("f:p:g," + colDef, "p"));
    int x = 2;
    for (JButton b : btns) {
        btnPB.add(b, cc.xy(x, 1));
        x += 2;
    }
    saveBtn.setEnabled(false);
    copyKeyBtn.setEnabled(false);

    label = UIHelper.createLabel("", SwingConstants.CENTER);

    gainAccessBtn = UIHelper.createIconBtn("Unmap", "", null);
    loseAccessBtn = UIHelper.createIconBtn("Map", "", null);

    PanelBuilder bpb = new PanelBuilder(new FormLayout("p", "f:p:g,p,8px,p,f:p:g"));
    bpb.add(gainAccessBtn, cc.xy(1, 2));
    bpb.add(loseAccessBtn, cc.xy(1, 4));

    PanelBuilder tpb = new PanelBuilder(new FormLayout("f:p:g,10px,p,10px,f:p:g", "p,4px,f:p:g"));

    tpb.add(UIHelper.createI18NLabel("MSTR_HAS_PERM", SwingConstants.CENTER), cc.xy(1, 1));
    tpb.add(otherDBLbl = UIHelper.createI18NLabel("MSTR_HAS_NOPERM", SwingConstants.CENTER), cc.xy(5, 1));

    tpb.add(dbScrollPane = UIHelper.createScrollPane(dbList), cc.xy(1, 3));
    tpb.add(bpb.getPanel(), cc.xy(3, 3));
    tpb.add(odbScrollPane = UIHelper.createScrollPane(otherDBList), cc.xy(5, 3));

    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p", "f:p:g,20px,p,8px,p,4px,f:p:g,4px,p,20px,p"),
            this);

    sendKeysBtn.setVisible(false);

    int y = 1;
    pb.add(tpb.getPanel(), cc.xyw(1, y, 2));
    y += 2;
    y += 2;
    pb.add(label, cc.xyw(1, y, 2));
    y += 2;
    pb.add(userScrollPane = UIHelper.createScrollPane(userTable), cc.xyw(1, y, 2));
    y += 2;
    pb.add(btnPB.getPanel(), cc.xy(2, y));
    y += 2;
    pb.addSeparator("", cc.xyw(1, y, 2));
    y += 2;

    dbList.setVisibleRowCount(8);
    otherDBList.setVisibleRowCount(8);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            Dimension size = userTable.getPreferredScrollableViewportSize();
            size.height = 10 * userTable.getRowHeight();
            userTable.setPreferredScrollableViewportSize(size);
        }
    });

    updateBtnUI(false);

    dbList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                loadData(false);

                gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1);
                loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1);
            }
        }
    });

    userTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                doUserSelected();
            }
        }
    });

    saveBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveUserData();
        }
    });

    sendKeysBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            sendKeys();
        }
    });

    mkKeysBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            makeKeys();
        }
    });

    copyKeyBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int inx = userTable.getSelectedRow();
            if (inx > -1) {
                String masterKey = userModel.getUserData().get(inx).getMasterKey();
                UIHelper.setTextToClipboard(masterKey);
            }
        }
    });

    showKeysBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            displayData();
        }
    });

    printKeysBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            printUserData();
        }
    });
    gainAccessBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changeMasterAccess(true);
        }
    });

    loseAccessBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changeMasterAccess(false);
        }
    });

    otherDBList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                otherDBName = (String) otherDBList.getSelectedValue();
                gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1);
                loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1);
            }
        }
    });

}

From source file:com.projity.pm.graphic.chart.ChartLegend.java

JList getListInstance(boolean cost) {
    final JList list = new JList() { // do not want to update the UI. see below also
        private static final long serialVersionUID = 1L;

        public void updateUI() {
            if (!Environment.isNewLook())
                super.updateUI();
        }//from   w  ww.j a va 2s. c  o  m
    };
    if (Environment.isNewLook()) // The PLAF can override the custom renderer. This avoids that
        list.setUI(new BasicListUI());
    list.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setCellRenderer(new ListRenderer());
    setListFields(list, cost);
    if (!simple) {
        list.setSelectedIndex(0); // start off with first choice selected         
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (chartInfo.isRestoring()) // don't want to listen if updating from workspace
                    return;
                if (e.getValueIsAdjusting() == false) {
                    chartInfo.setTraces(list.getSelectedValues());
                }
            }
        });
    }

    return list;
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * //from w w w  . j av  a 2s.co  m
 */
protected void createUI() {
    JTabbedPane tabbedPane = new JTabbedPane();

    rp = new RegProcessor();
    rp.processSQL();

    tree = new JTree(rp.getRoot(INCL_ANON));
    propsTable = new JTable();

    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            fillPropsTable();
        }
    });
    tree.setCellRenderer(new MyTreeCellRenderer());

    Component topComp = UIHelper.createScrollPane(tree);
    Component botComp = UIHelper.createScrollPane(propsTable);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp);

    splitPane.setDividerLocation(0.5);
    splitPane.setOneTouchExpandable(true);

    splitPane.setLastDividerLocation(300);
    Dimension minimumSize = new Dimension(200, 400);
    topComp.setMinimumSize(minimumSize);
    botComp.setMinimumSize(minimumSize);

    tabbedPane.add("Registration", splitPane);

    final List<Pair<String, String>> trackDescPairs = rp.getTrackKeyDescPairs();
    Vector<String> trkItems = new Vector<String>();
    for (Pair<String, String> p : trackDescPairs) {
        trkItems.add(p.second);
    }

    //Collections.sort(trkItems);
    final JList list = new JList(trkItems);
    //pb.add(UIHelper.createScrollPane(list), cc.xy(1, 1));
    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int inx = list.getSelectedIndex();
                if (inx > -1) {
                    fillUsageItemsList(trackDescPairs.get(inx).first);
                }
            }
        }
    });

    tabbedPane.add("Reg Stats", getStatsPane("Registration", rp.getRegNumHash().values(), "register"));

    DefaultListModel model = new DefaultListModel();
    trackItemsList = new JList(model);

    topComp = UIHelper.createScrollPane(list);
    botComp = UIHelper.createScrollPane(trackItemsList);
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp);
    splitPane.setDividerLocation(0.5);
    splitPane.setOneTouchExpandable(true);

    topComp.setMinimumSize(minimumSize);
    botComp.setMinimumSize(minimumSize);

    splitPane.setDividerLocation(0.5);
    trackUsageHash = rp.getTrackCatsHash();
    tabbedPane.add("Usage Tracking", splitPane);

    tabbedPane.add("User Stats", getStatsPane("Tracking", rp.getTrackIdHash().values(), "track"));

    add(tabbedPane, BorderLayout.CENTER);
}

From source file:org.gumtree.vis.hist2d.Hist2DChartEditor.java

private JPanel createHelpPanel(JFreeChart chart) {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = new Hist2DHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);/*from w  ww. ja  v a2 s  . c  o  m*/
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;

}

From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java

private void initAuthorsTable() {
    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override/*  w w  w  . ja  va2s  .  c o  m*/
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    authorsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ListSelectionModel selectionModel = authorsTable.getSelectionModel();
    selectionModel.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource();
            if (source.getMinSelectionIndex() >= 0) {
                authorsTableModel.setCurrentSlectedIndex(source.getMinSelectionIndex());
            }

            if (!e.getValueIsAdjusting()) {
                booksTableModel.setAuthorIndex(source.getMinSelectionIndex());
            }

        }
    });

    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    JPopupMenu authorsPopupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");

    authorsPopupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    int rowAtPoint = authorsTable.rowAtPoint(
                            SwingUtilities.convertPoint(authorsPopupMenu, new Point(0, 0), authorsTable));
                    if (rowAtPoint > -1) {
                        authorsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint);
                        authorsTableModel.setCurrentSlectedIndex(rowAtPoint);
                    }
                }
            });
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    deleteItem.addActionListener(new ActionListener() {
        private Author author;

        @Override
        public void actionPerformed(ActionEvent e) {
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    author = authorsTableModel.getAuthors().get(authorsTable.getSelectedRow());
                    log.debug("Deleting author: " + author.getFirstname() + " " + author.getSurname()
                            + " from database.");
                    authorManager.deleteAuthor(author);

                    return null;
                }

                @Override
                protected void done() {
                    try {
                        get();
                    } catch (InterruptedException | ExecutionException e) {
                        if (e.getCause() instanceof DataIntegrityViolationException) {
                            JOptionPane.showMessageDialog(MainWindow.this,
                                    "Couldn't delete author; there are still some books assigned to him.",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                        log.error("There was an exception thrown during deletion author: "
                                + author.getFirstname() + " " + author.getSurname(), e);

                        return;
                    }

                    updateModel();
                }
            }.execute();
        }
    });
    authorsPopupMenu.add(deleteItem);
    authorsTable.setComponentPopupMenu(authorsPopupMenu);
}

From source file:edu.ku.brc.specify.plugins.HostTaxonPlugin.java

@Override
public void initialize(Properties propertiesArg, boolean isViewModeArg) {
    super.initialize(propertiesArg, isViewModeArg);

    CellConstraints cc = new CellConstraints();

    String errMsg = null;//w w  w .java 2  s .  com

    relName = propertiesArg.getProperty("relname", null);
    if (StringUtils.isNotEmpty(relName)) {
        Collection curCollection = AppContextMgr.getInstance().getClassObject(Collection.class);

        String sql = String.format(
                "SELECT RightSideCollectionID FROM collectionreltype WHERE Name = \"%s\" AND LeftSideCollectionID = %d",
                relName, curCollection.getId());
        System.err.println(sql);
        hostCollId = BasicSQLUtils.getCount(sql);
        System.err.println("hostCollId: " + hostCollId + "   curColId: " + curCollection.getId());

        DataProviderSessionIFace session = null;
        try {
            session = DataProviderFactory.getInstance().createSession();
            colRelType = session.getData(CollectionRelType.class, "name", relName,
                    DataProviderSessionIFace.CompareType.Equals);
            if (colRelType != null) {
                leftSideCol = colRelType.getLeftSideCollection();
                rightSideCol = colRelType.getRightSideCollection();
            }

            if (rightSideCol != null) {
                hostCollId = rightSideCol.getId();
                System.err.println("2hostCollId: " + hostCollId + "   curColId: " + curCollection.getId());
                if (hostCollId != null) {
                    rightsideDiscipline = rightSideCol.getDiscipline();
                    if (rightsideDiscipline != null) {
                        taxonTreeDef = rightsideDiscipline.getTaxonTreeDef();
                    } else {
                        errMsg = UIRegistry.getLocalizedMessage("HostTaxonPlugin.ERR_MSG_RSD", relName);
                    }
                } else {
                    errMsg = UIRegistry.getLocalizedMessage("HostTaxonPlugin.ERR_BAD_NM", relName,
                            curCollection.getCollectionName());
                }
            } else {
                errMsg = UIRegistry.getLocalizedMessage("HostTaxonPlugin.ERR_MSG_RSC", relName);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            errMsg = UIRegistry.getLocalizedMessage("HostTaxonPlugin.ERR");

        } finally {
            if (session != null) {
                session.close();
            }
        }

        if (hostCollId != null && rightsideDiscipline != null) {
            if (isViewMode) {
                PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p"), this);
                text = UIHelper.createTextField("");
                ViewFactory.changeTextFieldUIForDisplay(text, false);
                pb.add(text, cc.xy(1, 1));

            } else {
                PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"), this);

                // Switching to Search only for Bug 8393 - rods 6/4/11 (6.3.00 release)
                //int btnOpts = ValComboBoxFromQuery.CREATE_EDIT_BTN | ValComboBoxFromQuery.CREATE_NEW_BTN | ValComboBoxFromQuery.CREATE_SEARCH_BTN;
                int btnOpts = ValComboBoxFromQuery.CREATE_SEARCH_BTN;
                cbx = new ValComboBoxFromQuery(DBTableIdMgr.getInstance().getInfoById(Taxon.getClassTableId()),
                        "fullName", "fullName", "fullName", "%s", null, null, "", null, // helpContext
                        btnOpts);
                pb.add(cbx, cc.xy(1, 1));

                cbx.registerQueryBuilder(createSearchQueryBuilder());

                cbx.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        itemSelected();
                    }
                });
            }
        }
    } else {
        errMsg = UIRegistry.getLocalizedMessage("HostTaxonPlugin.ERR_MSG_REL_EMPTY");
    }

    if (errMsg != null) {
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p"), this);
        JButton btn = UIHelper.createI18NButton("HostTaxonPlugin.ERR_CLICK");
        pb.add(btn, cc.xy(1, 1));

        final String dlgErrMsg = errMsg;
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                UIRegistry.showError(dlgErrMsg);
            }
        });
    }
}

From source file:au.org.ala.delta.intkey.ui.TaxonSelectionDialog.java

private void init(List<Item> taxa, boolean displayNumbering, boolean singleSelect,
        boolean includeSpecimenAsOption) {
    ResourceMap resourceMap = Application.getInstance().getContext().getResourceMap(TaxonSelectionDialog.class);
    resourceMap.injectFields(this);
    ActionMap actionMap = Application.getInstance().getContext().getActionMap(TaxonSelectionDialog.class, this);

    setTitle(MessageFormat.format(title, _directiveName));

    _fullTextTaxonFormatter = new ItemFormatter(true, CommentStrippingMode.RETAIN,
            AngleBracketHandlingMode.REPLACE, true, false, false);

    _panelButtons.setBorder(new EmptyBorder(0, 20, 10, 20));
    _panelButtons.setLayout(new GridLayout(0, 5, 5, 5));

    _btnOk = new JButton();
    _btnOk.setAction(actionMap.get("taxonSelectionDialog_OK"));

    _btnSelectAll = new JButton();
    _btnSelectAll.setAction(actionMap.get("taxonSelectionDialog_SelectAll"));

    _btnKeywords = new JButton();
    _btnKeywords.setAction(actionMap.get("taxonSelectionDialog_Keywords"));

    _btnImages = new JButton();
    _btnImages.setAction(actionMap.get("taxonSelectionDialog_Images"));
    _btnImages.setEnabled(false);//from  w  w  w.j  a v  a 2s.  co m

    _btnSearch = new JButton();
    _btnSearch.setAction(actionMap.get("taxonSelectionDialog_Search"));

    _btnCancel = new JButton();
    _btnCancel.setAction(actionMap.get("taxonSelectionDialog_Cancel"));

    _btnDeselectAll = new JButton();
    _btnDeselectAll.setAction(actionMap.get("taxonSelectionDialog_DeselectAll"));

    _btnFullText = new JButton();
    _btnFullText.setAction(actionMap.get("taxonSelectionDialog_FullText"));
    _btnFullText.setEnabled(false);

    _btnHelp = new JButton();
    _btnHelp.setAction(actionMap.get("taxonSelectionDialog_Help"));

    // Some of the buttons should not be displayed if not in advanced mode
    if (_context.getUI().isAdvancedMode()) {
        _panelButtons.add(_btnOk);
        _panelButtons.add(_btnSelectAll);
        _panelButtons.add(_btnKeywords);
        _panelButtons.add(_btnImages);
        _panelButtons.add(_btnSearch);
        _panelButtons.add(_btnCancel);
        _panelButtons.add(_btnDeselectAll);
        _panelButtons.add(_btnFullText);
        _panelButtons.add(_btnHelp);
    } else {
        _panelButtons.setLayout(new GridLayout(0, 4, 5, 0));
        _panelButtons.add(_btnOk);
        _panelButtons.add(_btnCancel);
        _panelButtons.add(_btnSelectAll);
        _panelButtons.add(_btnDeselectAll);
    }

    _selectedTaxa = null;

    _includeSpecimenAsOption = includeSpecimenAsOption;

    if (taxa != null) {
        _listModel = new DefaultListModel();

        if (_includeSpecimenAsOption) {
            _listModel.addElement(IntkeyContext.SPECIMEN_KEYWORD);
        }

        for (Item taxon : taxa) {
            _listModel.addElement(taxon);
        }
        _list.setCellRenderer(new TaxonCellRenderer(displayNumbering, false));
        _list.setModel(_listModel);
    }

    if (singleSelect) {
        _list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    _list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (_list.getSelectedIndices().length == 1
                    && !_list.getSelectedValue().equals(IntkeyContext.SPECIMEN_KEYWORD)) {
                Item taxon = (Item) _list.getSelectedValue();
                _btnImages.setEnabled(taxon.getImages().size() > 0);
                _btnFullText.setEnabled(true);
            } else {
                _btnImages.setEnabled(false);
                _btnFullText.setEnabled(false);
            }
        }
    });

    _list.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                // Treat double click on a list item as the ok button being
                // pressed.
                taxonSelectionDialog_OK();
            }
        }

    });

    _selectedKeywords = new ArrayList<String>();
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java

/**
 * Class Constructor.//w w  w  . j a  v  a 2  s.  c  o m
 *
 * @param model
 *
 * @see
 */
public RegistryObjectsTable(TableModel model) {
    // Gives a TableColumnModel so that AutoCreateColumnsFromModel will be false.
    super(model, new DefaultTableColumnModel());

    this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    if (model instanceof RegistryObjectsTableModel) {
        tableModel = (RegistryObjectsTableModel) model;
    } else if (model instanceof TableSorter) {
        tableModel = (RegistryObjectsTableModel) (((TableSorter) model).getModel());
    } else {
        Object[] unexpectedTableModelArgs = { model };
        MessageFormat form = new MessageFormat(resourceBundle.getString("error.unexpectedTableModel"));
        throw new IllegalArgumentException(form.format(unexpectedTableModelArgs));
    }

    setToolTipText(resourceBundle.getString("tip.registryObjectsTable"));

    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    ListSelectionModel rowSM = getSelectionModel();
    stdRowHeight = getRowHeight();
    setRowHeight(stdRowHeight * 3);

    rowSM.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            ListSelectionModel lsm = (ListSelectionModel) e.getSource();

            if (!lsm.isSelectionEmpty()) {
                setSelectedRow(lsm.getMinSelectionIndex());
            } else {
                setSelectedRow(-1);
            }
        }
    });

    createPopup();

    addRenderers();

    // Add listener to self so that I can bring up popup menus on right mouse click
    popupListener = new PopupListener();
    addMouseListener(popupListener);

    //add listener for 'authenticated' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this);

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

private Component createObsTable(ListSelectionModel seriesSelectionModel) {
    final XTable result = new XTable();
    ColorCellRenderer renderer = new ColorCellRenderer(FontAwesome.FA_CIRCLE_O);
    result.setDefaultRenderer(Color.class, renderer);
    result.setDefaultEditor(Color.class, new ColorCellEditor(colorSchemeSupport, renderer));
    result.setDefaultRenderer(Font.class, FontCellRenderer.INSTANCE);
    result.setDefaultEditor(Font.class, new FontCellEditor());
    result.setDefaultRenderer(Stroke.class, StrokeCellRenderer.INSTANCE);
    result.setDefaultEditor(Stroke.class, new StrokeCellEditor());
    seriesSelectionModel.addListSelectionListener(new ListSelectionListener() {
        @Override//from   w w  w.j ava  2 s.  com
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int index = e.getFirstIndex();
                result.setModel(index != -1 ? new ObsModel(support.seriesInfos[index].obsInfos) : null);
                result.getModel().addTableModelListener(new TableModelListener() {
                    @Override
                    public void tableChanged(TableModelEvent e) {
                        chart.fireChartChanged();
                    }
                });
            }
        }
    });
    return ModernUI.withEmptyBorders(new JScrollPane(result));
}