Search in sources :

Example 91 with KeyEvent

use of java.awt.event.KeyEvent in project cytoscape-impl by cytoscape.

the class ImportTablePanel method initComponents.

private void initComponents() {
    attrTypeButtonGroup = new ButtonGroup();
    nodeRadioButton = new JRadioButton("Node");
    edgeRadioButton = new JRadioButton("Edge");
    networkRadioButton = new JRadioButton("Network");
    ontologyComboBox = new JComboBox<>();
    browseOntologyButton = new JButton("Browse...");
    annotationComboBox = new JComboBox<>();
    browseAnnotationButton = new JButton("Browse...");
    targetDataSourceTextField = new JTextField();
    selectAttributeFileButton = new JButton();
    mappingAttributeComboBox = new JComboBox<>();
    delimiterLabel = new JLabel("Delimiter:");
    delimiterLabel.setHorizontalAlignment(JLabel.RIGHT);
    commaCheckBox = new JCheckBox("<html><b><font size=+1 face=Monospaced>,<font></b> <font size=-2>(comma)</font><html>");
    semicolonCheckBox = new JCheckBox("<html><b><font size=+1 face=Monospaced>;<font></b> <font size=-2>(semicolon)</font><html>");
    spaceCheckBox = new JCheckBox("<html><b><font size=-1 face=Monospaced>SPACE<font></b><html>");
    tabCheckBox = new JCheckBox("<html><b><font size=-1 face=Monospaced>TAB<font></b><html>");
    otherCheckBox = new JCheckBox("Other:");
    otherDelimiterTextField = new JTextField();
    defaultInteractionTextField = new JTextField();
    attributeFileLabel = new JLabel();
    attrTypeButtonGroup.add(nodeRadioButton);
    attrTypeButtonGroup.add(edgeRadioButton);
    attrTypeButtonGroup.add(networkRadioButton);
    /*
		 * Set tooltips options.
		 */
    ToolTipManager tp = ToolTipManager.sharedInstance();
    tp.setInitialDelay(40);
    tp.setDismissDelay(50000);
    if (importType == ONTOLOGY_IMPORT) {
        /*
			 * Data Source Panel Layouts.
			 */
        nodeRadioButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        nodeRadioButton.setMargin(new Insets(0, 0, 0, 0));
        nodeRadioButton.setSelected(true);
        nodeRadioButton.addActionListener((ActionEvent evt) -> {
            attributeRadioButtonActionPerformed(evt);
        });
        edgeRadioButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        edgeRadioButton.setMargin(new Insets(0, 0, 0, 0));
        edgeRadioButton.addActionListener((ActionEvent evt) -> {
            attributeRadioButtonActionPerformed(evt);
        });
        networkRadioButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        networkRadioButton.setMargin(new Insets(0, 0, 0, 0));
        networkRadioButton.addActionListener((ActionEvent evt) -> {
            attributeRadioButtonActionPerformed(evt);
        });
    }
    if (importType == ONTOLOGY_IMPORT) {
        panelBuilder = new OntologyPanelBuilder(this, factory, serviceRegistrar);
        panelBuilder.buildPanel();
    }
    if ((importType == TABLE_IMPORT) || (importType == NETWORK_IMPORT)) {
        // titleIconLabel.setIcon(SPREADSHEET_ICON_LARGE.getIcon());
        attributeFileLabel.setText("Input File");
        selectAttributeFileButton.setText("Select File(s)");
        selectAttributeFileButton.addActionListener((ActionEvent evt) -> {
            try {
                setPreviewPanel();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(serviceRegistrar.getService(CySwingApplication.class).getJFrame(), "<html>Could not read selected file.<p>See <b>Help->Error Dialog</b> for further details.</html>", "Error", JOptionPane.ERROR_MESSAGE);
                logger.warn("Could not read selected file.", e);
            }
        });
    }
    /*
		 * Layout data for advanced panel
		 */
    if (importType == ONTOLOGY_IMPORT) {
        mappingAttributeComboBox.setEnabled(true);
        mappingAttributeComboBox.addActionListener((ActionEvent evt) -> {
            updateTypes(getPreviewPanel().getFileType());
            setKeyList();
        });
    }
    final ChangeListener delimitersChangeListener = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            otherDelimiterTextField.setEnabled(otherCheckBox.isSelected());
            try {
                if (!updating)
                    updatePreview();
            } catch (IOException e) {
                logger.error("Error on ChangeEvent of checkbox " + ((JCheckBox) evt.getSource()).getText(), e);
            }
        }
    };
    commaCheckBox.addChangeListener(delimitersChangeListener);
    semicolonCheckBox.addChangeListener(delimitersChangeListener);
    spaceCheckBox.addChangeListener(delimitersChangeListener);
    tabCheckBox.addChangeListener(delimitersChangeListener);
    otherCheckBox.addChangeListener(delimitersChangeListener);
    otherDelimiterTextField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent evt) {
        }

        @Override
        public void keyReleased(KeyEvent evt) {
            try {
                if (otherCheckBox.isSelected())
                    updatePreview();
            } catch (IOException e) {
                logger.error("Error on otherDelimiterTextField.keyReleased", e);
            }
        }

        @Override
        public void keyTyped(KeyEvent evt) {
        }
    });
    defaultInteractionTextField.setText(TypeUtil.DEFAULT_INTERACTION);
    defaultInteractionTextField.setToolTipText("<html>If <b>Default Interaction</b>" + " is selected, this value will be used for <i>Interaction Type</i><br></html>");
    globalLayout();
    if (basicPanel != null)
        basicPanel.repaint();
    this.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            getPreviewPanel().disposeEditDialog();
        }
    });
}
Also used : ToolTipManager(javax.swing.ToolTipManager) JRadioButton(javax.swing.JRadioButton) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) IOException(java.io.IOException) JTextField(javax.swing.JTextField) IOException(java.io.IOException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) JAXBException(javax.xml.bind.JAXBException) JCheckBox(javax.swing.JCheckBox) KeyEvent(java.awt.event.KeyEvent) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent) ButtonGroup(javax.swing.ButtonGroup) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) KeyListener(java.awt.event.KeyListener)

