List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:org.openmicroscopy.shoola.agents.imviewer.util.player.MoviePlayerControl.java
/** Adds listeners to the UI components. */ private void initListeners() { JTextField editor = view.editor; editor.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) editorActionHandler();/*from ww w . j a v a 2s.co m*/ } }); //JButton attachButtonListener(view.play, PLAY_CMD); attachButtonListener(view.pause, PAUSE_CMD); attachButtonListener(view.stop, STOP_CMD); //JComboBox JComboBox box = view.movieTypes; box.setActionCommand("" + MOVIE_TYPE_CMD); box.addActionListener(this); //JSpinner view.fps.addChangeListener(this); //MoviePane attachFieldListeners(view.startT); attachFieldListeners(view.endT); attachFieldListeners(view.startZ); attachFieldListeners(view.endZ); attachButtonListener(view.acrossZ, ACROSS_Z_CMD); attachButtonListener(view.acrossT, ACROSS_T_CMD); //attachButtonListener(view.acrossZT, ACROSS_ZT_CMD); view.tSlider.addPropertyChangeListener(this); view.zSlider.addPropertyChangeListener(this); }
From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java
@Override public JComponent createComponent() { // create the component, that is shown in the sidebar final HelloWorldList list = new HelloWorldList(); list.setModel(ObjectUtils.defaultIfNull(createListModel(), new DefaultListModel<>())); list.setCellRenderer(new HelloWorldListRenderer()); // register keyboard events list.addKeyListener(new KeyAdapter() { @Override/*from ww w . j a v a2s .c o m*/ public void keyPressed(KeyEvent e) { if (!list.isEnabled()) return; // ENTER was pressed if (e.getKeyCode() == KeyEvent.VK_ENTER) { DbHelloWorldObject object = list.getSelectedValue(); if (object != null) new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null); } } }); // register mouse events list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (!list.isEnabled()) return; // single click with the right mouse button if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) { // fetch the clicked element int index = list.locationToIndex(e.getPoint()); if (index >= 0) list.setSelectedIndex(index); // show popup menu with further actions DbHelloWorldObject object = list.getSelectedValue(); JPopupMenu popup = createActionMenu(object); if (popup != null) popup.show(list, e.getPoint().x, e.getPoint().y); } // double click with the left mouse button else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { DbHelloWorldObject object = list.getSelectedValue(); if (object != null) new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null); } } }); return list; }
From source file:org.ut.biolab.medsavant.client.ontology.OntologyWizard.java
private AbstractWizardPage getNamePage() { return new DefaultWizardPage(PAGENAME_NAME) { private JTextField nameField = new JTextField(); private JComboBox typeCombo = new JComboBox(OntologyListItem.DEFAULT_ITEMS); {/*from w w w . ja va 2 s.c o m*/ addText("Choose a name for the ontology.\nThe name cannot already be in use. "); addComponent(nameField); nameField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (StringUtils.isNotEmpty(nameField.getText())) { name = nameField.getText(); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } else { fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT); } } }); addText("Indicate the type of ontology data:"); addComponent(typeCombo); typeCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { type = ((OntologyListItem) typeCombo.getSelectedItem()).getType(); switch (type) { case GO: oboField.setText(WebResources.GO_OBO_URL.toString()); mappingField.setText(WebResources.GO_TO_GENES_URL.toString()); break; case HPO: oboField.setText(WebResources.HPO_OBO_URL.toString()); mappingField.setText(WebResources.HPO_TO_GENES_URL.toString()); break; case OMIM: oboField.setText(WebResources.OMIM_OBO_URL.toString()); mappingField.setText(WebResources.OMIM_TO_HPO_URL.toString()); break; } } }); typeCombo.setSelectedIndex(0); } @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.NEXT); if (name == null || name.equals("")) { fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT); } else { fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } } }; }
From source file:gov.sandia.umf.platform.ui.jobs.RunPanel.java
public RunPanel() { root = new NodeBase(); model = new DefaultTreeModel(root); tree = new JTree(model); tree.setRootVisible(false);/*from w ww.j a v a2s .c o m*/ tree.setShowsRootHandles(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); NodeBase node = (NodeBase) value; Icon icon = node.getIcon(expanded); // A node knows whether it should hold other nodes or not, so don't pass leaf to it. if (icon == null) { if (leaf) icon = getDefaultLeafIcon(); else if (expanded) icon = getDefaultOpenIcon(); else icon = getDefaultClosedIcon(); } setIcon(icon); return this; } }); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { NodeBase newNode = (NodeBase) tree.getLastSelectedPathComponent(); if (newNode == null) return; if (newNode == displayNode) return; if (displayThread != null) synchronized (displayText) { displayThread.stop = true; } displayNode = newNode; if (displayNode instanceof NodeFile) viewFile(); else if (displayNode instanceof NodeJob) viewJob(); } }); tree.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int keycode = e.getKeyCode(); if (keycode == KeyEvent.VK_DELETE || keycode == KeyEvent.VK_BACK_SPACE) { delete(); } } }); tree.addTreeWillExpandListener(new TreeWillExpandListener() { public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { TreePath path = event.getPath(); // TODO: can this ever be null? Object o = path.getLastPathComponent(); if (o instanceof NodeJob) ((NodeJob) o).build(tree); } public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { } }); tree.addTreeExpansionListener(new TreeExpansionListener() { public void treeExpanded(TreeExpansionEvent event) { Rectangle node = tree.getPathBounds(event.getPath()); Rectangle visible = treePane.getViewport().getViewRect(); visible.height -= node.y - visible.y; visible.y = node.y; tree.repaint(visible); } public void treeCollapsed(TreeExpansionEvent event) { Rectangle node = tree.getPathBounds(event.getPath()); Rectangle visible = treePane.getViewport().getViewRect(); visible.height -= node.y - visible.y; visible.y = node.y; tree.repaint(visible); } }); Thread refreshThread = new Thread() { public void run() { try { // Initial load synchronized (running) { for (MNode n : AppData.runs) running.add(0, new NodeJob(n)); // This should be efficient on a doubly-linked list. for (NodeJob job : running) root.add(job); } EventQueue.invokeLater(new Runnable() { public void run() { model.nodeStructureChanged(root); if (model.getChildCount(root) > 0) tree.setSelectionRow(0); } }); // Periodic refresh to show status of running jobs int shortCycles = 100; // Force full scan on first cycle. while (true) { NodeBase d = displayNode; // Make local copy (atomic action) to prevent it changing from under us if (d instanceof NodeJob) ((NodeJob) d).monitorProgress(RunPanel.this); if (shortCycles++ < 20) { Thread.sleep(1000); continue; } shortCycles = 0; synchronized (running) { Iterator<NodeJob> i = running.iterator(); while (i.hasNext()) { NodeJob job = i.next(); if (job != d) job.monitorProgress(RunPanel.this); if (job.complete >= 1) i.remove(); } } } } catch (InterruptedException e) { } } }; refreshThread.setDaemon(true); refreshThread.start(); displayText = new JTextArea(); displayText.setEditable(false); final JCheckBox chkFixedWidth = new JCheckBox("Fixed-Width Font"); chkFixedWidth.setFocusable(false); chkFixedWidth.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int size = displayText.getFont().getSize(); if (chkFixedWidth.isSelected()) { displayText.setFont(new Font(Font.MONOSPACED, Font.PLAIN, size)); } else { displayText.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, size)); } } }); displayPane.setViewportView(displayText); ActionListener graphListener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (displayNode instanceof NodeFile) { NodeFile nf = (NodeFile) displayNode; if (nf.type == NodeFile.Type.Output || nf.type == NodeFile.Type.Result) { String graphType = e.getActionCommand(); if (displayPane.getViewport().getView() instanceof ChartPanel && displayGraph.equals(graphType)) { viewFile(); displayGraph = ""; } else { if (graphType.equals("Graph")) { Plot plot = new Plot(nf.path.getAbsolutePath()); if (!plot.columns.isEmpty()) displayPane.setViewportView(plot.createGraphPanel()); } else // Raster { Raster raster = new Raster(nf.path.getAbsolutePath(), displayPane.getHeight()); displayPane.setViewportView(raster.createGraphPanel()); } displayGraph = graphType; } } } } }; buttonGraph = new JButton("Graph", ImageUtil.getImage("analysis.gif")); buttonGraph.setFocusable(false); buttonGraph.addActionListener(graphListener); buttonGraph.setActionCommand("Graph"); buttonRaster = new JButton("Raster", ImageUtil.getImage("prnplot.gif")); buttonRaster.setFocusable(false); buttonRaster.addActionListener(graphListener); buttonRaster.setActionCommand("Raster"); Lay.BLtg(this, "C", Lay.SPL(Lay.BL("C", treePane = Lay.sp(tree)), Lay.BL("N", Lay.FL(chkFixedWidth, Lay.FL(buttonGraph, buttonRaster), "hgap=50"), "C", displayPane), "divpixel=250")); setFocusCycleRoot(true); }
From source file:com.openbravo.pos.panels.JTicketsFinder.java
private void init(DataLogicSales dlSales, DataLogicCustomers dlCustomers, Component parentComponent) { this.dlSales = dlSales; this.dlCustomers = dlCustomers; this.parentComponent = parentComponent; initComponents();// w w w.j a v a 2s . c om jScrollPane1.getVerticalScrollBar().setPreferredSize(new Dimension(35, 35)); m_jKeys.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent ke) { jButton3ActionPerformed(null); } }); jtxtTicketID.addEditorKeys(m_jKeys); jtxtMoney.addEditorKeys(m_jKeys); //jtxtTicketID.activate(); lpr = new ListProviderCreator(dlSales.getTicketsList(), this); jListTickets.setCellRenderer(new FindTicketsRenderer()); getRootPane().setDefaultButton(jcmdOK); initCombos(); defaultValues(); selectedTicket = null; }
From source file:edu.ku.brc.specify.plugins.ipadexporter.DataSetDlg.java
@Override public void createUI() { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,2px,p,8px")); DBTableInfo ti = DBTableIdMgr.getInstance().getInfoById(Institution.getClassTableId()); DBFieldInfo fi = ti.getFieldByName("name"); JLabel nmLabel = UIHelper.createFormLabel(fi.getTitle()); instNameTF = new ValTextField(); nameLen = fi.getLength();/*from w ww.ja va2s. c o m*/ statusLbl = UIHelper.createLabel(""); contentPanel = pb.getPanel(); int y = 1; pb.add(nmLabel, cc.xy(1, y)); pb.add(instNameTF, cc.xy(3, y)); y += 2; pb.add(statusLbl, cc.xyw(1, y, 3)); y += 2; pb.setDefaultDialogBorder(); KeyAdapter ka = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { okBtn.setEnabled(isValidInput(instNameTF.getText())); } }; instNameTF.addKeyListener(ka); super.createUI(); String title = cloudInstId == null ? inst.getName() : ""; instNameTF.setText(title); okBtn.setEnabled(isValidInput(instNameTF.getText())); }
From source file:com.dbschools.quickquiz.client.giver.MainWindow.java
private void addListeners() { takerTableDisplay.addTableKeyListener(new KeyAdapter() { @Override/*from w w w . java2s. c o m*/ public void keyPressed(KeyEvent e) { char keyChar = e.getKeyChar(); if (Character.isDigit(keyChar) && e.isControlDown()) { awardPoints(Integer.parseInt(Character.toString(keyChar))); } } }); final ListSelectionModel takerTableSelectionModel = takerTableDisplay.getSelectionModel(); takerTableSelectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { btnAwardPoints.setEnabled(!takerTableSelectionModel.isSelectionEmpty()); } }); countdownMeter.addCountdownFinishListener(new CountdownFinishListener() { public void countdownFinished() { SwingUtilities.invokeLater(new Runnable() { public void run() { btnSendQuestion.setEnabled(true); } }); } }); }
From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JPanCMTableArea.java
protected JTableInfoForCMFile getJTableInfoForCMFile() { if (jTableInfoForCMFile == null) { jTableInfoForCMFile = new JTableInfoForCMFile(); jTableInfoForCMFile.addKeyListener(new KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent e) { keyReleasedAction(jTableInfoForCMFile); }/*from ww w . j a v a2 s. c o m*/ }); jTableInfoForCMFile.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { mouseClickedAction(jTableInfoForCMFile, e); } }); } return jTableInfoForCMFile; }
From source file:op.care.prescription.DlgDiscontinue.java
/** * This method is called from within the constructor to * initialize the form./*from www. j ava2s. co m*/ * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the PrinterForm Editor. */ // <editor-fold defaultstate="collapsed" desc=" Erzeugter Quelltext ">//GEN-BEGIN:initComponents private void initComponents() { lblQuestion = new JLabel(); cmbArztAb = new JComboBox(); cmbKHAb = new JComboBox(); panel1 = new JPanel(); btnCancel = new JButton(); btnOK = new JButton(); //======== this ======== setResizable(false); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setModalityType(Dialog.ModalityType.APPLICATION_MODAL); Container contentPane = getContentPane(); contentPane.setLayout(new FormLayout("$rgap, 200dlu:grow, $lcgap, $rgap", "$rgap, $lgap, default, 2*($lgap, fill:16dlu), $lgap, fill:default, $lgap, $rgap")); //---- lblQuestion ---- lblQuestion.setText("Wer hat die Verordnung abgesetzt ?"); lblQuestion.setFont(new Font("Arial", Font.PLAIN, 18)); contentPane.add(lblQuestion, CC.xy(2, 3)); //---- cmbArztAb ---- cmbArztAb.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); cmbArztAb.setFont(new Font("Arial", Font.PLAIN, 14)); cmbArztAb.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { cmbArztAbKeyPressed(e); } }); contentPane.add(cmbArztAb, CC.xy(2, 5)); //---- cmbKHAb ---- cmbKHAb.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); cmbKHAb.setFont(new Font("Arial", Font.PLAIN, 14)); contentPane.add(cmbKHAb, CC.xy(2, 7)); //======== panel1 ======== { panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS)); //---- btnCancel ---- btnCancel.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/cancel.png"))); btnCancel.setText(null); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnCancelActionPerformed(e); } }); panel1.add(btnCancel); //---- btnOK ---- btnOK.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png"))); btnOK.setText(null); btnOK.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnOKActionPerformed(e); } }); panel1.add(btnOK); } contentPane.add(panel1, CC.xy(2, 9, CC.RIGHT, CC.DEFAULT)); setSize(490, 175); setLocationRelativeTo(getOwner()); }
From source file:pl.otros.logview.gui.message.editor.MessageColorizerBrowser.java
public MessageColorizerBrowser(OtrosApplication otrosApplication) { super(new BorderLayout()); this.container = otrosApplication.getAllPluginables().getMessageColorizers(); this.otrosApplication = otrosApplication; toolBar = new JToolBar(); editor = new MessageColorizerEditor(container, otrosApplication.getStatusObserver()); JLabel noEditable = new JLabel("Selected MessageColorizer is not editable.", SwingConstants.CENTER); JLabel nothingSelected = new JLabel("Nothing selected", SwingConstants.CENTER); listModel = new PluginableElementListModel<MessageColorizer>(container); jList = new JList(listModel); jList.setCellRenderer(new PluginableElementNameListRenderer()); cardLayout = new CardLayout(); contentPanel = new JPanel(cardLayout); contentPanel.add(editor, CARD_LAYOUT_EDITOR); contentPanel.add(noEditable, CARD_LAYOUT_NOT_EDITABLE); contentPanel.add(nothingSelected, CARD_LAYOUT_NO_SELECTED); cardLayout.show(contentPanel, CARD_LAYOUT_NOT_EDITABLE); JSplitPane mainSplitPane = new JSplitPane(SwingConstants.VERTICAL, new JScrollPane(jList), contentPanel); mainSplitPane.setDividerLocation(220); jList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override//from w w w .j a v a2 s . c om public void valueChanged(ListSelectionEvent e) { showSelected(); enableDisableButtonsForSelectedColorizer(); } }); jList.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_DELETE) { ActionEvent actionEvent = new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, ""); deleteAction.actionPerformed(actionEvent); } } }); JButton createNew = new JButton("Create new", Icons.ADD); createNew.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveAsButton.setEnabled(false); createNew(); } }); saveButton = new JButton("Save and use", Icons.DISK); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { PropertyPatternMessageColorizer mc = editor.createMessageColorizer(); File selectedFile = null; String f = mc.getFile(); if (StringUtils.isNotBlank(f)) { selectedFile = new File(mc.getFile()); } else { int response = chooser.showSaveDialog(MessageColorizerBrowser.this); if (response != JFileChooser.APPROVE_OPTION) { return; } selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".pattern")) { selectedFile = new File(selectedFile.getParentFile(), selectedFile.getName() + ".pattern"); } } removeMessageColorizerWithNullFile(); applyMessageColorizer(selectedFile); saveMessageColorizer(selectedFile); jList.setSelectedValue(mc, true); } catch (ConfigurationException e1) { String errorMessage = String.format("Can't save message colorizer: %s", e1.getMessage()); LOGGER.severe(errorMessage); MessageColorizerBrowser.this.otrosApplication.getStatusObserver().updateStatus(errorMessage, StatusObserver.LEVEL_ERROR); } } }); saveAsButton = new JButton("Save as", Icons.DISK_PLUS); saveAsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int response = chooser.showSaveDialog(MessageColorizerBrowser.this); if (response != JFileChooser.APPROVE_OPTION) { return; } File selectedFile = chooser.getSelectedFile(); selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".pattern")) { selectedFile = new File(selectedFile.getParentFile(), selectedFile.getName() + ".pattern"); } removeMessageColorizerWithNullFile(); applyMessageColorizer(selectedFile); saveMessageColorizer(selectedFile); jList.setSelectedValue(editor.createMessageColorizer(), true); } catch (ConfigurationException e1) { String errorMessage = String.format("Can't save message colorizer: %s", e1.getMessage()); LOGGER.severe(errorMessage); MessageColorizerBrowser.this.otrosApplication.getStatusObserver().updateStatus(errorMessage, StatusObserver.LEVEL_ERROR); } } }); useButton = new JButton("Use without saving"); useButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { removeMessageColorizerWithNullFile(); applyMessageColorizer(File.createTempFile("messageColorizer", "pattern")); } catch (Exception e) { LOGGER.severe("Cannot create message colorizer: " + e.getMessage()); } } }); deleteAction = new DeleteSelected(otrosApplication); deleteButton = new JButton(deleteAction); toolBar.setFloatable(false); toolBar.add(createNew); toolBar.add(saveButton); toolBar.add(saveAsButton); toolBar.add(useButton); toolBar.add(deleteButton); enableDisableButtonsForSelectedColorizer(); initFileChooser(); this.add(mainSplitPane); this.add(toolBar, BorderLayout.SOUTH); }