Example usage for java.awt.event KeyListener KeyListener

List of usage examples for java.awt.event KeyListener KeyListener

Introduction

In this page you can find the example usage for java.awt.event KeyListener KeyListener.

Prototype

KeyListener

Source Link

Usage

From source file:com.emental.mindraider.ui.dialogs.NewRdfModelJDialog.java

/**
 * Constructor./*  w w  w .  j  a va2s .  c  o  m*/
 */
public NewRdfModelJDialog() {

    super(Messages.getString("NewRdfModelJDialog.title"));

    JPanel framePanel = new JPanel();
    framePanel.setLayout(new GridLayout(3, 1));

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JLabel(Messages.getString("NewRdfModelJDialog.subject")));

    subjectNs = new JTextField(30);
    subjectNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS);
    p.add(subjectNs);
    p.add(new JLabel("#"));

    subjectLocalName = new JTextField(15);
    p.add(subjectLocalName);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    final JCheckBox literalCheckBox = new JCheckBox("literal", false);
    p.add(literalCheckBox);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton addButton = new JButton(Messages.getString("NewRdfModelJDialog.create"));
    p.add(addButton);
    addButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            createModel(literalCheckBox);
        }
    });

    JButton cancelButton = new JButton(Messages.getString("NewRdfModelJDialog.cancel"));
    p.add(cancelButton);
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            NewRdfModelJDialog.this.dispose();
        }
    });
    framePanel.add(p);

    subjectLocalName.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                createModel(literalCheckBox);
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);

    addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent e) {
            subjectLocalName.requestFocusInWindow();
        }
    });
}

From source file:com.emental.mindraider.ui.dialogs.OpenConceptByTagJDialog.java

public OpenConceptByTagJDialog(String dialogTitle, String selectionLabel, String buttonLabel,
        boolean showCancel) {
    super(dialogTitle);

    JPanel framePanel = new JPanel();
    framePanel.setBorder(new EmptyBorder(5, 10, 0, 10));
    framePanel.setLayout(new BorderLayout());

    // NORTH panel
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BorderLayout());
    northPanel.add(new JLabel(selectionLabel), BorderLayout.NORTH);

    final JTextField tagLabel = new JTextField(TEXTFIELD_WIDTH);

    // data// w w w.j  av a2  s  . c  o  m
    tags = MindRaider.tagCustodian.getAllTags();
    ;
    if (tags == null) {
        tagLabel.setEnabled(false);
    }
    tagLabel.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                logger.debug("Openning selected tag...");
                openTagSearchDialog();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
            getListModel().clear();
            shownTags.clear();
            if (tagLabel.getText().length() > 0) {
                for (TagEntry tag : tags) {
                    if (tag.getTagLabel().toLowerCase().startsWith(tagLabel.getText().toLowerCase())) {
                        getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                        shownTags.add(tag);
                    }
                }
            } else {
                // show all tags
                for (TagEntry tag : tags) {
                    getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                    shownTags.add(tag);
                }
            }
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    northPanel.add(tagLabel, BorderLayout.SOUTH);
    framePanel.add(northPanel, BorderLayout.NORTH);

    // CENTER panel
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BorderLayout());
    centerPanel.add(new JLabel(Messages.getString("OpenConceptByTagJDialog.matchingTags")), BorderLayout.NORTH);

    defaultListModel = new DefaultListModel();
    list = new JList(defaultListModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    // list.addListSelectionListener(this);
    list.setVisibleRowCount(15);
    JScrollPane listScrollPane = new JScrollPane(list);
    centerPanel.add(listScrollPane, BorderLayout.SOUTH);
    framePanel.add(centerPanel, BorderLayout.CENTER);

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton openButton = new JButton(buttonLabel);
    southPanel.add(openButton);
    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            openTagSearchDialog();
        }
    });

    if (showCancel) {
        JButton cancelButton = new JButton(Messages.getString("OpenNotebookJDialog.cancel"));
        southPanel.add(cancelButton);
        cancelButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                OpenConceptByTagJDialog.this.dispose();
            }
        });
    }

    framePanel.add(southPanel, BorderLayout.SOUTH);

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:com.floreantpos.ui.dialog.PasswordEntryDialog.java

