List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTree.java
public DesktopTree() { layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]"); panel = new JPanel(layout); topPanel = new JPanel(new BorderLayout()); topPanel.setVisible(false);/*from w w w. j a v a 2s .co m*/ panel.add(topPanel, "growx"); impl = new JTree(); treeView = new JScrollPane(impl); panel.add(treeView, "grow"); impl.setRootVisible(false); impl.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); impl.setExpandsSelectedPaths(true); impl.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { // select row Point p = e.getPoint(); TreePath treePath = impl.getPathForLocation(p.x, p.y); if (treePath != null) { TreeSelectionModel model = impl.getSelectionModel(); model.setSelectionPath(treePath); } // show popup menu createPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } }); impl.addKeyListener(new KeyAdapter() { protected static final int ENTER_CODE = 10; @Override public void keyPressed(KeyEvent e) { if (ENTER_CODE == e.getKeyCode() && e.getComponent() == DesktopTree.this.getComponent()) { if (enterPressAction != null) { enterPressAction.actionPerform(DesktopTree.this); } else { handleClickAction(); } } } }); }
From source file:net.sf.firemox.ui.component.SplashScreen.java
/** * Create a new instance of this class./*from ww w . ja v a 2 s . com*/ * * @param filename * the picture filename. * @param parent * the splash screen's parent. * @param waitTime * the maximum time before the screen is hidden. */ public SplashScreen(String filename, Frame parent, int waitTime) { super(parent); getContentPane().setLayout(null); toFront(); final JLabel l = new JLabel(new ImageIcon(filename)); final Dimension labelSize = l.getPreferredSize(); l.setLocation(0, 0); l.setSize(labelSize); setSize(labelSize); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setLocation(screenSize.width / 2 - labelSize.width / 2, screenSize.height / 2 - labelSize.height / 2); final JLabel mp = new JLabel(IdConst.PROJECT_DISPLAY_NAME); mp.setLocation(30, 305); mp.setSize(new Dimension(300, 30)); final JLabel version = new JLabel(IdConst.VERSION); version.setLocation(235, 418); version.setSize(new Dimension(300, 30)); final JTextArea disclaimer = new JTextArea(); disclaimer.setEditable(false); disclaimer.setLineWrap(true); disclaimer.setWrapStyleWord(true); disclaimer.setAutoscrolls(true); disclaimer.setFont(MToolKit.defaultFont); disclaimer.setTabSize(2); // Then try and read it locally Reader inGPL = null; try { inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE))); disclaimer.read(inGPL, ""); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(inGPL); } final JScrollPane disclaimerSPanel = new JScrollPane(); disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); disclaimerSPanel.setViewportView(disclaimer); disclaimerSPanel.setLocation(27, 340); disclaimerSPanel.setPreferredSize(new Dimension(283, 80)); disclaimerSPanel.setSize(disclaimerSPanel.getPreferredSize()); getContentPane().add(disclaimerSPanel); getContentPane().add(version); getContentPane().add(mp); getContentPane().add(l); final int pause = waitTime; final Runnable waitRunner = new Runnable() { public void run() { try { Thread.sleep(pause); while (!bKilled) { Thread.sleep(200); } } catch (InterruptedException e) { // Ignore this error } setVisible(false); dispose(); MagicUIComponents.magicForm.toFront(); } }; // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { setVisible(false); dispose(); if (MagicUIComponents.magicForm != null) MagicUIComponents.magicForm.toFront(); } }); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { setVisible(false); dispose(); MagicUIComponents.magicForm.toFront(); } } }); setVisible(true); start(waitRunner); }
From source file:org.executequery.gui.browser.FindAction.java
private JList initSearchResultsList() { final JList list = new JList(); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListCellRenderer listCellRenderer = getListCellRenderer(); if (listCellRenderer != null) { list.setCellRenderer(listCellRenderer); }/*from w w w . j a v a 2 s. c o m*/ list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { listValueSelected((T) list.getSelectedValue()); } } }); list.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_ENTER) { listValueSelected((T) list.getSelectedValue()); } else if (keyCode == KeyEvent.VK_BACK_SPACE) { searchField.requestFocus(); } } }); return list; }
From source file:de.codesourcery.jasm16.ide.ui.viewcontainers.EditorContainer.java
public static final void addEditorCloseKeyListener(Component comp, final IEditorView view) { comp.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_W && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) { System.out.println("*** Closing editor " + view + " ***"); if (view.hasViewContainer()) { view.getViewContainer().disposeView(view); } else { view.dispose();//from w w w. jav a 2 s. c o m } } } }); }
From source file:com.mirth.connect.connectors.http.HttpSender.java
public HttpSender() { this.parent = PlatformUI.MIRTH_FRAME; initComponents();//from w w w. ja va 2s . c om parent.setupCharsetEncodingForConnector(charsetEncodingCombobox); queryParametersPane.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { deselectRows(queryParametersTable, queryParametersDeleteButton); } }); headersPane.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { deselectRows(headersTable, headersDeleteButton); } }); queryParametersDeleteButton.setEnabled(false); headersDeleteButton.setEnabled(false); urlField.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent evt) { urlFieldChanged(); } }); sslWarningPanel = new SSLWarningPanel(); contentTypeField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { checkContentEnabled(); } @Override public void removeUpdate(DocumentEvent e) { checkContentEnabled(); } @Override public void changedUpdate(DocumentEvent e) { checkContentEnabled(); } }); }
From source file:net.pms.encoders.FFmpegDVRMSRemux.java
@Override public JComponent config() { FormLayout layout = new FormLayout("left:pref, 3dlu, p, 3dlu, 0:grow", "p, 3dlu, p, 3dlu, 0:grow"); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.EMPTY_BORDER); builder.setOpaque(false);//from ww w.j a v a 2 s. c o m CellConstraints cc = new CellConstraints(); JComponent cmp = builder.addSeparator(Messages.getString("FFmpegDVRMSRemux.1"), cc.xyw(1, 1, 5)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); builder.addLabel(Messages.getString("FFmpegDVRMSRemux.0"), cc.xy(1, 3)); altffpath = new JTextField(configuration.getFfmpegAlternativePath()); altffpath.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setFfmpegAlternativePath(altffpath.getText()); } }); builder.add(altffpath, cc.xyw(3, 3, 3)); return builder.getPanel(); }
From source file:org.openconcerto.erp.core.common.ui.DeviseField.java
public static void addFilteringKeyListener(final JTextField textField) { textField.addKeyListener(new KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent keyEvent) { final char keychar = keyEvent.getKeyChar(); if (keychar == KeyEvent.VK_BACK_SPACE) { return; }/*from w w w . jav a 2 s .c om*/ // pas plus de 2 chiffres apres la virgule int pointPosition = textField.getText().indexOf('.'); if (Character.isDigit(keychar)) { if (pointPosition > -1) { // System.err.println("Text Selected :: " + textField.getSelectedText()); if (textField.getSelectedText() == null) { if (textField.getCaretPosition() <= pointPosition) { return; } else { if (textField.getText().substring(pointPosition).length() <= 2) { return; } } } else { return; } } else { return; } } if (keychar == KeyEvent.VK_PERIOD && textField.getText().indexOf('.') < 0) return; // if (keychar == KeyEvent.VK_MINUS && (textField.getText().indexOf('-') < 0) && // textField.getCaretPosition() == 0) // return; keyEvent.consume(); } }); }
From source file:com.mirth.connect.connectors.ws.WebServiceSender.java
public WebServiceSender() { this.parent = PlatformUI.MIRTH_FRAME; initComponents();/* www . j ava 2s .c om*/ SyntaxDocument document = new SyntaxDocument(); document.setTokenMarker(new XMLTokenMarker()); soapEnvelope.setDocument(document); KeyListener keyListener = new KeyAdapter() { public void keyReleased(KeyEvent evt) { urlFieldChanged(); } }; wsdlUrlField.addKeyListener(keyListener); soapActionField.addKeyListener(keyListener); headersPane.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { deselectRows(headersTable, headersDeleteButton); } }); headersDeleteButton.setEnabled(false); sslWarningPanel = new SSLWarningPanel(); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java
@Override public void addFieldListener(final FieldListener listener) { final JTextField field = (JTextField) impl.getEditor(); field.addFocusListener(new FocusAdapter() { @Override/*from w w w. ja va2s . c o m*/ public void focusLost(FocusEvent e) { fireFieldListener(listener, field.getText()); } }); field.addKeyListener(new KeyAdapter() { protected static final int ENTER_CODE = 10; @Override public void keyPressed(KeyEvent e) { if (ENTER_CODE == e.getKeyCode()) { fireFieldListener(listener, field.getText()); } } }); }
From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JPanCMTableArea.java
protected JTableInfoForCMFolder getJTableInfoForCMFolder() { if (jTableInfoForCMFolder == null) { jTableInfoForCMFolder = new JTableInfoForCMFolder(); jTableInfoForCMFolder.addKeyListener(new KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent e) { keyReleasedAction(jTableInfoForCMFolder); }//from ww w. j a v a 2s . c o m }); jTableInfoForCMFolder.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { mouseClickedAction(jTableInfoForCMFolder, e); } }); } return jTableInfoForCMFolder; }