Search in sources :

Example 36 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project jdk8u_jdk by JetBrains.

the class bug6777378 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(20);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            try {
                UIManager.setLookAndFeel(new MetalLookAndFeel());
            } catch (Exception e) {
                e.printStackTrace();
            }
            JTable table = new JTable(new AbstractTableModel() {

                public int getRowCount() {
                    return 10;
                }

                public int getColumnCount() {
                    return 10;
                }

                public Object getValueAt(int rowIndex, int columnIndex) {
                    return "" + rowIndex + " " + columnIndex;
                }
            });
            header = new JTableHeader(table.getColumnModel());
            header.setToolTipText("hello");
            frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(header);
            frame.setSize(300, 300);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    Point point = header.getLocationOnScreen();
    robot.mouseMove(point.x + 20, point.y + 50);
    robot.mouseMove(point.x + 30, point.y + 50);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
Also used : SunToolkit(sun.awt.SunToolkit) JTableHeader(javax.swing.table.JTableHeader) AbstractTableModel(javax.swing.table.AbstractTableModel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel)

Example 37 with AbstractTableModel

use of javax.swing.table.AbstractTableModel 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 38 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project processdash by dtuma.

the class TaskScheduleDialog method handleEvNodeChanged.

private void handleEvNodeChanged(EVTask node) {
    try {
        TreePath tp = new TreePath(node.getPath());
        int row = treeTable.getTree().getRowForPath(tp);
        if (row != -1) {
            AbstractTableModel model = (AbstractTableModel) treeTable.getModel();
            model.fireTableChanged(new TableModelEvent(model, row));
        }
    } catch (Exception e) {
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TableModelEvent(javax.swing.event.TableModelEvent) AbstractTableModel(javax.swing.table.AbstractTableModel) Point(java.awt.Point) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) MalformedURLException(java.net.MalformedURLException)

Example 39 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project CodenameOne by codenameone.

the class L10nEditor method initTable.

private void initTable() {
    bundleTable.setModel(new AbstractTableModel() {

        public int getRowCount() {
            return keys.size();
        }

        public int getColumnCount() {
            return 1 + localeList.size();
        }

        public boolean isCellEditable(int row, int col) {
            boolean b = col != 0;
            if (b) {
                String s = (String) getValueAt(row, col);
                return s == null || !s.contains("\n");
            }
            return b;
        }

        public String getColumnName(int columnIndex) {
            if (columnIndex == 0) {
                return "Key";
            }
            return (String) localeList.get(columnIndex - 1);
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 0) {
                return keys.get(rowIndex);
            }
            Hashtable h = res.getL10N(localeName, (String) localeList.get(columnIndex - 1));
            return h.get(keys.get(rowIndex));
        }

        public void setValueAt(Object val, int rowIndex, int columnIndex) {
            res.setModified();
            if (columnIndex == 0) {
                if (!keys.contains(val)) {
                // ...
                }
                return;
            }
            // Hashtable h = (Hashtable)bundle.get(localeList.get(columnIndex - 1));
            // h.put(keys.get(rowIndex), val);
            String currentKey = (String) keys.get(rowIndex);
            res.setLocaleProperty(localeName, (String) localeList.get(columnIndex - 1), currentKey, val);
            if (currentKey.equals("@im")) {
                StringTokenizer tok = new StringTokenizer((String) val, "|");
                boolean modified = false;
                while (tok.hasMoreTokens()) {
                    String currentIm = tok.nextToken();
                    if ("ABC".equals(currentIm) || "123".equals(currentIm) || "Abc".equals(currentIm) || "abc".equals(currentIm)) {
                        continue;
                    }
                    String prop = "@im-" + currentIm;
                    if (!keys.contains(prop)) {
                        keys.add(prop);
                        for (Object locale : localeList) {
                            res.setLocaleProperty(localeName, (String) locale, prop, "");
                        }
                        modified = true;
                    }
                }
                if (modified) {
                    fireTableDataChanged();
                }
                return;
            }
            if (currentKey.equals("@vkb")) {
                boolean modified = false;
                StringTokenizer tok = new StringTokenizer((String) val, "|");
                while (tok.hasMoreTokens()) {
                    String currentIm = tok.nextToken();
                    if ("ABC".equals(currentIm) || "123".equals(currentIm) || ".,123".equals(currentIm) || ".,?".equals(currentIm)) {
                        continue;
                    }
                    String prop = "@vkb-" + currentIm;
                    if (!keys.contains(prop)) {
                        keys.add(prop);
                        for (Object locale : localeList) {
                            res.setLocaleProperty(localeName, (String) locale, prop, "");
                        }
                        modified = true;
                    }
                }
                if (modified) {
                    fireTableDataChanged();
                }
            }
        }
    });
    bundleTable.setDefaultRenderer(Object.class, new SwingRenderer() {

        private JCheckBox chk = new JCheckBox();

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (column > 0) {
                // constant value
                String key = (String) keys.get(row);
                if (key.startsWith("@")) {
                    if (key.equalsIgnoreCase("@rtl")) {
                        chk.setSelected(value != null && "true".equalsIgnoreCase(value.toString()));
                        updateComponentSelectedState(chk, isSelected, table, row, column, hasFocus);
                        return chk;
                    }
                    if (key.startsWith("@vkb") || key.startsWith("@im")) {
                        JButton b = new JButton("...");
                        updateComponentSelectedState(b, isSelected, table, row, column, hasFocus);
                        return b;
                    }
                }
            }
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }
    });
    bundleTable.setDefaultEditor(Object.class, new DefaultCellEditor(new JTextField()) {

        private Object currentValue;

        String editedKey;

        private DefaultCellEditor standardEditor = new DefaultCellEditor(new JTextField());

        private DefaultCellEditor buttonEditor = new DefaultCellEditor(new JTextField()) {

            private JButton button = new JButton("...");

            {
                button.setBorderPainted(false);
                button.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        if (editedKey.equals("@vkb") || editedKey.equals("@im")) {
                            currentValue = editInputModeOrder((String) currentValue, editedKey.equals("@vkb"));
                            fireEditingStoppedExt();
                            return;
                        }
                        /*if(editedKey.startsWith("@vkb")) {
                                VKBEditor v = new VKBEditor(button, editedKey.substring(5), (String)currentValue);
                                currentValue = v.getValue();
                                fireEditingStoppedExt();
                                return;
                            }*/
                        if (editedKey.startsWith("@im")) {
                            currentValue = editTextFieldInputMode((String) currentValue);
                            fireEditingStoppedExt();
                            return;
                        }
                    }
                });
            }

            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                editedKey = (String) keys.get(row);
                return button;
            }
        };

        private DefaultCellEditor checkBoxEditor = new DefaultCellEditor(new JCheckBox()) {

            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                return super.getTableCellEditorComponent(table, new Boolean("true".equalsIgnoreCase((String) value)), isSelected, row, column);
            }

            public Object getCellEditorValue() {
                Boolean b = (Boolean) super.getCellEditorValue();
                if (b.booleanValue()) {
                    return "true";
                }
                return "false";
            }
        };

        private TableCellEditor current = standardEditor;

        {
            buttonEditor.setClickCountToStart(1);
            checkBoxEditor.setClickCountToStart(1);
        }

        private void updateEditor(int row) {
            // constant value
            final String key = (String) keys.get(row);
            if (key.startsWith("@")) {
                if (key.equalsIgnoreCase("@rtl")) {
                    current = checkBoxEditor;
                    return;
                }
                if (key.startsWith("@vkb") || key.startsWith("@im")) {
                    current = buttonEditor;
                    return;
                }
            }
            current = standardEditor;
        }

        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            updateEditor(row);
            currentValue = value;
            return current.getTableCellEditorComponent(table, value, isSelected, row, column);
        }

        public void fireEditingStoppedExt() {
            fireEditingStopped();
        }

        public Object getCellEditorValue() {
            if (current == buttonEditor) {
                return currentValue;
            }
            return current.getCellEditorValue();
        }

        public boolean stopCellEditing() {
            return current.stopCellEditing();
        }

        public void cancelCellEditing() {
            current.cancelCellEditing();
        }

        public void addCellEditorListener(CellEditorListener l) {
            current.addCellEditorListener(l);
            super.addCellEditorListener(l);
        }

        public void removeCellEditorListener(CellEditorListener l) {
            current.removeCellEditorListener(l);
            super.removeCellEditorListener(l);
        }

        public boolean isCellEditable(EventObject anEvent) {
            return current.isCellEditable(anEvent);
        }

        public boolean shouldSelectCell(EventObject anEvent) {
            return current.shouldSelectCell(anEvent);
        }
    });
    locales.setModel(new DefaultComboBoxModel(localeList.toArray()));
    removeLocale.setEnabled(localeList.size() > 1);
}
Also used : Hashtable(java.util.Hashtable) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) CellEditorListener(javax.swing.event.CellEditorListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JTextField(javax.swing.JTextField) SwingRenderer(com.codename1.ui.resource.util.SwingRenderer) EventObject(java.util.EventObject) DefaultCellEditor(javax.swing.DefaultCellEditor) JCheckBox(javax.swing.JCheckBox) StringTokenizer(java.util.StringTokenizer) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) EventObject(java.util.EventObject) TableCellEditor(javax.swing.table.TableCellEditor) Component(java.awt.Component) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride)

