Search in sources :

Example 46 with ListSelectionModel

use of javax.swing.ListSelectionModel in project jabref by JabRef.

the class IntegrityCheckAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    IntegrityCheck check = new IntegrityCheck(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getBibtexKeyPatternPreferences(), Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()));
    List<IntegrityMessage> messages = check.checkBibtexDatabase();
    if (messages.isEmpty()) {
        JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found."));
    } else {
        Map<String, Boolean> showMessage = new HashMap<>();
        // prepare data model
        Object[][] model = new Object[messages.size()][4];
        int i = 0;
        for (IntegrityMessage message : messages) {
            model[i][0] = message.getEntry().getId();
            model[i][1] = message.getEntry().getCiteKeyOptional().orElse("");
            model[i][2] = message.getFieldName();
            model[i][3] = message.getMessage();
            showMessage.put(message.getMessage(), true);
            i++;
        }
        // construct view
        JTable table = new JTable(model, new Object[] { "ID", Localization.lang("BibTeX key"), Localization.lang("Field"), Localization.lang("Message") });
        // hide IDs
        TableColumnModel columnModel = table.getColumnModel();
        columnModel.removeColumn(columnModel.getColumn(0));
        RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {

            @Override
            public boolean include(Entry<?, ?> entry) {
                return showMessage.get(entry.getStringValue(3));
            }
        };
        TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
        sorter.setRowFilter(filter);
        table.setRowSorter(sorter);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setDefaultEditor(Object.class, null);
        ListSelectionModel selectionModel = table.getSelectionModel();
        selectionModel.addListSelectionListener(event -> {
            if (!event.getValueIsAdjusting()) {
                try {
                    String entryId = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
                    String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][2];
                    frame.getCurrentBasePanel().editEntryByIdAndFocusField(entryId, fieldName);
                } catch (ArrayIndexOutOfBoundsException exception) {
                }
            }
        });
        // BibTeX key
        table.getColumnModel().getColumn(0).setPreferredWidth(100);
        // field name
        table.getColumnModel().getColumn(1).setPreferredWidth(60);
        // message
        table.getColumnModel().getColumn(2).setPreferredWidth(400);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
        JScrollPane scrollPane = new JScrollPane(table);
        String title = Localization.lang("%0 problem(s) found", String.valueOf(messages.size()));
        JDialog dialog = new JDialog(frame, title, false);
        JPopupMenu menu = new JPopupMenu();
        for (String messageString : showMessage.keySet()) {
            JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(messageString, true);
            menuItem.addActionListener(event -> {
                showMessage.put(messageString, menuItem.isSelected());
                ((AbstractTableModel) table.getModel()).fireTableDataChanged();
            });
            menu.add(menuItem);
        }
        JButton menuButton = new JButton(Localization.lang("Filter"));
        menuButton.addActionListener(entry -> menu.show(menuButton, 0, menuButton.getHeight()));
        FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "fill:pref:grow, 2dlu, pref"));
        builder.add(scrollPane).xy(1, 1);
        builder.add(menuButton).xy(1, 3, "c, b");
        dialog.add(builder.getPanel());
        dialog.setSize(600, 600);
        // show view
        dialog.setVisible(true);
    }
}
Also used : HashMap(java.util.HashMap) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) IntegrityCheck(org.jabref.logic.integrity.IntegrityCheck) IntegrityMessage(org.jabref.logic.integrity.IntegrityMessage) RowFilter(javax.swing.RowFilter) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) ListSelectionModel(javax.swing.ListSelectionModel) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel) JDialog(javax.swing.JDialog)

Example 47 with ListSelectionModel

use of javax.swing.ListSelectionModel in project jabref by JabRef.

the class BasicAction method initRawPanel.

// Panel with text import functionality
private void initRawPanel() {
    rawPanel.setLayout(new BorderLayout());
    // Textarea
    textPane.setEditable(false);
    document = textPane.getStyledDocument();
    addStylesToDocument();
    try {
        document.insertString(0, "", document.getStyle("regular"));
    } catch (BadLocationException ex) {
        LOGGER.warn("Problem setting style", ex);
    }
    OverlayPanel testPanel = new OverlayPanel(textPane, Localization.lang("paste text here"));
    testPanel.setPreferredSize(new Dimension(450, 255));
    testPanel.setMaximumSize(new Dimension(450, Integer.MAX_VALUE));
    // Setup fields (required to be done before setting up popup menu)
    fieldList = new JList<>(getAllFields());
    fieldList.setCellRenderer(new SimpleCellRenderer(fieldList.getFont()));
    ListSelectionModel listSelectionModel = fieldList.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener(new FieldListSelectionHandler());
    fieldList.addMouseListener(new FieldListMouseListener());
    // After the call to getAllFields
    initPopupMenuAndToolbar();
    //Add listener to components that can bring up popup menus.
    MouseListener popupListener = new PopupListener(inputMenu);
    textPane.addMouseListener(popupListener);
    testPanel.addMouseListener(popupListener);
    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(toolBar, BorderLayout.NORTH);
    leftPanel.add(testPanel, BorderLayout.CENTER);
    JPanel inputPanel = setUpFieldListPanel();
    // parse with FreeCite button
    parseWithFreeCiteButton.addActionListener(event -> {
        if (parseWithFreeCiteAndAddEntries()) {
            okPressed = false;
            dispose();
        }
    });
    rawPanel.add(leftPanel, BorderLayout.CENTER);
    rawPanel.add(inputPanel, BorderLayout.EAST);
    JLabel desc = new JLabel("<html><h3>" + Localization.lang("Plain text import") + "</h3><p>" + Localization.lang("This is a simple copy and paste dialog. First load or paste some text into " + "the text input area.<br>After that, you can mark text and assign it to a BibTeX field.") + "</p></html>");
    desc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    rawPanel.add(desc, BorderLayout.SOUTH);
}
Also used : JPanel(javax.swing.JPanel) ListSelectionModel(javax.swing.ListSelectionModel) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) OverlayPanel(org.jabref.gui.util.component.OverlayPanel) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) BadLocationException(javax.swing.text.BadLocationException)

