Example usage for javax.swing ListSelectionModel SINGLE_SELECTION

List of usage examples for javax.swing ListSelectionModel SINGLE_SELECTION

Introduction

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

Prototype

int SINGLE_SELECTION

To view the source code for javax.swing ListSelectionModel SINGLE_SELECTION.

Click Source Link

Document

A value for the selectionMode property: select one list index at a time.

Usage

From source file:net.sf.jabref.gui.preftabs.PreferencesDialog.java

public PreferencesDialog(JabRefFrame parent) {
    super(parent, Localization.lang("JabRef preferences"), false);
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    frame = parent;//from ww w  .j a va2  s  . c  o m

    main = new JPanel();
    JPanel mainPanel = new JPanel();
    JPanel lower = new JPanel();

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(lower, BorderLayout.SOUTH);

    final CardLayout cardLayout = new CardLayout();
    main.setLayout(cardLayout);

    List<PrefsTab> tabs = new ArrayList<>();
    tabs.add(new GeneralTab(prefs));
    tabs.add(new NetworkTab(prefs));
    tabs.add(new FileTab(frame, prefs));
    tabs.add(new FileSortTab(prefs));
    tabs.add(new EntryEditorPrefsTab(frame, prefs));
    tabs.add(new GroupsPrefsTab(prefs));
    tabs.add(new AppearancePrefsTab(prefs));
    tabs.add(new ExternalTab(frame, this, prefs));
    tabs.add(new TablePrefsTab(prefs));
    tabs.add(new TableColumnsTab(prefs, parent));
    tabs.add(new LabelPatternPrefTab(prefs, parent.getCurrentBasePanel()));
    tabs.add(new PreviewPrefsTab(prefs));
    tabs.add(new NameFormatterTab(prefs));
    tabs.add(new ImportSettingsTab(prefs));
    tabs.add(new XmpPrefsTab(prefs));
    tabs.add(new AdvancedTab(prefs));

    // add all tabs
    tabs.forEach(tab -> main.add((Component) tab, tab.getTabName()));

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new);
    JList<String> chooser = new JList<>(tabNames);
    chooser.setBorder(BorderFactory.createEtchedBorder());
    // Set a prototype value to control the width of the list:
    chooser.setPrototypeCellValue("This should be wide enough");
    chooser.setSelectedIndex(0);
    chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Add the selection listener that will show the correct panel when
    // selection changes:
    chooser.addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        String o = chooser.getSelectedValue();
        cardLayout.show(main, o);
    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new GridLayout(4, 1));
    buttons.add(importPreferences, 0);
    buttons.add(exportPreferences, 1);
    buttons.add(showPreferences, 2);
    buttons.add(resetPreferences, 3);

    JPanel westPanel = new JPanel();
    westPanel.setLayout(new BorderLayout());
    westPanel.add(chooser, BorderLayout.CENTER);
    westPanel.add(buttons, BorderLayout.SOUTH);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(main, BorderLayout.CENTER);
    mainPanel.add(westPanel, BorderLayout.WEST);

    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(new OkAction());
    CancelAction cancelAction = new CancelAction();
    cancel.addActionListener(cancelAction);
    lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower);
    buttonBarBuilder.addGlue();
    buttonBarBuilder.addButton(ok);
    buttonBarBuilder.addButton(cancel);
    buttonBarBuilder.addGlue();

    // Key bindings:
    KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);

    // Import and export actions:
    exportPreferences.setToolTipText(Localization.lang("Export preferences to file"));
    exportPreferences.addActionListener(e -> {
        String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")),
                Collections.singletonList(".xml"), JFileChooser.SAVE_DIALOG, false);
        if (filename == null) {
            return;
        }
        File file = new File(filename);
        if (!file.exists() || (JOptionPane.showConfirmDialog(PreferencesDialog.this,
                Localization.lang("'%0' exists. Overwrite file?", file.getName()),
                Localization.lang("Export preferences"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) {

            try {
                prefs.exportPreferences(filename);
            } catch (JabRefException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Export preferences"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    importPreferences.setToolTipText(Localization.lang("Import preferences from file"));
    importPreferences.addActionListener(e -> {
        String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")),
                Collections.singletonList(".xml"), JFileChooser.OPEN_DIALOG, false);
        if (filename != null) {
            try {
                prefs.importPreferences(filename);
                updateAfterPreferenceChanges();
                JOptionPane.showMessageDialog(PreferencesDialog.this,
                        Localization.lang("You must restart JabRef for this to come into effect."),
                        Localization.lang("Import preferences"), JOptionPane.WARNING_MESSAGE);
            } catch (JabRefException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Import preferences"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    showPreferences.addActionListener(
            e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame)
                    .setVisible(true));
    resetPreferences.addActionListener(e -> {
        if (JOptionPane.showConfirmDialog(PreferencesDialog.this,
                Localization.lang("Are you sure you want to reset all settings to default values?"),
                Localization.lang("Reset preferences"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            try {
                prefs.clear();
                JOptionPane.showMessageDialog(PreferencesDialog.this,
                        Localization.lang("You must restart JabRef for this to come into effect."),
                        Localization.lang("Reset preferences"), JOptionPane.WARNING_MESSAGE);
            } catch (BackingStoreException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Reset preferences"), JOptionPane.ERROR_MESSAGE);
            }
            updateAfterPreferenceChanges();
        }
    });

    setValues();

    pack();

}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

private boolean autoDetectPaths() {

    if (OS.WINDOWS) {
        List<File> progFiles = findProgramFilesDir();
        File sOffice = null;/*from  www . j  a v  a 2s .  c o m*/
        List<File> sofficeFiles = new ArrayList<>();
        for (File dir : progFiles) {
            if (fileSearchCancelled) {
                return false;
            }
            sOffice = findFileDir(dir, "soffice.exe");
            if (sOffice != null) {
                sofficeFiles.add(sOffice);
            }
        }
        if (sOffice == null) {
            JOptionPane.showMessageDialog(parent, Localization.lang(
                    "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."),
                    Localization.lang("Could not find OpenOffice/LibreOffice installation"),
                    JOptionPane.INFORMATION_MESSAGE);
            JFileChooser jfc = new JFileChooser(new File("C:\\"));
            jfc.setDialogType(JFileChooser.OPEN_DIALOG);
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                @Override
                public boolean accept(File file) {
                    return file.isDirectory();
                }

                @Override
                public String getDescription() {
                    return Localization.lang("Directories");
                }
            });
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.showOpenDialog(parent);
            if (jfc.getSelectedFile() != null) {
                sOffice = jfc.getSelectedFile();
            }
        }
        if (sOffice == null) {
            return false;
        }

        if (sofficeFiles.size() > 1) {
            // More than one file found
            DefaultListModel<File> mod = new DefaultListModel<>();
            for (File tmpfile : sofficeFiles) {
                mod.addElement(tmpfile);
            }
            JList<File> fileList = new JList<>(mod);
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            fileList.setSelectedIndex(0);
            FormBuilder b = FormBuilder.create()
                    .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref"));
            b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1);
            b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3);
            b.add(fileList).xy(1, 5);
            int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                    Localization.lang("Choose OpenOffice/LibreOffice executable"),
                    JOptionPane.OK_CANCEL_OPTION);
            if (answer == JOptionPane.CANCEL_OPTION) {
                return false;
            } else {
                sOffice = fileList.getSelectedValue();
            }

        } else {
            sOffice = sofficeFiles.get(0);
        }
        return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe");
    } else if (OS.OS_X) {
        File rootDir = new File("/Applications");
        File[] files = rootDir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName())
                        || "LibreOffice.app".equals(file.getName()))) {
                    rootDir = file;
                    break;
                }
            }
        }
        File sOffice = findFileDir(rootDir, SOFFICE_BIN);
        if (fileSearchCancelled) {
            return false;
        }
        if (sOffice == null) {
            return false;
        } else {
            return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN);
        }
    } else {
        // Linux:
        String usrRoot = "/usr/lib";
        File inUsr = findFileDir(new File(usrRoot), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if (inUsr == null) {
            inUsr = findFileDir(new File("/usr/lib64"), SOFFICE);
            if (inUsr != null) {
                usrRoot = "/usr/lib64";
            }
        }

        if (fileSearchCancelled) {
            return false;
        }
        File inOpt = findFileDir(new File("/opt"), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if ((inUsr != null) && (inOpt == null)) {
            return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
        } else if (inOpt != null) {
            if (inUsr == null) {
                return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
            } else { // Found both
                JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
                JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
                ButtonGroup bg = new ButtonGroup();
                bg.add(optRB);
                bg.add(usrRB);
                FormBuilder b = FormBuilder.create()
                        .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
                b.add(Localization.lang(
                        "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
                        .xy(1, 1);
                b.add(optRB).xy(1, 3);
                b.add(usrRB).xy(1, 5);
                int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                        Localization.lang("Choose OpenOffice/LibreOffice executable"),
                        JOptionPane.OK_CANCEL_OPTION);
                if (answer == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (optRB.isSelected()) {
                    return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
                } else {
                    return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
                }
            }
        }
    }
    return false;
}

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

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

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

            if (value instanceof Date) {

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

            }

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

        }
    });
    booksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JPopupMenu booksPopupMenu = new JPopupMenu();
    JMenuItem deleteBook = new JMenuItem("Delete");
    booksPopupMenu.addPopupMenuListener(new PopupMenuListener() {

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

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

        }

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

        }
    });
    deleteBook.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (booksTable.getSelectedRow() == -1) {
                JOptionPane.showMessageDialog(MainWindow.this, "You haven't selected any book.");
                return;
            }
            Book book = booksTableModel.getBooks().get(booksTable.getSelectedRow());
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    log.debug("Deleting book: " + book.getName() + " from database.");
                    bookManager.deleteBook(book);
                    return null;
                }

                @Override
                protected void done() {
                    try {
                        get();
                    } catch (Exception e) {
                        log.error("There was an exception thrown while deleting a book.", e);
                        return;
                    }

                    updateModel();
                }

            }.execute();

        }
    });
    booksPopupMenu.add(deleteBook);
    booksTable.setComponentPopupMenu(booksPopupMenu);
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void initContentSearchTable() {
    contentSearchTable//from  w w w .j av  a2s  .c o m
            .setModel(new DefaultTableModel(new Object[][] {}, new String[] { "Content Type", "Contains" }) {
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return true;
                }
            });

    contentSearchTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    contentSearchTable.setDragEnabled(false);
    contentSearchTable.setSortable(false);
    contentSearchTable.getTableHeader().setReorderingAllowed(false);

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

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

    TableColumn column = contentSearchTable.getColumnModel().getColumn(0);
    column.setCellRenderer(new MirthComboBoxTableCellRenderer(ContentType.getDisplayValues()));
    column.setCellEditor(new MirthComboBoxTableCellEditor(contentSearchTable, ContentType.getDisplayValues(), 1,
            false, null));
    column.setMinWidth(CONTENT_TYPE_COLUMN_WIDTH);
    column.setMaxWidth(CONTENT_TYPE_COLUMN_WIDTH);

    deleteContentSearchButton.setEnabled(false);
}

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