Example 40 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project vcell by virtualcell.

the class FRAPEstimationPanel_NotUsed method initTable.

private void initTable() {
    TableModel tableModel = new AbstractTableModel() {

        public String getColumnName(int col) {
            return FRAP_ESTIMATE_COLUMN_NAMES[col].toString();
        }

        public int getRowCount() {
            return FRAPParameterEstimateEnum.values().length;
        }

        public int getColumnCount() {
            return FRAP_ESTIMATE_COLUMN_NAMES.length;
        }

        public Object getValueAt(int row, int col) {
            if (col == PARAMETER_TYPE_COLUMN) {
                return FRAPParameterEstimateEnum.values()[row].parameterTypeName;
            } else if (col == UNIT_COLUMN) {
                return FRAPParameterEstimateEnum.values()[row].unit;
            }
            return FRAPParameterEstimateEnum.values()[row].value;
        }

        public boolean isCellEditable(int row, int col) {
            return false;
        }

        public void setValueAt(Object value, int row, int col) {
            if (col == PARAMETER_TYPE_COLUMN || col == UNIT_COLUMN) {
                throw new IllegalArgumentException("Can't update 'Parameter Type' or 'Unit' column");
            }
            FRAPParameterEstimateEnum.values()[row].value = (Double) value;
            fireTableCellUpdated(row, col);
        }
    };
    table.setModel(tableModel);
    table.getTableHeader().getColumnModel().getColumn(UNIT_COLUMN).setMaxWidth(50);
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Aggregations

AbstractTableModel (javax.swing.table.AbstractTableModel)46 TableModel (javax.swing.table.TableModel)8 JTable (javax.swing.JTable)7 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 PackageEntry (com.intellij.psi.codeStyle.PackageEntry)4 JFrame (javax.swing.JFrame)4 JBTable (com.intellij.ui.table.JBTable)3 JPanel (javax.swing.JPanel)3 EmptyBorder (javax.swing.border.EmptyBorder)3 JTableHeader (javax.swing.table.JTableHeader)3 IndTestDSep (edu.cmu.tetrad.search.IndTestDSep)2 IntTextField (edu.cmu.tetradapp.util.IntTextField)2 Font (java.awt.Font)2 Point (java.awt.Point)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2