private JPanel createInputPanel() {
    JPanel inputPanel = new JPanel(new BorderLayout(5, 5));

    tfPassword = new JPasswordField();
    tfPassword.setFont(tfPassword.getFont().deriveFont(Font.BOLD, PosUIManager.getNumberFieldFontSize()));
    tfPassword.setFocusable(true);/*from ww w  .  j a  v  a 2s  .c  o  m*/
    tfPassword.requestFocus();
    tfPassword.setBackground(Color.WHITE);
    tfPassword.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {

        }

        @Override
        public void keyReleased(KeyEvent e) {
            String secretKey = getPasswordAsString();
            if (secretKey != null && secretKey.length() == TerminalConfig.getDefaultPassLen()) {
                statusLabel.setText(""); //$NON-NLS-1$
                if (checkLogin(secretKey)) {
                    setCanceled(false);
                    dispose();
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }
    });
    inputPanel.add(tfPassword, BorderLayout.NORTH);

    statusLabel = new JLabel();
    statusLabel.setHorizontalAlignment(JLabel.CENTER);
    inputPanel.add(statusLabel);

    return inputPanel;
}

From source file:org.nuclos.client.layout.wysiwyg.editor.ui.panels.WYSIWYGMetaInformationPicker.java

/**
 * //from w  ww .j  a va2s  . c  om
 * @param values
 * @param parent
 */
private WYSIWYGMetaInformationPicker(Window owner, List<String> values, TableLayoutPanel parent) {
    super(owner);

    this.setIconImage(NuclosIcons.getInstance().getScaledDialogIcon(48).getImage());

    Container contentPane = this.getContentPane();
    contentPane.setLayout(new TableLayout(layoutDefinition));

    originalValues = values;

    filter = new JTextField();

    /** the keybinding*/
    filter.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            /** up and down cursor for selecting the next or previous entry */
            if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
                int selectedItem = itemList.getSelectedIndex();
                if (e.getKeyCode() == KeyEvent.VK_UP)
                    selectedItem--;
                else if (e.getKeyCode() == KeyEvent.VK_DOWN)
                    selectedItem++;

                if (selectedItem < 0) {
                    selectedItem = listModel.getSize() - 1;
                } else if (selectedItem == listModel.getSize()) {
                    selectedItem = 0;
                }

                itemList.setSelectedIndex(selectedItem);
                itemList.ensureIndexIsVisible(selectedItem);
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                /** enter for saving, esc for cancel */
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                    selectedEntity = null;
                dispose();

            } else {
                /** every other key is used for filtering the entries */
                filterItems(WYSIWYGMetaInformationPicker.this.filter.getText());
            }
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

    });
    /** request focus in the filter window */
    filter.requestFocusInWindow();

    this.add(filter, new TableLayoutConstraints(1, 1, 3, 1));
    itemList = new JList(listModel);
    itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    itemList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (itemList.getSelectedValue() != null)
                selectedEntity = (String) itemList.getSelectedValue();
        }

    });
    freeExpr = new JCheckBox(SpringLocaleDelegate.getInstance()
            .getMessageFromResource("wysiwg.metainformation.picker.freeexpr"));
    this.add(freeExpr, new TableLayoutConstraints(1, 2, 3, 2));
    freeExpr.setVisible(true);

    // double click on item to select
    itemList.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                performSaveAction();
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

    });

    filterItems(null);

    JScrollPane scrollpane = new JScrollPane(itemList);

    this.add(scrollpane, new TableLayoutConstraints(1, 4, 3, 4));

    JButton apply = new JButton(BUTTON_LABELS.LABEL_APPLY);
    apply.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            performSaveAction();
        }

    });
    this.add(apply, new TableLayoutConstraints(1, 6));

    JButton cancel = new JButton(BUTTON_LABELS.LABEL_CANCEL);
    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            performCancelAction();
        }

    });

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            performCancelAction();
        }
    });

    this.add(cancel, new TableLayoutConstraints(3, 6));

    this.setBounds(this.getBounds().x, this.getBounds().y, 300, 400);
    this.setTitle(TABLELAYOUT_PANEL.SELECT_FIELD_FOR_METAINFORMATION);
    this.setModal(true);
}

From source file:com.nvinayshetty.DTOnator.Ui.InputWindow.java

private void initListeners() {
    inputFeedText.addMouseListener(new ContextMenuMouseListener());
    inputFeedText.addKeyListener(new KeyListener() {
        @Override/*from   w  ww.ja v  a  2  s. co m*/
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                onOK();
                break;
            case KeyEvent.VK_ESCAPE:
                onCancel();
                break;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
    makeFieldsPrivate.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (makeFieldsPrivate.isSelected()) {
                setEncapsulationOptionsVisible(true);
                SetEncapsulationOptionsSelected(true);
            } else {
                setEncapsulationOptionsVisible(false);
            }
        }
    });
}

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

