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:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Shows a dialog that enales the user to convert the lat/lon formats. 
 *///w w  w  .  j a  va 2 s  . c  o m
protected void showGeoRefConvertDialog() {
    if (geoRefConvertDlg != null) {
        geoRefConvertDlg.toFront();
        return;
    }

    UsageTracker.incrUsageCount("WB.ShowGeoRefConverter");

    JStatusBar statusBar = UIRegistry.getStatusBar();

    if (!workbench.containsGeoRefData()) {
        statusBar.setErrorMessage(getResourceString("NoGeoRefColumns"));
        return;
    }

    List<String> outputFormats = new Vector<String>();
    String dddddd = getResourceString("DDDDDD");
    String ddmmmm = getResourceString("DDMMMM");
    String ddmmss = getResourceString("DDMMSS");
    String ddddddnsew = getResourceString("DDDDDDNSEW");
    String ddmmmmnsew = getResourceString("DDMMMMNSEW");
    String ddmmssnsew = getResourceString("DDMMSSNSEW");
    outputFormats.add(dddddd);
    outputFormats.add(ddmmmm);
    outputFormats.add(ddmmss);
    outputFormats.add(ddddddnsew);
    outputFormats.add(ddmmmmnsew);
    outputFormats.add(ddmmssnsew);

    final int locTabId = DBTableIdMgr.getInstance().getIdByClassName(Locality.class.getName());
    final int latColIndex = workbench.getColumnIndex(locTabId, "latitude1");
    final int lonColIndex = workbench.getColumnIndex(locTabId, "longitude1");
    final int lat2ColIndex = workbench.getColumnIndex(locTabId, "latitude2");
    final int lon2ColIndex = workbench.getColumnIndex(locTabId, "longitude2");

    JFrame mainFrame = (JFrame) UIRegistry.getTopWindow();

    String title = UIRegistry.getResourceString("GeoRefConv");
    String description = UIRegistry.getResourceString("GeoRefConvDesc");
    final ToggleButtonChooserPanel<String> toggle = new ToggleButtonChooserPanel<String>(outputFormats,
            description, Type.RadioButton);
    final JCheckBox symbolCkBx = UIHelper.createCheckBox(UIRegistry.getResourceString("GEOREF_USE_SYMBOLS"));
    JPanel pane = new JPanel(new BorderLayout());
    pane.add(toggle, BorderLayout.CENTER);
    pane.add(symbolCkBx, BorderLayout.SOUTH);
    geoRefConvertDlg = new CustomDialog(mainFrame, title, false, CustomDialog.OKCANCEL, pane) {

        @Override
        public void setVisible(boolean visible) {
            super.setVisible(visible);

            Dimension prefSize = this.getPreferredSize();
            prefSize.width += 60;
            this.setSize(prefSize);
        }

        @Override
        protected void cancelButtonPressed() {
            geoRefConvertDlg = null;
            super.cancelButtonPressed();
        }

        @Override
        protected void okButtonPressed() {
            checkCurrentEditState();

            // figure out which rows the user is working with
            int[] selection = spreadSheet.getSelectedRowModelIndexes();
            if (selection.length == 0) {
                // if none are selected, map all of them
                int rowCnt = spreadSheet.getRowCount();
                selection = new int[rowCnt];
                for (int i = 0; i < rowCnt; ++i) {
                    selection[i] = spreadSheet.convertRowIndexToModel(i);
                }
            }

            // since Arrays.copyOf() isn't in Java SE 5...
            int[] selRows = new int[selection.length];
            for (int i = 0; i < selection.length; ++i) {
                selRows[i] = selection[i];
            }

            // don't call super.okButtonPressed() b/c it will close the window
            isCancelled = false;
            btnPressed = OK_BTN;
            LatLonConverter.DEGREES_FORMAT degFmt = symbolCkBx.isSelected()
                    ? LatLonConverter.DEGREES_FORMAT.Symbol
                    : LatLonConverter.DEGREES_FORMAT.None;
            Vector<CellPosition> unconverted = new Vector<CellPosition>();
            switch (toggle.getSelectedIndex()) {
            case 0: {
                unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt));
                unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt));
                break;
            }
            case 1: {
                unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt));
                unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt));
                break;
            }
            case 2: {
                unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt));
                unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt));
                break;
            }
            case 3: {
                unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt));
                unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt));

                break;
            }
            case 4: {
                unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt));
                unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt));

                break;
            }
            case 5: {
                unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt));
                unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt));
                unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(),
                        GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt));

                break;
            }
            }
            if (unconverted.size() != 0) {
                UIRegistry.displayLocalizedStatusBarError("WB_UNCONVERTED_GEOREFS", unconverted.size());
                final JList<?> unconvertedcells = UIHelper.createList(unconverted);
                unconvertedcells.addListSelectionListener(new ListSelectionListener() {

                    @Override
                    public void valueChanged(ListSelectionEvent arg0) {
                        CellPosition rowCol = (CellPosition) unconvertedcells.getSelectedValue();
                        spreadSheet.scrollCellToVisible(rowCol.getFirst(), rowCol.getSecond());

                    }

                });
                JLabel lbl = UIHelper.createLabel(UIRegistry.getResourceString("WB_UNCONVERTED_GEOREFS_MSG"));
                JPanel innerPane = new JPanel(new BorderLayout());
                innerPane.add(lbl, BorderLayout.NORTH);
                innerPane.add(unconvertedcells, BorderLayout.CENTER);
                CustomDialog cd = new CustomDialog((Frame) UIRegistry.getTopWindow(),
                        UIRegistry.getResourceString("WB_UNCONVERTED_GEOREFS_TITLE"), false,
                        CustomDialog.OKHELP, innerPane);
                cd.setHelpContext("UnconvertableGeoCoords");
                UIHelper.centerAndShow(cd);
            }
        }
    };
    geoRefConvertDlg.setModal(false);
    toggle.setSelectedIndex(0);
    toggle.setOkBtn(geoRefConvertDlg.getOkBtn());
    toggle.createUI();
    geoRefConvertDlg.addWindowListener(new WindowListener() {

        /* (non-Javadoc)
         * @see java.awt.event.WindowStateListener#windowStateChanged(java.awt.event.WindowEvent)
         */
        @Override
        public void windowClosed(WindowEvent e) {
            geoRefConvertDlg = null;
        }

        /* (non-Javadoc)
         * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
         */
        @Override
        public void windowActivated(WindowEvent arg0) {
            // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
         */
        @Override
        public void windowClosing(WindowEvent arg0) {
            // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
         */
        @Override
        public void windowDeactivated(WindowEvent arg0) {
            // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
         */
        @Override
        public void windowDeiconified(WindowEvent arg0) {
            // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
         */
        @Override
        public void windowIconified(WindowEvent arg0) {
            // TODO Auto-generated method stub

        }

        /* (non-Javadoc)
         * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
         */
        @Override
        public void windowOpened(WindowEvent arg0) {
            // TODO Auto-generated method stub

        }

    });
    geoRefConvertDlg.setOkLabel(getResourceString("APPLY"));
    geoRefConvertDlg.setCancelLabel(getResourceString("CLOSE"));
    geoRefConvertDlg.setVisible(true);
}

From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java

/**
 * @return/*from   w  w w .  jav a2s .c  o m*/
 * @throws SQLException
 */
private Pair<String, String> chooseTable() throws SQLException {
    MySQLDMBSUserMgr mgr = new MySQLDMBSUserMgr();

    final Vector<DBNamePair> availOldPairs = new Vector<DBNamePair>();
    final Vector<DBNamePair> availNewPairs = new Vector<DBNamePair>();

    try {
        if (mgr.connectToDBMS(itUsrPwd.first, itUsrPwd.second, hostName)) {
            BasicSQLUtils.setSkipTrackExceptions(true);

            Connection conn = mgr.getConnection();
            Vector<Object[]> dbNames = BasicSQLUtils.query(conn, "show databases");
            for (Object[] row : dbNames) {
                System.err.println("Setting [" + row[0].toString() + "] ");
                conn.setCatalog(row[0].toString());

                boolean isSp5 = false;
                boolean isSp6 = false;

                Vector<Object[]> tables = BasicSQLUtils.query(conn, "show tables");
                for (Object[] tblRow : tables) {
                    if (row[0].toString().equals("debugdb")) {
                        System.err.println(tblRow[0].toString());
                    }
                    if (tblRow[0].toString().equals("usysversion")) {
                        isSp5 = true;
                        break;

                    } else if (tblRow[0].toString().equals("gift")) {
                        isSp6 = true;
                        break;
                    }
                }

                if (isSp5 || isSp6) {
                    String collName = null;
                    Vector<Object[]> tableDesc = BasicSQLUtils.query(conn,
                            "SELECT CollectionName FROM collection");
                    if (tableDesc.size() > 0) {
                        collName = tableDesc.get(0)[0].toString();
                    }

                    if (collName == null) {
                        continue;
                    }

                    if (isSp5) {
                        availOldPairs.add(new DBNamePair(collName, row[0].toString()));
                    } else {
                        availNewPairs.add(new DBNamePair(collName, row[0].toString()));
                    }
                }

                System.err.println("isSp5 [" + isSp5 + "] isSp6 [" + isSp6 + "] ");
            }

            Comparator<Pair<String, String>> comparator = new Comparator<Pair<String, String>>() {
                @Override
                public int compare(Pair<String, String> o1, Pair<String, String> o2) {
                    return o1.second.compareTo(o2.second);
                }
            };
            Collections.sort(availOldPairs, comparator);
            Collections.sort(availNewPairs, comparator);

            mgr.close();
            BasicSQLUtils.setSkipTrackExceptions(false);

            final JList oldlist = new JList(availOldPairs);
            final JList newList = new JList(availNewPairs);
            CellConstraints cc = new CellConstraints();
            PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "p,2px,f:p:g,4px,p"));
            pb.addSeparator("Specify 5 Databases", cc.xy(1, 1));
            pb.add(UIHelper.createScrollPane(oldlist), cc.xy(1, 3));

            pb.addSeparator("Specify 6 Databases", cc.xy(3, 1));
            pb.add(UIHelper.createScrollPane(newList), cc.xy(3, 3));

            ArrayList<String> list = new ArrayList<String>(labels.length);
            for (String s : labels) {
                list.add(s);
            }
            chkPanel = new ToggleButtonChooserPanel<String>(list, Type.Checkbox);
            chkPanel.setUseScrollPane(true);
            chkPanel.createUI();
            //pb.add(chkPanel, cc.xyw(1, 5, 3));

            /*ActionListener al = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                boolean isSelected = chkPanel.getButtons().get(0).isSelected();
                int inx = chkPanel.getSelectedIndex();
                if (inx == 0)
                {
                    Vector<JToggleButton> btns = chkPanel.getButtons();
                    for (int i=1;i<btns.size();i++)
                    {
                        btns.get(i).setEnabled(!isSelected);
                    }
                } 
            }
            };
                    
            chkPanel.getButtons().get(0).addActionListener(al);
            chkPanel.getButtons().get(chkPanel.getButtons().size()-1).addActionListener(al);*/

            ListSelectionListener oldDBListener = new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (!e.getValueIsAdjusting()) {
                        DBNamePair pair = (DBNamePair) oldlist.getSelectedValue();
                        if (pair != null) {
                            int index = 0;
                            for (DBNamePair p : availNewPairs) {
                                if (p.second.startsWith(pair.second)) {
                                    final int inx = index;
                                    SwingUtilities.invokeLater(new Runnable() {
                                        @Override
                                        public void run() {
                                            newList.setSelectedIndex(inx);
                                            newList.ensureIndexIsVisible(inx);
                                        }
                                    });
                                }
                                index++;
                            }
                        }
                    }
                }
            };

            oldlist.getSelectionModel().addListSelectionListener(oldDBListener);

            MouseAdapter ma = new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    super.mouseClicked(e);

                    Vector<JToggleButton> btns = chkPanel.getButtons();
                    if (e.getSource() == btns.get(0)) {
                        boolean isSelected = btns.get(0).isSelected();

                        for (int i = 1; i < btns.size(); i++) {
                            btns.get(i).setEnabled(!isSelected);
                        }
                    } else if (e.getSource() == btns.get(btns.size() - 1)) {
                        boolean isSelected = btns.get(btns.size() - 1).isSelected();
                        for (int i = 0; i < btns.size() - 1; i++) {
                            if (i > 0)
                                btns.get(i).setSelected(!isSelected);
                            btns.get(i).setEnabled(!isSelected);
                        }
                    }
                }
            };
            chkPanel.getButtons().get(0).addMouseListener(ma);
            chkPanel.getButtons().get(chkPanel.getButtons().size() - 1).addMouseListener(ma);

            /*ChangeListener cl = new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e)
            {
                Vector<JToggleButton> btns = chkPanel.getButtons();
                if (e.getSource() == btns.get(0))
                {
                    boolean isSelected = btns.get(0).isSelected();
                    System.out.println(isSelected);
                            
                    for (int i=1;i<btns.size();i++)
                    {
                        btns.get(i).setEnabled(!isSelected);
                    }
                } else if (e.getSource() == btns.get(btns.size()-1))
                {
                    boolean isSelected = btns.get(0).isSelected();
                    System.out.println(isSelected);
                            
                    for (int i=0;i<btns.size()-1;i++)
                    {
                        btns.get(i).setEnabled(!isSelected);
                    }
                }
            }
            };
            chkPanel.getButtons().get(0).addChangeListener(cl);
            chkPanel.getButtons().get(chkPanel.getButtons().size()-1).addChangeListener(cl);*/

            pb.setDefaultDialogBorder();

            final CustomDialog dlg = new CustomDialog(null, "Select a DB to Verify", true, pb.getPanel());

            ListSelectionListener lsl = new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (!e.getValueIsAdjusting()) {
                        dlg.getOkBtn().setEnabled(oldlist.getSelectedIndex() > -1);
                    }
                }
            };
            oldlist.addListSelectionListener(lsl);
            newList.addListSelectionListener(lsl);

            oldlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            newList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

            MouseAdapter listMA = new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    if (e.getClickCount() == 2) {
                        dlg.getOkBtn()
                                .setEnabled(oldlist.getSelectedIndex() > -1 && newList.getSelectedIndex() > -1);
                        dlg.getOkBtn().doClick();
                    }
                }
            };
            oldlist.addMouseListener(listMA);
            newList.addMouseListener(listMA);

            dlg.createUI();
            dlg.pack();
            //dlg.setSize(300, 800);
            dlg.pack();
            dlg.setVisible(true);
            if (dlg.isCancelled()) {
                return null;
            }

            DBNamePair oldPair = (DBNamePair) oldlist.getSelectedValue();
            namePairToConvert = (DBNamePair) newList.getSelectedValue();
            namePairToConvert.first = oldPair.second;
            return namePairToConvert;
        }
    } catch (Exception ex) {

    }
    return null;
}

