Search in sources :

Example 71 with GridLayout

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);
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) GridLayout(java.awt.GridLayout) DataColumnSpec(org.knime.core.data.DataColumnSpec) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) Icon(javax.swing.Icon) Border(javax.swing.border.Border) HashSet(java.util.HashSet)

Example 72 with GridLayout

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;
}
Also used : Enumeration(java.util.Enumeration) Cursor(java.awt.Cursor) Point(java.awt.Point) ItemListener(java.awt.event.ItemListener) SearchOptions(org.knime.core.node.tableview.FindPosition.SearchOptions) TableCellRenderer(javax.swing.table.TableCellRenderer) StringUtils(org.apache.commons.lang3.StringUtils) GraphicsEnvironment(java.awt.GraphicsEnvironment) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) MouseAdapter(java.awt.event.MouseAdapter) ChangeListener(javax.swing.event.ChangeListener) BorderLayout(java.awt.BorderLayout) KeyStroke(javax.swing.KeyStroke) ScrollPaneConstants(javax.swing.ScrollPaneConstants) ChangeEvent(javax.swing.event.ChangeEvent) ItemEvent(java.awt.event.ItemEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) Font(java.awt.Font) Collection(java.util.Collection) JMenu(javax.swing.JMenu) MouseInputAdapter(javax.swing.event.MouseInputAdapter) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) Objects(java.util.Objects) Dimension(java.awt.Dimension) PropertyChangeListener(java.beans.PropertyChangeListener) AbstractAction(javax.swing.AbstractAction) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) JTable(javax.swing.JTable) CheckUtils(org.knime.core.node.util.CheckUtils) JPanel(javax.swing.JPanel) TableContentFilter(org.knime.core.node.tableview.TableContentModel.TableContentFilter) Toolkit(java.awt.Toolkit) ListSelectionModel(javax.swing.ListSelectionModel) Rectangle(java.awt.Rectangle) ActionListener(java.awt.event.ActionListener) TableColumnModel(javax.swing.table.TableColumnModel) GraphicsDevice(java.awt.GraphicsDevice) Action(javax.swing.Action) ArrayList(java.util.ArrayList) GridLayout(java.awt.GridLayout) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) AbstractButton(javax.swing.AbstractButton) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) DataTable(org.knime.core.data.DataTable) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JViewport(javax.swing.JViewport) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) SearchOptions(org.knime.core.node.tableview.FindPosition.SearchOptions) JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) KeyStroke(javax.swing.KeyStroke) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 73 with GridLayout

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);
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) Color(java.awt.Color) Map(java.util.Map)

Example 74 with GridLayout

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));
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JRadioButton(javax.swing.JRadioButton) FlowLayout(java.awt.FlowLayout) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) JSpinner(javax.swing.JSpinner) Dimension(java.awt.Dimension)

Example 75 with GridLayout

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);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) GridLayout(java.awt.GridLayout) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) Border(javax.swing.border.Border) HashSet(java.util.HashSet)

Aggregations

GridLayout (java.awt.GridLayout)189 JPanel (javax.swing.JPanel)149 JLabel (javax.swing.JLabel)79 BorderLayout (java.awt.BorderLayout)67 Dimension (java.awt.Dimension)51 JButton (javax.swing.JButton)41 ActionEvent (java.awt.event.ActionEvent)36 JScrollPane (javax.swing.JScrollPane)34 ActionListener (java.awt.event.ActionListener)32 Insets (java.awt.Insets)28 JCheckBox (javax.swing.JCheckBox)28 JTextField (javax.swing.JTextField)28 GridBagConstraints (java.awt.GridBagConstraints)24 GridBagLayout (java.awt.GridBagLayout)23 ButtonGroup (javax.swing.ButtonGroup)22 FlowLayout (java.awt.FlowLayout)21 BoxLayout (javax.swing.BoxLayout)21 TitledBorder (javax.swing.border.TitledBorder)19 PlotCanvas (smile.plot.PlotCanvas)16 EmptyBorder (javax.swing.border.EmptyBorder)15