public MirthTreeTable(String prefix, Set<String> defaultVisibleColumns) {
    customHiddenColumnMap = new HashMap<String, Set<String>>();

    this.prefix = prefix;
    this.defaultVisibleColumns = defaultVisibleColumns;

    columnOrderMap = new HashMap<String, Integer>();
    sortOrderColumn = -1;//from w ww  .  j ava  2 s.c o m
    sortOrder = null;

    if (StringUtils.isNotEmpty(prefix)) {
        try {
            userPreferences = Preferences.userNodeForPackage(Mirth.class);
            String columns = userPreferences.get(prefix + "ColumnOrderMap", "");

            if (StringUtils.isNotEmpty(columns)) {
                columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns,
                        Map.class);
            }
        } catch (Exception e) {
        }

        try {
            String order = userPreferences.get(prefix + "SortOrder", "");

            if (StringUtils.isNotEmpty(order)) {
                sortOrder = ObjectXMLSerializer.getInstance().deserialize(order, SortOrder.class);
                sortOrderColumn = userPreferences.getInt(prefix + "SortOrderColumn", -1);
            }
        } catch (Exception e) {
        }
    }

    addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            boolean isAccelerated = (((e.getModifiers()
                    & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0)
                    || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0));
            if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) {
                PlatformUI.MIRTH_FRAME.doContextSensitiveSave();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }
    });

    /*
     * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping
     * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can
     * override it.
     */
    putClientProperty("terminateEditOnFocusLost", Boolean.FALSE);

    JTableHeader header = getTableHeader();
    header.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            saveColumnOrder();
        }
    });
    header.setDefaultRenderer(new SortableHeaderCellRenderer(header.getDefaultRenderer()));

    final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon());

    columnControlButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu columnMenu = getColumnMenu();
            Dimension buttonSize = columnControlButton.getSize();
            int xPos = columnControlButton.getComponentOrientation().isLeftToRight()
                    ? buttonSize.width - columnMenu.getPreferredSize().width
                    : 0;
            columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight());
        }

    });

    setColumnControl(columnControlButton);
}

From source file:com.rapidminer.gui.new_plotter.gui.GlobalConfigurationPanel.java

