Example usage for javax.swing.event ListSelectionEvent getValueIsAdjusting

List of usage examples for javax.swing.event ListSelectionEvent getValueIsAdjusting

Introduction

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

Prototype

public boolean getValueIsAdjusting() 

Source Link

Document

Returns whether or not this is one in a series of multiple events, where changes are still being made.

Usage

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

/**
 * @return/*w  w w.jav  a  2 s.  c om*/
 * @throws SQLException
 */
public Pair<String, String> chooseTable(final String title, final String subTitle, final boolean doSp5DBs)
        throws SQLException {
    MySQLDMBSUserMgr mgr = new MySQLDMBSUserMgr();

    Vector<DBNamePair> availPairs = new Vector<DBNamePair>();

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

        //String sql = String.format("SELECT DISTINCT `COLUMNS`.TABLE_SCHEMA FROM `COLUMNS` WHERE `COLUMNS`.TABLE_NAME = '%s'", doSp5DBs ? "collectionobjectcatalog" : "taxon");
        Connection conn = mgr.getConnection();
        Vector<Object[]> dbNames = BasicSQLUtils.query(conn, "show databases");
        for (Object[] row : dbNames) {
            String dbName = row[0].toString();

            //System.out.print("Database Found ["+dbName+"]  ");
            conn.setCatalog(dbName);

            boolean isSp5DB = false;
            Vector<Object[]> tables = BasicSQLUtils.query(conn, "show tables");
            for (Object[] tblRow : tables) {
                String tableName = tblRow[0].toString();
                if (tableName.equalsIgnoreCase("usysversion")) {
                    isSp5DB = true;
                    break;
                }
            }

            if ((!isSp5DB && doSp5DBs) || (isSp5DB && !doSp5DBs)) {
                continue;
            }

            // make all table names lowercase
            try {
                Integer count = BasicSQLUtils.getCount(conn, "select COUNT(*) FROM collection");
                if (count == null) {
                    for (Object[] tblRow : tables) {
                        String tableName = tblRow[0].toString();
                        if (!tableName.equals(tableName.toLowerCase())) {
                            BasicSQLUtils.update(conn,
                                    "RENAME TABLE " + tableName + " TO " + tableName.toLowerCase());
                        }
                    }
                }

            } catch (Exception ex) {
                ex.printStackTrace();
            }

            Vector<Object> tableDesc = BasicSQLUtils.querySingleCol(conn,
                    "select CollectionName FROM collection");
            if (tableDesc.size() > 0) {
                String collName = tableDesc.get(0).toString();
                availPairs.add(new DBNamePair(collName, row[0].toString()));
            }
        }

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

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

        final JList list = new JList(availPairs);
        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,f:p:g"));
        pb.add(UIHelper.createLabel(subTitle), cc.xy(1, 1));
        pb.add(UIHelper.createScrollPane(list, true), cc.xy(1, 3));
        pb.setDefaultDialogBorder();

        final CustomDialog dlg = new CustomDialog(null, title, true, pb.getPanel());
        list.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1);
                }
            }
        });

        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1);
                    dlg.getOkBtn().doClick();
                }
            }
        });

        dlg.createUI();
        dlg.pack();
        Dimension d = dlg.getPreferredSize();
        d.height = 700;
        dlg.setSize(d);
        UIHelper.centerAndShow(dlg);

        if (dlg.isCancelled()) {
            return null;
        }

        return namePairToConvert = (DBNamePair) list.getSelectedValue();
    }

    return null;
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Handles list selection events for this application.
 *//*from  ww  w  . jav  a  2  s  .  com*/
public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) {
        return;
    }

    if (e.getSource().equals(bucketsTable.getSelectionModel())) {
        bucketSelectedAction();
    } else if (e.getSource().equals(objectsTable.getSelectionModel())) {
        objectSelectedAction();
    }
}

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