Example 92 with KeyEvent

use of java.awt.event.KeyEvent in project Spark by igniterealtime.

the class InputTextAreaDialog method getInput.

/**
 * Prompt and return input.
 *
 * @param title       the title of the dialog.
 * @param description the dialog description.
 * @param icon        the icon to use.
 * @param parent      the parent to use.
 * @return the user input.
 */
public String getInput(String title, String description, Icon icon, Component parent) {
    textArea = new JTextArea();
    textArea.setLineWrap(true);
    TitlePanel titlePanel = new TitlePanel(title, description, icon, true);
    // Construct main panel w/ layout.
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    // The user should only be able to close this dialog.
    final Object[] options = { Res.getString("ok"), Res.getString("cancel") };
    optionPane = new JOptionPane(new JScrollPane(textArea), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(optionPane, BorderLayout.CENTER);
    // Let's make sure that the dialog is modal. Cannot risk people
    // losing this dialog.
    JOptionPane p = new JOptionPane();
    dialog = p.createDialog(parent, title);
    dialog.setModal(true);
    dialog.pack();
    dialog.setSize(width, height);
    dialog.setContentPane(mainPanel);
    dialog.setLocationRelativeTo(parent);
    optionPane.addPropertyChangeListener(this);
    // Add Key Listener to Send Field
    textArea.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_TAB) {
                optionPane.requestFocus();
            } else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                dialog.dispose();
            }
        }
    });
    textArea.requestFocus();
    dialog.setVisible(true);
    return stringValue;
}
Also used : JScrollPane(javax.swing.JScrollPane) KeyEvent(java.awt.event.KeyEvent) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) KeyAdapter(java.awt.event.KeyAdapter) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel)

Example 93 with KeyEvent

use of java.awt.event.KeyEvent in project Spark by igniterealtime.

the class VCardEditor method displayProfile.

/**
 * Displays a users profile.
 *
 * @param jid
 *            the jid of the user.
 * @param vcard
 *            the users vcard.
 * @param parent
 *            the parent component, used for location handling.
 */
