use of javax.swing.Box in project knime-core by knime.
the class VariableFileReaderNodeDialog method createPreviewPanel.
private JPanel createPreviewPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Preview"));
Box hintBox = Box.createHorizontalBox();
Box tableBox = Box.createHorizontalBox();
hintBox.add(Box.createGlue());
hintBox.add(new JLabel("Click column header to change " + "column properties (* = name/type user settings)"));
hintBox.add(Box.createGlue());
PreviewTableContentView ptcv = new PreviewTableContentView();
m_previewTableView = new TableView(ptcv);
tableBox.add(m_previewTableView);
// add the analyzer warning at the bottom
m_analyzeWarn = new JLabel("");
m_analyzeWarn.setForeground(Color.red);
JPanel analBox = new JPanel();
analBox.setLayout(new BoxLayout(analBox, BoxLayout.X_AXIS));
analBox.add(Box.createHorizontalGlue());
analBox.add(m_analyzeWarn);
// reserve a certain height for the (in the beginning invisible) label
analBox.add(Box.createVerticalStrut(25));
analBox.add(Box.createHorizontalGlue());
panel.add(Box.createGlue());
panel.add(hintBox);
panel.add(Box.createVerticalStrut(10));
panel.add(tableBox);
panel.add(analBox);
panel.add(Box.createGlue());
// this is the callback for the preview table header click
ptcv.addPropertyChangeListener(PreviewTableContentView.PROPERTY_SPEC_CHANGED, new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
// thats the col idx the mouse was clicked on
Integer colNr = (Integer) evt.getNewValue();
setNewUserSettingsForColumn(colNr.intValue());
}
});
return panel;
}
use of javax.swing.Box in project knime-core by knime.
the class RuleEngineNodeDialog method createTopPart.
/*
* top part (from left to right) = variable list, operator list, editor box
*/
private Box createTopPart() {
/*
* Variable list (column names)
*/
m_variableModel = new DefaultListModel();
m_variableList = new JList(m_variableModel);
m_variableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_variableList.setCellRenderer(new DataColumnSpecListCellRenderer());
m_variableList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent arg0) {
if (arg0.getValueIsAdjusting()) {
return;
}
if (m_lastUsedTextfield != null) {
String existingText = m_lastUsedTextfield.getText();
if (existingText.equals(RULE_LABEL)) {
existingText = "";
}
if (!m_variableList.isSelectionEmpty()) {
String newText = ((DataColumnSpec) m_variableList.getSelectedValue()).getName();
m_lastUsedTextfield.setText((existingText + " $" + newText + "$").trim());
m_lastUsedTextfield.requestFocusInWindow();
if (m_lastUsedTextfield == m_ruleLabelEditor) {
m_outcomeIsColumn.setSelected(true);
}
}
}
m_variableList.clearSelection();
}
});
/*
* Operators (<, >, <=, >=, =, AND, OR, etc)
*/
m_operatorModel = new DefaultListModel();
m_operatorList = new JList(m_operatorModel);
m_operatorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_operatorList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent arg0) {
if (!arg0.getValueIsAdjusting() && !m_operatorList.isSelectionEmpty()) {
String existingText = m_ruleEditor.getText();
if (existingText.equals(RULE_LABEL)) {
existingText = "";
}
String newText = (String) m_operatorList.getSelectedValue();
m_ruleEditor.setText(existingText + " " + newText);
m_ruleEditor.requestFocusInWindow();
m_operatorList.clearSelection();
}
}
});
Box editorBox = createEditorPart();
Box listBox = Box.createHorizontalBox();
JScrollPane variableScroller = new JScrollPane(m_variableList);
variableScroller.setBorder(BorderFactory.createTitledBorder("Columns"));
JScrollPane operatorScroller = new JScrollPane(m_operatorList);
operatorScroller.setBorder(BorderFactory.createTitledBorder("Operators"));
listBox.add(variableScroller);
listBox.add(operatorScroller);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listBox, editorBox);
Dimension minimumSize = new Dimension(200, 50);
listBox.setMinimumSize(minimumSize);
editorBox.setMinimumSize(minimumSize);
Box topBox = Box.createHorizontalBox();
topBox.add(splitPane);
topBox.add(Box.createHorizontalGlue());
return topBox;
}
use of javax.swing.Box in project knime-core by knime.
the class RuleEngineNodeDialog method createEditorPart.
/*
* Editor part (from top to bottom, from left to right): default label
* (label, text field) new column name (label, text field) rule editor (rule
* text field, outcome text field, add button, clear button) error text
* field
*/
private Box createEditorPart() {
/*
* Default label box
*/
m_defaultLabelEditor = new JTextField(10);
m_defaultLabelEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
m_defaultLabelEditor.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
if (m_defaultLabelEditor.getText().equals(DEFAULT_LABEL)) {
m_defaultLabelEditor.setText("");
}
m_lastUsedTextfield = m_defaultLabelEditor;
}
});
JPanel defaultLabelBox = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.1;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(0, 20, 0, 0);
defaultLabelBox.add(new JLabel("Default label (if no rule matches): "), c);
c.insets = new Insets(0, 0, 0, 0);
c.gridx++;
c.weightx = 1;
c.fill = GridBagConstraints.HORIZONTAL;
defaultLabelBox.add(m_defaultLabelEditor, c);
c.fill = GridBagConstraints.NONE;
c.weightx = 0.1;
// also add a variable Model + corresponding icon to make this
// option controllable via a variable
FlowVariableModel fvm = createFlowVariableModel(RuleEngineSettings.CFG_DEFAULT_LABEL, FlowVariable.Type.STRING);
fvm.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent evt) {
FlowVariableModel svm = (FlowVariableModel) (evt.getSource());
m_defaultLabelEditor.setEnabled(!svm.isVariableReplacementEnabled());
}
});
c.gridx++;
defaultLabelBox.add(new FlowVariableModelButton(fvm), c);
c.gridx++;
defaultLabelBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
c.gridy++;
c.gridx = 1;
m_defaultLabelIsColumn = new JCheckBox("is a column reference");
defaultLabelBox.add(m_defaultLabelIsColumn, c);
/*
* New column name box
*/
m_newColumnName = new JTextField(10);
m_newColumnName.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
m_newColumnName.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
if (m_newColumnName.getText().equals(NEW_COL_NAME)) {
m_newColumnName.setText("");
}
}
});
Box newColNameBox = Box.createHorizontalBox();
newColNameBox.add(Box.createHorizontalStrut(20));
newColNameBox.add(new JLabel("Appended column name: "));
newColNameBox.add(Box.createHorizontalGlue());
newColNameBox.add(m_newColumnName);
newColNameBox.add(Box.createHorizontalGlue());
newColNameBox.add(Box.createHorizontalStrut(10));
newColNameBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
/*
* Rule Box
*/
JPanel ruleBox = new JPanel(new GridBagLayout());
m_ruleEditor = new JTextField(RULE_LABEL, 35);
m_ruleEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
m_ruleEditor.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
if (m_ruleEditor.getText().equals(RULE_LABEL)) {
m_ruleEditor.setText("");
}
m_lastUsedTextfield = m_ruleEditor;
}
});
m_ruleLabelEditor = new JTextField(OUTCOME_LABEL, 10);
m_ruleLabelEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
m_ruleLabelEditor.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
if (m_ruleLabelEditor.getText().equals(OUTCOME_LABEL)) {
m_ruleLabelEditor.setText("");
}
m_lastUsedTextfield = m_ruleLabelEditor;
}
});
m_lastUsedTextfield = m_ruleEditor;
/*
* Add Button
*/
JButton add = new JButton("Add");
add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
LOGGER.debug("adding: " + m_ruleEditor.getText() + "=>" + m_ruleLabelEditor.getText());
addRule();
m_lastUsedTextfield = m_ruleEditor;
}
});
/*
* Clear Button
*/
JButton clear = new JButton("Clear");
clear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
m_ruleEditor.setText("");
m_ruleLabelEditor.setText("");
}
});
m_outcomeIsColumn = new JCheckBox("is a column reference");
/*
* Putting the rule editor together (rule, outcome, add, clear)
*/
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(0, 20, 0, 0);
c.weightx = 0.8;
c.fill = GridBagConstraints.HORIZONTAL;
ruleBox.add(new JLabel("Condition"), c);
c.gridx++;
c.weightx = 0.1;
c.insets = new Insets(0, 5, 0, 0);
ruleBox.add(new JLabel("Outcome"), c);
c.gridx = 0;
c.gridy++;
c.insets = new Insets(0, 20, 0, 0);
ruleBox.add(m_ruleEditor, c);
c.insets = new Insets(0, 5, 0, 0);
c.gridx++;
c.weightx = 0.1;
ruleBox.add(m_ruleLabelEditor, c);
c.insets = new Insets(0, 10, 0, 0);
c.fill = GridBagConstraints.NONE;
c.gridx++;
ruleBox.add(add, c);
c.gridx++;
ruleBox.add(clear, c);
c.gridy++;
c.gridx = 1;
c.insets = new Insets(0, 5, 0, 0);
ruleBox.add(m_outcomeIsColumn, c);
/*
* Putting it all together
*/
Box editorBox = Box.createVerticalBox();
editorBox.add(newColNameBox);
editorBox.add(Box.createVerticalStrut(20));
editorBox.add(defaultLabelBox);
editorBox.add(Box.createVerticalStrut(20));
editorBox.add(ruleBox);
editorBox.add(Box.createVerticalStrut(20));
m_error = new JLabel(" ");
m_error.setForeground(Color.RED);
editorBox.add(m_error);
editorBox.setBorder(BorderFactory.createEtchedBorder());
return editorBox;
}
use of javax.swing.Box in project knime-core by knime.
the class RuleEngineNodeDialog method createBottomPart.
/*
* Bottom part (from left ot right): rule list, button part
*/
private Box createBottomPart() {
/*
* Put all rules row by row
*/
Box bottom = Box.createHorizontalBox();
/*
* Rule List
*/
m_ruleModel = new DefaultListModel();
m_rules = new JList(m_ruleModel);
m_rules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Box bottomLeft = Box.createVerticalBox();
bottomLeft.add(new JScrollPane(m_rules));
bottomLeft.add(Box.createVerticalGlue());
bottom.add(bottomLeft);
bottom.add(createButtonPart());
return bottom;
}
use of javax.swing.Box in project knime-core by knime.
the class DialogComponentButtonGroup method createButtonGroupBox.
/**
* Creates a <code>Box</code> with the buttons of the given
* <code>ButtonGroup</code>. Surrounded by a border if the label is
* not null.
* @param group the <code>ButtonGroup</code> to create the box with
* @param label the optional label of the group Set to <code>null</code>
* for none label
* @param set to <code>true</code> to have the box in a vertical
* orientation
* @return a <code>Box</code> with all buttons of the given
* <code>ButtonGroup</code>
*/
private static Box createButtonGroupBox(final ButtonGroup group, final String label, final boolean vertical) {
Box buttonBox = null;
if (vertical) {
buttonBox = Box.createVerticalBox();
buttonBox.add(Box.createVerticalGlue());
} else {
buttonBox = Box.createHorizontalBox();
buttonBox.add(Box.createHorizontalGlue());
}
final Dimension titleSize;
if (label != null) {
final TitledBorder borderTitle = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), label);
titleSize = borderTitle.getMinimumSize(buttonBox);
buttonBox.setBorder(borderTitle);
} else {
titleSize = null;
}
for (final Enumeration<AbstractButton> buttons = group.getElements(); buttons.hasMoreElements(); ) {
final AbstractButton button = buttons.nextElement();
buttonBox.add(button);
if (vertical) {
buttonBox.add(Box.createVerticalGlue());
} else {
buttonBox.add(Box.createHorizontalGlue());
}
}
final Dimension preferredSize = buttonBox.getPreferredSize();
if (titleSize != null && titleSize.getWidth() > preferredSize.getWidth()) {
// add 5 to have a little space at the end looks nicer
preferredSize.setSize(titleSize.getWidth() + 5, preferredSize.getHeight());
}
buttonBox.setPreferredSize(preferredSize);
buttonBox.setMinimumSize(preferredSize);
return buttonBox;
}
Aggregations