use of javax.swing.border.Border 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 javax.swing.border.Border in project knime-core by knime.
the class AbstractPainterDataValueRenderer method getListCellRendererComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
setComponentOrientation(list.getComponentOrientation());
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setValue(value);
setEnabled(list.isEnabled());
setFont(list.getFont());
Border border = null;
if (cellHasFocus) {
if (isSelected) {
border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
}
if (border == null) {
border = UIManager.getBorder("List.focusCellHighlightBorder");
}
} else {
border = getNoFocusBorder();
}
setBorder(border);
return this;
}
use of javax.swing.border.Border in project knime-core by knime.
the class TableRowHeaderView method updateUI.
/**
* Changes look and feel here (by calling {@link JTable#updateUI()})
* and also in the renderer.
* {@inheritDoc}
*/
@Override
public void updateUI() {
super.updateUI();
m_headerBackground = UIManager.getColor("TableHeader.background");
setBackground(m_headerBackground);
Border b = UIManager.getBorder("TableHeader.border");
TableCellRenderer renderer = getColumnModel().getColumn(0).getCellRenderer();
if (renderer instanceof DataCellHeaderRenderer) {
((DataCellHeaderRenderer) renderer).setBorder(b);
}
}
use of javax.swing.border.Border in project knime-core by knime.
the class Plotter2DScrollPaneLayout method layoutContainer.
/**
* Overwrites the method of the parent class to arrange the header at the
* bottom of the view.
*
* @param parent parent container of the component rendered by this layout
* manager
* @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
*/
@Override
public void layoutContainer(final Container parent) {
/*
* Sync the (now obsolete) policy fields with the JScrollPane.
*/
JScrollPane scrollPane = (JScrollPane) parent;
vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
Rectangle availR = scrollPane.getBounds();
availR.x = 0;
availR.y = 0;
Insets insets = parent.getInsets();
availR.x = insets.left;
availR.y = insets.top;
availR.width -= insets.left + insets.right;
availR.height -= insets.top + insets.bottom;
// causes to add the other one as well)
if (vsb != null) {
availR.width -= vsb.getPreferredSize().width;
// also expand the scroll panes prefered size
}
if (hsb != null) {
availR.height -= hsb.getPreferredSize().height;
}
/*
* Get the scrollPane's orientation.
*/
boolean leftToRight = scrollPane.getComponentOrientation().isLeftToRight();
/*
* If there's a visible column header remove the space it needs from the
* top of availR. The column header is treated as if it were fixed
* height, arbitrary width.
*/
Rectangle colHeadR = new Rectangle(0, 0, 0, 0);
if ((colHead != null) && (colHead.isVisible())) {
int colHeadHeight = Math.min(availR.height, colHead.getPreferredSize().height);
colHeadR.height = colHeadHeight;
// availR.y += colHeadHeight;
// we do not adjust the y coordinate but the height of th
// available Rec
availR.height -= colHeadHeight;
}
/*
* If there's a visible row header remove the space it needs from the
* left or right of availR. The row header is treated as if it were
* fixed width, arbitrary height.
*/
Rectangle rowHeadR = new Rectangle(0, 0, 0, 0);
if ((rowHead != null) && (rowHead.isVisible())) {
int rowHeadWidth = Math.min(availR.width, rowHead.getPreferredSize().width);
rowHeadR.width = rowHeadWidth;
availR.width -= rowHeadWidth;
if (leftToRight) {
rowHeadR.x = availR.x;
availR.x += rowHeadWidth;
} else {
rowHeadR.x = availR.x + availR.width;
}
}
/*
* If there's a JScrollPane.viewportBorder, remove the space it occupies
* for availR.
*/
Border viewportBorder = scrollPane.getViewportBorder();
Insets vpbInsets;
if (viewportBorder != null) {
vpbInsets = viewportBorder.getBorderInsets(parent);
availR.x += vpbInsets.left;
availR.y += vpbInsets.top;
availR.width -= vpbInsets.left + vpbInsets.right;
availR.height -= vpbInsets.top + vpbInsets.bottom;
} else {
vpbInsets = new Insets(0, 0, 0, 0);
}
/*
* At this point availR is the space available for the viewport and
* scrollbars. rowHeadR is correct except for its height and y and
* colHeadR is correct except for its width and x. Once we're through
* computing the dimensions of these three parts we can go back and set
* the dimensions of rowHeadR.height, rowHeadR.y, colHeadR.width,
* colHeadR.x and the bounds for the corners.
*
* We'll decide about putting up scrollbars by comparing the viewport
* views preferred size with the viewports extent size (generally just
* its size). Using the preferredSize is reasonable because layout
* proceeds top down - so we expect the viewport to be laid out next.
* And we assume that the viewports layout manager will give the view
* it's preferred size. One exception to this is when the view
* implements Scrollable and
* Scrollable.getViewTracksViewport{Width,Height} methods return true.
* If the view is tracking the viewports width we don't bother with a
* horizontal scrollbar, similarly if view.getViewTracksViewport(Height)
* is true we don't bother with a vertical scrollbar.
*/
Component view = (viewport != null) ? viewport.getView() : null;
Dimension viewPrefSize = (view != null) ? view.getPreferredSize() : new Dimension(0, 0);
Dimension extentSize = (viewport != null) ? viewport.toViewCoordinates(availR.getSize()) : new Dimension(0, 0);
boolean viewTracksViewportWidth = false;
boolean viewTracksViewportHeight = false;
boolean isEmpty = (availR.width < 0 || availR.height < 0);
Scrollable sv;
// case anyway.
if (!isEmpty && view instanceof Scrollable) {
sv = (Scrollable) view;
viewTracksViewportWidth = sv.getScrollableTracksViewportWidth();
viewTracksViewportHeight = sv.getScrollableTracksViewportHeight();
} else {
sv = null;
}
/*
* If there's a vertical scrollbar and we need one, allocate space for
* it (we'll make it visible later). A vertical scrollbar is considered
* to be fixed width, arbitrary height.
*/
Rectangle vsbR = new Rectangle(0, availR.y - vpbInsets.top, 0, 0);
boolean vsbNeeded;
if (isEmpty) {
vsbNeeded = false;
} else if (vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
vsbNeeded = true;
} else if (vsbPolicy == VERTICAL_SCROLLBAR_NEVER) {
vsbNeeded = false;
} else {
// vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
vsbNeeded = !viewTracksViewportHeight && (viewPrefSize.height > extentSize.height);
}
if ((vsb != null) && vsbNeeded) {
adjustForVSB(true, availR, vsbR, vpbInsets, leftToRight);
extentSize = viewport.toViewCoordinates(availR.getSize());
}
/*
* If there's a horizontal scrollbar and we need one, allocate space for
* it (we'll make it visible later). A horizontal scrollbar is
* considered to be fixed height, arbitrary width.
*/
Rectangle hsbR = new Rectangle(availR.x - vpbInsets.left, 0, 0, 0);
boolean hsbNeeded;
if (isEmpty) {
hsbNeeded = false;
} else if (hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
hsbNeeded = true;
} else if (hsbPolicy == HORIZONTAL_SCROLLBAR_NEVER) {
hsbNeeded = false;
} else {
// hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
hsbNeeded = !viewTracksViewportWidth && (viewPrefSize.width > extentSize.width);
}
if ((hsb != null) && hsbNeeded) {
adjustForHSB(true, availR, hsbR, vpbInsets, colHeadR);
/*
* If we added the horizontal scrollbar then we've implicitly
* reduced the vertical space available to the viewport. As a
* consequence we may have to add the vertical scrollbar, if that
* hasn't been done so already. Of course we don't bother with any
* of this if the vsbPolicy is NEVER.
*/
if ((vsb != null) && !vsbNeeded && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
extentSize = viewport.toViewCoordinates(availR.getSize());
vsbNeeded = viewPrefSize.height > extentSize.height;
if (vsbNeeded) {
adjustForVSB(true, availR, vsbR, vpbInsets, leftToRight);
}
}
}
if (viewport != null) {
viewport.setBounds(availR);
if (sv != null) {
extentSize = viewport.toViewCoordinates(availR.getSize());
boolean oldHSBNeeded = hsbNeeded;
boolean oldVSBNeeded = vsbNeeded;
viewTracksViewportWidth = sv.getScrollableTracksViewportWidth();
viewTracksViewportHeight = sv.getScrollableTracksViewportHeight();
if (vsb != null && vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED) {
boolean newVSBNeeded = !viewTracksViewportHeight && (viewPrefSize.height > extentSize.height);
if (newVSBNeeded != vsbNeeded) {
vsbNeeded = newVSBNeeded;
adjustForVSB(vsbNeeded, availR, vsbR, vpbInsets, leftToRight);
extentSize = viewport.toViewCoordinates(availR.getSize());
}
}
if (hsb != null && hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED) {
boolean newHSBbNeeded = !viewTracksViewportWidth && (viewPrefSize.width > extentSize.width);
if (newHSBbNeeded != hsbNeeded) {
hsbNeeded = newHSBbNeeded;
adjustForHSB(hsbNeeded, availR, hsbR, vpbInsets, colHeadR);
if ((vsb != null) && !vsbNeeded && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
extentSize = viewport.toViewCoordinates(availR.getSize());
vsbNeeded = viewPrefSize.height > extentSize.height;
if (vsbNeeded) {
adjustForVSB(true, availR, vsbR, vpbInsets, leftToRight);
}
}
}
}
if (oldHSBNeeded != hsbNeeded || oldVSBNeeded != vsbNeeded) {
viewport.setBounds(availR);
// You could argue that we should recheck the
// Scrollable methods again until they stop changing,
// but they might never stop changing, so we stop here
// and don't do any additional checks.
}
}
}
/*
* We now have the final size of the viewport: availR. Now fixup the
* header and scrollbar widths/heights.
*/
vsbR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
hsbR.width = availR.width + vpbInsets.left + vpbInsets.right;
rowHeadR.height = availR.height + vpbInsets.top + vpbInsets.bottom;
rowHeadR.y = availR.y - vpbInsets.top;
colHeadR.width = availR.width + vpbInsets.left + vpbInsets.right;
colHeadR.x = availR.x - vpbInsets.left;
colHeadR.y = availR.height + vpbInsets.bottom;
if (rowHead != null) {
rowHead.setBounds(rowHeadR);
}
if (colHead != null) {
colHead.setBounds(colHeadR);
}
if (vsb != null) {
if (vsbNeeded) {
vsb.setVisible(true);
vsb.setBounds(vsbR);
} else {
vsb.setVisible(false);
}
}
if (hsb != null) {
if (hsbNeeded) {
hsb.setVisible(true);
hsb.setBounds(hsbR);
} else {
hsb.setVisible(false);
}
}
if (lowerLeft != null) {
lowerLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x, hsbR.y, leftToRight ? rowHeadR.width : vsbR.width, hsbR.height);
}
if (lowerRight != null) {
lowerRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x, hsbR.y, leftToRight ? vsbR.width : rowHeadR.width, hsbR.height);
}
if (upperLeft != null) {
upperLeft.setBounds(leftToRight ? rowHeadR.x : vsbR.x, colHeadR.y, leftToRight ? rowHeadR.width : vsbR.width, colHeadR.height);
}
if (upperRight != null) {
upperRight.setBounds(leftToRight ? vsbR.x : rowHeadR.x, colHeadR.y, leftToRight ? vsbR.width : rowHeadR.width, colHeadR.height);
}
}
use of javax.swing.border.Border 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