List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTextArea.java
@Override protected JTextArea createTextComponentImpl() { final JTextArea impl = new TextAreaFlushableField(); if (isTabTraversal()) { Set<KeyStroke> forwardFocusKey = Collections.singleton(getKeyStroke(KeyEvent.VK_TAB, 0)); impl.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardFocusKey); Set<KeyStroke> backwardFocusKey = Collections .singleton(getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK)); impl.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardFocusKey); impl.addKeyListener(new KeyAdapter() { @Override//from w w w.ja va 2 s . co m public void keyPressed(KeyEvent e) { if (isEnabled() && isEditable() && e.getKeyCode() == KeyEvent.VK_TAB && e.getModifiers() == KeyEvent.CTRL_MASK) { if (StringUtils.isEmpty(impl.getText())) { impl.setText("\t"); } else { impl.append("\t"); } } } }); } impl.setLineWrap(true); impl.setWrapStyleWord(true); int height = (int) impl.getPreferredSize().getHeight(); impl.setMinimumSize(new Dimension(0, height)); composition = new JScrollPane(impl); composition.setPreferredSize(new Dimension(150, height)); composition.setMinimumSize(new Dimension(0, height)); doc.putProperty("filterNewlines", false); return impl; }
From source file:edu.cwru.sepia.agent.visual.VisualAgent.java
private void setupScreen() { gamePanel = createGamePanel();//from w w w . j ava 2 s.c o m actions = new HashSet<Action>(); final KeyAdapter canvasKeyListener = new KeyAdapter() { public void keyPressed(KeyEvent e) { // System.out.println(e.getKeyCode()); if (e.getKeyCode() == KeyEvent.VK_ENTER) { stepSignal.drainPermits(); stepSignal.release(); } } }; Runnable runner = new Runnable() { @Override public void run() { screen = new GameScreen(gamePanel, controlPanel, statusPanel); screen.pack(); gamePanel.addKeyListener(canvasKeyListener); controlPanel.addStepperListener(VisualAgent.this); } }; SwingUtilities.invokeLater(runner); }
From source file:me.mayo.telnetkek.MainPanel.java
public void setup() { this.txtServer.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { @Override/*from ww w . j av a 2 s. co m*/ public void keyTyped(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ENTER) { MainPanel.this.triggerConnect(); } } }); this.loadServerList(); final URL icon = this.getClass().getResource("/icon.png"); if (icon != null) { setIconImage(Toolkit.getDefaultToolkit().createImage(icon)); } setupTablePopup(); this.getConnectionManager().updateTitle(false); this.tblPlayers.setModel(playerListTableModel); this.tblPlayers.getRowSorter().toggleSortOrder(0); this.setLocationRelativeTo(null); this.setVisible(true); }
From source file:org.openCage.gpad.UI2File.java
public UI2File(@NotNull JTextArea area, @NotNull BackgroundExecutor executor, @NotNull Localize localize, @NotNull File file) {/*from w w w . j a va2s . co m*/ this.textArea = area; this.localize = localize; this.file = file; executor.addPeriodicAndExitTask(new FV() { @Override public void call() { write(); } }); textArea.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (textArea.isEditable() && !changed) { changed = true; } } }); init(); setInitialText(); }
From source file:uk.co.markfrimston.tasktree.Main.java
public Main(TaskTree taskTree) { super();/* w w w . ja v a 2 s .c o m*/ this.taskTree = taskTree; this.setTitle("Task Tree"); this.setSize(new Dimension(300, 500)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel quickInPanel = new JPanel(new BorderLayout()); this.quickIn = new JTextArea(); this.quickIn.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_ENTER) { String newText = quickIn.getText().trim(); if (newText != null && newText.length() > 0) { addTask(Main.this.taskTree.getRoot(), 0, newText, true); try { Main.this.taskTree.changesMade(); } catch (Exception e) { error(e.getMessage()); } } quickIn.setText(""); } } }); this.quickIn.setPreferredSize(new Dimension(300, 75)); this.quickIn.setBorder(BorderFactory.createTitledBorder("Quick Input")); quickInPanel.add(this.quickIn, BorderLayout.CENTER); this.syncButton = new JButton("Sync"); this.syncButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new SyncThread(Main.this).start(); } }); quickInPanel.add(this.syncButton, BorderLayout.EAST); this.getContentPane().add(quickInPanel, BorderLayout.NORTH); this.tree = new JTree(taskTree.getTreeModel()); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object newVal = htmlFilter(String.valueOf(node.getUserObject())); if (node.getChildCount() > 0 && !tree.isExpanded(new TreePath(node.getPath()))) { DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) node.getFirstLeaf(); newVal = htmlFilter(String.valueOf(node.getUserObject())) + " <span style='color:silver;font-style:italic'>" + "(" + String.valueOf(firstLeaf.getUserObject()) + ")</span>"; } newVal = "<html>" + newVal + "</html>"; return super.getTreeCellRendererComponent(tree, newVal, selected, expanded, leaf, row, hasFocus); } }; ImageIcon bulletIcon = new ImageIcon(Main.class.getResource("bullet.gif")); renderer.setLeafIcon(bulletIcon); renderer.setOpenIcon(bulletIcon); renderer.setClosedIcon(bulletIcon); renderer.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0)); this.tree.setCellRenderer(renderer); this.tree.setRootVisible(false); this.tree.setShowsRootHandles(true); this.tree.addMouseListener(new MouseAdapter() { protected void doSelectRow(MouseEvent arg0) { int row = tree.getRowForLocation(arg0.getX(), arg0.getY()); if (row != -1) { tree.setSelectionRow(row); if (arg0.isPopupTrigger()) { popup.show(tree, arg0.getX(), arg0.getY()); } } } public void mousePressed(MouseEvent arg0) { doSelectRow(arg0); } public void mouseReleased(MouseEvent arg0) { doSelectRow(arg0); } }); JScrollPane treeScroll = new JScrollPane(tree); treeScroll.setBorder(BorderFactory.createTitledBorder("Task List")); this.getContentPane().add(treeScroll, BorderLayout.CENTER); this.popup = new JPopupMenu(); JMenuItem addBefore = new JMenuItem("Add Before"); addBefore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected); promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addBefore); JMenuItem addAfter = new JMenuItem("Add After"); addAfter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected) + 1; promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addAfter); JMenuItem addNested = new JMenuItem("Add Nested"); addNested.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); int pos = selected.getChildCount(); promptAndInsert(selected, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { ex.getMessage(); } } }); this.popup.add(addNested); this.popup.add(new JSeparator()); JMenuItem moveTop = new JMenuItem("Move to Top"); moveTop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, 0); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveTop); JMenuItem moveUp = new JMenuItem("Move Up"); moveUp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.max(parent.getIndex(selected) - 1, 0); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveUp); JMenuItem moveDown = new JMenuItem("Move Down"); moveDown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.min(parent.getIndex(selected) + 1, parent.getChildCount() - 1); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveDown); JMenuItem moveBottom = new JMenuItem("Move to Bottom"); moveBottom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, parent.getChildCount() - 1); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveBottom); this.popup.add(new JSeparator()); JMenuItem rename = new JMenuItem("Edit"); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); String newText = prompt((String) selected.getUserObject()); if (newText != null && newText.length() > 0) { selected.setUserObject(newText); Main.this.taskTree.getTreeModel().reload(selected); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } } }); this.popup.add(rename); JMenuItem delete = new JMenuItem("Delete"); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptAndRemove(getSelectedNode()); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(delete); this.setVisible(true); loadConfig(); load(); syncButton.setVisible(this.taskTree.hasSyncCapability()); }
From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboLicenseName.java
public JComboLicenseName() { final JTextField editor; this.initLicenseComboBox(); this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (isEnabled()) { if (e.getActionCommand().equals("comboBoxChanged") || e.getActionCommand().equals("comboBoxEdited")) { if (getSelectedIndex() > 0) { setSelectedIndex(getSelectedIndex()); IdentifyMediator.getInstance() .setSelectedLicenseName(String.valueOf(getSelectedItem())); log.debug("selected license name : " + IdentifyMediator.getInstance().getSelectedLicenseName()); } else { IdentifyMediator.getInstance().setSelectedLicenseName(""); }/* w w w .jav a 2 s . c o m*/ } } } }); editor = (JTextField) this.getEditor().getEditorComponent(); editor.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { char ch = e.getKeyChar(); if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch))) return; if (ch == KeyEvent.VK_ENTER) { hidePopup(); return; } String str = editor.getText(); if (getComponentCount() > 0) { removeAllItems(); } addItem(str); try { String tmpLicense = null; ArrayList<String> AllLicenseList = new ArrayList<String>(); AllLicenseList = LicenseAPIWrapper.getAllLicenseList(); if (str.length() > 0) { for (int i = 0; i < AllLicenseList.size(); i++) { tmpLicense = AllLicenseList.get(i); if (tmpLicense.toLowerCase().startsWith(str.toLowerCase())) addItem(tmpLicense); } } else { for (int i = 0; i < AllLicenseList.size(); i++) { addItem(AllLicenseList.get(i)); } } } catch (Exception e1) { log.warn(e1.getMessage()); } hidePopup(); if (str.length() > 0) showPopup(); } }); editor.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { if (editor.getText().length() > 0) showPopup(); } public void focusLost(FocusEvent e) { hidePopup(); } }); }
From source file:com.sec.ose.osi.ui.frm.main.identification.JComboProjectName.java
public JComboProjectName() { this.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); this.setEditable(true); this.setPreferredSize(new Dimension(400, 27)); this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { long start = System.currentTimeMillis(); actionOnProjectSelectedonProjectComboBox(); long end = System.currentTimeMillis(); log.debug(/*w w w .j a v a 2 s .co m*/ "[JComboProjectName.addActionListener()] Project Loding TIME : " + (end - start) / 1000.0); } }); final JTextField editor = (JTextField) this.getEditor().getEditorComponent(); editor.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { char ch = e.getKeyChar(); int count = 0; String newProjectName = editor.getText(); if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch))) { return; } if (newProjectName.length() <= 0 && ch == KeyEvent.VK_BACK_SPACE) { count++; if (count >= 2) { String projectName = IdentifyMediator.getInstance().getSelectedProjectName(); ((JTextField) JComboProjectName.this.getEditor().getEditorComponent()).setText(projectName); count = 0; return; } } if (JComboProjectName.this.getComponentCount() > 0) { JComboProjectName.this.removeAllItems(); } JComboProjectName.this.addItem(newProjectName); try { Collection<OSIProjectInfo> ProjectsInfo = OSIProjectInfoMgr.getInstance().getAllProjects(); String tmpProName = null; boolean bAnalysis = false; if (newProjectName.length() > 0) { for (OSIProjectInfo projectInfo : ProjectsInfo) { tmpProName = projectInfo.getProjectName(); bAnalysis = projectInfo.isAnalyzed(); if (tmpProName.toLowerCase().contains(newProjectName.toLowerCase()) && bAnalysis) JComboProjectName.this.addItem(tmpProName); } if (JComboProjectName.this.getItemCount() <= 1) { JComboProjectName.this.removeAllItems(); JOptionPane.showOptionDialog(null, "There is no project.", "Project Filter", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, buttonOK, "OK"); } } else { for (OSIProjectInfo projectInfo : ProjectsInfo) { if (projectInfo.isManaged() == true && projectInfo.isAnalyzed()) { JComboProjectName.this.addItem(projectInfo.getProjectName()); } } JComboProjectName.this.addItem(DIVIDER_LINE); for (OSIProjectInfo projectInfo : ProjectsInfo) { if (projectInfo.isManaged() == false && projectInfo.isAnalyzed()) { JComboProjectName.this.addItem(projectInfo.getProjectName()); } } ((JTextField) JComboProjectName.this.getEditor().getEditorComponent()).setText(""); } } catch (Exception e1) { log.warn(e1.getMessage()); } JComboProjectName.this.hidePopup(); if (newProjectName.length() > 0) JComboProjectName.this.showPopup(); } }); }
From source file:ve.zoonosis.controller.funcionales.CrearEspecieController.java
@Override public final void inicializar() { iniForm();/*from w w w. jav a2 s . c o m*/ ct = -1; registrarEspecie.setEnabled(false); registrarAnimal.setEnabled(false); try { rb = new RequestBuilder("services/funcionales/EspecieWs/ListaEspecies.php"); List<Especie> especiess = rb.ejecutarJson(List.class, Especie.class); especies.setModel(new DefaultComboBoxModel(especiess.toArray())); especies.setSelectedIndex(-1); AutoCompleteDecorator.decorate(especies); } catch (URISyntaxException | RuntimeException ex) { LOG.LOGGER.log(Level.SEVERE, null, ex); } RestrictedTextField r = new RestrictedTextField(nombreEspecie); r.setLimit(45); r.setOnlyLetter(true); RestrictedTextField r3 = new RestrictedTextField(nombreAnimal); r3.setLimit(45); r3.setOnlyLetter(true); nombreEspecie.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { registrarEspecie.setEnabled(validarEspecie()); } }); nombreAnimal.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { registrarAnimal.setEnabled(validarAnimal()); } }); especies.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { registrarAnimal.setEnabled(validarAnimal()); } }); registrarEspecie.addActionListener(new ResgistrarEspecie()); registrarAnimal.addActionListener(new ResgistrarAnimal()); iniciarDialogo(); }
From source file:edu.harvard.mcz.imagecapture.ui.FilteringAgentJComboBox.java
private void init() { // listen for loss of focus on the text field this.getEditor().getEditorComponent().addFocusListener(this); this.setEditable(true); final JTextField textfield = (JTextField) this.getEditor().getEditorComponent(); textfield.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent keyEvent) { log.debug(keyEvent);/* ww w . j a v a2 s .co m*/ SwingUtilities.invokeLater(new Runnable() { public void run() { filter(textfield.getText(), true); } }); } }); }
From source file:sturesy.core.ui.loaddialog.TreeListPair.java
private void registerListeners() { _fileTree.registerListener(folder -> informSourceListChanged(true)); _ui.getContentList().addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent keyEvent) { informContentListKeyEvent(keyEvent.getKeyCode()); }/*from ww w . jav a 2 s . com*/ }); }