From source file:de.main.sessioncreator.DesktopApplication1View.java

public void getAreasBacgroundW(File f) {
    fileHelper.getAreas(f);/*from w ww  .  j  a  va2 s.  c o  m*/
    Iterator<Map.Entry<String, List>> it = fileHelper.areaMap.entrySet().iterator();
    while (it.hasNext()) {
        DefaultListModel dlm = new DefaultListModel();
        JList list = new JList(dlm);
        list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        JScrollPane scrollPane = new JScrollPane(list);
        scrollPane.getViewport().setView(list);
        Map.Entry en = it.next();
        wizardtabpAreas.addTab(en.getKey().toString().substring(3), scrollPane);
        for (Object o : fileHelper.areaMap.get(en.getKey().toString())) {
            dlm.addElement(o);
        }
        MouseListener mouseListener = new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent mouseEvent) {
                JList tabList = (JList) mouseEvent.getSource();
                if (mouseEvent.getClickCount() == 2) {
                    int index = tabList.locationToIndex(mouseEvent.getPoint());
                    if (index >= 0) {
                        Object o = tabList.getModel().getElementAt(index);
                        wizardtaChoosenAreas.append(o.toString() + "\n");
                    }
                }
            }
        };
        list.addMouseListener(mouseListener);
        ListSelectionListener listListener = new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                JList list = (JList) e.getSource();
                if (e.getValueIsAdjusting() == false) {

                    if (list.getSelectedIndex() == -1) {
                        //No selection, disable add button.
                        wizardbtnAddAreas.setEnabled(false);

                    } else {
                        //Selection, enable the add button.
                        wizardbtnAddAreas.setEnabled(true);
                    }
                }
            }
        };
        list.addListSelectionListener(listListener);
    }
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