private void initSourceMapTable(Map<String, Object> sourceMap) {
    Object[][] data = new Object[sourceMap.size()][2];
    int i = 0;/*from ww  w  .  j  a v a  2 s.c o m*/

    for (Entry<String, Object> entry : sourceMap.entrySet()) {
        data[i][0] = entry.getKey();
        data[i][1] = entry.getValue();
        i++;
    }

    sourceMapTable = new MirthTable();

    sourceMapTable.setModel(new RefreshTableModel(data, new Object[] { "Variable", "Value" }) {
        @Override
        public boolean isCellEditable(int row, int column) {
            return true;
        }
    });

    sourceMapTable.setDragEnabled(false);
    sourceMapTable.setRowSelectionAllowed(true);
    sourceMapTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    sourceMapTable.setRowHeight(UIConstants.ROW_HEIGHT);
    sourceMapTable.setFocusable(false);
    sourceMapTable.setOpaque(true);
    sourceMapTable.getTableHeader().setResizingAllowed(false);
    sourceMapTable.getTableHeader().setReorderingAllowed(false);
    sourceMapTable.setSortable(true);

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

    sourceMapTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                deleteButton.setEnabled(sourceMapTable.getSelectedRow() > -1);
            }
        }
    });

    class SourceMapTableCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JTable table;
        private int column;
        private JTextField textField;
        private Object originalValue;
        private String newValue;

        public SourceMapTableCellEditor(JTable table, int column) {
            super();
            this.table = table;
            this.column = column;
            textField = new JTextField();
            textField.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    textField.setCaretPosition(textField.getText().length());
                }
            });
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            if (evt == null) {
                return false;
            }
            if (evt instanceof MouseEvent) {
                return ((MouseEvent) evt).getClickCount() >= 2;
            }
            return true;
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                int column) {
            originalValue = value;
            newValue = null;
            textField.setText(String.valueOf(value));
            return textField;
        }

        @Override
        public Object getCellEditorValue() {
            if (newValue != null) {
                return newValue;
            } else {
                return originalValue;
            }
        }

        @Override
        public boolean stopCellEditing() {
            if (!valueChanged()) {
                super.cancelCellEditing();
            } else {
                newValue = textField.getText();
            }
            return super.stopCellEditing();
        }

        private boolean valueChanged() {
            String value = textField.getText();
            if (StringUtils.isBlank(value)) {
                return false;
            }

            for (int i = 0; i < table.getRowCount(); i++) {
                Object tableValue = table.getValueAt(i, column);
                if (tableValue != null && String.valueOf(tableValue).equals(value)) {
                    return false;
                }
            }

            return true;
        }
    }

    sourceMapTable.getColumnModel().getColumn(0).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 0));
    sourceMapTable.getColumnModel().getColumn(1).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 1));

    sourceMapScrollPane.setViewportView(sourceMapTable);
    deleteButton.setEnabled(false);
}