Example 48 with ListSelectionModel

use of javax.swing.ListSelectionModel in project knime-core by knime.

the class AbstractTablePanel method highlightRow.

/**
 * Highlights the row on the given index
 *
 * @param index index of the row to highlight
 */
private void highlightRow(final int index) {
    if (index > -1) {
        final ListSelectionModel selectionModel = getTable().getSelectionModel();
        if (selectionModel != null) {
            // select the fresh added rows
            selectionModel.setSelectionInterval(index, index);
            // scroll first selected row into view
            getTable().scrollRectToVisible(new Rectangle(getTable().getCellRect(index, 0, true)));
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) ListSelectionModel(javax.swing.ListSelectionModel)

Example 49 with ListSelectionModel

use of javax.swing.ListSelectionModel in project knime-core by knime.

the class AbstractAggregationPanel method addRows.

/**
 * @param rows {@link List} of {@link AggregationFunctionRow}s to add to the table model
 * @since 2.11
 */
protected void addRows(final List<R> rows) {
    if (rows == null) {
        throw new IllegalArgumentException("methods must not be null");
    }
    final T tableModel = getTableModel();
    final int rowCountBefore = tableModel.getRowCount();
    tableModel.add(rows);
    final int rowCountAfter = tableModel.getRowCount();
    final JTable table = getTable();
    final ListSelectionModel selectionModel = table.getSelectionModel();
    if (selectionModel != null) {
        // select the fresh added rows
        selectionModel.setSelectionInterval(rowCountBefore, rowCountAfter - 1);
        // scroll first selected row into view
        table.scrollRectToVisible(new Rectangle(table.getCellRect(rowCountBefore, 0, true)));
    }
}
Also used : JTable(javax.swing.JTable) Rectangle(java.awt.Rectangle) ListSelectionModel(javax.swing.ListSelectionModel)

Example 50 with ListSelectionModel

use of javax.swing.ListSelectionModel in project liferay-ide by liferay.

the class LiferayProjectTemplateList method restoreSelection.

public void restoreSelection() {
    PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
    String templateName = propertiesComponent.getValue(_PROJECT_WIZARD_TEMPLATE);
    if ((templateName != null) && (_templateList.getModel() instanceof CollectionListModel)) {
        List<ProjectTemplate> list = ((CollectionListModel<ProjectTemplate>) _templateList.getModel()).toList();
        ProjectTemplate template = ContainerUtil.find(list, template1 -> templateName.equals(template1.getName()));
        if (template != null) {
            _templateList.setSelectedValue(template, true);
        }
    }
    ListSelectionModel listSelectionModel = _templateList.getSelectionModel();
    listSelectionModel.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent event) {
            ProjectTemplate template = getSelectedTemplate();
            if (template != null) {
                PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
                propertiesComponent.setValue(_PROJECT_WIZARD_TEMPLATE, template.getName());
            }
        }
    });
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionModel(javax.swing.ListSelectionModel) CollectionListModel(com.intellij.ui.CollectionListModel) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) ProjectTemplate(com.intellij.platform.ProjectTemplate) ArchivedProjectTemplate(com.intellij.platform.templates.ArchivedProjectTemplate) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

ListSelectionModel (javax.swing.ListSelectionModel)80 BorderLayout (java.awt.BorderLayout)20 Dimension (java.awt.Dimension)20 JButton (javax.swing.JButton)20 JPanel (javax.swing.JPanel)19 ListSelectionEvent (javax.swing.event.ListSelectionEvent)19 ListSelectionListener (javax.swing.event.ListSelectionListener)19 ActionEvent (java.awt.event.ActionEvent)18 JTable (javax.swing.JTable)18 ActionListener (java.awt.event.ActionListener)17 Point (java.awt.Point)16 JScrollPane (javax.swing.JScrollPane)15 MouseEvent (java.awt.event.MouseEvent)14 MouseAdapter (java.awt.event.MouseAdapter)13 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)13 TableColumn (javax.swing.table.TableColumn)13 Insets (java.awt.Insets)12 TableModel (javax.swing.table.TableModel)11 TableRowSorter (javax.swing.table.TableRowSorter)10 FlowLayout (java.awt.FlowLayout)9