private void createComponents() {

    // create panel for global configuration

    {/*from  w  w w. j  a va  2  s  . c o  m*/
        // add title label
        JLabel titleLabel = new ResourceLabel("plotter.configuration_dialog.chart_title");

        String title = getPlotConfiguration().getTitleText();
        if (title == null) {
            title = "";
        }

        titleTextField = new JTextField(title);
        titleLabel.setLabelFor(titleTextField);
        titleTextField.addKeyListener(new KeyListener() {

            @Override
            public void keyTyped(KeyEvent e) {
                return;
            }

            @Override
            public void keyReleased(KeyEvent e) {
                String newTitle = titleTextField.getText();
                String titleText = getCurrentPlotInstance().getMasterPlotConfiguration().getTitleText();
                if (titleText != null) {
                    if (!titleText.equals(newTitle) || titleText == null && newTitle.length() > 0) {
                        if (newTitle.length() > 0) {
                            getPlotConfiguration().setTitleText(newTitle);
                        } else {
                            getPlotConfiguration().setTitleText(null);
                        }
                    }
                } else {
                    if (newTitle.length() > 0) {
                        getPlotConfiguration().setTitleText(newTitle);
                    } else {
                        getPlotConfiguration().setTitleText(null);
                    }
                }

                if (newTitle.equals("Iris") && SwingTools.isControlOrMetaDown(e)
                        && e.getKeyCode() == KeyEvent.VK_D) {
                    startAnimation();
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {
                return;
            }
        });
        titleTextField.setPreferredSize(new Dimension(115, 23));

        titleConfigButton = new JToggleButton(new PopupAction(true, "plotter.configuration_dialog.open_popup",
                chartTitleConfigurationContainer, PopupPosition.HORIZONTAL));

        addThreeComponentRow(this, titleLabel, titleTextField, titleConfigButton);
    }

    // add orientation check box
    {
        JLabel plotOrientationLabel = new ResourceLabel(
                "plotter.configuration_dialog.global_config_panel.plot_orientation");

        PlotOrientation[] orientations = { PlotOrientation.HORIZONTAL, PlotOrientation.VERTICAL };
        plotOrientationComboBox = new JComboBox(orientations);
        plotOrientationLabel.setLabelFor(plotOrientationComboBox);
        plotOrientationComboBox.setRenderer(new EnumComboBoxCellRenderer("plotter"));
        plotOrientationComboBox.setSelectedIndex(0);
        plotOrientationComboBox.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                return;

            }

            @Override
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                getPlotConfiguration()
                        .setOrientation((PlotOrientation) plotOrientationComboBox.getSelectedItem());
            }

            @Override
            public void popupMenuCanceled(PopupMenuEvent e) {
                return;
            }
        });

        addTwoComponentRow(this, plotOrientationLabel, plotOrientationComboBox);
    }

    // add legend popup button
    {
        JLabel legendStyleConfigureLabel = new ResourceLabel(
                "plotter.configuration_dialog.global_config_panel.legend_style");

        JToggleButton legendStyleConfigButton = new JToggleButton(
                new PopupAction(true, "plotter.configuration_dialog.open_popup", legendConfigContainer,
                        PopupAction.PopupPosition.HORIZONTAL));
        legendStyleConfigureLabel.setLabelFor(legendStyleConfigButton);

        addTwoComponentRow(this, legendStyleConfigureLabel, legendStyleConfigButton);

    }

    // add legend popup button
    {
        JLabel axisStyleConfigureLabel = new ResourceLabel(
                "plotter.configuration_dialog.global_config_panel.axis_style");

        JToggleButton axisStyleConfigureButton = new JToggleButton(
                new PopupAction(true, "plotter.configuration_dialog.open_popup", axisConfigurationContainer,
                        PopupAction.PopupPosition.HORIZONTAL));
        axisStyleConfigureLabel.setLabelFor(axisStyleConfigureButton);

        addTwoComponentRow(this, axisStyleConfigureLabel, axisStyleConfigureButton);
    }

    // add color scheme dialog button
    {
        JLabel colorConfigureLabel = new ResourceLabel(
                "plotter.configuration_dialog.global_config_panel.color_scheme");

        colorsSchemesComboBoxModel = new DefaultComboBoxModel();
        colorSchemesComboBox = new JComboBox(colorsSchemesComboBoxModel);
        colorConfigureLabel.setLabelFor(colorSchemesComboBox);
        colorSchemesComboBox.setRenderer(new ColorSchemeComboBoxRenderer());
        colorSchemesComboBox.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                return;

            }

            @Override
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                ColorScheme colorScheme = (ColorScheme) colorSchemesComboBox.getSelectedItem();
                if (colorScheme != null) {
                    getPlotConfiguration().setActiveColorScheme(colorScheme.getName());
                }
            }

            @Override
            public void popupMenuCanceled(PopupMenuEvent e) {
                return;
            }
        });

        JButton colorConfigButton = new JButton(
                new ResourceAction(true, "plotter.configuration_dialog.open_color_scheme_dialog") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        createColorSchemeDialog();
                    }
                });

        addThreeComponentRow(this, colorConfigureLabel, colorSchemesComboBox, colorConfigButton);

    }

    // add plot background color
    {
        plotBackGroundColorLabel = new ResourceLabel(
                "plotter.configuration_dialog.global_config_panel.select_plot_background_color");

        plotBackgroundColorChooserButton = new JButton(
                new ResourceAction(true, "plotter.configuration_dialog.select_plot_color") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        createPlotBackgroundColorDialog();

                    }
                });
        plotBackGroundColorLabel.setLabelFor(plotBackgroundColorChooserButton);

        addTwoComponentRow(this, plotBackGroundColorLabel, plotBackgroundColorChooserButton);

    }

    // add chart background color
    {
        frameBackGroundColorLabel = new ResourceLabel(
                "plotter.configuration_dialog.global_config_panel.select_frame_background_color");

        frameBackgroundColorChooserButton = new JButton(
                new ResourceAction(true, "plotter.configuration_dialog.select_frame_color") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        createFrameBackgroundColorDialog();
                    }
                });
        frameBackGroundColorLabel.setLabelFor(frameBackgroundColorChooserButton);

        addTwoComponentRow(this, frameBackGroundColorLabel, frameBackgroundColorChooserButton);

        // GridBagConstraints itemConstraint = new GridBagConstraints();
        // itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
        // itemConstraint.weightx = 1.0;
        // this.add(frameBackgroundColorChooserButton, itemConstraint);

    }

    // add spacer panel
    {
        JPanel spacerPanel = new JPanel();
        GridBagConstraints itemConstraint = new GridBagConstraints();
        itemConstraint.fill = GridBagConstraints.BOTH;
        itemConstraint.weightx = 1;
        itemConstraint.weighty = 1;
        itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
        this.add(spacerPanel, itemConstraint);
    }

}

