Search in sources :

Example 86 with JTable

use of javax.swing.JTable in project processdash by dtuma.

the class QuickLauncher method buildUI.

private void buildUI() throws Exception {
    String windowTitle;
    String versionNumber = getVersionNumber();
    if (versionNumber == null)
        windowTitle = resources.getString("Window_Title");
    else
        windowTitle = resources.format("Window_Title2_FMT", versionNumber);
    frame = new JFrame(windowTitle);
    DashboardIconFactory.setLauncherWindowIcon(frame);
    JPanel contents = new JPanel();
    contents.setLayout(new BoxLayout(contents, BoxLayout.Y_AXIS));
    launcherFactory = new InstanceLauncherFactory();
    DropTransferHandler th = new DropTransferHandler(this, launcherFactory);
    contents.setTransferHandler(th);
    contents.add(new JLabel(resources.getString("Window_Prompt")));
    contents.add(new OptionCheckbox("Read_Only", "-DreadOnly=true\n" + "-Dteamdash.wbs.readOnly=true", null, processFactory, false));
    contents.add(new OptionCheckbox("Disable_Export", "-D" + Settings.SYS_PROP_PREFIX + "export.disableAutoExport=true\n" + "-D" + Settings.SYS_PROP_PREFIX + "backup.extraDirectories=", null, processFactory, true));
    contents.add(new OptionCheckbox("Use_External_Templates", null, "-D" + Settings.SYS_PROP_PREFIX + "templates.disableSearchPath=true", processFactory, false));
    JTable table = new JTable(instanceList);
    TableColumnModel cols = table.getColumnModel();
    for (int i = 0; i < InstanceList.COLUMN_WIDTHS.length; i++) {
        int width = InstanceList.COLUMN_WIDTHS[i];
        cols.getColumn(i).setPreferredWidth(width);
    }
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setTransferHandler(th);
    table.setPreferredScrollableViewportSize(new Dimension(380, 100));
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setBackground(Color.WHITE);
    contents.add(scrollPane);
    actionHandler = new InstanceActionHandler(table, instanceList);
    instanceList.addTableModelListener((TableModelListener) EventHandler.create(TableModelListener.class, this, "updateCursor"));
    frame.getContentPane().add(contents);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) JFrame(javax.swing.JFrame) JTable(javax.swing.JTable)

Example 87 with JTable

use of javax.swing.JTable in project suite by stupidsing.

the class SwingTableMain method run.