private void initComponents() {
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    splitPane.setOneTouchExpandable(true);

    topPanel = new JPanel();

    List<String> columns = new ArrayList<String>();

    for (ChannelColumnPlugin plugin : LoadedExtensions.getInstance().getChannelColumnPlugins().values()) {
        if (plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }/*from  www. j  a v a  2s. co  m*/
    }

    columns.addAll(Arrays.asList(DEFAULT_COLUMNS));

    for (ChannelColumnPlugin plugin : LoadedExtensions.getInstance().getChannelColumnPlugins().values()) {
        if (!plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }
    }

    channelTable = new MirthTreeTable("channelPanel", new LinkedHashSet<String>(columns));

    channelTable.setColumnFactory(new ChannelTableColumnFactory());

    ChannelTreeTableModel model = new ChannelTreeTableModel();
    model.setColumnIdentifiers(columns);
    model.setNodeFactory(new DefaultChannelTableNodeFactory());
    channelTable.setTreeTableModel(model);

    channelTable.setDoubleBuffered(true);
    channelTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    channelTable.getTreeSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    channelTable.setHorizontalScrollEnabled(true);
    channelTable.packTable(UIConstants.COL_MARGIN);
    channelTable.setRowHeight(UIConstants.ROW_HEIGHT);
    channelTable.setOpaque(true);
    channelTable.setRowSelectionAllowed(true);
    channelTable.setSortable(true);
    channelTable.putClientProperty("JTree.lineStyle", "Horizontal");
    channelTable.setAutoCreateColumnsFromModel(false);
    channelTable.setShowGrid(true, true);
    channelTable.restoreColumnPreferences();
    channelTable.setMirthColumnControlEnabled(true);

    channelTable.setDragEnabled(true);
    channelTable.setDropMode(DropMode.ON);
    channelTable.setTransferHandler(new ChannelTableTransferHandler() {
        @Override
        public boolean canImport(TransferSupport support) {
            // Don't allow files to be imported when the save task is enabled 
            if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && isSaveEnabled()) {
                return false;
            }
            return super.canImport(support);
        }

        @Override
        public void importFile(final File file, final boolean showAlerts) {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        String fileString = StringUtils.trim(parent.readFileToString(file));

                        try {
                            // If the table is in channel view, don't allow groups to be imported
                            ChannelGroup group = ObjectXMLSerializer.getInstance().deserialize(fileString,
                                    ChannelGroup.class);
                            if (group != null && !((ChannelTreeTableModel) channelTable.getTreeTableModel())
                                    .isGroupModeEnabled()) {
                                return;
                            }
                        } catch (Exception e) {
                        }

                        if (showAlerts && !parent.promptObjectMigration(fileString, "channel or group")) {
                            return;
                        }

                        try {
                            importChannel(
                                    ObjectXMLSerializer.getInstance().deserialize(fileString, Channel.class),
                                    showAlerts);
                        } catch (Exception e) {
                            try {
                                importGroup(ObjectXMLSerializer.getInstance().deserialize(fileString,
                                        ChannelGroup.class), showAlerts, !showAlerts);
                            } catch (Exception e2) {
                                if (showAlerts) {
                                    parent.alertThrowable(parent, e,
                                            "Invalid channel or group file:\n" + e.getMessage());
                                }
                            }
                        }
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public boolean canMoveChannels(List<Channel> channels, int row) {
            if (row >= 0) {
                TreePath path = channelTable.getPathForRow(row);
                if (path != null) {
                    AbstractChannelTableNode node = (AbstractChannelTableNode) path.getLastPathComponent();

                    if (node.isGroupNode()) {
                        Set<String> currentChannelIds = new HashSet<String>();
                        for (Enumeration<? extends MutableTreeTableNode> channelNodes = node
                                .children(); channelNodes.hasMoreElements();) {
                            currentChannelIds.add(((AbstractChannelTableNode) channelNodes.nextElement())
                                    .getChannelStatus().getChannel().getId());
                        }

                        for (Iterator<Channel> it = channels.iterator(); it.hasNext();) {
                            if (currentChannelIds.contains(it.next().getId())) {
                                it.remove();
                            }
                        }

                        return !channels.isEmpty();
                    }
                }
            }

            return false;
        }

        @Override
        public boolean moveChannels(List<Channel> channels, int row) {
            if (row >= 0) {
                TreePath path = channelTable.getPathForRow(row);
                if (path != null) {
                    AbstractChannelTableNode node = (AbstractChannelTableNode) path.getLastPathComponent();

                    if (node.isGroupNode()) {
                        Set<String> currentChannelIds = new HashSet<String>();
                        for (Enumeration<? extends MutableTreeTableNode> channelNodes = node
                                .children(); channelNodes.hasMoreElements();) {
                            currentChannelIds.add(((AbstractChannelTableNode) channelNodes.nextElement())
                                    .getChannelStatus().getChannel().getId());
                        }

                        for (Iterator<Channel> it = channels.iterator(); it.hasNext();) {
                            if (currentChannelIds.contains(it.next().getId())) {
                                it.remove();
                            }
                        }

                        if (!channels.isEmpty()) {
                            ListSelectionListener[] listeners = ((DefaultListSelectionModel) channelTable
                                    .getSelectionModel()).getListSelectionListeners();
                            for (ListSelectionListener listener : listeners) {
                                channelTable.getSelectionModel().removeListSelectionListener(listener);
                            }

                            try {
                                ChannelTreeTableModel model = (ChannelTreeTableModel) channelTable
                                        .getTreeTableModel();
                                Set<String> channelIds = new HashSet<String>();
                                for (Channel channel : channels) {
                                    model.addChannelToGroup(node, channel.getId());
                                    channelIds.add(channel.getId());
                                }

                                List<TreePath> selectionPaths = new ArrayList<TreePath>();
                                for (Enumeration<? extends MutableTreeTableNode> channelNodes = node
                                        .children(); channelNodes.hasMoreElements();) {
                                    AbstractChannelTableNode channelNode = (AbstractChannelTableNode) channelNodes
                                            .nextElement();
                                    if (channelIds
                                            .contains(channelNode.getChannelStatus().getChannel().getId())) {
                                        selectionPaths.add(new TreePath(
                                                new Object[] { model.getRoot(), node, channelNode }));
                                    }
                                }

                                parent.setSaveEnabled(true);
                                channelTable.expandPath(new TreePath(
                                        new Object[] { channelTable.getTreeTableModel().getRoot(), node }));
                                channelTable.getTreeSelectionModel().setSelectionPaths(
                                        selectionPaths.toArray(new TreePath[selectionPaths.size()]));
                                return true;
                            } finally {
                                for (ListSelectionListener listener : listeners) {
                                    channelTable.getSelectionModel().addListSelectionListener(listener);
                                }
                            }
                        }
                    }
                }
            }

            return false;
        }
    });

    channelTable.setTreeCellRenderer(new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
                    hasFocus);

            TreePath path = channelTable.getPathForRow(row);
            if (path != null && ((AbstractChannelTableNode) path.getLastPathComponent()).isGroupNode()) {
                setIcon(UIConstants.ICON_GROUP);
            }

            return label;
        }
    });
    channelTable.setLeafIcon(UIConstants.ICON_CHANNEL);
    channelTable.setOpenIcon(UIConstants.ICON_GROUP);
    channelTable.setClosedIcon(UIConstants.ICON_GROUP);

    channelTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            channelListSelected(evt);
        }
    });

    // listen for trigger button and double click to edit channel.
    channelTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }

        @Override
        public void mouseClicked(MouseEvent evt) {
            int row = channelTable.rowAtPoint(new Point(evt.getX(), evt.getY()));
            if (row == -1) {
                return;
            }

            if (evt.getClickCount() >= 2 && channelTable.getSelectedRowCount() == 1
                    && channelTable.getSelectedRow() == row) {
                AbstractChannelTableNode node = (AbstractChannelTableNode) channelTable.getPathForRow(row)
                        .getLastPathComponent();
                if (node.isGroupNode()) {
                    doEditGroupDetails();
                } else {
                    doEditChannel();
                }
            }
        }
    });

    // Key Listener trigger for DEL
    channelTable.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
                if (channelTable.getSelectedModelRows().length == 0) {
                    return;
                }

                boolean allGroups = true;
                boolean allChannels = true;
                for (int row : channelTable.getSelectedModelRows()) {
                    AbstractChannelTableNode node = (AbstractChannelTableNode) channelTable.getPathForRow(row)
                            .getLastPathComponent();
                    if (node.isGroupNode()) {
                        allChannels = false;
                    } else {
                        allGroups = false;
                    }
                }

                if (allChannels) {
                    doDeleteChannel();
                } else if (allGroups) {
                    doDeleteGroup();
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent evt) {
        }

        @Override
        public void keyTyped(KeyEvent evt) {
        }
    });

    // MIRTH-2301
    // Since we are using addHighlighter here instead of using setHighlighters, we need to remove the old ones first.
    channelTable.setHighlighters();

    // Set highlighter.
    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        channelTable.addHighlighter(highlighter);
    }

    HighlightPredicate revisionDeltaHighlighterPredicate = new HighlightPredicate() {
        @Override
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == channelTable.convertColumnIndexToView(
                    channelTable.getColumnExt(DEPLOYED_REVISION_DELTA_COLUMN_NAME).getModelIndex())) {
                if (channelTable.getValueAt(adapter.row, adapter.column) != null
                        && ((Integer) channelTable.getValueAt(adapter.row, adapter.column)).intValue() > 0) {
                    return true;
                }

                if (channelStatuses != null) {
                    String channelId = (String) channelTable.getModel()
                            .getValueAt(channelTable.convertRowIndexToModel(adapter.row), ID_COLUMN_NUMBER);
                    ChannelStatus status = channelStatuses.get(channelId);
                    if (status != null && status.isCodeTemplatesChanged()) {
                        return true;
                    }
                }
            }
            return false;
        }
    };
    channelTable.addHighlighter(new ColorHighlighter(revisionDeltaHighlighterPredicate, new Color(255, 204, 0),
            Color.BLACK, new Color(255, 204, 0), Color.BLACK));

    HighlightPredicate lastDeployedHighlighterPredicate = new HighlightPredicate() {
        @Override
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == channelTable.convertColumnIndexToView(
                    channelTable.getColumnExt(LAST_DEPLOYED_COLUMN_NAME).getModelIndex())) {
                Calendar checkAfter = Calendar.getInstance();
                checkAfter.add(Calendar.MINUTE, -2);

                if (channelTable.getValueAt(adapter.row, adapter.column) != null
                        && ((Calendar) channelTable.getValueAt(adapter.row, adapter.column))
                                .after(checkAfter)) {
                    return true;
                }
            }
            return false;
        }
    };
    channelTable.addHighlighter(new ColorHighlighter(lastDeployedHighlighterPredicate, new Color(240, 230, 140),
            Color.BLACK, new Color(240, 230, 140), Color.BLACK));

    channelScrollPane = new JScrollPane(channelTable);
    channelScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    filterPanel = new JPanel();
    filterPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(164, 164, 164)));

    tagsFilterButton = new IconButton();
    tagsFilterButton
            .setIcon(new ImageIcon(getClass().getResource("/com/mirth/connect/client/ui/images/wrench.png")));
    tagsFilterButton.setToolTipText("Show Channel Filter");
    tagsFilterButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            tagsFilterButtonActionPerformed();
        }
    });

    tagsLabel = new JLabel();

    ButtonGroup tableModeButtonGroup = new ButtonGroup();

    tableModeGroupsButton = new IconToggleButton(UIConstants.ICON_GROUP);
    tableModeGroupsButton.setToolTipText("Groups");
    tableModeGroupsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (!switchTableMode(true)) {
                tableModeChannelsButton.setSelected(true);
            }
        }
    });
    tableModeButtonGroup.add(tableModeGroupsButton);

    tableModeChannelsButton = new IconToggleButton(UIConstants.ICON_CHANNEL);
    tableModeChannelsButton.setToolTipText("Channels");
    tableModeChannelsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (!switchTableMode(false)) {
                tableModeGroupsButton.setSelected(true);
            }
        }
    });
    tableModeButtonGroup.add(tableModeChannelsButton);

    tabPane = new JTabbedPane();

    splitPane.setTopComponent(topPanel);
    splitPane.setBottomComponent(tabPane);
}