From source file:simx.profiler.info.actor.ActorTypeInfoTopComponent.java

/**
 * This constructor initializes the top component. It configures the
 * tales creates the visulizations.//from w w w .  j a  va  2 s  .  com
 */
public ActorTypeInfoTopComponent() {
    initComponents();
    setName(Bundle.CTL_ActorTypeInfoTopComponent());
    setToolTipText(Bundle.HINT_ActorTypeInfoTopComponent());

    this.content = new InstanceContent();

    this.associateLookup(new AbstractLookup(this.content));

    ListSelectionModel listSelectionModel = this.instancesTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((final ListSelectionEvent e) -> {
        if (instancesTable.getSelectedRow() != -1) {
            final ActorInstance actorInstance = actorInstances.get(instancesTable.getSelectedRow());
            final ActorType actorType = actorInstance.type;
            final Set<Object> selectedObjects = new HashSet<>();
            selectedObjects.add(actorType);
            selectedObjects.add(actorInstance);
            content.set(selectedObjects, null);
        }
    });

    listSelectionModel = this.messagesSentTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messagesSentTable.getSelectedRow() != -1) {
            messagesReceivedTable.clearSelection();
            messagesProcessedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = sentMessages.get(messagesSentTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    listSelectionModel = this.messagesReceivedTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messagesReceivedTable.getSelectedRow() != -1) {
            messagesSentTable.clearSelection();
            messagesProcessedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = receivedMessages.get(messagesReceivedTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    listSelectionModel = this.messagesProcessedTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messagesProcessedTable.getSelectedRow() != -1) {
            messagesSentTable.clearSelection();
            messagesReceivedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = processedMessages.get(messagesProcessedTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    this.messagesSentDataSet = new DefaultPieDataset();
    this.messagesReceivedDataSet = new DefaultPieDataset();
    this.messagesProcessedDataSet = new DefaultPieDataset();

    this.createPieChart(this.messagesSentDataSet, this.messagesSentPanel);
    this.createPieChart(this.messagesReceivedDataSet, this.messagesReceivedPanel);
    this.createPieChart(this.messagesProcessedDataSet, this.messagesProcessedPanel);
}

From source file:au.org.ala.delta.editor.ui.ItemEditor.java

/**
 * Adds the event handlers to the UI components.
 *///w w w  .  ja  v a 2  s.com
private void addEventHandlers(ActionMap map) {
    spinner.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (_editsDisabled) {
                return;
            }

            updateItemSelection((Integer) spinner.getValue());
        }
    });

    rtfEditor.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            itemEditPerformed();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            itemEditPerformed();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            itemEditPerformed();
        }
    });
    rtfEditor.addKeyListener(new SelectionNavigationKeyListener() {

        @Override
        protected void advanceSelection() {
            _validator.verify(rtfEditor);
        }

    });
    taxonSelectionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    taxonSelectionList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (_editsDisabled) {
                return;
            }
            _selectedItem = _dataSet.getItem(taxonSelectionList.getSelectedIndex() + 1);
            updateDisplay();
        }
    });

    btnDone.setAction(map.get("itemEditDone"));
    chckbxTreatAsVariant.setAction(map.get("itemVarianceChanged"));
    btnSelect.setAction(map.get("selectItemByName"));
    taxonSelectionList.setSelectionAction(map.get("taxonSelected"));
    _validator = new TextComponentValidator(new ItemValidator(), this);

    // Give the item description text area focus.
    addInternalFrameListener(new InternalFrameAdapter() {
        @Override
        public void internalFrameActivated(InternalFrameEvent e) {
            rtfEditor.requestFocusInWindow();
        }
    });
}