From source file:au.org.ala.delta.intkey.ui.OpenDataSetDialog.java

public OpenDataSetDialog(Frame owner, List<Pair<String, String>> datasetIndexData, File startBrowseDirectory) {
    super(owner, true);
    setPreferredSize(new Dimension(450, 300));

    ActionMap actionMap = Application.getInstance().getContext().getActionMap(this);
    ResourceMap resourceMap = Application.getInstance().getContext().getResourceMap(OpenDataSetDialog.class);
    resourceMap.injectFields(this);

    setTitle(title);//from   www.ja  v  a2s.  c  om

    _selectedDatasetPath = null;

    _pnlList = new JPanel();
    _pnlList.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(_pnlList, BorderLayout.CENTER);
    _pnlList.setLayout(new BorderLayout(0, 0));

    _lblSelectByTitle = new JLabel(selectByTitleCaption);
    _pnlList.add(_lblSelectByTitle, BorderLayout.NORTH);

    _sclPnList = new JScrollPane();
    _pnlList.add(_sclPnList, BorderLayout.CENTER);

    _listDatasetIndex = new JList();
    _sclPnList.setViewportView(_listDatasetIndex);

    _pnlBottom = new JPanel();
    _pnlBottom.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(_pnlBottom, BorderLayout.SOUTH);
    _pnlBottom.setLayout(new BorderLayout(0, 0));

    _lblSelectByFileName = new JLabel(selectByFileCaption);
    _pnlBottom.add(_lblSelectByFileName, BorderLayout.NORTH);

    _pnlButtons = new JPanel();
    _pnlButtons.setBorder(new EmptyBorder(10, 0, 0, 0));
    _pnlBottom.add(_pnlButtons, BorderLayout.SOUTH);

    _btnOK = new JButton();
    _btnOK.setAction(actionMap.get("OpenDataSetDialog_OK"));
    _pnlButtons.add(_btnOK);

    _btnCancel = new JButton();
    _btnCancel.setAction(actionMap.get("OpenDataSetDialog_Cancel"));
    _pnlButtons.add(_btnCancel);

    _btnHelp = new JButton();
    _btnHelp.setAction(actionMap.get("OpenDataSetDialog_Help"));
    _pnlButtons.add(_btnHelp);

    _pnlFile = new JPanel();
    _pnlBottom.add(_pnlFile, BorderLayout.CENTER);
    _pnlFile.setLayout(new BorderLayout(0, 0));

    _txtFldFileName = new JTextField();
    _pnlFile.add(_txtFldFileName, BorderLayout.CENTER);
    _txtFldFileName.setColumns(10);
    _txtFldFileName.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            // Clear any selected item in the list of the text field is
            // modified.
            _listDatasetIndex.clearSelection();
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // do nothing
        }

        @Override
        public void keyPressed(KeyEvent e) {
            // do nothing

        }
    });

    _btnBrowse = new JButton();
    _btnBrowse.setAction(actionMap.get("OpenDataSetDialog_Browse"));
    _pnlFile.add(_btnBrowse, BorderLayout.EAST);

    DefaultListModel model = new DefaultListModel();

    for (Pair<String, String> datasetInfo : datasetIndexData) {
        model.addElement(datasetInfo);
    }

    _listDatasetIndex.setModel(model);
    _listDatasetIndex.setCellRenderer(new DatasetIndexCellRenderer());

    _listDatasetIndex.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // Clear any filename in the text field if an item is selected
            // from the text box.
            _txtFldFileName.setText(null);
        }
    });

    _startBrowseDirectory = startBrowseDirectory;
}

From source file:ca.sqlpower.swingui.object.VariablesPanel.java

/**
 * Default constructor for the variables panel.
 * @param variableHelper A helper that will be used in order to
 * resolve discover and resolve variables.
 * @param action An implementation of {@link VariableInserter} that 
 * gets called once the variable has been created. This action will be executed
 * on the Swing Event Dispatch Thread.//from ww w  .  jav  a2s. c  om
 * @param varDefinition The default variable definition string.
 */