public void displayProfile(final String jid, VCard vcard, JComponent parent) {
    VCardViewer viewer = new VCardViewer(jid);
    final JFrame dlg = new JFrame(Res.getString("title.view.profile.for", jid));
    avatarLabel = new JLabel();
    avatarLabel.setHorizontalAlignment(JButton.RIGHT);
    avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray));
    // The user should only be able to close this dialog.
    Object[] options = { Res.getString("button.view.profile"), Res.getString("close") };
    final JOptionPane pane = new JOptionPane(viewer, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    // mainPanel.add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
    // GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5,
    // 5, 5), 0, 0));
    dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16).getImage());
    dlg.pack();
    dlg.setSize(350, 250);
    dlg.setResizable(true);
    dlg.setContentPane(pane);
    dlg.setLocationRelativeTo(parent);
    PropertyChangeListener changeListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent e) {
            if (pane.getValue() instanceof Integer) {
                pane.removePropertyChangeListener(this);
                dlg.dispose();
                return;
            }
            String value = (String) pane.getValue();
            if (Res.getString("close").equals(value)) {
                pane.removePropertyChangeListener(this);
                dlg.dispose();
            } else if (Res.getString("button.view.profile").equals(value)) {
                pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                SparkManager.getVCardManager().viewFullProfile(jid, pane);
            }
        }
    };
    pane.addPropertyChangeListener(changeListener);
    dlg.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
                dlg.dispose();
            }
        }
    });
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
}
Also used : KeyEvent(java.awt.event.KeyEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) JFrame(javax.swing.JFrame) KeyAdapter(java.awt.event.KeyAdapter) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) VCardViewer(org.jivesoftware.spark.ui.VCardViewer)

Example 94 with KeyEvent

use of java.awt.event.KeyEvent in project Spark by igniterealtime.

the class FrequentContactsPlugin method initialize.