@Override
protected boolean run(String[] args) {
    JLabel label = new JLabel("Hello World~~~");
    JTextPane editor = new JTextPane();
    editor.setFont(new Font("Monospac821 BT", Font.PLAIN, 10));
    JTable table = new JTable(new AbstractTableModel() {

        private static final long serialVersionUID = -1;

        @Override
        public int getColumnCount() {
            return 3;
        }

        @Override
        public int getRowCount() {
            return 3;
        }

        @Override
        public Object getValueAt(int row, int col) {
            return row * col;
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            return true;
        }
    });
    JButton button = new JButton("Click Me!");
    // alt-C as hot key
    button.setMnemonic(KeyEvent.VK_C);
    button.addActionListener(event -> System.out.println("GOT " + event));
    // flow layout allows the components to be their preferred size
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(label);
    panel.add(editor);
    panel.add(table);
    panel.add(button);
    JFrame frame = new JFrame();
    frame.setContentPane(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // frame.setLocation(200, 200);
    // pack it up for display
    frame.pack();
    frame.setVisible(true);
    return true;
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Font(java.awt.Font) JTextPane(javax.swing.JTextPane) JFrame(javax.swing.JFrame) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 88 with JTable

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

the class RuleEngine2PortsSimpleNodeDialog method createSettingsPanel.

/**
 * @param settingsType The kind of the dialog.
 * @return The "Settings" panel.
 */
protected JPanel createSettingsPanel(final RuleNodeSettings settingsType) {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.ipadx = 4;
    gbc.ipady = 4;
    gbc.insets = new Insets(1, 2, 0, 2);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    panel.add(new JLabel("Rules column:"), gbc);
    gbc.gridx++;
    gbc.weightx = 1;
    panel.add(m_ruleColumn, gbc);
    gbc.gridx++;
    gbc.weightx = 0;
    panel.add(new JLabel("=>"), gbc);
    gbc.gridx++;
    gbc.weightx = 1;
    panel.add(m_outcomeColumn, gbc);
    gbc.weightx = 0;
    gbc.gridx++;
    panel.add(m_outcomeType, gbc);
    gbc.gridy++;
    gbc.gridx--;
    panel.add(m_treatOutcomesWithDollarAsReferences, gbc);
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.gridwidth = 1;
    addAppendOrReplace(panel, gbc);
    gbc.gridx = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weighty = 1;
    gbc.gridwidth = 5;
    m_errorPanel = new JScrollPane(m_errors);
    m_errorPanel.setBorder(new TitledBorder("Errors"));
    panel.add(m_errorPanel, gbc);
    panel.add(m_noErrors, gbc);
    m_errors.getColumnModel().getColumn(0).setMaxWidth(1000);
    m_errors.getColumnModel().getColumn(0).setPreferredWidth(44);
    final TableColumn contentColumn = m_errors.getColumnModel().getColumn(1);
    final DefaultTableCellRenderer origRenderer = new DefaultTableCellRenderer();
    contentColumn.setCellRenderer(new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
            Component ret = origRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (value instanceof MissingValue) {
                MissingValue mv = (MissingValue) value;
                if (ret instanceof JLabel) {
                    JLabel retLabel = (JLabel) ret;
                    retLabel.setText(mv.getError());
                }
                ret.setBackground(Color.RED);
            }
            return ret;
        }
    });
    gbc.gridy++;
    gbc.weighty = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    JScrollPane warningPanel = new JScrollPane(m_warnings);
    warningPanel.setBorder(new TitledBorder("Warnings"));
    m_warnings.setFont(UIManager.getFont("TextField.font"));
    panel.add(warningPanel, gbc);
    return panel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) MissingValue(org.knime.core.data.MissingValue) JLabel(javax.swing.JLabel) TitledBorder(javax.swing.border.TitledBorder) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) PortObject(org.knime.core.node.port.PortObject) Component(java.awt.Component)

Example 89 with JTable

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

the class InFieldsTable method updateData.

/**
 * Set the table data.
 *
 * @param fields the fields
 * @param spec the input spec might be null
 * @param flowVars the flow variables
 */
