Search in sources :

Example 11 with KeyEvent

use of java.awt.event.KeyEvent in project gitblit by gitblit.

the class UsersPanel method initialize.

private void initialize() {
    JButton refreshUsers = new JButton(Translation.get("gb.refresh"));
    refreshUsers.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshUsers();
        }
    });
    JButton createUser = new JButton(Translation.get("gb.create"));
    createUser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            createUser();
        }
    });
    final JButton editUser = new JButton(Translation.get("gb.edit"));
    editUser.setEnabled(false);
    editUser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editUser(getSelectedUsers().get(0));
        }
    });
    final JButton delUser = new JButton(Translation.get("gb.delete"));
    delUser.setEnabled(false);
    delUser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteUsers(getSelectedUsers());
        }
    });
    NameRenderer nameRenderer = new NameRenderer();
    tableModel = new UsersTableModel();
    defaultSorter = new TableRowSorter<UsersTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    int w = 130;
    name = table.getColumnName(UsersTableModel.Columns.Type.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    name = table.getColumnName(UsersTableModel.Columns.Teams.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    name = table.getColumnName(UsersTableModel.Columns.Repositories.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(UsersTableModel.Columns.Name.ordinal());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean selected = table.getSelectedRow() > -1;
            boolean singleSelection = table.getSelectedRows().length == 1;
            editUser.setEnabled(singleSelection && selected);
            delUser.setEnabled(selected);
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                editUser(getSelectedUsers().get(0));
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    JPanel userFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    userFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    userFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel userTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    userTablePanel.add(userFilterPanel, BorderLayout.NORTH);
    userTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    JPanel userControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    userControls.add(refreshUsers);
    userControls.add(createUser);
    userControls.add(editUser);
    userControls.add(delUser);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.users"), "user_16x16.png");
    add(header, BorderLayout.NORTH);
    add(userTablePanel, BorderLayout.CENTER);
    add(userControls, BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

Example 12 with KeyEvent

use of java.awt.event.KeyEvent in project gitblit by gitblit.

the class SettingsPanel method initialize.

private void initialize() {
    JButton refreshSettings = new JButton(Translation.get("gb.refresh"));
    refreshSettings.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshSettings();
        }
    });
    final JButton editSetting = new JButton(Translation.get("gb.edit"));
    editSetting.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int viewRow = table.getSelectedRow();
            int modelRow = table.convertRowIndexToModel(viewRow);
            String key = tableModel.keys.get(modelRow);
            SettingModel setting = tableModel.settings.get(key);
            editSetting(setting);
        }
    });
    NameRenderer nameRenderer = new NameRenderer();
    final SettingPanel settingPanel = new SettingPanel();
    tableModel = new SettingsTableModel();
    defaultSorter = new TableRowSorter<SettingsTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    table.setDefaultRenderer(SettingModel.class, new SettingCellRenderer());
    String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRows().length == 1;
            editSetting.setEnabled(singleSelection);
            if (singleSelection) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                SettingModel setting = tableModel.get(modelRow);
                settingPanel.setSetting(setting);
            } else {
                settingPanel.clear();
            }
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                SettingModel setting = tableModel.get(modelRow);
                editSetting(setting);
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterSettings(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterSettings(filterTextfield.getText());
        }
    });
    JPanel settingFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    settingFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    settingFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel settingsTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    settingsTablePanel.add(settingFilterPanel, BorderLayout.NORTH);
    settingsTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    settingsTablePanel.add(settingPanel, BorderLayout.SOUTH);
    JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    settingsControls.add(refreshSettings);
    settingsControls.add(editSetting);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.settings"), "settings_16x16.png");
    add(header, BorderLayout.NORTH);
    add(settingsTablePanel, BorderLayout.CENTER);
    add(settingsControls, BorderLayout.SOUTH);
}
Also used : SettingModel(com.gitblit.models.SettingModel) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

Example 13 with KeyEvent

use of java.awt.event.KeyEvent in project binnavi by google.

the class ConsoleCodeDocument method insertString.

/**
   * Insert a String of source code to be highlighted to the document. The string is then inserted
   * character by character if longer than 1 char.
   * 
   * @param offs the position in the document
   * @param str the String containig source code
   * @param attr the attributes to set
   */