From source file:com.mirth.connect.client.ui.ChannelSetup.java

private void initChannelTagsUI() {
    tagTable.setSortable(true);//from w  w w . ja  v a 2  s. co m
    tagTable.getTableHeader().setReorderingAllowed(false);

    tagTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            deleteTagButton.setEnabled(getSelectedRow(tagTable) != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        tagTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR));
    }

    deleteTagButton.setEnabled(false);

    DefaultTableModel model = new DefaultTableModel(new Object[][] {}, new String[] { "Tag" }) {
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }
    };

    tagTable.setModel(model);
}

From source file:com.mirth.connect.client.ui.ChannelSetup.java

private void initMetaDataTable() {
    metaDataTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    DefaultTableModel model = new DefaultTableModel(new Object[][] {}, new String[] { METADATA_NAME_COLUMN_NAME,
            METADATA_TYPE_COLUMN_NAME, METADATA_MAPPING_COLUMN_NAME }) {
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }/*from  ww w  . ja v a  2  s  . c  o m*/

        @Override
        public void setValueAt(Object value, int row, int column) {
            // Enable the revert button if any data was changed.
            if (!value.equals(getValueAt(row, column))) {
                revertMetaDataButton.setEnabled(true);
            }

            super.setValueAt(value, row, column);
        }
    };

    model.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                parent.setSaveEnabled(true);
            }
        }

    });

    class AlphaNumericCellEditor extends TextFieldCellEditor {

        public AlphaNumericCellEditor() {
            super();
            MirthFieldConstraints constraints = new MirthFieldConstraints("^[a-zA-Z_0-9]*$");
            constraints.setLimit(30);
            getTextField().setDocument(constraints);
        }

        @Override
        protected boolean valueChanged(String value) {
            return true;
        }

    }

    metaDataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    metaDataTable.setDragEnabled(false);
    metaDataTable.setSortable(false);
    metaDataTable.getTableHeader().setReorderingAllowed(false);
    metaDataTable.setModel(model);

    metaDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            deleteMetaDataButton.setEnabled(metaDataTable.getSelectedRow() != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        metaDataTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR));
    }

    metaDataTable.getColumnModel()
            .getColumn(metaDataTable.getColumnModel().getColumnIndex(METADATA_NAME_COLUMN_NAME))
            .setCellEditor(new AlphaNumericCellEditor());
    metaDataTable.getColumnModel()
            .getColumn(metaDataTable.getColumnModel().getColumnIndex(METADATA_MAPPING_COLUMN_NAME))
            .setCellEditor(new AlphaNumericCellEditor());

    TableColumn column = metaDataTable.getColumnModel()
            .getColumn(metaDataTable.getColumnModel().getColumnIndex(METADATA_TYPE_COLUMN_NAME));
    column.setCellRenderer(new MirthComboBoxTableCellRenderer(MetaDataColumnType.values()));
    column.setCellEditor(
            new MirthComboBoxTableCellEditor(metaDataTable, MetaDataColumnType.values(), 1, false, null));
    column.setMinWidth(100);
    column.setMaxWidth(100);

    deleteMetaDataButton.setEnabled(false);
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

