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);
}
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;
}
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;
}
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());
}
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());
}
Aggregations