List of usage examples for java.awt.event KeyEvent getComponent
public Component getComponent()
From source file:MyButtonUI.java
public void keyPressed(KeyEvent e) { int code = e.getKeyCode(); if (code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE) { JComponent c = (JComponent) e.getComponent(); c.setBorder(m_borderLowered);/*w w w .j ava 2 s. co m*/ c.setBackground(m_backgroundPressed); } }
From source file:MyButtonUI.java
public void keyReleased(KeyEvent e) { int code = e.getKeyCode(); if (code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE) { JComponent c = (JComponent) e.getComponent(); c.setBorder(m_borderRaised);//from w ww. j a va 2s . c o m c.setBackground(m_backgroundNormal); } }
From source file:vincent.DynamicDataDemo.java
/** * Constructs a new demonstration application. * // ww w . ja v a2 s. c om * @param title the frame title. */ public DynamicDataDemo(final String title) { super(title); this.series = new TimeSeries("Random Data"); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(content); // Zone de saisie de commande vers le port srie : TextField zoneSaisie = new TextField(10); chartPanel.add(zoneSaisie); zoneSaisie.setLocation(100, 300); zoneSaisie.validate(); zoneSaisie.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { TextField textField = (TextField) e.getComponent(); try { BufferedWriter writer = tempSerialReader.getEcrivainPortSerie(); writer.write(textField.getText()); writer.write('\r'); writer.flush(); } catch (IOException l_ex) { LOG.error("erreur d'criture sur le port srie: ", l_ex); } } } }); temperatureCouranteLabel = new Label("XX.XC"); chartPanel.add(temperatureCouranteLabel); chartPanel.add(tempsDeChauffeEtRelicat); chartPanel.add(paramsPid); tempSerialReader = new TempSerialReader(this); }
From source file:com.egangotri.transliteratorAsSwing.TransliteratorJFrame.java
public void keyReleased(KeyEvent e) { if (e.getComponent() == this.tb1) { setText(); } }
From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java
public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { JList<String> jlist = (JList<String>) e.getComponent(); if (jlist.getSelectedIndex() >= 0) { if (jlist.equals(lstAmazon)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.AWS, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Amazon S3."); corruptedItems.remove("amazon" + jlist.getSelectedValue()); } else if (jlist.equals(lstAzure)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.AZURE, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Azure."); corruptedItems.remove("azure" + jlist.getSelectedValue()); } else if (jlist.equals(lstGoogle)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.GOOGLE, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Google."); corruptedItems.remove("google" + jlist.getSelectedValue()); } else if (jlist.equals(lstRackspace)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.RACKSPACE, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Rackspace."); corruptedItems.remove("rackspace" + jlist.getSelectedValue()); } else if (jlist.equals(lstHybris)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Hybris."); }/*from w w w . j a v a 2s . c o m*/ } } else if (e.getKeyChar() == 'c') { JList<String> jlist = (JList<String>) e.getComponent(); if (jlist.getSelectedIndex() >= 0) { byte[] corruptedPayload = "I_AM_THE_BOGUS_PAYLOAD".getBytes(); if (jlist.equals(lstAmazon)) { JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Amazon S3.", "Corruption", JOptionPane.WARNING_MESSAGE); System.out.println("Corrupted " + jlist.getSelectedValue() + " on Amazon S3."); corruptedItems.add("amazon" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.AWS, jlist.getSelectedValue(), corruptedPayload)).start(); } else if (jlist.equals(lstAzure)) { System.out.println("Corrupted " + jlist.getSelectedValue() + " on Azure."); JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Azure.", "Corruption", JOptionPane.WARNING_MESSAGE); corruptedItems.add("azure" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.AZURE, jlist.getSelectedValue(), corruptedPayload)).start(); } else if (jlist.equals(lstGoogle)) { JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Google.", "Corruption", JOptionPane.WARNING_MESSAGE); System.out.println("Corrupted " + jlist.getSelectedValue() + " on Google."); corruptedItems.add("google" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.GOOGLE, jlist.getSelectedValue(), corruptedPayload)).start(); } else if (jlist.equals(lstRackspace)) { JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Rackspace.", "Corruption", JOptionPane.WARNING_MESSAGE); System.out.println("Corrupted " + jlist.getSelectedValue() + " on Rackspace."); corruptedItems.add("rackspace" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.RACKSPACE, jlist.getSelectedValue(), corruptedPayload)).start(); } } } }
From source file:com.frostwire.gui.player.MediaPlayer.java
protected MediaPlayer() { lastRandomFiles = new LinkedList<MediaSource>(); playExecutor = ExecutorsHelper.newProcessingQueue("AudioPlayer-PlayExecutor"); String playerPath;//from ww w . j ava 2s. c o m playerPath = getPlayerPath(); MPlayer.initialise(new File(playerPath)); mplayer = new MPlayer(); mplayer.addPositionListener(new PositionListener() { public void positionChanged(float currentTimeInSecs) { notifyProgress(currentTimeInSecs); } }); mplayer.addStateListener(new StateListener() { public void stateChanged(MediaPlaybackState newState) { if (newState == MediaPlaybackState.Closed) { // This is the case // mplayer is // done with the // current file playNextMedia(); } } }); mplayer.addIcyInfoListener(new IcyInfoListener() { public void newIcyInfoData(String data) { notifyIcyInfo(data); } }); repeatMode = RepeatMode.values()[PlayerSettings.LOOP_PLAYLIST.getValue()]; shuffle = PlayerSettings.SHUFFLE_PLAYLIST.getValue(); playNextMedia = true; volume = PlayerSettings.PLAYER_VOLUME.getValue(); notifyVolumeChanged(); KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_SPACE) { Object s = e.getComponent(); if (!(s instanceof JTextField) && !(s instanceof JTable && ((JTable) s).isEditing() && !(s instanceof JCheckBox))) { togglePause(); return true; } } return false; } }); // prepare to receive UI events MPlayerUIEventHandler.instance().addListener(this); }
From source file:brainflow.app.toplevel.BrainFlow.java
private void initializeToolBar() { CommandGroup mainToolbarGroup = new CommandGroup("main-toolbar"); mainToolbarGroup.bind(getApplicationFrame()); ToggleGroup interpToggleGroup = new ToggleGroup("toggle-interp-group"); interpToggleGroup.bind(getApplicationFrame()); bindCommand(new OpenImageCommand(), true); bindCommand(new SnapshotCommand(), true); bindCommand(new NewCanvasCommand(), true); bindCommand(new CreateAxialViewCommand(), true); bindCommand(new CreateSagittalViewCommand(), true); bindCommand(new CreateCoronalViewCommand(), true); bindCommand(new CreateMontageViewCommand(), true); bindCommand(new CreateVerticalOrthogonalCommand(), true); bindCommand(new CreateHorizontalOrthogonalCommand(), true); bindCommand(new CreateTriangularOrthogonalCommand(), true); CommandGroup orthoGroup = new CommandGroup("ortho-view-group"); orthoGroup.bind(getApplicationFrame()); final NextSliceCommand nextSliceCommand = new NextSliceCommand(); bindCommand(nextSliceCommand, false); final PreviousSliceCommand previousSliceCommand = new PreviousSliceCommand(); bindCommand(previousSliceCommand, false); bindCommand(new PageBackSliceCommand(), true); bindCommand(new PageForwardSliceCommand(), true); bindCommand(new IncreaseContrastCommand(), true); bindCommand(new DecreaseContrastCommand(), true); bindCommand(new NearestInterpolationToggleCommand(), true); bindCommand(new LinearInterpolationToggleCommand(), true); bindCommand(new CubicInterpolationToggleCommand(), true); bindCommand(new ToggleAxisLabelCommand(), true); bindCommand(new ToggleCrossCommand(), true); //JToolBar mainToolbar = mainToolbarGroup.createToolBar(); final CommandBar mainToolbar = new CommandBar(); // for nimbus look and feel mainToolbar.setPaintBackground(false); // for nimbus look and feel mainToolbar.setBorder(new EmptyBorder(0, 0, 0, 0)); final ButtonFactory buttonFactory = createToolBarButtonFactory(); mainToolbarGroup.visitMembers(new GroupVisitor() { @Override/*from w w w.j av a2 s.c o m*/ public void visit(ActionCommand actionCommand) { JideButton jb = new JideButton(actionCommand.getActionAdapter()); jb.setButtonStyle(JideButton.TOOLBAR_STYLE); jb.setText(""); mainToolbar.add(jb); } @Override public void visit(CommandGroup commandGroup) { JComponent jc = commandGroup.createButton(buttonFactory); mainToolbar.add(jc); } }); mainToolbar.setKey("toolbar"); brainFrame.getDockableBarManager().addDockableBar(mainToolbar); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event.getID() == KeyEvent.KEY_PRESSED) { KeyEvent ke = (KeyEvent) event; Component comp = ke.getComponent(); if (ke.getKeyCode() == KeyEvent.VK_LEFT) { ImageView view = BrainFlow.get().getSelectedView(); if (/*view.hasFocus() || */ parentIsImageView(comp)) { previousSliceCommand.execute(); } } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) { ImageView view = BrainFlow.get().getSelectedView(); if ( /*view.hasFocus() */ parentIsImageView(comp)) { nextSliceCommand.execute(); } else { System.out.println("no focus"); } } } } }, AWTEvent.KEY_EVENT_MASK); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event.getID() == MouseEvent.MOUSE_RELEASED) { MouseEvent me = (MouseEvent) event; if (me.isPopupTrigger()) { showActionMenu(me); } } } }, AWTEvent.MOUSE_EVENT_MASK); }
From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java
/** * This method initializes jTable //from www .j a va 2 s .c o m * * @return javax.swing.JTable */ private JTable getJTable() { if (jTableNumbers == null) { jTableNumbers = new JTable(new NumberTableModel()); JComboBox<String> jComboNumberTypes = new JComboBox<String>(); jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes())); jComboNumberTypes.setEditable(true); TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE); DefaultCellEditor comboBoxEditor = new DefaultCellEditor(jComboNumberTypes); //TODO: enable autocomplete for numbertypes picklist. //AutoCompleteDecorator.decorate((JComboBox) comboBoxEditor.getComponent()); typeColumn.setCellEditor(comboBoxEditor); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for pick list of number types."); typeColumn.setCellRenderer(renderer); jTableNumbers.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { thisPane.setStateToDirty(); } }); jTableNumbers.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupNumbers.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupNumbers.show(e.getComponent(), e.getX(), e.getY()); } } }); jPopupNumbers = new JPopupMenu(); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (clickedOnNumsRow >= 0) { int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected number?", "Delete Number", JOptionPane.OK_CANCEL_OPTION); if (ok == JOptionPane.OK_OPTION) { log.debug("deleting numbers row " + clickedOnNumsRow); ((NumberTableModel) jTableNumbers.getModel()).deleteRow(clickedOnNumsRow); setStateToDirty(); } else { log.debug("number row delete canceled by user."); } } else { JOptionPane.showMessageDialog(thisPane, "Unable to select row to delete. Try empting number and type and pressing Save."); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisPane, "Failed to delete a number row. " + ex.getMessage()); } } }); jPopupNumbers.add(mntmDeleteRow); } return jTableNumbers; }
From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java
/** * This method initializes jTableCollectors * //from w w w . j av a 2 s . c o m * @return javax.swing.JTable */ private JTable getJTableCollectors() { if (jTableCollectors == null) { jTableCollectors = new JTable(new CollectorTableModel()); // Note: When setting the values, the table column editor needs to be reset there, as the model is replaced. //JTextField field = new JTextField(); FilteringAgentJComboBox field = new FilteringAgentJComboBox(); //field.setInputVerifier(MetadataRetriever.getInputVerifier(Collector.class, "CollectorName", field)); //jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new PicklistTableCellEditor(field, true)); jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new ComboBoxCellEditor(field)); jTableCollectors.setRowHeight(jTableCollectors.getRowHeight() + 4); jTableCollectors.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { thisPane.setStateToDirty(); } }); jTableCollectors.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnCollsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupCollectors.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnCollsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupCollectors.show(e.getComponent(), e.getX(), e.getY()); } } }); jPopupCollectors = new JPopupMenu(); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { log.debug(clickedOnCollsRow); if (clickedOnCollsRow >= 0) { int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected collector?", "Delete Collector", JOptionPane.OK_CANCEL_OPTION); if (ok == JOptionPane.OK_OPTION) { log.debug("deleting collectors row " + clickedOnCollsRow); ((CollectorTableModel) jTableCollectors.getModel()).deleteRow(clickedOnCollsRow); setStateToDirty(); } else { log.debug("collector row delete canceled by user."); } } else { JOptionPane.showMessageDialog(thisPane, "Unable to select row to delete. Try empting the value and pressing Save."); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisPane, "Failed to delete a collector row. " + ex.getMessage()); } } }); jPopupCollectors.add(mntmDeleteRow); } return jTableCollectors; }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
public JPanel createDetailsView() { final VFSJFileChooser chooser = getFileChooser(); JPanel p = new JPanel(new BorderLayout()); final JTable detailsTable = new JTable(getDetailsTableModel()) { // Handle Escape key events here @Override/*from ww w. java 2 s .c o m*/ protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) && (getCellEditor() == null)) { // We are not editing, forward to filechooser. chooser.dispatchEvent(e); return true; } return super.processKeyBinding(ks, e, condition, pressed); } @Override public void tableChanged(TableModelEvent e) { super.tableChanged(e); if (e.getFirstRow() == TableModelEvent.HEADER_ROW) { // update header with possibly changed column set updateDetailsColumnModel(this); } } }; // detailsTable.setRowSorter(getRowSorter()); detailsTable.setAutoCreateColumnsFromModel(false); detailsTable.setComponentOrientation(chooser.getComponentOrientation()); //detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); detailsTable.setShowGrid(false); detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); // detailsTable.addKeyListener(detailsKeyListener); Font font = list.getFont(); detailsTable.setFont(font); detailsTable.setIntercellSpacing(new Dimension(0, 0)); TableCellRenderer headerRenderer = new AlignableTableHeaderRenderer( detailsTable.getTableHeader().getDefaultRenderer()); detailsTable.getTableHeader().setDefaultRenderer(headerRenderer); TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser); detailsTable.setDefaultRenderer(Object.class, cellRenderer); // So that drag can be started on a mouse press detailsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); detailsTable.addMouseListener(getMouseHandler()); // No need to addListSelectionListener because selections are forwarded // to our JList. // 4835633 : tell BasicTableUI that this is a file list detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE); if (listViewWindowsStyle) { detailsTable.addFocusListener(repaintListener); } JTableHeader header = detailsTable.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(detailsTableModel.new ColumnListener()); header.setReorderingAllowed(true); // TAB/SHIFT-TAB should transfer focus and ENTER should select an item. // We don't want them to navigate within the table ActionMap am = SwingUtilities.getUIActionMap(detailsTable); am.remove("selectNextRowCell"); am.remove("selectPreviousRowCell"); am.remove("selectNextColumnCell"); am.remove("selectPreviousColumnCell"); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); JScrollPane scrollpane = new JScrollPane(detailsTable); scrollpane.setComponentOrientation(chooser.getComponentOrientation()); LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground"); // Adjust width of first column so the table fills the viewport when // first displayed (temporary listener). scrollpane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JScrollPane sp = (JScrollPane) e.getComponent(); fixNameColumnWidth(sp.getViewport().getSize().width); sp.removeComponentListener(this); } }); // 4835633. // If the mouse is pressed in the area below the Details view table, the // event is not dispatched to the Table MouseListener but to the // scrollpane. Listen for that here so we can clear the selection. scrollpane.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { JScrollPane jsp = ((JScrollPane) e.getComponent()); JTable table = (JTable) jsp.getViewport().getView(); if (!e.isShiftDown() || (table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) { clearSelection(); TableCellEditor tce = table.getCellEditor(); if (tce != null) { tce.stopCellEditing(); } } } }); detailsTable.setForeground(list.getForeground()); detailsTable.setBackground(list.getBackground()); if (listViewBorder != null) { scrollpane.setBorder(listViewBorder); } p.add(scrollpane, BorderLayout.CENTER); detailsTableModel.fireTableStructureChanged(); return p; }