/**
 * @param parentList// w ww. ja  v a  2  s  .  c o m
 */
protected void fillNextList(final JList parentList) {
    if (processingLists) {
        return;
    }

    processingLists = true;

    final int curInx = listBoxList.indexOf(parentList);
    if (curInx > -1) {
        int startSize = listBoxPanel.getComponentCount();
        for (int i = curInx + 1; i < listBoxList.size(); i++) {
            listBoxPanel.remove(spList.get(i));
        }
        int removed = startSize - listBoxPanel.getComponentCount();
        for (int i = 0; i < removed; i++) {
            tableTreeList.remove(tableTreeList.size() - 1);
        }

    } else {
        listBoxPanel.removeAll();
        tableTreeList.clear();
    }

    QryListRendererIFace item = (QryListRendererIFace) parentList.getSelectedValue();
    if (item instanceof ExpandableQRI) {
        JList newList;
        DefaultListModel model;
        JScrollPane sp;

        if (curInx == listBoxList.size() - 1) {
            newList = new JList(model = new DefaultListModel());
            newList.addMouseListener(new MouseAdapter() {

                /* (non-Javadoc)
                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
                 */
                @Override
                public void mouseClicked(MouseEvent e) {
                    if (e.getClickCount() == 2) {
                        if (currentInx != -1) {
                            JList list = (JList) e.getSource();
                            QryListRendererIFace qriFace = (QryListRendererIFace) list.getSelectedValue();
                            if (BaseQRI.class.isAssignableFrom(qriFace.getClass())) {
                                BaseQRI qri = (BaseQRI) qriFace;
                                if (qri.isInUse()) {
                                    //remove the field
                                    for (QueryFieldPanel qfp : QueryBldrPane.this.queryFieldItems) {
                                        FieldQRI fqri = qfp.getFieldQRI();
                                        if (fqri == qri || (fqri instanceof RelQRI && fqri.getTable() == qri)) {
                                            boolean clearIt = qfp.getSchemaItem() != null;
                                            QueryBldrPane.this.removeQueryFieldItem(qfp);
                                            if (clearIt) {
                                                qfp.setField(null, null);
                                            }
                                            break;
                                        }
                                    }
                                } else {
                                    // add the field
                                    try {
                                        FieldQRI fieldQRI = buildFieldQRI(qri);
                                        if (fieldQRI == null) {
                                            throw new Exception("null FieldQRI");
                                        }
                                        SpQueryField qf = new SpQueryField();
                                        qf.initialize();
                                        qf.setFieldName(fieldQRI.getFieldName());
                                        qf.setStringId(fieldQRI.getStringId());
                                        query.addReference(qf, "fields");
                                        if (!isExportMapping) {
                                            addQueryFieldItem(fieldQRI, qf, false);
                                        } else {
                                            addNewMapping(fieldQRI, qf, null, false);
                                        }
                                    } catch (Exception ex) {
                                        log.error(ex);
                                        UsageTracker.incrHandledUsageCount();
                                        edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                                                .capture(QueryBldrPane.class, ex);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            });
            newList.setCellRenderer(qryRenderer);
            listBoxList.add(newList);
            sp = new JScrollPane(newList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            JLabel colHeader = UIHelper.createLabel(item.getTitle());
            colHeader.setHorizontalAlignment(SwingConstants.CENTER);
            colHeader.setBackground(listBoxPanel.getBackground());
            colHeader.setOpaque(true);

            sp.setColumnHeaderView(colHeader);

            spList.add(sp);

            newList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    if (!e.getValueIsAdjusting()) {
                        fillNextList(listBoxList.get(curInx + 1));
                    }
                }
            });

        } else {
            newList = listBoxList.get(curInx + 1);
            model = (DefaultListModel) newList.getModel();
            sp = spList.get(curInx + 1);
            JLabel colHeaderLbl = (JLabel) sp.getColumnHeader().getComponent(0);
            if (item instanceof TableQRI) {
                colHeaderLbl.setText(((TableQRI) item).getTitle());
            } else {
                colHeaderLbl.setText(getResourceString("QueryBldrPane.QueryFields"));
            }
        }

        createNewList((TableQRI) item, model);

        listBoxPanel.remove(addBtn);
        listBoxPanel.add(sp);
        tableTreeList.add(((ExpandableQRI) item).getTableTree());
        listBoxPanel.add(addBtn);
        currentInx = -1;

    } else {
        listBoxPanel.add(addBtn);
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            updateAddBtnState();

            // Is all this really necessary
            listBoxPanel.validate();
            listBoxPanel.repaint();
            scrollPane.validate();
            scrollPane.invalidate();
            scrollPane.doLayout();
            scrollPane.repaint();
            validate();
            invalidate();
            doLayout();
            repaint();
            UIRegistry.forceTopFrameRepaint();
        }
    });

    processingLists = false;
    currentInx = curInx;

}

From source file:src.gui.ItSIMPLE.java

/**
 * @return the planListFramePanel/*  w  w  w  .  jav  a2s  . co  m*/
 */
private ItFramePanel getPlanListFramePanel() {
    if (planListFramePanel == null) {
        planListFramePanel = new ItFramePanel(":: Plan", ItFramePanel.MINIMIZE_MAXIMIZE);
        planListFramePanel.setParentSplitPane(planDetailsSplitPane);

        planListModel = new DefaultListModel();
        planList = new JList(planListModel);
        planList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                // this is done to enable or disable the remove plan action button
                if (planList.getSelectedIndex() < 0) {
                    removePlanActionButton.setEnabled(false);
                    editPlanActionButton.setEnabled(false);
                } else {
                    removePlanActionButton.setEnabled(true);
                    editPlanActionButton.setEnabled(true);
                }
            }
        });

        planList.addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent e) {
                if (planList.getSelectedIndex() > 0 && e.getClickCount() == 2) {
                    editPlanAction.actionPerformed(null);
                }
            }

            public void mouseEntered(MouseEvent arg0) {
            }

            public void mouseExited(MouseEvent arg0) {
            }

            public void mousePressed(MouseEvent arg0) {
            }

            public void mouseReleased(MouseEvent arg0) {
            }

        });

        // initialize the buttons
        addPlanActionButton = new JButton(addPlanAction);
        addPlanActionButton.setToolTipText("Add an action to the plan");

        removePlanActionButton = new JButton(removePlanAction);
        removePlanActionButton.setToolTipText("Remove selected action");

        editPlanActionButton = new JButton(editPlanAction);
        editPlanActionButton.setToolTipText("Edit selected action");

        importPlanButton = new JButton(importPlanAction);
        importPlanButton.setToolTipText("Import plan from xml file");

        exportPlanButton = new JButton(exportPlanAction);
        exportPlanButton.setToolTipText("Export current plan");

        checkPlanValidityButton = new JButton(checkPlanValidity);
        checkPlanValidityButton.setToolTipText(
                "<html>Validate plan with validator VAL <br>(based on the generated PDDL model).</html>");

        //quickEvaluateButton = new JButton(quickEvaluation);
        //quickEvaluateButton.setToolTipText("Quick evaluation of the selected plan");

        //fullEvaluationButton = new JButton(generateEvaluatioReport);
        //fullEvaluationButton.setToolTipText("<html>Full evaluation of the selected plan. <br> Generate a plan evaluation in the planReport. <br> This is restricted to non-time-based domain only.</html>");
        //fullEvaluationButton.setText("");

        addPlanActionButton.setEnabled(false);
        removePlanActionButton.setEnabled(false);
        editPlanActionButton.setEnabled(false);
        checkPlanValidityButton.setEnabled(false);
        //quickEvaluateButton.setEnabled(false);
        //fullEvaluationButton.setEnabled(false);
        importPlanButton.setEnabled(false);
        exportPlanButton.setEnabled(false);

        JToolBar planListToolBar = new JToolBar();
        planListToolBar.add(addPlanActionButton);
        planListToolBar.add(removePlanActionButton);
        planListToolBar.add(editPlanActionButton);
        planListToolBar.addSeparator();
        planListToolBar.add(checkPlanValidityButton);
        //planListToolBar.add(quickEvaluateButton);
        //planListToolBar.add(fullEvaluationButton);
        planListToolBar.addSeparator();
        planListToolBar.add(importPlanButton);
        planListToolBar.add(exportPlanButton);

        JScrollPane listScrollPane = new JScrollPane(planList);

        JPanel listPanel = new JPanel(new BorderLayout());
        listPanel.add(listScrollPane, BorderLayout.CENTER);
        listPanel.add(planListToolBar, BorderLayout.SOUTH);

        planListFramePanel.setContent(listPanel, false);

    }

    return planListFramePanel;
}