void updateData(final JavaSnippetFields fields, final DataTableSpec spec, final Map<String, FlowVariable> flowVars) {
    m_spec = spec;
    m_flowVars = flowVars;
    m_model.clear();
    for (int r = 0; r < fields.getInColFields().size(); r++) {
        InCol field = fields.getInColFields().get(r);
        m_model.addRow();
        String colName = field.getKnimeName();
        DataColumnSpec colSpec = spec.getColumnSpec(colName);
        Object value = null != colSpec ? colSpec : colName;
        m_model.setValueAt(value, r, Column.COLUMN);
        m_model.setValueAt(field.getJavaName(), r, Column.JAVA_FIELD);
        Optional<?> factory = ConverterUtil.getDataCellToJavaConverterFactory(field.getConverterFactoryId());
        if (!factory.isPresent()) {
            // seems to be missing.
            if (field.getJavaType() != null) {
                factory = ConverterUtil.getConverterFactory(field.getDataType(), field.getJavaType());
            }
        }
        if (factory.isPresent()) {
            m_model.setValueAt(factory.get(), r, Column.JAVA_TYPE);
        } else {
            final Class<?> type = field.getJavaType();
            if (type != null) {
                m_model.setValueAt(type, r, Column.JAVA_TYPE);
            } else {
                m_model.setValueAt(field.getJavaTypeName(), r, Column.JAVA_TYPE);
            }
        }
    }
    int offset = m_model.getRowCount();
    for (int r = 0; r < fields.getInVarFields().size(); r++) {
        InVar field = fields.getInVarFields().get(r);
        m_model.addRow();
        String name = field.getKnimeName();
        FlowVariable flowVar = m_flowVars.get(name);
        Object value = null != flowVar ? flowVar : name;
        m_model.setValueAt(value, offset + r, Column.COLUMN);
        m_model.setValueAt(field.getJavaName(), offset + r, Column.JAVA_FIELD);
        m_model.setValueAt(field.getJavaType(), offset + r, Column.JAVA_TYPE);
    }
    JTable table = getTable();
    final TableColumnModel columnModel = table.getColumnModel();
    columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellRenderer(new InputTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellEditor(createInputCellEditor());
    columnModel.getColumn(m_model.getIndex(Column.JAVA_FIELD)).setCellRenderer(FieldsTableUtil.createJavaFieldTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellRenderer(FieldsTableUtil.createJavaTypeTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellEditor(FieldsTableUtil.createJavaTypeTableCellEditor());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) JTable(javax.swing.JTable) TableColumnModel(javax.swing.table.TableColumnModel) InVar(org.knime.base.node.jsnippet.util.field.InVar) InCol(org.knime.base.node.jsnippet.util.field.InCol) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 90 with JTable

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

the class OutFieldsTable method updateData.

/**
 * Set the table data.
 *
 * @param fields the fields
 * @param spec the input spec
 * @param flowVars the flow variables
 */
void updateData(final JavaSnippetFields fields, final DataTableSpec spec, final Map<String, FlowVariable> flowVars) {
    m_spec = spec;
    m_flowVars = flowVars;
    m_model.clear();
    fields.getOutColFields().forEach(field -> addRow(field));
    fields.getOutVarFields().forEach(field -> addRow(field));
    /*
         * There is no simple way of disabling a boolean cell renderer if the cell is not editable.
         *
         * Hence, here we wrap the hidden Default BooleanRenderer and disable if not editable.
         */
    final TableCellRenderer boolRenderer = new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
            final Component c = table.getDefaultRenderer(Boolean.class).getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            c.setEnabled(table.isCellEditable(row, column));
            return c;
        }
    };
    final TableColumnModel columnModel = getTable().getColumnModel();
    columnModel.getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellEditor(new DefaultCellEditor(new JCheckBox()));
    columnModel.getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellRenderer(boolRenderer);
    if (!m_flowVarsOnly) {
        // Field type column does not exist for flowVarsOnly
        columnModel.getColumn(m_model.getIndex(Column.FIELD_TYPE)).setCellEditor(createFieldTypeCellEditor());
    }
    columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellRenderer(new InputTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellEditor(new InputTableCellEditor(this, m_spec, m_flowVars));
    columnModel.getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellRenderer(new DataTypeTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellEditor(new DataTypeTableCellEditor(this, m_spec, m_flowVars));
    if (!m_flowVarsOnly) {
        // Field type column does not exist for flowVarsOnly
        columnModel.getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellEditor(new DefaultCellEditor(new JCheckBox()));
        columnModel.getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellRenderer(boolRenderer);
    }
    columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellRenderer(FieldsTableUtil.createJavaTypeTableCellRenderer());
    columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellEditor(FieldsTableUtil.createJavaTypeTableCellEditor());
    columnModel.getColumn(m_model.getIndex(Column.JAVA_FIELD)).setCellRenderer(FieldsTableUtil.createJavaFieldTableCellRenderer());
}
Also used : JCheckBox(javax.swing.JCheckBox) FlowVariableTableCellRenderer(org.knime.core.node.util.FlowVariableTableCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) JTable(javax.swing.JTable) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

JTable (javax.swing.JTable)584 JScrollPane (javax.swing.JScrollPane)282 JPanel (javax.swing.JPanel)217 Dimension (java.awt.Dimension)145 JButton (javax.swing.JButton)139 BorderLayout (java.awt.BorderLayout)133 JLabel (javax.swing.JLabel)129 ActionEvent (java.awt.event.ActionEvent)109 ActionListener (java.awt.event.ActionListener)81 TableColumn (javax.swing.table.TableColumn)79 DefaultTableModel (javax.swing.table.DefaultTableModel)75 Component (java.awt.Component)66 BoxLayout (javax.swing.BoxLayout)66 FlowLayout (java.awt.FlowLayout)58 MouseEvent (java.awt.event.MouseEvent)58 JTextField (javax.swing.JTextField)57 TableColumnModel (javax.swing.table.TableColumnModel)52 GridBagConstraints (java.awt.GridBagConstraints)46 TableCellRenderer (javax.swing.table.TableCellRenderer)43 Test (org.junit.Test)43