public VariablesPanel(SPVariableHelper variableHelper, VariableInserter action, String varDefinition) {
    this.variableHelper = variableHelper;
    this.action = action;

    this.generalLabel = new JLabel("General");
    this.generalLabel.setFont(this.generalLabel.getFont().deriveFont(Font.BOLD));

    this.pickerLabel = new JLabel("Pick a variable");
    this.varNameText = new JTextField();
    this.varNameText.setEditable(false);
    this.varNameText.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseClicked(MouseEvent e) {
            ShowPickerAction act = new ShowPickerAction();
            act.actionPerformed(null);
        }
    });
    this.varPicker = new JButton(new ShowPickerAction());

    this.optionsLabel = new JLabel("Options");
    this.optionsLabel.setFont(this.optionsLabel.getFont().deriveFont(Font.BOLD));

    this.varDefaultLabel = new JLabel("Default value");
    this.varDefaultText = new JTextField();
    this.varDefaultText.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    currentDefValue = varDefaultText.getText();
                    updateGUI();
                }
            });
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });

    this.varEditLabel = new JLabel("Customization");
    this.varEditText = new JTextField();
    this.varEditText.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    int carPos = varEditText.getCaretPosition();
                    String text = varEditText.getText().replace("$", "").replace("{", "").replace("}", "");
                    currentPickedVariable = SPVariableHelper.stripDefaultValue(text);
                    if (currentPickedVariable == null) {
                        currentPickedVariable = "";
                    }
                    currentDefValue = SPVariableHelper.getDefaultValue(text);
                    if (currentDefValue == null) {
                        currentDefValue = "";
                    }
                    if (SPVariableHelper.getNamespace(text) == null) {
                        namespaceBox.setSelected(false);
                    } else {
                        namespaceBox.setSelected(true);
                    }
                    updateGUI();
                    try {
                        varEditText.setCaretPosition(carPos);
                    } catch (IllegalArgumentException e) {
                        varEditText.setCaretPosition(carPos - 1);
                    }
                }
            });
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });

    this.namespaceLabel = new JLabel("Constrain to namespace");
    this.namespaceBox = new JCheckBox("");
    if (SPVariableHelper.getNamespace(varDefinition) != null || "".equals(varDefinition)) {
        this.namespaceBox.setSelected(true);
    } else {
        this.namespaceBox.setSelected(false);
    }
    this.namespaceBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateGUI();
        }
    });

    this.previewLabel = new JLabel("Preview");
    this.previewLabel.setFont(this.previewLabel.getFont().deriveFont(Font.BOLD));
    this.varPreviewLabel1 = new JLabel("Current value is");
    this.varPreviewLabel1.setForeground(Color.GRAY);
    this.varPreviewLabel2 = new JLabel();
    this.varPreviewLabel2.setForeground(Color.GRAY);

    this.panel = new JPanel(new MigLayout());

    this.panel.add(this.generalLabel, "growx, span, wrap");
    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.pickerLabel);
    this.panel.add(this.varNameText, "growx, wmin 275, wmax 275, gapright 0");
    this.panel.add(this.varPicker, "wmax 20, hmax 20, wrap, gapleft 0");

    this.panel.add(this.optionsLabel, "growx, span, wrap");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.varDefaultLabel);
    this.panel.add(this.varDefaultText, "span, wrap, wmin 300, wmax 300");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(namespaceLabel);
    this.panel.add(namespaceBox, "span, wrap");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.varEditLabel);
    this.panel.add(this.varEditText, "span, wmin 300, wmax 300, wrap");

    this.panel.add(this.previewLabel, "growx, span, wrap");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.varPreviewLabel1);
    this.panel.add(this.varPreviewLabel2, "span, growx");

    this.currentPickedVariable = varDefinition;
    updateGUI();
}

From source file:net.lldp.checksims.ui.results.ScrollViewer.java

/**
 * Create a scroll viewer from a sortable Matrix Viewer
 * @param results the sortableMatrix to view
 * @param toRevalidate frame to revalidate sometimes
 *///from   ww  w.  j a  v  a  2 s.  com
