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();
}
});
}
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;
}
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();
}
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();
}
});
}
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);
}
});
}
Aggregations