From source file:com.emental.mindraider.ui.dialogs.OpenConceptByTagJDialog.java

public OpenConceptByTagJDialog(String dialogTitle, String selectionLabel, String buttonLabel,
        boolean showCancel) {
    super(dialogTitle);

    JPanel framePanel = new JPanel();
    framePanel.setBorder(new EmptyBorder(5, 10, 0, 10));
    framePanel.setLayout(new BorderLayout());

    // NORTH panel
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BorderLayout());
    northPanel.add(new JLabel(selectionLabel), BorderLayout.NORTH);

    final JTextField tagLabel = new JTextField(TEXTFIELD_WIDTH);

    // data/*from   w w w  .ja v  a 2 s.com*/
    tags = MindRaider.tagCustodian.getAllTags();
    ;
    if (tags == null) {
        tagLabel.setEnabled(false);
    }
    tagLabel.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                logger.debug("Openning selected tag...");
                openTagSearchDialog();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
            getListModel().clear();
            shownTags.clear();
            if (tagLabel.getText().length() > 0) {
                for (TagEntry tag : tags) {
                    if (tag.getTagLabel().toLowerCase().startsWith(tagLabel.getText().toLowerCase())) {
                        getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                        shownTags.add(tag);
                    }
                }
            } else {
                // show all tags
                for (TagEntry tag : tags) {
                    getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                    shownTags.add(tag);
                }
            }
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    northPanel.add(tagLabel, BorderLayout.SOUTH);
    framePanel.add(northPanel, BorderLayout.NORTH);

    // CENTER panel
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BorderLayout());
    centerPanel.add(new JLabel(Messages.getString("OpenConceptByTagJDialog.matchingTags")), BorderLayout.NORTH);

    defaultListModel = new DefaultListModel();
    list = new JList(defaultListModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    // list.addListSelectionListener(this);
    list.setVisibleRowCount(15);
    JScrollPane listScrollPane = new JScrollPane(list);
    centerPanel.add(listScrollPane, BorderLayout.SOUTH);
    framePanel.add(centerPanel, BorderLayout.CENTER);

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton openButton = new JButton(buttonLabel);
    southPanel.add(openButton);
    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            openTagSearchDialog();
        }
    });

    if (showCancel) {
        JButton cancelButton = new JButton(Messages.getString("OpenNotebookJDialog.cancel"));
        southPanel.add(cancelButton);
        cancelButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                OpenConceptByTagJDialog.this.dispose();
            }
        });
    }

    framePanel.add(southPanel, BorderLayout.SOUTH);

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