From source file:net.sourceforge.pmd.cpd.GUI.java

private JComponent makeMatchList() {

    resultsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override/*from w  ww . j  av  a  2  s.c o m*/
        public void valueChanged(ListSelectionEvent e) {
            populateResultArea();
        }
    });

    resultsTable.registerKeyboardAction(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            copyMatchListSelectionsToClipboard();
        }
    }, "Copy", COPY_KEY_STROKE, JComponent.WHEN_FOCUSED);

    resultsTable.registerKeyboardAction(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            deleteMatchlistSelections();
        }
    }, "Del", DELETE_KEY_STROKE, JComponent.WHEN_FOCUSED);

    int[] alignments = new int[matchColumns.length];
    for (int i = 0; i < alignments.length; i++) {
        alignments[i] = matchColumns[i].alignment();
    }

    resultsTable.setDefaultRenderer(Object.class, new AlignmentRenderer(alignments));

    final JTableHeader header = resultsTable.getTableHeader();
    header.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            sortOnColumn(header.columnAtPoint(new Point(e.getX(), e.getY())));
        }
    });

    return new JScrollPane(resultsTable);
}

From source file:net.sourceforge.squirrel_sql.client.preferences.WikiTablePreferencesPanel.java

/**
 * The overview panel contains a list of all available configurations.
 * There are some methods provided for creating, copying or deleting configurations.
 * @return/*from   www.j ava 2 s . c om*/
 */