public void initialize() {
    transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts");
    contacts = new JList(model);
    contacts.setCellRenderer(new InternalRenderer());
    window = new Window(SparkManager.getMainWindow());
    final JPanel mainPanel = new JPanel(new BorderLayout());
    final JLabel titleLabel = new JLabel(Res.getString("label.frequent.contacts"));
    titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
    titleLabel.setHorizontalAlignment(JLabel.CENTER);
    mainPanel.add(titleLabel, BorderLayout.NORTH);
    mainPanel.add(contacts, BorderLayout.CENTER);
    mainPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
    window.add(mainPanel);
    // Add Listeners
    contacts.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                contacts.setSelectedIndex(contacts.locationToIndex(e.getPoint()));
                String user = jidMap.get(contacts.getSelectedValue());
                ContactItem contact = SparkManager.getContactList().getContactItemByJID(user);
                SparkManager.getContactList().setSelectedUser(contact.getJID());
                SparkManager.getContactList().showPopup(contacts, e, contact);
            }
            if (e.getClickCount() == 2) {
                final JLabel label = (JLabel) contacts.getSelectedValue();
                String user = jidMap.get(label);
                if (user != null) {
                    final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
                    SparkManager.getChatManager().activateChat(user, contactUsername);
                    window.dispose();
                }
            }
        }
    });
    contacts.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                final JLabel label = (JLabel) contacts.getSelectedValue();
                String user = jidMap.get(label);
                if (user != null) {
                    final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
                    SparkManager.getChatManager().activateChat(user, contactUsername);
                    window.dispose();
                }
            } else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                window.dispose();
            }
        }
    });
    contacts.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
        }

        public void focusLost(FocusEvent e) {
            window.dispose();
        }
    });
    // Add KeyMappings
    SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "favoritePeople");
    SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "favoritePeople");
    SparkManager.getMainWindow().getRootPane().getActionMap().put("favoritePeople", new AbstractAction("favoritePeople") {

        private static final long serialVersionUID = 6836584242669218932L;

        public void actionPerformed(ActionEvent e) {
            // Show History Popup
            showPopup();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) File(java.io.File) FocusListener(java.awt.event.FocusListener) AbstractAction(javax.swing.AbstractAction) JList(javax.swing.JList)

Example 95 with KeyEvent

use of java.awt.event.KeyEvent in project Spark by igniterealtime.

the class UserManager method searchContacts.

public void searchContacts(String contact, final JFrame parent) {
    if (parents.get(parent) == null && parent.getGlassPane() != null) {
        parents.put(parent, parent.getGlassPane());
    }
    // Make sure we are using the default glass pane
    final Component glassPane = parents.get(parent);
    parent.setGlassPane(glassPane);
    final Map<String, ContactItem> contactMap = new HashMap<>();
    final List<ContactItem> contacts = new ArrayList<>();
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    for (ContactGroup contactGroup : contactList.getContactGroups()) {
        contactGroup.clearSelection();
        for (ContactItem contactItem : contactGroup.getContactItems()) {
            if (!contactMap.containsKey(contactItem.getJID())) {
                contacts.add(contactItem);
                contactMap.put(contactItem.getJID(), contactItem);
            }
        }
    }
    // Sort
    Collections.sort(contacts, itemComparator);
    final JContactItemField contactField = new JContactItemField(new ArrayList<>(contacts));
    JPanel layoutPanel = new JPanel();
    layoutPanel.setLayout(new GridBagLayout());
    JLabel enterLabel = new JLabel(Res.getString("label.contact.to.find"));
    enterLabel.setFont(new Font("dialog", Font.BOLD, 10));
    layoutPanel.add(enterLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    layoutPanel.add(contactField, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0));
    layoutPanel.setBorder(BorderFactory.createBevelBorder(0));
    contactField.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent keyEvent) {
            if (keyEvent.getKeyChar() == KeyEvent.VK_ENTER) {
                if (ModelUtil.hasLength(contactField.getText())) {
                    ContactItem item = contactMap.get(contactField.getText());
                    if (item == null) {
                        item = contactField.getSelectedContactItem();
                    }
                    if (item != null) {
                        parent.setGlassPane(glassPane);
                        parent.getGlassPane().setVisible(false);
                        contactField.dispose();
                        SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
                    }
                }
            } else if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
                parent.setGlassPane(glassPane);
                parent.getGlassPane().setVisible(false);
                contactField.dispose();
            }
        }
    });
    contactField.getList().addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                contactField.setSelectetIndex(e);
                ContactItem item = contactField.getSelectedContactItem();
                MouseEvent exx = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX() + 20, e.getY(), e.getClickCount(), false);
                SparkManager.getContactList().setSelectedUser(item.getJID());
                SparkManager.getContactList().showPopup(contactField.getPopup(), exx, item);
            }
            if (e.getClickCount() == 2) {
                if (ModelUtil.hasLength(contactField.getText())) {
                    ContactItem item = contactMap.get(contactField.getText());
                    if (item == null) {
                        item = contactField.getSelectedContactItem();
                    }
                    if (item != null) {
                        parent.setGlassPane(glassPane);
                        parent.getGlassPane().setVisible(false);
                        contactField.dispose();
                        SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
                    }
                }
            }
        }
    });
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setLayout(new GridBagLayout());
    mainPanel.add(layoutPanel, new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(SparkManager.getMainWindow().getTopToolBar().getHeight() + SparkManager.getWorkspace().getStatusBar().getHeight() + 47, 1, 5, 1), 200, 0));
    mainPanel.setOpaque(false);
    contactField.setText(contact);
    parent.setGlassPane(mainPanel);
    parent.getGlassPane().setVisible(true);
    contactField.focus();
    mainPanel.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent mouseEvent) {
            parent.setGlassPane(glassPane);
            parent.getGlassPane().setVisible(false);
            contactField.dispose();
        }
    });
    parent.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent windowEvent) {
            parent.setGlassPane(glassPane);
            parent.getGlassPane().setVisible(false);
            contactField.dispose();
            parent.removeWindowListener(this);
        }

        public void windowDeactivated(final WindowEvent windowEvent) {
            TimerTask task = new SwingTimerTask() {

                public void doRun() {
                    if (contactField.canClose()) {
                        windowClosing(windowEvent);
                    }
                }
            };
            TaskEngine.getInstance().schedule(task, 250);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) HashMap(java.util.HashMap) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) WindowAdapter(java.awt.event.WindowAdapter) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) TimerTask(java.util.TimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) JContactItemField(org.jivesoftware.spark.component.JContactItemField) Component(java.awt.Component) MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) ContactList(org.jivesoftware.spark.ui.ContactList) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) WindowEvent(java.awt.event.WindowEvent) ContactGroup(org.jivesoftware.spark.ui.ContactGroup)

Aggregations

KeyEvent (java.awt.event.KeyEvent)301 KeyAdapter (java.awt.event.KeyAdapter)159 MouseEvent (java.awt.event.MouseEvent)79 ActionEvent (java.awt.event.ActionEvent)74 JPanel (javax.swing.JPanel)69 ActionListener (java.awt.event.ActionListener)61 MouseAdapter (java.awt.event.MouseAdapter)59 KeyListener (java.awt.event.KeyListener)54 Dimension (java.awt.Dimension)50 JLabel (javax.swing.JLabel)48 JTextField (javax.swing.JTextField)44 BorderLayout (java.awt.BorderLayout)40 JButton (javax.swing.JButton)40 JScrollPane (javax.swing.JScrollPane)35 Insets (java.awt.Insets)33 Point (java.awt.Point)33 FocusEvent (java.awt.event.FocusEvent)31 GridBagConstraints (java.awt.GridBagConstraints)23 BoxLayout (javax.swing.BoxLayout)22 GridBagLayout (java.awt.GridBagLayout)20