BamInternalFrame(BamFileRef ref) {
    super(ref.bamFile.getName(), true, false, true, true);
    this.ref = ref;
    JPanel mainPane = new JPanel(new BorderLayout(5, 5));
    setContentPane(mainPane);/*from  w  w w  . ja  va2 s  . com*/
    JTabbedPane tabbedPane = new JTabbedPane();
    mainPane.add(tabbedPane, BorderLayout.CENTER);

    JPanel pane = new JPanel(new BorderLayout(5, 5));
    tabbedPane.addTab("BAM", pane);

    this.tableModel = new BamTableModel();
    this.jTable = createTable(tableModel);
    this.jTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    this.jTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JScrollPane scroll1 = new JScrollPane(this.jTable);

    this.infoTableModel = new FlagTableModel();
    JTable tInfo = createTable(this.infoTableModel);

    this.genotypeTableModel = new SAMTagAndValueModel();
    JTable tGen = createTable(this.genotypeTableModel);

    this.groupTableModel = new ReadGroupTableModel();
    JTable tGrp = createTable(this.groupTableModel);

    JPanel splitH = new JPanel(new GridLayout(1, 0, 5, 5));
    splitH.add(new JScrollPane(tInfo));
    splitH.add(new JScrollPane(tGen));
    splitH.add(new JScrollPane(tGrp));

    JSplitPane splitVert = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scroll1, splitH);

    this.jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            int row = jTable.getSelectedRow();
            SAMRecord ctx;
            if (row == -1 || (ctx = tableModel.getElementAt(row)) == null) {
                infoTableModel.setContext(null);
                genotypeTableModel.setContext(null);
                groupTableModel.setContext(null);
            } else {
                infoTableModel.setContext(ctx);
                genotypeTableModel.setContext(ctx);
                groupTableModel.setContext(ctx);
            }

        }
    });

    pane.add(splitVert);

    //header as text
    pane = new JPanel(new BorderLayout(5, 5));
    tabbedPane.addTab("Header", pane);
    JTextArea area = new JTextArea(String.valueOf(ref.header.getTextHeader()));
    area.setCaretPosition(0);
    area.setEditable(false);
    pane.add(new JScrollPane(area), BorderLayout.CENTER);

    //dict
    pane = new JPanel(new BorderLayout(5, 5));
    tabbedPane.addTab("Reference", pane);
    JTable dictTable = createTable(new SAMSequenceDictionaryTableModel(ref.header.getSequenceDictionary()));
    dictTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    pane.add(new JScrollPane(dictTable), BorderLayout.CENTER);

    this.selList = new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            listSelectionChanged();
        }
    };

    this.addInternalFrameListener(new InternalFrameAdapter() {
        @Override
        public void internalFrameActivated(InternalFrameEvent e) {
            jTable.getSelectionModel().addListSelectionListener(selList);
        }

        @Override
        public void internalFrameDeactivated(InternalFrameEvent e) {
            jTable.getSelectionModel().removeListSelectionListener(selList);
        }
    });
}