public void getAreasBacgroundW(File f) {
    fileHelper.getAreas(f);//from   w  w  w  .ja  v a  2s  . 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:edu.ku.brc.specify.conversion.ConvertVerifier.java

/**
 * @return//  www  .  j ava2s.c  om
 * @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:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java

/**
 * An action for when a row is selected in the table
 *///from  w w w . j a  va 2  s.c  om
private void MessageListSelected(ListSelectionEvent evt) {
    if (!evt.getValueIsAdjusting()) {
        int row = getSelectedMessageIndex();

        if (row >= 0) {
            // Cancel all pretty printing tasks
            for (Future<Void> worker : prettyPrintWorkers) {
                worker.cancel(true);
            }
            prettyPrintWorkers.clear();

            parent.setVisibleTasks(parent.messageTasks, parent.messagePopupMenu, 6, 6, true);
            parent.setVisibleTasks(parent.messageTasks, parent.messagePopupMenu, 7, -1, isChannelDeployed);

            this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            // Get the table node
            MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable.getPathForRow(row)
                    .getLastPathComponent();

            if (messageNode.isNodeActive()) {
                // Get the messageId from the message node
                Long messageId = messageNode.getMessageId();
                // Get the metaDataId from the message node
                Integer metaDataId = messageNode.getMetaDataId();

                // Attempt to get the message from the message cache
                Message message = messageCache.get(messageId);
                List<Attachment> attachments = attachmentCache.get(messageId);

                // If the message is not in the cache, retrieve it from the server
                if (message == null) {
                    try {
                        message = parent.mirthClient.getMessageContent(channelId, messageId,
                                selectedMetaDataIds);
                        // If the message was not found (ie. it may have been deleted during the request), do nothing
                        if (message == null || message.getConnectorMessages().size() == 0) {
                            clearDescription(
                                    "Could not retrieve message content. The message may have been deleted.");
                            this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                            return;
                        }

                        attachments = parent.mirthClient.getAttachmentsByMessageId(channelId, messageId, false);
                    } catch (Throwable t) {
                        if (t.getMessage().contains("Java heap space")) {
                            parent.alertError(parent,
                                    "There was an out of memory error when trying to retrieve message content.\nIncrease your heap size and try again.");
                        } else if (t instanceof RequestAbortedException) {
                            // The client is no longer waiting for the message content request
                        } else {
                            parent.alertThrowable(parent, t);
                        }
                        this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                        return;
                    }
                    // Add the retrieved message to the message cache
                    messageCache.put(messageId, message);
                    attachmentCache.put(messageId, attachments);
                }

                ConnectorMessage connectorMessage = message.getConnectorMessages().get(metaDataId);

                if (connectorMessage != null) {
                    // Update the message tabs
                    updateDescriptionMessages(connectorMessage);
                    // Update the mappings tab
                    updateDescriptionMappings(connectorMessage);
                    // Update the attachments tab
                    updateAttachmentsTable(messageId);
                    // Update the errors tab
                    updateDescriptionErrors(connectorMessage);
                    // Show relevant tabs. Not using errorCode here just in case for some reason there are errors even though errorCode is 0
                    updateDescriptionTabs(connectorMessage.getProcessingError() != null
                            || connectorMessage.getPostProcessorError() != null
                            || connectorMessage.getResponseError() != null, attachments.size() > 0);
                    updateMessageRadioGroup();

                    if (attachmentTable == null || attachmentTable.getSelectedRow() == -1
                            || descriptionTabbedPane.indexOfTab("Attachments") == -1) {
                        parent.setVisibleTasks(parent.messageTasks, parent.messagePopupMenu, 9, 10, false);
                    }
                }
            } else {
                clearDescription(null);
            }

            this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

        }
    }
}

From source file:com.actelion.research.table.view.JVisualization.java

public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
        invalidateOffImage(mChartType == cChartTypeBoxPlot || mChartType == cChartTypeBars
                || mChartType == cChartTypePies);
    }/*from   w w  w . j  a  v  a  2s  .com*/
}

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

