List of usage examples for java.awt.event KeyEvent VK_ENTER
int VK_ENTER
To view the source code for java.awt.event KeyEvent VK_ENTER.
Click Source Link
From source file:net.sf.jabref.gui.AutoCompleteListener.java
@Override public void keyPressed(KeyEvent e) { if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) { JTextComponent comp = (JTextComponent) e.getSource(); // replace typed characters by characters from completion lastBeginning = lastCompletions[lastShownCompletion]; int end = comp.getSelectionEnd(); comp.select(end, end);/*from www. ja v a2 s .c o m*/ toSetIn = null; if (consumeEnterKey) { e.consume(); } } // Cycle through alternative completions when user presses PGUP/PGDN: else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), 1); e.consume(); } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), -1); e.consume(); } // else if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) { // StringBuffer currentword = getCurrentWord((JTextComponent) e.getSource()); // // delete last char to obey semantics of back space // currentword.deleteCharAt(currentword.length()-1); // doCompletion(currentword, e); // } else if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { if (e.getKeyCode() != KeyEvent.VK_SHIFT) { // shift is OK, everyhting else leads to a reset resetAutoCompletion(); } else { LOGGER.debug("Special case: shift pressed. No action."); } } else { LOGGER.debug("Special case: defined character, but not caught above"); } }
From source file:com.emental.mindraider.ui.dialogs.NewRdfModelJDialog.java
/** * Constructor.// w w w . j ava2s . c o m */ public NewRdfModelJDialog() { super(Messages.getString("NewRdfModelJDialog.title")); JPanel framePanel = new JPanel(); framePanel.setLayout(new GridLayout(3, 1)); JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.RIGHT)); p.add(new JLabel(Messages.getString("NewRdfModelJDialog.subject"))); subjectNs = new JTextField(30); subjectNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS); p.add(subjectNs); p.add(new JLabel("#")); subjectLocalName = new JTextField(15); p.add(subjectLocalName); framePanel.add(p); p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.RIGHT)); final JCheckBox literalCheckBox = new JCheckBox("literal", false); p.add(literalCheckBox); framePanel.add(p); p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton addButton = new JButton(Messages.getString("NewRdfModelJDialog.create")); p.add(addButton); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { createModel(literalCheckBox); } }); JButton cancelButton = new JButton(Messages.getString("NewRdfModelJDialog.cancel")); p.add(cancelButton); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { NewRdfModelJDialog.this.dispose(); } }); framePanel.add(p); subjectLocalName.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) { createModel(literalCheckBox); } } public void keyReleased(KeyEvent keyEvent) { } public void keyTyped(KeyEvent keyEvent) { } }); getContentPane().add(framePanel, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { subjectLocalName.requestFocusInWindow(); } }); }
From source file:pipeline.parameter_cell_views.TextBox.java
public TextBox() { super();/*from ww w . j a va 2 s. c o m*/ setLayout(new GridBagLayout()); parameterName = new JLabel(""); textField = new JTextArea(currentValue); textField.getDocument().addDocumentListener(new valueListener()); // textField.setMinimumSize(new Dimension(150,40)); textField.setLineWrap(true); textField.addMouseListener(this); textField.addKeyListener(new KeyAdapter() { // from http://www.java.net/node/650657 @Override public void keyPressed(KeyEvent evt) { int iKey = evt.getKeyCode(); JComponent component = (JTextArea) evt.getComponent(); DefaultFocusManager focusManager = new DefaultFocusManager(); if ((iKey == KeyEvent.VK_ENTER) || // (iKey == KeyEvent.VK_DOWN) || (iKey == KeyEvent.VK_PAGE_UP) || (iKey == KeyEvent.VK_PAGE_DOWN) || (iKey == KeyEvent.VK_TAB)) { evt.consume(); focusManager.focusNextComponent(component); } // if (iKey == KeyEvent.VK_UP) // focusManager.focusPreviousComponent(component); } }); c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridheight = 2; c.weighty = 1.0; c.weightx = 1.0; c.gridwidth = 1; scrollPane = new JScrollPane(textField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); add(scrollPane, c); scrollPane.setPreferredSize(new Dimension(1000, 500)); scrollPane.setMinimumSize(new Dimension(10, 60)); c.weighty = 0; add(parameterName, c); parameterNameAdded = true; parameterName.setMinimumSize(new Dimension(100, 30)); }
From source file:com.googlecode.gmail4j.util.LoginDialog.java
/** * Creates the required listeners//w w w . jav a 2s . c om * * @param login Credentials object for filling the data */ private void createListeners(final Credentials login) { pass.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { setCredentials(login); dialog.setVisible(false); } } }); ok.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { setCredentials(login); dialog.setVisible(false); } }); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { log.warn("Login dialog closed, no username/password specified"); latch.countDown(); } }); }
From source file:com.emental.mindraider.ui.dialogs.OpenConceptByTagJDialog.java
public OpenConceptByTagJDialog(String dialogTitle, String selectionLabel, String buttonLabel, boolean showCancel) { super(dialogTitle); JPanel framePanel = new JPanel(); framePanel.setBorder(new EmptyBorder(5, 10, 0, 10)); framePanel.setLayout(new BorderLayout()); // NORTH panel JPanel northPanel = new JPanel(); northPanel.setLayout(new BorderLayout()); northPanel.add(new JLabel(selectionLabel), BorderLayout.NORTH); final JTextField tagLabel = new JTextField(TEXTFIELD_WIDTH); // data//from w ww .ja v a 2s . co m tags = MindRaider.tagCustodian.getAllTags(); ; if (tags == null) { tagLabel.setEnabled(false); } tagLabel.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) { logger.debug("Openning selected tag..."); openTagSearchDialog(); } } public void keyReleased(KeyEvent keyEvent) { getListModel().clear(); shownTags.clear(); if (tagLabel.getText().length() > 0) { for (TagEntry tag : tags) { if (tag.getTagLabel().toLowerCase().startsWith(tagLabel.getText().toLowerCase())) { getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")"); shownTags.add(tag); } } } else { // show all tags for (TagEntry tag : tags) { getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")"); shownTags.add(tag); } } } public void keyTyped(KeyEvent keyEvent) { } }); northPanel.add(tagLabel, BorderLayout.SOUTH); framePanel.add(northPanel, BorderLayout.NORTH); // CENTER panel JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout()); centerPanel.add(new JLabel(Messages.getString("OpenConceptByTagJDialog.matchingTags")), BorderLayout.NORTH); defaultListModel = new DefaultListModel(); list = new JList(defaultListModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); // list.addListSelectionListener(this); list.setVisibleRowCount(15); JScrollPane listScrollPane = new JScrollPane(list); centerPanel.add(listScrollPane, BorderLayout.SOUTH); framePanel.add(centerPanel, BorderLayout.CENTER); JPanel southPanel = new JPanel(); southPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton openButton = new JButton(buttonLabel); southPanel.add(openButton); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openTagSearchDialog(); } }); if (showCancel) { JButton cancelButton = new JButton(Messages.getString("OpenNotebookJDialog.cancel")); southPanel.add(cancelButton); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OpenConceptByTagJDialog.this.dispose(); } }); } framePanel.add(southPanel, BorderLayout.SOUTH); getContentPane().add(framePanel, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
@Override public void keyPressed(KeyEvent e) { if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) { JTextComponent comp = (JTextComponent) e.getSource(); // replace typed characters by characters from completion lastBeginning = lastCompletions.get(lastShownCompletion); int end = comp.getSelectionEnd(); comp.select(end, end);/*from www . j a va2 s .c o m*/ toSetIn = null; if (consumeEnterKey) { e.consume(); } } // Cycle through alternative completions when user presses PGUP/PGDN: else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), 1); e.consume(); } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), -1); e.consume(); } // else if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) { // StringBuffer currentword = getCurrentWord((JTextComponent) e.getSource()); // // delete last char to obey semantics of back space // currentword.deleteCharAt(currentword.length()-1); // doCompletion(currentword, e); // } else if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { if (e.getKeyCode() == KeyEvent.VK_SHIFT) { // shift is OK, everything else leads to a reset LOGGER.debug("Special case: shift pressed. No action."); } else { resetAutoCompletion(); } } else { LOGGER.debug("Special case: defined character, but not caught above"); } }
From source file:org.squidy.designer.zoom.NavigationShape.java
/** * Default constructor required for JAXB. *//*from w w w . j a v a 2 s. com*/ public NavigationShape() { super(); addInputEventListener(new PBasicInputEventHandler() { private JTextField titleInput = new JTextField(getTitle()); { titleInputWrapper = new JComponentWrapper(titleInput); titleInput.setFont(fontBreadcrumb); addChild(titleInputWrapper); // titleInputWrapper.setScale(2); ShapeUtils.setApparent(titleInputWrapper, false); titleInput.addKeyListener(new KeyAdapter() { /** * @param e */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (ShapeUtils.isApparent(titleInputWrapper)) { prepareTitleIfNecessary(); } } } }); } /** * Prepare title if user did new input and title is different than * current title. */ void prepareTitleIfNecessary() { String oldTitle = getTitle(); String newTitle = titleInput.getText(); if (!oldTitle.equals(newTitle)) { if (changeTitle(oldTitle, newTitle)) { setTitle(titleInput.getText()); ShapeUtils.setApparent(titleInputWrapper, false); invalidateTitle(); invalidateBreadcrumb(); invalidatePaint(); } } else { ShapeUtils.setApparent(titleInputWrapper, false); } } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseClicked * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseClicked(PInputEvent event) { if (!event.isHandled()) { switch (event.getClickCount()) { case 1: if (!event.getPickedNode().equals(titleInputWrapper) && ShapeUtils.isApparent(titleInputWrapper)) { prepareTitleIfNecessary(); event.setHandled(true); } break; case 2: Point2D p = event.getPositionRelativeTo(NavigationShape.this); if (titleBounds != null && titleBounds.contains(p)) { if (!ShapeUtils.isApparent(titleInputWrapper)) { titleInputWrapper.setOffset(titleBounds.getX(), titleBounds.getY()); titleInput.setText(getTitle()); // titleInput.requestFocus(); ShapeUtils.setApparent(titleInputWrapper, true); } event.setHandled(true); } break; } } } }); }
From source file:vincent.DynamicDataDemo.java
/** * Constructs a new demonstration application. * // w w w . j a va 2 s . c o m * @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:experiments.SimpleExample.java
public void runga(int ng, int chromeSize, int popsize, double left, double right, FitnessFunction fitnessfun, BufferedWriter output) {//from w w w .j a v a2s . com long startTime = System.currentTimeMillis(); int numEvolutions = ng; Configuration gaConf = new DefaultConfiguration(); gaConf.reset(); gaConf.setPreservFittestIndividual(true); gaConf.setKeepPopulationSizeConstant(false); gaConf.getGeneticOperators().clear(); try { gaConf.addGeneticOperator(new MutationOperator(gaConf, new KeyboardMutationRateCalc(gaConf, 0.01, 0.1, 0.05, chromeSize))); gaConf.addGeneticOperator(new CrossoverOperator(gaConf, new KeyboardCrossoverRateCalc(gaConf, 0.7, 0.99, 0.8, chromeSize))); } catch (InvalidConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Genotype genotype = null; try { //(Gene) Gene[] sampleGenes = new Gene[chromeSize];//2 for (int i = 0; i < sampleGenes.length; i++) { sampleGenes[i] = new DoubleGene(gaConf, left, right); } // (Chromosome) IChromosome sampleChromosome = new Chromosome(gaConf, sampleGenes); gaConf.setSampleChromosome(sampleChromosome); gaConf.setPopulationSize(popsize); gaConf.setFitnessFunction(fitnessfun); genotype = Genotype.randomInitialGenotype(gaConf); } catch (InvalidConfigurationException e) { e.printStackTrace(); System.exit(-2); } // JOptionPane.showMessageDialog(frame.getContentPane(), // "?ing!", "?", JOptionPane.INFORMATION_MESSAGE); JFreeChart jfc = createChart(); frame = new JFrame("Test Chart"); frame.getContentPane().add(new ChartPanel(jfc), new BorderLayout().CENTER); frame.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { int ch = e.getKeyCode(); switch (ch) { case KeyEvent.VK_ENTER: flag = false; break; case KeyEvent.VK_SPACE: flag2 = !flag2; break; case 37: Older.downc(); break; case 38: Older.downm(); break; case 39: Older.upc(); break; case 40: Older.upm(); break; default: break; } } }); frame.pack(); frame.setVisible(true); int progress = 0; int percentEvolution = numEvolutions / 10; int i = 0; while (flag) { // for (int i = 0; i < numEvolutions; i++) { if (flag2) { genotype.evolve(); IChromosome fittest = genotype.getFittestChromosome(); double fitness = fittest.getFitnessValue(); fitlist.add(fitness); jfc = createChart(); frame.getContentPane().removeAll(); frame.getContentPane().add(new ChartPanel(jfc), new BorderLayout().CENTER); frame.pack(); frame.setVisible(true); System.out.println("mutation: " + Older.old_mutation); System.out.println("crossover: " + Older.old_crossover); // Print progress. // --------------- if (percentEvolution > 0 && i % percentEvolution == 0) { progress++; System.out.println("Currently fittest Chromosome has fitness " + fitness); } } i++; // if(i>15000)break; } // Print summary. // -------------- IChromosome fittest = genotype.getFittestChromosome(); System.out.println("Fittest Chromosome has fitness " + (fittest.getFitnessValue())); try { output.write(fittest.getFitnessValue() + "\t"); DecimalFormat myformat = new DecimalFormat("#0.00"); for (int ii = 0; ii < chromeSize; ii++) { // System.out.println(myformat.format(((DoubleGene)fittest.getGene(i)).doubleValue())); System.out.print(myformat.format(fittest.getGene(ii).getAllele()) + " "); // output.write(myformat // .format(fittest.getGene(i).getAllele()) + " "); } System.out.println(); output.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("? " + (endTime - startTime) + "ms"); System.out.println("sum counts: " + MaxFunction.counts); }
From source file:com.declarativa.interprolog.gui.Ini.java
public Ini(AbstractPrologEngine e, boolean autoDisplay) { /// super("PrologEngine listener (Swing)"); System.out.println("ENTRA"); if (e != null) { engine = e;/*from w w w .j a va2 s . c o m*/ } else { throw new IPException("missing Prolog engine"); } String VF = e.getImplementationPeer().visualizationFilename(); if (engine.getLoadFromJar()) { engine.consultFromPackage(VF, Ini.class); } else { engine.consultRelative(VF, Ini.class); } engine.teachMoreObjects(guiExamples()); if (engine == null) { dispose(); // no interface object permitted! } else { topLevelCount++; } debug = engine.isDebug(); loadedFiles = new Vector(); initComponents(); //constructWindowContents(); /// constructMenu(); addWindowListener(this); prologInput.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { // sendToProlog(); e.consume(); } } }); //prologOutput.append("Welcome to an InterProlog top level\n" + e.getPrologVersion() + "\n\n"); prologOutput.append("\n ARG ENGINE v18 ALPHA "); prologOutput.append("\t Argument Engine based on WFS \n\n"); prologOutput.append("\t UIKM Group - Umea University \n\n"); prologOutput.append("\t {esteban, jcnieves, helena}@cs.umu.se \n\n"); if (autoDisplay) { setVisible(true); // focusInput(); } }