public ScrollViewer(SimilarityMatrix exportMatrix, SortableMatrixViewer results, JFrame toRevalidate) {
    resultsView = new JScrollPane(results);
    setBackground(Color.black);
    resultsView.addComponentListener(new ComponentListener() {

        @Override
        public void componentHidden(ComponentEvent arg0) {
        }

        @Override
        public void componentMoved(ComponentEvent arg0) {
        }

        @Override
        public void componentResized(ComponentEvent ce) {
            Dimension size = ce.getComponent().getSize();
            results.padToSize(size);
        }

        @Override
        public void componentShown(ComponentEvent arg0) {
        }
    });

    resultsView.getViewport().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Rectangle r = resultsView.getViewport().getViewRect();
            results.setViewAt(r);
        }
    });

    resultsView.setBackground(Color.black);
    sidebar = new JPanel();

    setPreferredSize(new Dimension(900, 631));
    setMinimumSize(new Dimension(900, 631));
    sidebar.setPreferredSize(new Dimension(200, 631));
    sidebar.setMaximumSize(new Dimension(200, 3000));
    resultsView.setMinimumSize(new Dimension(700, 631));
    resultsView.setPreferredSize(new Dimension(700, 631));

    sidebar.setBackground(Color.GRAY);

    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    this.add(sidebar);
    this.add(resultsView);

    resultsView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    resultsView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    resultsView.getVerticalScrollBar().setUnitIncrement(16);
    resultsView.getHorizontalScrollBar().setUnitIncrement(16);

    Integer[] presetThresholds = { 80, 60, 40, 20, 0 };
    JComboBox<Integer> threshHold = new JComboBox<Integer>(presetThresholds);
    threshHold.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Integer item = (Integer) event.getItem();
                results.updateThreshold(item / 100.0);
                toRevalidate.revalidate();
                toRevalidate.repaint();
            }
        }
    });
    threshHold.setSelectedIndex(0);
    results.updateThreshold((Integer) threshHold.getSelectedItem() / 100.0);

    JTextField student1 = new JTextField(15);
    JTextField student2 = new JTextField(15);

    KeyListener search = new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            results.highlightMatching(student1.getText(), student2.getText());
            toRevalidate.revalidate();
            toRevalidate.repaint();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }
    };

    student1.addKeyListener(search);
    student2.addKeyListener(search);

    Collection<MatrixPrinter> printerNameSet = MatrixPrinterRegistry.getInstance()
            .getSupportedImplementations();
    JComboBox<MatrixPrinter> exportAs = new JComboBox<>(new Vector<>(printerNameSet));
    JButton exportAsSave = new JButton("Save");

    JFileChooser fc = new JFileChooser();

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setCurrentDirectory(new java.io.File("."));
    fc.setDialogTitle("Save results");

    exportAsSave.addActionListener(ae -> {
        MatrixPrinter method = (MatrixPrinter) exportAs.getSelectedItem();

        int err = fc.showDialog(toRevalidate, "Save");
        if (err == JFileChooser.APPROVE_OPTION) {
            try {
                FileUtils.writeStringToFile(fc.getSelectedFile(), method.printMatrix(exportMatrix));
            } catch (InternalAlgorithmError | IOException e1) {
                // TODO log / show error
            }
        }
    });

    JPanel thresholdLabel = new JPanel();
    JPanel studentSearchLabel = new JPanel();
    JPanel fileOutputLabel = new JPanel();

    thresholdLabel.setBorder(BorderFactory.createTitledBorder("Matching Threshold"));
    studentSearchLabel.setBorder(BorderFactory.createTitledBorder("Student Search"));
    fileOutputLabel.setBorder(BorderFactory.createTitledBorder("Save Results"));

    thresholdLabel.add(threshHold);
    studentSearchLabel.add(student1);
    studentSearchLabel.add(student2);
    fileOutputLabel.add(exportAs);
    fileOutputLabel.add(exportAsSave);

    studentSearchLabel.setPreferredSize(new Dimension(200, 100));
    studentSearchLabel.setMinimumSize(new Dimension(200, 100));
    thresholdLabel.setPreferredSize(new Dimension(200, 100));
    thresholdLabel.setMinimumSize(new Dimension(200, 100));
    fileOutputLabel.setPreferredSize(new Dimension(200, 100));
    fileOutputLabel.setMinimumSize(new Dimension(200, 100));

    sidebar.setMaximumSize(new Dimension(200, 4000));

    sidebar.add(thresholdLabel);
    sidebar.add(studentSearchLabel);
    sidebar.add(fileOutputLabel);
}