/**
 * Makes the destination table with a parameter that is true if a new destination should be
 * added as well.//from   w w  w. jav  a2  s. c  o  m
 */
public void makeDestinationTable(boolean addNew) {
    List<Connector> destinationConnectors;
    Object[][] tableData;
    int tableSize;

    destinationConnectors = currentChannel.getDestinationConnectors();
    tableSize = destinationConnectors.size();

    if (addNew) {
        tableSize++;
    }

    int chain = 1;

    tableData = new Object[tableSize][5];

    for (int i = 0; i < tableSize; i++) {
        if (tableSize - 1 == i && addNew) {
            Connector connector = makeNewConnector(true);

            // Set the default inbound and outbound dataType and properties
            String dataType = currentChannel.getSourceConnector().getTransformer().getOutboundDataType();
            // Use a different properties object for the inbound and outbound
            DataTypeProperties defaultInboundProperties = LoadedExtensions.getInstance().getDataTypePlugins()
                    .get(dataType).getDefaultProperties();
            DataTypeProperties defaultOutboundProperties = LoadedExtensions.getInstance().getDataTypePlugins()
                    .get(dataType).getDefaultProperties();
            DataTypeProperties defaultResponseInboundProperties = LoadedExtensions.getInstance()
                    .getDataTypePlugins().get(dataType).getDefaultProperties();
            DataTypeProperties defaultResponseOutboundProperties = LoadedExtensions.getInstance()
                    .getDataTypePlugins().get(dataType).getDefaultProperties();

            connector.getTransformer().setInboundDataType(dataType);
            connector.getTransformer().setInboundProperties(defaultInboundProperties);
            connector.getTransformer().setOutboundDataType(dataType);
            connector.getTransformer().setOutboundProperties(defaultOutboundProperties);
            connector.getResponseTransformer().setInboundDataType(dataType);
            connector.getResponseTransformer().setInboundProperties(defaultResponseInboundProperties);
            connector.getResponseTransformer().setOutboundDataType(dataType);
            connector.getResponseTransformer().setOutboundProperties(defaultResponseOutboundProperties);

            connector.setName(getNewDestinationName(tableSize));
            connector.setTransportName(DESTINATION_DEFAULT);

            // We need to add the destination first so that the metadata ID is initialized.
            currentChannel.addDestination(connector);

            if (connector.isEnabled()) {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_blue.png")),
                        UIConstants.ENABLED_STATUS);
            } else {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_black.png")),
                        UIConstants.DISABLED_STATUS);
            }
            tableData[i][1] = connector.getName();
            tableData[i][2] = connector.getMetaDataId();
            tableData[i][3] = new ConnectorTypeData(destinationConnectors.get(i).getTransportName());

            if (i > 0 && !connector.isWaitForPrevious()) {
                chain++;
            }

            tableData[i][4] = chain;
        } else {

            if (destinationConnectors.get(i).isEnabled()) {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_blue.png")),
                        UIConstants.ENABLED_STATUS);
            } else {
                tableData[i][0] = new CellData(
                        new ImageIcon(
                                com.mirth.connect.client.ui.Frame.class.getResource("images/bullet_black.png")),
                        UIConstants.DISABLED_STATUS);
            }
            tableData[i][1] = destinationConnectors.get(i).getName();
            tableData[i][2] = destinationConnectors.get(i).getMetaDataId();
            tableData[i][3] = new ConnectorTypeData(destinationConnectors.get(i).getTransportName());

            if (i > 0 && !destinationConnectors.get(i).isWaitForPrevious()) {
                chain++;
            }

            tableData[i][4] = chain;
        }
    }

    destinationTable = new MirthTable();

    destinationTable.setModel(new javax.swing.table.DefaultTableModel(tableData,
            new String[] { STATUS_COLUMN_NAME, DESTINATION_COLUMN_NAME, METADATA_COLUMN_NAME,
                    CONNECTOR_TYPE_COLUMN_NAME, DESTINATION_CHAIN_COLUMN_NAME }) {

        boolean[] canEdit = new boolean[] { false, true, false, false, false };

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    });

    destinationTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    // Set the custom cell editor for the Destination Name column.
    destinationTable.getColumnModel()
            .getColumn(destinationTable.getColumnModel().getColumnIndex(DESTINATION_COLUMN_NAME))
            .setCellEditor(new DestinationTableCellEditor());
    destinationTable.setCustomEditorControls(true);

    // Must set the maximum width on columns that should be packed.
    destinationTable.getColumnExt(STATUS_COLUMN_NAME).setMaxWidth(UIConstants.MAX_WIDTH);
    destinationTable.getColumnExt(STATUS_COLUMN_NAME).setMinWidth(UIConstants.MIN_WIDTH);

    // Set the cell renderer for the status column.
    destinationTable.getColumnExt(STATUS_COLUMN_NAME).setCellRenderer(new ImageCellRenderer());

    // Set the maximum width and cell renderer for the metadata ID column
    destinationTable.getColumnExt(METADATA_COLUMN_NAME).setMaxWidth(UIConstants.METADATA_ID_COLUMN_WIDTH);
    destinationTable.getColumnExt(METADATA_COLUMN_NAME).setMinWidth(UIConstants.METADATA_ID_COLUMN_WIDTH);
    destinationTable.getColumnExt(METADATA_COLUMN_NAME)
            .setCellRenderer(new NumberCellRenderer(SwingConstants.CENTER, false));

    // Set the cell renderer for the destination connector type
    destinationTable.getColumnExt(CONNECTOR_TYPE_COLUMN_NAME).setCellRenderer(new ConnectorTypeCellRenderer());

    // Set the cell renderer and the max width for the destination chain column
    destinationTable.getColumnExt(DESTINATION_CHAIN_COLUMN_NAME)
            .setCellRenderer(new NumberCellRenderer(SwingConstants.CENTER, false));
    destinationTable.getColumnExt(DESTINATION_CHAIN_COLUMN_NAME).setMaxWidth(50);

    destinationTable.setSelectionMode(0);
    destinationTable.setRowSelectionAllowed(true);
    destinationTable.setRowHeight(UIConstants.ROW_HEIGHT);
    destinationTable.setFocusable(true);
    destinationTable.setSortable(false);
    destinationTable.getTableHeader().setReorderingAllowed(false);

    destinationTable.setOpaque(true);

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

    // This action is called when a new selection is made on the destination
    // table.
    destinationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                if (lastModelIndex != -1 && lastModelIndex != destinationTable.getRowCount() && !isDeleting) {
                    Connector destinationConnector = currentChannel.getDestinationConnectors()
                            .get(lastModelIndex);

                    ConnectorProperties props = destinationConnectorPanel.getProperties();
                    ((DestinationConnectorPropertiesInterface) props).getDestinationConnectorProperties()
                            .setResourceIds(resourceIds.get(destinationConnector.getMetaDataId()));
                    destinationConnector.setProperties(props);
                }

                if (!loadConnector()) {
                    if (lastModelIndex == destinationTable.getRowCount()) {
                        destinationTable.setRowSelectionInterval(lastModelIndex - 1, lastModelIndex - 1);
                    } else {
                        destinationTable.setRowSelectionInterval(lastModelIndex, lastModelIndex);
                    }
                } else {
                    lastModelIndex = destinationTable.getSelectedModelIndex();
                }

                /*
                 * Loading the connector may have updated the current destination with incorrect
                 * properties, so after updating lastModelIndex we need to update the
                 * destination panel again.
                 */
                saveDestinationPanel();
                checkVisibleDestinationTasks();
            }
        }
    });

    destinationTable.requestFocus();

    // Mouse listener for trigger-button popup on the table.
    destinationTable.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mousePressed(java.awt.event.MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
            checkSelectionAndPopupMenu(evt);
        }
    });

    // Checks to see what to set the new row selection to based on
    // last index and if a new destination was added.
    int last = lastModelIndex;

    // Select each destination in turn so that the connector types can be decorated
    for (int row = 0; row < destinationTable.getRowCount(); row++) {
        destinationTable.setRowSelectionInterval(row, row);
        destinationConnectorPanel.decorateConnectorType();
    }

    if (addNew) {
        destinationTable.setRowSelectionInterval(destinationTable.getRowCount() - 1,
                destinationTable.getRowCount() - 1);
    } else if (last == -1) {
        destinationTable.setRowSelectionInterval(0, 0); // Makes sure the
    } // event is called
      // when the table is
      // created.
    else if (last == destinationTable.getRowCount()) {
        destinationTable.setRowSelectionInterval(last - 1, last - 1);
    } else {
        destinationTable.setRowSelectionInterval(last, last);
    }

    destinationTablePane.setViewportView(destinationTable);
    destinationTablePane.setWheelScrollingEnabled(true);

    // Key Listener trigger for DEL
    destinationTable.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                parent.doDeleteDestination();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }
    });

    destinationTable.addMouseWheelListener(new MouseWheelListener() {

        public void mouseWheelMoved(MouseWheelEvent e) {
            destinationTablePane.getMouseWheelListeners()[0].mouseWheelMoved(e);
        }
    });
}