From source file:components.TableSelectionDemo.java

public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    //Cell selection is disabled in Multiple Interval Selection
    //mode. The enabled state of cellCheck is a convenient flag
    //for this status.
    if ("Row Selection" == command) {
        table.setRowSelectionAllowed(rowCheck.isSelected());
        //In MIS mode, column selection allowed must be the
        //opposite of row selection allowed.
        if (!cellCheck.isEnabled()) {
            table.setColumnSelectionAllowed(!rowCheck.isSelected());
        }/*w w  w .j av a 2 s  . c  om*/
    } else if ("Column Selection" == command) {
        table.setColumnSelectionAllowed(columnCheck.isSelected());
        //In MIS mode, row selection allowed must be the
        //opposite of column selection allowed.
        if (!cellCheck.isEnabled()) {
            table.setRowSelectionAllowed(!columnCheck.isSelected());
        }
    } else if ("Cell Selection" == command) {
        table.setCellSelectionEnabled(cellCheck.isSelected());
    } else if ("Multiple Interval Selection" == command) {
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        //If cell selection is on, turn it off.
        if (cellCheck.isSelected()) {
            cellCheck.setSelected(false);
            table.setCellSelectionEnabled(false);
        }
        //And don't let it be turned back on.
        cellCheck.setEnabled(false);
    } else if ("Single Interval Selection" == command) {
        table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        //Cell selection is ok in this mode.
        cellCheck.setEnabled(true);
    } else if ("Single Selection" == command) {
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //Cell selection is ok in this mode.
        cellCheck.setEnabled(true);
    }

    //Update checkboxes to reflect selection mode side effects.
    rowCheck.setSelected(table.getRowSelectionAllowed());
    columnCheck.setSelected(table.getColumnSelectionAllowed());
    if (cellCheck.isEnabled()) {
        cellCheck.setSelected(table.getCellSelectionEnabled());
    }
}