Search in sources :

Example 46 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project omegat by omegat-org.

the class FilenamePatternsEditorController method show.

public static List<String> show(List<String> excludes) {
    result = null;
    data = new ArrayList<String>(excludes);
    final FilenamePatternsEditor dialog = new FilenamePatternsEditor(Core.getMainWindow().getApplicationFrame(), true);
    @SuppressWarnings("serial") final AbstractTableModel model = new AbstractTableModel() {

        public int getColumnCount() {
            return 1;
        }

        public String getColumnName(int column) {
            return OStrings.getString("FILENAMEPATTERNS_MASK");
        }

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

        public Object getValueAt(int row, int col) {
            return data.get(row);
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            data.set(rowIndex, aValue.toString());
        }

        public boolean isCellEditable(int row, int col) {
            return true;
        }
    };
    dialog.table.setModel(model);
    dialog.btnOk.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (dialog.table.getCellEditor() != null) {
                dialog.table.getCellEditor().stopCellEditing();
            }
            result = data;
            dialog.dispose();
        }
    });
    dialog.btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });
    dialog.btnAdd.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            data.add("");
            model.fireTableDataChanged();
            dialog.table.changeSelection(data.size() - 1, 0, false, false);
            dialog.table.editCellAt(data.size() - 1, 0);
            dialog.table.transferFocus();
        }
    });
    dialog.btnRemove.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (dialog.table.getSelectedRow() >= 0 && dialog.table.getSelectedRow() < data.size()) {
                data.remove(dialog.table.getSelectedRow());
            }
            model.fireTableDataChanged();
        }
    });
    ListSelectionListener listener = e -> dialog.btnRemove.setEnabled(dialog.table.getSelectedRow() != -1);
    dialog.table.getSelectionModel().addListSelectionListener(listener);
    listener.valueChanged(null);
    dialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
    StaticUIUtils.setEscapeClosable(dialog);
    dialog.getRootPane().setDefaultButton(dialog.btnOk);
    dialog.setVisible(true);
    return result;
}
Also used : List(java.util.List) ActionListener(java.awt.event.ActionListener) Core(org.omegat.core.Core) OStrings(org.omegat.util.OStrings) AbstractTableModel(javax.swing.table.AbstractTableModel) StaticUIUtils(org.omegat.util.gui.StaticUIUtils) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AbstractTableModel(javax.swing.table.AbstractTableModel) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

AbstractTableModel (javax.swing.table.AbstractTableModel)45 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 JBTable (com.intellij.ui.table.JBTable)3 JFrame (javax.swing.JFrame)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