From source file:corelyzer.ui.CorelyzerApp.java

private void setupUI() {
    String versionNumber = CorelyzerApp.getApp().getCorelyzerVersion();
    if ((versionNumber == null) || versionNumber.equals("")) {
        versionNumber = "undetermined";
    }/* ww w .  j  av  a2s. c o  m*/

    this.baseTitle = "Corelyzer " + versionNumber;

    mainFrame = new JFrame(baseTitle);
    mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    mainFrame.setSize(320, 100);
    mainFrame.setLocation(600, 100);
    mainFrame.addWindowListener(this);

    GridLayout layout = new GridLayout(1, 1);
    mainFrame.getContentPane().setLayout(layout);

    rootPanel = new JPanel(new GridLayout(1, 5));
    rootPanel.setBorder(BorderFactory.createTitledBorder("Main Panel"));

    // add lists/panels
    JPanel sessionPanel = new JPanel(new GridLayout(1, 1));
    sessionPanel.setBorder(BorderFactory.createTitledBorder("Session"));
    sessionList = new JList(getSessionListModel());
    sessionList.setName("SessionList");
    sessionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    sessionList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = sessionList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentSessionIdx(idx);
            }
        }
    });
    sessionList.addMouseListener(this);
    JScrollPane sessionScrollPane = new JScrollPane(sessionList);
    sessionPanel.add(sessionScrollPane);
    rootPanel.add(sessionPanel);

    JPanel trackPanel = new JPanel(new GridLayout(1, 1));
    trackPanel.setBorder(BorderFactory.createTitledBorder("Track"));
    trackList = new JList(getTrackListModel());
    trackList.setName("TrackList");
    trackList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    trackList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = trackList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentTrackIdx(idx);
                updateHighlightedSections();
            }
        }
    });
    trackList.addMouseListener(this);
    JScrollPane trackScrollPane = new JScrollPane(trackList);
    trackPanel.add(trackScrollPane);
    rootPanel.add(trackPanel);

    JPanel sectionsPanel = new JPanel(new GridLayout(1, 1));
    sectionsPanel.setBorder(BorderFactory.createTitledBorder("Sections"));
    sectionList = new JList(getSectionListModel());
    sectionList.setName("SectionList");
    sectionList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            if (event.getValueIsAdjusting())
                return;
            updateHighlightedSections();
        }
    });
    sectionList.addMouseListener(this);
    JScrollPane sectionsScrollPane = new JScrollPane(sectionList);
    sectionsPanel.add(sectionsScrollPane);
    rootPanel.add(sectionsPanel);

    JPanel dataFilesPanel = new JPanel(new GridLayout(1, 1));
    dataFilesPanel.setBorder(BorderFactory.createTitledBorder("Data Files"));
    dataFileList = new JList(getDataFileListModel());
    dataFileList.setName("DatafileList");
    dataFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dataFileList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = dataFileList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentDatasetIdx(idx);
            }
        }
    });
    dataFileList.addMouseListener(this);
    JScrollPane dataFilesScrollPane = new JScrollPane(dataFileList);
    dataFilesPanel.add(dataFilesScrollPane);
    rootPanel.add(dataFilesPanel);

    JPanel fieldsPanel = new JPanel(new GridLayout(1, 1));
    fieldsPanel.setBorder(BorderFactory.createTitledBorder("Fields"));
    fieldList = new JList(getFieldListModel());
    fieldList.setName("FieldList");
    fieldList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    fieldList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = fieldList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentFieldIdx(idx);
            }
        }
    });
    JScrollPane fieldsScrollPane = new JScrollPane(fieldList);
    fieldsPanel.add(fieldsScrollPane);
    rootPanel.add(fieldsPanel);

    mainFrame.getContentPane().add(rootPanel);

    setupMenuStuff();
    setupPopupMenu();

    // init new mode tool frame
    toolFrame = new CRToolPalette();
    toolFrame.pack();
    int canvasWidth = preferences().screenWidth;
    Dimension mydim = toolFrame.getSize();
    int myLocX = canvasWidth / 2 - mydim.width / 2;
    toolFrame.setLocation(myLocX, 0);
    toolFrame.setVisible(true);

    // delete key listener on track and section list
    KeyListener listKeyListener = new KeyListener() {
        public void keyPressed(final KeyEvent keyEvent) {
        }

        public void keyReleased(final KeyEvent keyEvent) {

            int keyCode = keyEvent.getKeyCode();

            if (keyCode == KeyEvent.VK_DELETE) {
                Object actionSource = keyEvent.getSource();

                if (actionSource.equals(trackList)) {
                    controller.deleteSelectedTrack();
                } else if (actionSource.equals(sectionList)) {
                    int[] rows = getSectionList().getSelectedIndices();
                    onDeleteSelectedSections(rows);
                }
            }
        }

        public void keyTyped(final KeyEvent keyEvent) {
        }
    };

    trackList.addKeyListener(listKeyListener);
    sectionList.addKeyListener(listKeyListener);
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

