use of java.awt.GridLayout in project knime-core by knime.
the class MissingValueHandling2Panel method createContent.
/**
* @param setting
* @param spec
* @throws InternalError
*/
private void createContent(final MissingValueHandling2ColSetting setting, final DataColumnSpec... spec) throws InternalError {
final List<String> warningMessages = new ArrayList<String>();
// if we got incompatible types the original type is overwritten by unkown.
int settingTypeBackup = setting.getType();
JPanel tabPanel = new JPanel(new BorderLayout(0, 5));
final JPanel panel = new JPanel(new GridLayout(0, 2));
final Icon icon;
final String name;
final Border border;
final JComponent removePanel;
if (setting.isMetaConfig()) {
switch(setting.getType()) {
case MissingValueHandling2ColSetting.TYPE_INT:
icon = IntCell.TYPE.getIcon();
name = "Integer";
border = BorderFactory.createTitledBorder("Integer Columns");
break;
case MissingValueHandling2ColSetting.TYPE_STRING:
icon = StringCell.TYPE.getIcon();
name = "String";
border = BorderFactory.createTitledBorder("String Columns");
break;
case MissingValueHandling2ColSetting.TYPE_DOUBLE:
icon = DoubleCell.TYPE.getIcon();
name = "Double";
border = BorderFactory.createTitledBorder("Double Columns");
break;
case MissingValueHandling2ColSetting.TYPE_UNKNOWN:
icon = DataType.getType(DataCell.class).getIcon();
name = "Unknown";
border = BorderFactory.createTitledBorder("Unknown Columns");
break;
default:
throw new InternalError("No such type.");
}
removePanel = new JLabel();
} else {
final List<String> names = new ArrayList<String>(Arrays.asList(setting.getNames()));
for (DataColumnSpec cspec : spec) {
names.remove(cspec.getName());
}
if (!names.isEmpty()) {
throw new NullPointerException("Not equal on init: '" + Arrays.toString(setting.getNames()) + "' vs. '" + Arrays.toString(spec) + "'.");
}
name = setting.getDisplayName();
icon = spec[0].getType().getIcon();
JButton requestRemoveButton = new JButton("Remove");
requestRemoveButton.addActionListener(new ActionListener() {
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(final ActionEvent e) {
firePropertyChange(REMOVE_ACTION, null, null);
}
});
removePanel = new JPanel();
removePanel.setLayout(new GridLayout(2, 0));
removePanel.add(requestRemoveButton);
final List<DataColumnSpec> notExistingColumns = getNotExistingColumns(spec);
final List<DataColumnSpec> incompatibleColumns = getIncompatibleTypedColumns(setting.getType(), spec);
if (!notExistingColumns.isEmpty()) {
warningMessages.add("Some columns no longer exist (red bordered)");
}
if (!incompatibleColumns.isEmpty()) {
warningMessages.add(String.format("Some columns have an incompatible type to %s (yellow borderd)", typeToString(setting.getType())));
}
final Set<DataColumnSpec> invalidColumns = new HashSet<DataColumnSpec>();
invalidColumns.addAll(notExistingColumns);
invalidColumns.addAll(incompatibleColumns);
if (!incompatibleColumns.isEmpty()) {
setting.setType(MissingValueHandling2ColSetting.TYPE_UNKNOWN);
}
if (!invalidColumns.isEmpty() && // if all columns are invalid a clean is the same as a remove
!(invalidColumns.size() == spec.length)) {
JButton removeNotExistingColumns = new JButton("Clean");
removeNotExistingColumns.setToolTipText("Removes all invalid columns from the configuration.");
removeNotExistingColumns.addActionListener(new ActionListener() {
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(final ActionEvent e) {
MissingValueHandling2Panel.this.removeAll();
// recreate the content, based on the new settings with removed invalid columns
createContent(diff(m_setting, invalidColumns), diff(spec, invalidColumns));
firePropertyChange(REMOVED_INVALID_COLUMNS, null, invalidColumns.toArray(new DataColumnSpec[invalidColumns.size()]));
}
});
removePanel.add(removeNotExistingColumns);
}
if (!warningMessages.isEmpty()) {
LOGGER.warn("get warnings during panel validation: " + warningMessages);
border = BorderFactory.createLineBorder(Color.RED, 2);
tabPanel.add(createWarningLabel(warningMessages), BorderLayout.NORTH);
} else {
border = BorderFactory.createLineBorder(Color.BLACK);
}
}
createWestLayout(setting, tabPanel, icon, name, spec);
panel.add(createSpacer(1));
panel.add(removePanel);
createEastLayout(setting, panel, spec);
setting.setType(settingTypeBackup);
m_setting = setting;
setBorder(border);
tabPanel.add(panel, BorderLayout.CENTER);
tabPanel.add(createSpacer(65), BorderLayout.SOUTH);
add(tabPanel);
}
use of java.awt.GridLayout in project knime-core by knime.
the class TableView method registerFindAction.
/**
* Creates and registers the "Find ..." action on this component. Multiple invocation of this method have no effect
* (lazy initialization).
*
* @return The non-null action representing the find task.
* @see #registerNavigationActions()
*/
public TableAction registerFindAction() {
if (m_findAction == null) {
String name = "Find...";
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
TableAction action = new TableAction(stroke, name) {
@Override
public void actionPerformed(final ActionEvent e) {
if (!hasData()) {
return;
}
if (m_searchPosition == null) {
initNewSearchPostion(new SearchOptions(true, false, true));
}
m_searchPosition.reset();
SearchOptions searchOptions = m_searchPosition.getSearchOptions();
boolean isSearchRowID = searchOptions.isSearchRowID();
boolean isSearchColumnName = searchOptions.isSearchColumnName();
boolean isSearchData = searchOptions.isSearchData();
JCheckBox rowKeyBox = new JCheckBox("Search RowID Column", isSearchRowID);
JCheckBox colNameBox = new JCheckBox("Search Column Names", isSearchColumnName);
JCheckBox dataBox = new JCheckBox("Search Data", isSearchData);
JCheckBox[] asArray = new JCheckBox[] { rowKeyBox, colNameBox, dataBox };
rowKeyBox.addItemListener(new AtLeastOnButtonSelectedItemListener(dataBox, asArray));
colNameBox.addItemListener(new AtLeastOnButtonSelectedItemListener(rowKeyBox, asArray));
dataBox.addItemListener(new AtLeastOnButtonSelectedItemListener(rowKeyBox, asArray));
JCheckBox ignoreCaseBox = new JCheckBox("Case insensitive", m_searchString.map(i -> i.isIgnoreCase()).orElse(false));
JCheckBox regexBox = new JCheckBox("Regular Expression", m_searchString.map(i -> i.isRegex()).orElse(false));
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("Options: "), BorderLayout.NORTH);
JPanel centerPanel = new JPanel(new GridLayout(0, 1));
centerPanel.add(rowKeyBox);
centerPanel.add(colNameBox);
centerPanel.add(dataBox);
centerPanel.add(new JLabel());
centerPanel.add(ignoreCaseBox);
centerPanel.add(regexBox);
centerPanel.add(new JLabel());
panel.add(centerPanel, BorderLayout.CENTER);
panel.add(new JLabel(" "), BorderLayout.WEST);
panel.add(new JLabel("Find String: "), BorderLayout.SOUTH);
SearchString newSearchString;
while (true) {
String in = (String) JOptionPane.showInputDialog(TableView.this, panel, "Search", JOptionPane.QUESTION_MESSAGE, null, null, m_searchString.map(s -> s.getSearchString()).orElse(""));
if (StringUtils.isEmpty(in)) {
// canceled
return;
}
try {
newSearchString = new SearchString(in, ignoreCaseBox.isSelected(), regexBox.isSelected());
break;
} catch (PatternSyntaxException pse) {
JOptionPane.showMessageDialog(TableView.this, pse.getMessage(), "Invalid regular expression", JOptionPane.ERROR_MESSAGE);
}
}
searchOptions = new SearchOptions(rowKeyBox.isSelected(), colNameBox.isSelected(), dataBox.isSelected());
find(newSearchString, searchOptions);
}
};
registerAction(action);
m_findAction = action;
}
return m_findAction;
}
use of java.awt.GridLayout in project knime-core by knime.
the class ColorLegendTab method update.
/**
* Updates the color legend with the column names and the referring color.
*
* @param mapping column name - color
*/
public void update(final Map<String, Color> mapping) {
removeAll();
m_mapping = mapping;
JPanel composite = new JPanel();
int rows = (int) Math.ceil((double) mapping.size() / (double) ROWS);
composite.setLayout(new GridLayout(5, rows));
for (Map.Entry<String, Color> entry : mapping.entrySet()) {
composite.add(createOneItem(entry.getKey(), entry.getValue()));
}
add(composite);
}
use of java.awt.GridLayout in project knime-core by knime.
the class BasisFunctionPredictor2NodeDialog method addOtherControls.
/**
* {@inheritDoc}
*/
@Override
protected void addOtherControls(final JPanel panel) {
m_dontKnow = new JSpinner(new SpinnerNumberModel(0.0, 0.0, 1.0, 0.1));
m_defaultButton = new JRadioButton("Default ", true);
m_setButton = new JRadioButton("Use ");
m_ignoreButton = new JRadioButton("Ignore ", true);
// add don't know probability
m_ignoreButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
selectionChanged();
}
});
ButtonGroup bg = new ButtonGroup();
bg.add(m_ignoreButton);
bg.add(m_defaultButton);
bg.add(m_setButton);
m_dontKnow.setEditor(new JSpinner.NumberEditor(m_dontKnow, "#.##########"));
m_dontKnow.setPreferredSize(new Dimension(75, 25));
JPanel dontKnowPanel = new JPanel(new GridLayout(3, 1));
dontKnowPanel.setBorder(BorderFactory.createTitledBorder(" Don't Know Class "));
FlowLayout left = new FlowLayout(FlowLayout.LEFT);
final JPanel ignorePanel = new JPanel(left), defaultPanel = new JPanel(left);
ignorePanel.add(m_ignoreButton);
defaultPanel.add(m_defaultButton);
dontKnowPanel.add(ignorePanel);
dontKnowPanel.add(defaultPanel);
JPanel usePanel = new JPanel(left);
dontKnowPanel.add(usePanel);
usePanel.add(m_setButton);
usePanel.add(m_dontKnow);
panel.add(dontKnowPanel);
m_defaultButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
m_dontKnow.setEnabled(false);
}
});
m_setButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
m_dontKnow.setEnabled(true);
}
});
getLayout().putConstraint(SpringLayout.EAST, dontKnowPanel, 0, SpringLayout.EAST, panel);
getLayout().putConstraint(SpringLayout.WEST, dontKnowPanel, 0, SpringLayout.WEST, panel);
super.setLastAdded(dontKnowPanel);
getPanel().setPreferredSize(new Dimension(400, 240));
}
use of java.awt.GridLayout in project knime-core by knime.
the class DataValidatorColPanel method createContent.
/**
* @param spec the specs to create the layout from
*/
private void createContent(final List<DataColumnSpec> spec) {
final List<String> warningMessages = new ArrayList<String>();
JPanel parentPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
final Border border;
final JComponent removeButtons;
JButton requestRemoveButton = new JButton("Remove");
requestRemoveButton.addActionListener(new ActionListener() {
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(final ActionEvent e) {
firePropertyChange(REMOVE_ACTION, null, null);
}
});
removeButtons = new JPanel();
removeButtons.setLayout(new GridLayout(2, 0));
removeButtons.add(requestRemoveButton);
final List<DataColumnSpec> notExistingColumns = getNotExistingColumns(spec);
if (!notExistingColumns.isEmpty()) {
warningMessages.add("Some columns no longer exist (red bordered)");
}
final Set<DataColumnSpec> invalidColumns = new HashSet<DataColumnSpec>();
invalidColumns.addAll(notExistingColumns);
if (!invalidColumns.isEmpty() && // if all columns are invalid a clean is the same as a remove
!(invalidColumns.size() == spec.size())) {
JButton removeNotExistingColumns = new JButton("Clean");
removeNotExistingColumns.setToolTipText("Removes all invalid columns from the configuration.");
removeNotExistingColumns.addActionListener(new ActionListener() {
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(final ActionEvent e) {
DataValidatorColPanel.this.removeAll();
// recreate the content, based on the new settings with removed invalid columns
diff(m_setting, invalidColumns);
createContent(diff(spec, invalidColumns));
firePropertyChange(REMOVED_COLUMNS, null, invalidColumns.toArray(new DataColumnSpec[invalidColumns.size()]));
}
});
removeButtons.add(removeNotExistingColumns);
}
if (!warningMessages.isEmpty()) {
LOGGER.warn("get warnings during panel validation: " + warningMessages);
border = BorderFactory.createLineBorder(Color.RED, 2);
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(10, 10, 10, 10);
c.anchor = GridBagConstraints.NORTH;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
parentPanel.add(createWarningLabel(warningMessages), c);
} else {
border = BorderFactory.createLineBorder(Color.BLACK);
}
final JPanel centerPanel = new JPanel(new BorderLayout());
createCenterLayout(m_setting, centerPanel);
int xOffset = 0;
if (m_parent != null || m_forceColListToBeShown) {
createWestLayout(parentPanel, spec);
JPanel northPanel = new JPanel(new BorderLayout());
northPanel.add(removeButtons, BorderLayout.EAST);
centerPanel.add(northPanel, BorderLayout.NORTH);
setBorder(border);
xOffset += 1;
} else {
setBorder(BorderFactory.createTitledBorder("Column Settings"));
}
c.fill = GridBagConstraints.NONE;
c.insets = new Insets(10, 10, 10, 10);
c.gridx = xOffset;
c.gridy = 1;
c.gridwidth = 1;
c.weightx = 0;
parentPanel.add(centerPanel, c);
if (m_forceColListToBeShown) {
// Table Validator Configuration
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.EAST;
c.insets = new Insets(0, 0, 0, 0);
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
c.weightx = 1;
add(parentPanel, c);
} else {
// Table Validator (Reference) Configuration
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(0, 0, 0, 0);
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
c.weightx = 1;
add(parentPanel, c);
}
updateUiElements(spec);
}
Aggregations