List of usage examples for java.awt.event FocusListener FocusListener
FocusListener
From source file:com.t3.macro.api.functions.input.ColumnPanel.java
/** Adjusts the runtime behavior of controls. Called when displayed. */ public void runtimeFixup() { // When first displayed, the focus will go to the first field. lastFocus = findFirstFocusable();/*from w ww . j av a 2 s . co m*/ // When a field gains the focus, save it in lastFocus. FocusListener listener = new FocusListener() { @Override public void focusGained(FocusEvent fe) { JComponent src = (JComponent) fe.getSource(); lastFocus = src; if (src instanceof JTextField) ((JTextField) src).selectAll(); // // debugging // String s = (src instanceof JTextField) ? // " (" + ((JTextField)src).getText() + ")" : ""; // System.out.println(" Got focus " + src.getClass().getName() + s); } @Override public void focusLost(FocusEvent arg0) { } }; for (JComponent c : inputFields) { // Each control saves itself to lastFocus when it gains focus. c.addFocusListener(listener); // Implement control-specific adjustments if (c instanceof ColumnPanel) { ColumnPanel cp = (ColumnPanel) c; cp.runtimeFixup(); } } if (lastFocus != null) scrollRectToVisible(lastFocus.getBounds()); }
From source file:com.github.cric.app.ui.SettingPanel.java
private JTextField textField(String defaultValue, boolean isInt) { JTextField field = new JTextField(defaultValue); addBorder(field, Color.GRAY); field.addFocusListener(new FocusListener() { @Override/* w w w .j av a 2 s .c o m*/ public void focusLost(FocusEvent e) { handleFocusLost(field, isInt); } @Override public void focusGained(FocusEvent e) { addBorder(field, Color.GRAY); field.selectAll(); } }); return field; }
From source file:com.dbschools.quickquiz.client.giver.MainWindow.java
private void customizeDefaultButtonHandling() { final FocusListener focusListener = new FocusListener() { public final void focusGained(final FocusEvent e) { final Component comp = e.getComponent(); final JRootPane pane = getRootPane(); if (comp == txtChatLine) { pane.setDefaultButton(btnSendChatLine); } else if (comp == cbxQuestions || comp == txtTimeLimit) { pane.setDefaultButton(btnSendQuestion); } else if (comp == sprPoints) { pane.setDefaultButton(btnAwardPoints); }//from w w w .ja v a 2 s.com } public void focusLost(FocusEvent e) { // Ignore } }; txtChatLine.addFocusListener(focusListener); cbxQuestions.addFocusListener(focusListener); txtTimeLimit.addFocusListener(focusListener); sprPoints.addFocusListener(focusListener); }
From source file:net.minelord.gui.panes.IRCPane.java
public IRCPane() { super();//from w ww . j a v a 2 s. c o m this.setBorder(new EmptyBorder(5, 5, 5, 5)); this.setLayout(null); nickSelectPane = new JPanel(); nickSelectPane.setLayout(null); nickSelectPane.setBounds(325, 70, 200, 200); TitledBorder title = BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Pick a nick"); title.setTitleJustification(TitledBorder.RIGHT); nickSelectPane.setBorder(title); nickSelect = new JTextField(); final JButton done = new JButton("Done"); nickSelect.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { String nick = nickSelect.getText(); boolean success = true; if (nick.length() > 0) { if (nick.substring(0, 1).matches("[0-9]") || nick.charAt(0) == '-' || nick.contains(" ")) success = false; } else success = false; if (success) IRCPane.nick = nick; done.setEnabled(success); } @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == 10) done.doClick(); } }); nickSelect.setBounds(50, 65, 100, 30); done.setBounds(50, 125, 100, 30); done.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { remove(nickSelectPane); repaint(); startClient(nickSelect.getText()); } }); done.setEnabled(false); nickSelectPane.add(nickSelect); nickSelectPane.add(done); add(nickSelectPane); addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent paramFocusEvent) { } @Override public void focusGained(FocusEvent paramFocusEvent) { if (nickSelectPane.getParent() != null) nickSelect.requestFocus(); if (input != null && input.getParent() != null) input.requestFocus(); } }); instance = this; }
From source file:org.esa.snap.ui.tooladapter.dialogs.ToolParameterEditorDialog.java
public JPanel createMainPanel() { GridBagLayout layout = new GridBagLayout(); layout.columnWidths = new int[] { 100, 390 }; mainPanel = new JPanel(layout); addTextPropertyEditor(mainPanel, "Name: ", "name", parameter.getName(), 0, true); addTextPropertyEditor(mainPanel, "Alias: ", "alias", parameter.getAlias(), 1, true); //dataType// w ww . j a v a2 s . c o m mainPanel.add(new JLabel("Type"), getConstraints(2, 0, 1)); JComboBox comboEditor = new JComboBox(typesMap.keySet().toArray()); comboEditor.setSelectedItem(typesMap.getKey(parameter.getDataType())); comboEditor.addActionListener(ev -> { JComboBox cb = (JComboBox) ev.getSource(); String typeName = (String) cb.getSelectedItem(); if (!parameter.getDataType().equals(typesMap.get(typeName))) { parameter.setDataType((Class<?>) typesMap.get(typeName)); //reset value set parameter.setValueSet(null); paramContext.getPropertySet().getProperty(parameter.getName()).getDescriptor().setValueSet(null); try { valuesContext.getPropertySet().getProperty("valueSet").setValue(null); } catch (ValidationException e) { logger.warning(e.getMessage()); } //editor must updated try { if (editorComponent != null) { mainPanel.remove(editorComponent); } editorComponent = uiWrapper.reloadUIComponent((Class<?>) typesMap.get(typeName)); if (!("File".equals(typeName) || "List".equals(typeName))) { editorComponent.setInputVerifier(new TypedValueValidator( "The value entered is not of the specified data type", parameter.getDataType())); } mainPanel.add(editorComponent, getConstraints(3, 1, 1)); mainPanel.revalidate(); } catch (Exception e) { logger.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } } }); mainPanel.add(comboEditor, getConstraints(2, 1, 1)); //defaultValue mainPanel.add(new JLabel("Default value"), getConstraints(3, 0, 1)); try { editorComponent = uiWrapper.getUIComponent(); mainPanel.add(editorComponent, getConstraints(3, 1, 1)); } catch (Exception e) { e.printStackTrace(); } addTextPropertyEditor(mainPanel, "Description: ", "description", parameter.getDescription(), 4, false); addTextPropertyEditor(mainPanel, "Label: ", "label", parameter.getLabel(), 5, false); addTextPropertyEditor(mainPanel, "Unit: ", "unit", parameter.getUnit(), 6, false); addTextPropertyEditor(mainPanel, "Interval: ", "interval", parameter.getInterval(), 7, false); JComponent valueSetEditor = addTextPropertyEditor(mainPanel, "Value set: ", "valueSet", StringUtils.join(parameter.getValueSet(), ArrayConverter.SEPARATOR), 8, false); valueSetEditor.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { } @Override public void focusLost(FocusEvent ev) { //the value set may impact the editor try { String newValueSet = ((JTextField) valueSetEditor).getText(); if (newValueSet.isEmpty()) { parameter.setValueSet(null); valuesContext.getPropertySet().getProperty("valueSet").setValue(null); } else { parameter.setValueSet(newValueSet.split(ArrayConverter.SEPARATOR)); valuesContext.getPropertySet().getProperty("valueSet") .setValue(newValueSet.split(ArrayConverter.SEPARATOR)); } if (editorComponent != null) { mainPanel.remove(editorComponent); } createContextForValueEditor(); if (!(File.class.equals(parameter.getDataType()) || parameter.getDataType().isArray())) { editorComponent.setInputVerifier(new TypedValueValidator( "The value entered is not of the specified data type", parameter.getDataType())); } mainPanel.add(editorComponent, getConstraints(3, 1, 1)); mainPanel.revalidate(); } catch (Exception e) { logger.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } } }); addTextPropertyEditor(mainPanel, "Condition: ", "condition", parameter.getCondition(), 9, false); addTextPropertyEditor(mainPanel, "Pattern: ", "pattern", parameter.getPattern(), 10, false); addTextPropertyEditor(mainPanel, "Format: ", "format", parameter.getFormat(), 11, false); addBoolPropertyEditor(mainPanel, "Not null", "notNull", parameter.isNotNull(), 12); addBoolPropertyEditor(mainPanel, "Not empty", "notEmpty", parameter.isNotEmpty(), 13); addTextPropertyEditor(mainPanel, "ItemAlias: ", "itemAlias", parameter.getItemAlias(), 14, false); addBoolPropertyEditor(mainPanel, "Deprecated", "deprecated", parameter.isDeprecated(), 15); return mainPanel; }
From source file:ome.formats.importer.gui.ImportDialog.java
/** * Display a dialog so the user can choose project/dataset for importing * //from w w w . jav a 2 s .c o m * @param config - ImportConfig * @param owner - parent frame * @param title - dialog title * @param modal - modal yes/no * @param store - Initialized OMEROMetadataStore */ ImportDialog(ImportConfig config, JFrame owner, String title, boolean modal, OMEROMetadataStoreClient store) { this.store = store; if (store != null) { projectItems = ProjectItem.createProjectItems(store.getProjects()); } setLocation(200, 200); setTitle(title); setModal(modal); setResizable(false); setSize(new Dimension(dialogWidth, dialogHeight)); setLocationRelativeTo(owner); tabbedPane = new JTabbedPane(); tabbedPane.setOpaque(false); // content panes must be opaque this.config = config; /////////////////////// START IMPORT PANEL //////////////////////// // Set up the import panel for tPane, quit, and send buttons double mainTable[][] = { { TableLayout.FILL, 120, 5, 160, TableLayout.FILL }, // columns { TableLayout.PREFERRED, 10, TableLayout.PREFERRED, TableLayout.FILL, 40, 30 } }; // rows importPanel = GuiCommonElements.addMainPanel(tabbedPane, mainTable, 0, 10, 0, 10, debug); String message = "Import these images into which dataset?"; GuiCommonElements.addTextPane(importPanel, message, "0, 0, 4, 0", debug); // Set up the project/dataset table double pdTable[][] = { { TableLayout.FILL, 5, 40 }, // columns { 35, 35 } }; // rows // Panel containing the project / dataset layout pdPanel = GuiCommonElements.addMainPanel(importPanel, pdTable, 0, 0, 0, 0, debug); pbox = GuiCommonElements.addComboBox(pdPanel, "Project: ", projectItems, 'P', "Select dataset to use for this import.", 60, "0,0,F,C", debug); pbox.addActionListener(this); // Fixing broken mac buttons. String offsetButtons = ",C"; //if (GuiCommonElements.offsetButtons == true) offsetButtons = ",t"; addProjectBtn = GuiCommonElements.addIconButton(pdPanel, "", addIcon, 20, 60, null, null, "2,0,f" + offsetButtons, debug); addProjectBtn.addActionListener(this); dbox = GuiCommonElements.addComboBox(pdPanel, "Dataset: ", datasetItems, 'D', "Select dataset to use for this import.", 60, "0,1,F,C", debug); dbox.setEnabled(false); addDatasetBtn = GuiCommonElements.addIconButton(pdPanel, "", addIcon, 20, 60, null, null, "2,1,f" + offsetButtons, debug); addDatasetBtn.addActionListener(this); //addDatasetBtn.setEnabled(false); importPanel.add(pdPanel, "0, 2, 4, 2"); // File naming section double namedTable[][] = { { 30, TableLayout.FILL }, // columns { 24, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL } }; // rows namedPanel = GuiCommonElements.addBorderedPanel(importPanel, namedTable, "File Naming", debug); String fullPathTooltip = "The full file+path name for the file. For example: \"c:/myfolder/mysubfolder/myfile.dv\""; String partPathTooltip = "A partial path and file name for the file. For example: \"mysubfolder/myfile.dv\""; fullPathButton = GuiCommonElements.addRadioButton(namedPanel, "the full path+file name of your file", 'u', fullPathTooltip, "1,1", debug); fullPathButton.addActionListener(this); partPathButton = GuiCommonElements.addRadioButton(namedPanel, "a partial path+file name with...", 'u', partPathTooltip, "1,2", debug); partPathButton.addActionListener(this); numOfDirectoriesField = GuiCommonElements.addWholeNumberField(namedPanel, "", "0", "of the directories immediately before it.", 0, "Add this number of directories to the file names", 3, 40, "1,3,L,C", debug); numOfDirectoriesField.addActionListener(this); numOfDirectoriesField.setText(Integer.toString(config.getNumOfDirectories())); // focus on the partial path button if you enter the numofdirfield numOfDirectoriesField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { partPathButton.setSelected(true); } public void focusLost(FocusEvent e) { } }); ButtonGroup group = new ButtonGroup(); group.add(fullPathButton); group.add(partPathButton); //if (config.useFullPath.get() == true ) if (config.getUserFullPath() == true) group.setSelected(fullPathButton.getModel(), true); else group.setSelected(partPathButton.getModel(), true); useCustomNamingChkBox = GuiCommonElements.addCheckBox(namedPanel, "Override default file naming. Instead use:", "0,0,1,0", debug); useCustomNamingChkBox.addActionListener(this); //if (config.useCustomImageNaming.get() == true) if (config.getCustomImageNaming() == true) { useCustomNamingChkBox.setSelected(true); enabledPathButtons(true); } else { useCustomNamingChkBox.setSelected(false); enabledPathButtons(false); } importPanel.add(namedPanel, "0, 3, 4, 2"); archiveImage = GuiCommonElements.addCheckBox(importPanel, "Archive the original imported file(s) to the server.", "0,4,4,4", debug); archiveImage.addActionListener(this); archiveImage.setSelected(config.archiveImage.get()); // Override config.archiveImage.get() if // import.config is set for forceFileArchiveOn if (config.getForceFileArchiveOn() == true) archiveImage.setSelected(true); if (ARCHIVE_ENABLED) { archiveImage.setVisible(true); } else { archiveImage.setVisible(false); } // Buttons at the bottom of the form cancelBtn = GuiCommonElements.addButton(importPanel, "Cancel", 'L', "Cancel", "1, 5, f, c", debug); cancelBtn.addActionListener(this); importBtn = GuiCommonElements.addButton(importPanel, "Add to Queue", 'Q', "Import", "3, 5, f, c", debug); importBtn.addActionListener(this); importBtn.setEnabled(false); this.getRootPane().setDefaultButton(importBtn); this.getRootPane().setDefaultButton(importBtn); GuiCommonElements.enterPressesWhenFocused(importBtn); /////////////////////// START METADATA PANEL //////////////////////// double metadataTable[][] = { { TableLayout.FILL }, // columns { TableLayout.FILL, 10, TableLayout.FILL } }; // rows metadataPanel = GuiCommonElements.addMainPanel(tabbedPane, metadataTable, 0, 10, 0, 10, debug); double pixelTable[][] = { { 10, TableLayout.FILL, 10, TableLayout.FILL, 10, TableLayout.FILL, 10 }, // columns { 68, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL } }; // rows pixelPanel = GuiCommonElements.addBorderedPanel(metadataPanel, pixelTable, "Pixel Size Defaults", debug); message = "These X, Y & Z pixel size values (typically measured in microns) " + "will be used if no values are included in the image file metadata:"; GuiCommonElements.addTextPane(pixelPanel, message, "1, 0, 6, 0", debug); xPixelSize = GuiCommonElements.addDecimalNumberField(pixelPanel, "X: ", null, "", 0, "", 8, 80, "1,1,L,C", debug); yPixelSize = GuiCommonElements.addDecimalNumberField(pixelPanel, "Y: ", null, "", 0, "", 8, 80, "3,1,L,C", debug); zPixelSize = GuiCommonElements.addDecimalNumberField(pixelPanel, "Z: ", null, "", 0, "", 8, 80, "5,1,L,C", debug); metadataPanel.add(pixelPanel, "0, 0"); double channelTable[][] = { { 10, TableLayout.FILL, 10, TableLayout.FILL, 10, TableLayout.FILL, 10 }, // columns { 68, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL } }; // rows channelPanel = GuiCommonElements.addBorderedPanel(metadataPanel, channelTable, "Channel Defaults", debug); rChannel = GuiCommonElements.addWholeNumberField(channelPanel, "R: ", "0", "", 0, "", 8, 80, "1,1,L,C", debug); gChannel = GuiCommonElements.addWholeNumberField(channelPanel, "G: ", "1", "", 0, "", 8, 80, "3,1,L,C", debug); bChannel = GuiCommonElements.addWholeNumberField(channelPanel, "B: ", "2", "", 0, "", 8, 80, "5,1,L,C", debug); message = "These RGB channel wavelengths (typically measured in nanometers)" + " will be used if no channel values are included in the image file metadata:"; GuiCommonElements.addTextPane(channelPanel, message, "1, 0, 6, 0", debug); //metadataPanel.add(channelPanel, "0, 2"); /////////////////////// START TABBED PANE //////////////////////// this.add(tabbedPane); tabbedPane.addTab("Import Settings", null, importPanel, "Import Settings"); tabbedPane.addTab("Metadata Defaults", null, metadataPanel, "Metadata Defaults"); getProjectDatasets(projectItems[0].getProject()); buildProjectsAndDatasets(); setVisible(true); }
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
/** * This method initializes jTextFieldUser * /* w ww . ja va2 s . co m*/ * @return javax.swing.JTextField */ private JTextField getJTextFieldUser() { if (jTextFieldUser == null) { jTextFieldUser = new JTextField(); jTextFieldUser.setPreferredSize(new Dimension(200, 22)); jTextFieldUser.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { mEventHandler.handle(EventHandler.TF_USER_ID); } }); jTextFieldUser.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { mEventHandler.handle(EventHandler.ENTER_KEY_TYTPED); } } }); jTextFieldUser.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { jTextFieldUser.selectAll(); } @Override public void focusLost(FocusEvent e) { jTextFieldUser.select(0, 0); } }); } return jTextFieldUser; }
From source file:org.pentaho.ui.xul.swing.SwingElement.java
public void setOnblur(final String method) { super.setOnblur(method); if (getJComponent() != null) { getJComponent().addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { invoke(method);/*from ww w . ja v a 2 s .com*/ } public void focusGained(FocusEvent e) { } }); } }
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
/** * This method initializes jPasswordField * /*from www .jav a2 s.c om*/ * @return javax.swing.JPasswordField */ private JPasswordField getJPasswordField() { if (jPasswordField == null) { jPasswordField = new JPasswordField(); jPasswordField.setPreferredSize(new Dimension(200, 22)); jPasswordField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { mEventHandler.handle(EventHandler.PTF_USER_PASSWORD); } }); jPasswordField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { mEventHandler.handle(EventHandler.ENTER_KEY_TYTPED); } } }); jPasswordField.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { jPasswordField.selectAll(); } @Override public void focusLost(FocusEvent e) { jPasswordField.select(0, 0); } }); } return jPasswordField; }
From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java
/** * //from w ww. j a v a 2 s .com */ public void createUI() { //setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setLayout(new BorderLayout()); setOpaque(false); textField = new JTextField(10); // we are going to handle focus traversal manually // so that we can do searches when 'tab' is pressed textField.setFocusTraversalKeysEnabled(false); setControlSize(textField); ImageIcon img = IconManager.getIcon("DropDownArrow", IconManager.IconSize.NonStd); //$NON-NLS-1$ dbBtn = UIHelper.isMacOS() ? new MacGradiantBtn(img) : new JButton(img); dbBtn.setFocusable(false); PanelBuilder pb = new PanelBuilder(new FormLayout("f:d:g,p", "f:p:g"), this); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); pb.add(textField, cc.xy(1, 1)); pb.add(dbBtn, cc.xy(2, 1)); textField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (ignoreTab && e.getKeyCode() == KeyEvent.VK_TAB) { ignoreTab = false; } else { cbxKeyReleased(e); } super.keyReleased(e); } @Override public void keyPressed(KeyEvent e) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } super.keyReleased(e); } }); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { prevEnteredText = textField.getText(); boolean oldWasCleared = wasCleared; if (!ignoreDocChange) { wasCleared = wasCleared || selectedId != null; idList.clear(); list.clear(); selectedId = null; if (oldWasCleared != wasCleared && wasCleared) { notifyListenersOfChange( StringUtils.isEmpty(prevEnteredText) ? null : TextFieldWithQuery.this); } } } }); StringBuilder sb = new StringBuilder(); for (String k : keyColumns) { String title = k; DBFieldInfo fi = tableInfo.getFieldByName(k); if (fi != null) { title = fi.getTitle(); } if (sb.length() > 0) sb.append(", "); sb.append(title); } textField.setToolTipText(UIRegistry.getFormattedResStr("TFWQ_SEARCHES_FLDS", sb.toString())); textField.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { if (e instanceof CausedFocusEvent) { switch (((CausedFocusEvent) e).getCause()) { case TRAVERSAL: case TRAVERSAL_BACKWARD: case TRAVERSAL_FORWARD: case TRAVERSAL_UP: case TRAVERSAL_DOWN: ignoreTab = true; } } } @Override public void focusLost(FocusEvent e) { int len = textField.getText().length(); if (len < 1) { setText(""); //$NON-NLS-1$ /////////////////////////////////////////////////////////////////////////////////// // We only want to generate a change event if it once had a value and then it is // cleared and the user tabs to a new control. - rods 02/28/08 /////////////////////////////////////////////////////////////////////////////////// if (wasCleared || selectedId != null) { notifyListenersOfChange(TextFieldWithQuery.this); } } textField.setCaretPosition(0); } }); dbBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } log.debug("currentText: " + currentText); doQuery(currentText, currentText, 0); } }); }