@Override
public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) {
        int selectionCount = 0;
        boolean isResult = false;
        if (e.getSource() != null && e.getSource().equals(jSourcesTable.getSelectionModel())) {
            selectionCount = jSourcesTable.getSelectedRowCount();
        } else if (e.getSource() != null && e.getSource().equals(jVictimTable.getSelectionModel())) {
            selectionCount = jVictimTable.getSelectedRowCount();
        } else if (e.getSource() != null && e.getSource().equals(jResultsTable.getSelectionModel())) {
            selectionCount = jResultsTable.getSelectedRowCount();
            isResult = true;//from  ww w .j av a 2  s .c om
        }

        if (selectionCount != 0) {
            showInfo(selectionCount + ((selectionCount == 1) ? " Eintrag gewhlt" : " Eintrge gewhlt"),
                    isResult);
        }
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Setup the row (or selection) listener for the the Image Window. 
 *//*w  w w  . java  2s. co  m*/
protected void setupWorkbenchRowChangeListener() {
    workbenchRowChangeListener = new ListSelectionListener() {
        private int previouslySelectedRowIndex = -1;

        @SuppressWarnings("synthetic-access")
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() || !imageFrame.isVisible()) {
                // ignore this until the user quits changing the selection
                return;
            }

            if (spreadSheet.getCellEditor() != null) {
                spreadSheet.getCellEditor().stopCellEditing();
            }

            // check to make sure the selection actually changed
            int newSelectionIndex = spreadSheet.getSelectedRow();
            if (newSelectionIndex != previouslySelectedRowIndex) {
                previouslySelectedRowIndex = newSelectionIndex;

                showCardImageForSelectedRow();
            }
        }
    };
}