private Component createOverviewPanel() {
    JPanel jp = new JPanel(new BorderLayout());
    jp.setBorder(
            BorderFactory.createTitledBorder(s_stringMgr.getString("WikiTablePreferencesPanel.titleOverview"))); //$NON-NLS-1$

    wikiConfigListModel = new DefaultListModel();

    wikiConfigList = new JList(wikiConfigListModel);
    wikiConfigList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    wikiConfigList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    IWikiTableConfiguration selectedValue = (IWikiTableConfiguration) wikiConfigList
                            .getSelectedValue();
                    showDataFor(selectedValue);
                    if (selectedValue != null) {
                        copyButton.setEnabled(true);
                    } else {
                        copyButton.setEnabled(false);
                    }
                }
            });

        }
    });

    JScrollPane sp = new JScrollPane(wikiConfigList);

    JPanel buttonPanel = new JPanel(new FlowLayout());
    newButton = new JButton(s_stringMgr.getString("WikiTablePreferencesPanel.new")); //$NON-NLS-1$
    newButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            IWikiTableConfiguration newConfig = new GenericWikiTableConfigurationBean();
            addNewConfigToList(newConfig);
        }

        private void addNewConfigToList(IWikiTableConfiguration newConfig) {
            wikiConfigListModel.addElement(newConfig);
            wikiConfigList.setSelectedValue(newConfig, true);
        }
    });
    buttonPanel.add(newButton);

    copyButton = new JButton(s_stringMgr.getString("WikiTablePreferencesPanel.copy")); //$NON-NLS-1$
    copyButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            IWikiTableConfiguration newConfig = ((IWikiTableConfiguration) wikiConfigList.getSelectedValue())
                    .copyAsUserSpecific();

            int suffix = 0;

            String originalName = newConfig.getName();

            do {
                suffix++;
                newConfig.setName(originalName + "_" + suffix); //$NON-NLS-1$
            } while (!isUniqueName(newConfig));

            addNewConfigToList(newConfig);
        }

    });

    buttonPanel.add(copyButton);

    deleteButton = new JButton(s_stringMgr.getString("WikiTablePreferencesPanel.delete")); //$NON-NLS-1$
    deleteButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int selectedIndex = wikiConfigList.getSelectedIndex();
            wikiConfigList.setSelectedIndex(0);
            wikiConfigListModel.remove(selectedIndex);
            // we always have at least on item - the build in configuration
            //            wikiConfigList.invalidate();
        }
    });
    buttonPanel.add(deleteButton);

    jp.add(sp, BorderLayout.CENTER);
    jp.add(buttonPanel, BorderLayout.SOUTH);

    return jp;
}