@Override
public void insertString(final int offs, final String str, final AttributeSet attr) {
    if (offs < 0) {
        return;
    }
    if (str.length() > 1) {
        int i;
        for (i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '\n') {
                remainingTextString = str.substring(i + 1);
                remainingTextAttr = attr;
                inputKeyListener.keyPressed(new KeyEvent(new Container(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_ENTER, '\n'));
                break;
            } else {
                insertChar(offs + i, "" + str.charAt(i));
            }
        }
    } else if (str.length() == 1) {
        insertChar(offs, str);
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) Container(java.awt.Container)

Example 14 with KeyEvent

use of java.awt.event.KeyEvent in project binnavi by google.

the class AtomicTypePanel method createControls.

private void createControls() {
    setLayout(new BorderLayout());
    final JPanel contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    add(contentPanel, BorderLayout.CENTER);
    final GridBagLayout gbl_m_contentPanel = new GridBagLayout();
    gbl_m_contentPanel.columnWidths = new int[] { 0, 0, 0 };
    gbl_m_contentPanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 };
    gbl_m_contentPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gbl_m_contentPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
    contentPanel.setLayout(gbl_m_contentPanel);
    final JLabel lblNewLabel = new JLabel("Name:");
    final GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
    gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
    gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
    gbc_lblNewLabel.gridx = 0;
    gbc_lblNewLabel.gridy = 0;
    contentPanel.add(lblNewLabel, gbc_lblNewLabel);
    name = new JTextField();
    name.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(final KeyEvent e) {
            updatePreview();
        }
    });
    final GridBagConstraints gbc_m_name = new GridBagConstraints();
    gbc_m_name.insets = new Insets(0, 0, 5, 0);
    gbc_m_name.fill = GridBagConstraints.HORIZONTAL;
    gbc_m_name.gridx = 1;
    gbc_m_name.gridy = 0;
    contentPanel.add(name, gbc_m_name);
    name.setColumns(10);
    final JLabel lblSize = new JLabel("Size (bits):");
    final GridBagConstraints gbc_lblSize = new GridBagConstraints();
    gbc_lblSize.anchor = GridBagConstraints.WEST;
    gbc_lblSize.insets = new Insets(0, 0, 5, 5);
    gbc_lblSize.gridx = 0;
    gbc_lblSize.gridy = 1;
    contentPanel.add(lblSize, gbc_lblSize);
    size = new JTextField();
    final GridBagConstraints gbc_m_size = new GridBagConstraints();
    gbc_m_size.insets = new Insets(0, 0, 5, 0);
    gbc_m_size.fill = GridBagConstraints.HORIZONTAL;
    gbc_m_size.gridx = 1;
    gbc_m_size.gridy = 1;
    contentPanel.add(size, gbc_m_size);
    size.setColumns(10);
    signed = new JCheckBox("Signed");
    final GridBagConstraints gbc_m_signed = new GridBagConstraints();
    gbc_m_signed.anchor = GridBagConstraints.WEST;
    gbc_m_signed.insets = new Insets(0, 0, 5, 5);
    gbc_m_signed.gridx = 0;
    gbc_m_signed.gridy = 2;
    contentPanel.add(signed, gbc_m_signed);
    lblPreview = new JLabel("Preview:");
    final GridBagConstraints gbc_lblPreview = new GridBagConstraints();
    gbc_lblPreview.insets = new Insets(0, 0, 5, 5);
    gbc_lblPreview.gridx = 0;
    gbc_lblPreview.gridy = 3;
    contentPanel.add(lblPreview, gbc_lblPreview);
    preview = new JTextArea();
    preview.setEditable(false);
    final GridBagConstraints gbc_preview = new GridBagConstraints();
    gbc_preview.insets = new Insets(0, 0, 5, 0);
    gbc_preview.fill = GridBagConstraints.BOTH;
    gbc_preview.gridx = 1;
    gbc_preview.gridy = 3;
    contentPanel.add(preview, gbc_preview);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) KeyAdapter(java.awt.event.KeyAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) KeyEvent(java.awt.event.KeyEvent) JCheckBox(javax.swing.JCheckBox) BorderLayout(java.awt.BorderLayout) EmptyBorder(javax.swing.border.EmptyBorder)

Example 15 with KeyEvent

use of java.awt.event.KeyEvent in project jdk8u_jdk by JetBrains.

the class SpanishDiacriticsTest method init.

@Override
public void init() {
    SwingUtilities.invokeLater(() -> {
        JFrame frame = new JFrame();
        JTextField textField = new JTextField(20);
        textField.addKeyListener(new KeyAdapter() {

            @Override
            public void keyTyped(KeyEvent e) {
                LockSupport.parkNanos(1_000_000_000L);
            }
        });
        frame.add(textField);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter)

Aggregations

KeyEvent (java.awt.event.KeyEvent)135 KeyAdapter (java.awt.event.KeyAdapter)69 MouseEvent (java.awt.event.MouseEvent)31 ActionEvent (java.awt.event.ActionEvent)23 ActionListener (java.awt.event.ActionListener)19 KeyListener (java.awt.event.KeyListener)19 JPanel (javax.swing.JPanel)18 MouseAdapter (java.awt.event.MouseAdapter)17 JLabel (javax.swing.JLabel)17 JButton (javax.swing.JButton)14 JTextField (javax.swing.JTextField)14 JScrollPane (javax.swing.JScrollPane)13 BorderLayout (java.awt.BorderLayout)12 NotNull (org.jetbrains.annotations.NotNull)12 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)11 FlowLayout (java.awt.FlowLayout)10 Tree (com.intellij.ui.treeStructure.Tree)9 Project (com.intellij.openapi.project.Project)8 Dimension (java.awt.Dimension)8