List of usage examples for java.awt.event FocusEvent getSource
public Object getSource()
From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java
@Override public void focusLost(FocusEvent e) { if (e.getSource() == table) { // Propagate the event final FocusListener[] listeners = getListeners(FocusListener.class); if (listeners != null) { final FocusEvent event = new FocusEvent(this, e.getID(), e.isTemporary(), e.getOppositeComponent()); for (FocusListener listener : listeners) { listener.focusLost(event); }/*from w w w . j ava 2s.c o m*/ } } }
From source file:com.github.fritaly.dualcommander.DualCommander.java
@Override public void focusGained(FocusEvent e) { if (e.getSource() == leftPane) { this.activePane = leftPane; if (logger.isDebugEnabled()) { logger.debug("Active pane is now left"); }//from w ww . j av a 2s .c o m } else if (e.getSource() == rightPane) { this.activePane = rightPane; if (logger.isDebugEnabled()) { logger.debug("Active pane is now right"); } } }
From source file:com.github.fritaly.dualcommander.DualCommander.java
@Override public void focusLost(FocusEvent e) { if (e.getSource() == leftPane) { this.activePane = null; if (logger.isDebugEnabled()) { logger.debug("Active pane is now null"); }/*from w ww .java 2s.c om*/ } else if (e.getSource() == rightPane) { this.activePane = null; if (logger.isDebugEnabled()) { logger.debug("Active pane is now null"); } } }
From source file:com.att.aro.ui.view.menu.tools.RegexWizard.java
@Override public void focusLost(FocusEvent e) { JTextArea field = (JTextArea) e.getSource(); if (field.getName().equals(requestField.getName())) { setRequestHighlightedText(field.getSelectedText()); updateFocus(true, false, false); } else if (field.getName().equals(headerField.getName())) { setHeaderHighlightedText(field.getSelectedText()); updateFocus(false, false, true); } else if (field.getName().equals(responseField.getName())) { setResponseHighlightedText(field.getSelectedText()); updateFocus(false, true, false); } else {// if(field.getName().equals(regexRequestField.getName()) || field.getName().equals(regexResponseField.getName()) || // field.getName().equals(regexHeaderField.getName())){ clearHighlightedTexts();// w w w.ja va 2 s. c o m if (field.getName().equals(regexRequestField.getName())) { updateFocus(true, false, false); } else if (field.getName().equals(regexResponseField.getName())) { updateFocus(false, true, false); } else { updateFocus(false, false, true); } } }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextField.java
/** * @param textField/* www .j av a 2 s . c om*/ */ protected void addFocusAdapter(final JTextField textField) { textField.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { ((JTextField) e.getSource()).selectAll(); repaint(); } @Override public void focusLost(FocusEvent e) { isNew = false; validateState(); repaint(); } }); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java
/** * Creates the proper UI component for the Mapping item. * @param dbFieldType the field type// w w w .j a va 2 s .c om * @param caption the caption * @param fieldName the name of the field * @param dataFieldLength the length of the definition for that field * @param fieldType the field type * @return a UI component for editing */ protected JComponent createUIComp(final Class<?> dbFieldTypeArg, final String caption, final String fieldName, final Short fieldType, final Short fieldLength, final short columns, final short rows, final WorkbenchTemplateMappingItem wbtmi) { short uiType = WorkbenchTemplateMappingItem.UNKNOWN; //System.out.println(wbtmi.getCaption()+" "+wbtmi.getDataType()+" "+wbtmi.getFieldLength()); Class<?> dbFieldType = dbFieldTypeArg; if (dbFieldType == null) { // if we can't find a class for the field (i.e. Genus Species, or other 'fake' fields), we say it's a string dbFieldType = String.class; } JComponent comp; Component focusComp; // handle dates if (dbFieldType.equals(Calendar.class) || dbFieldType.equals(Date.class)) { //ValFormattedTextField txt = new ValFormattedTextField("Date"); //txt.setColumns(columns == -1 ? DEFAULT_TEXTFIELD_COLS : columns); ValTextField txt = new ValTextField(columns); txt.getDocument().addDocumentListener(docListener); comp = txt; focusComp = comp; uiType = WorkbenchTemplateMappingItem.TEXTFIELD_DATE; } // else if (dbFieldType.equals(Boolean.class)) // strings // { // ValCheckBox checkBox = new ValCheckBox(caption, false, false); // checkBox.addChangeListener(changeListener); // comp = checkBox; // focusComp = comp; // uiType = WorkbenchTemplateMappingItem.CHECKBOX; // } else if (useComboBox(wbtmi)) { //ValComboBox comboBox = new ValComboBox(getValues(wbtmi), true); final JComboBox comboBox = new JComboBox(getValues(wbtmi)); comboBox.setName("Form Combo"); comboBox.setEditable(true); comboBox.addActionListener(new ActionListener() { /* (non-Javadoc) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(ActionEvent arg0) { if (arg0.getSource() == comboBox) { //System.out.println("ComboBox Action!" + ((JComboBox )arg0.getSource()).getName()); stateChange(); } } }); // comboBox.getEditor().getEditorComponent().addFocusListener(new FocusListener() { // // /* (non-Javadoc) // * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent) // */ // @Override // public void focusGained(FocusEvent arg0) { // System.out.println("FOCUS GAINED"); // // } // // /* (non-Javadoc) // * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent) // */ // @Override // public void focusLost(FocusEvent arg0) { // System.out.println("FOCUS LOST"); // // } // // }); comp = comboBox; focusComp = comp; uiType = WorkbenchTemplateMappingItem.COMBOBOX; } else if (useTextField(fieldName, fieldType, fieldLength)) { ValTextField txt = new ValTextField(columns); txt.getDocument().addDocumentListener(docListener); txt.setInputVerifier(new LengthInputVerifier(caption, fieldLength)); comp = txt; focusComp = comp; uiType = WorkbenchTemplateMappingItem.TEXTFIELD; } else { JScrollPane taScrollPane = createTextArea(columns, rows); ((JTextArea) taScrollPane.getViewport().getView()) .setInputVerifier(new LengthInputVerifier(caption, fieldLength)); comp = taScrollPane; focusComp = taScrollPane.getViewport().getView(); uiType = WorkbenchTemplateMappingItem.TEXTAREA; } wbtmi.setFieldType(uiType); focusComp.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { selectControl(e.getSource()); } public void focusLost(FocusEvent e) { //stateChange(); } }); comp.setEnabled(!readOnly); focusComp.setEnabled(!readOnly); comp.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (!readOnly) { if ((e.isControlDown() || e.isMetaDown()) && e.getKeyCode() == KeyEvent.VK_N) { workbenchPane.addRowAfter(); } } super.keyTyped(e); } }); return comp; }
From source file:edu.ku.brc.ui.UIHelper.java
@SuppressWarnings("unchecked") public static <T> T addAutoSelect(final JTextField tf) { if (!isMacOS()) { tf.addFocusListener(new FocusAdapter() { @Override/* w w w. j a va 2 s.c om*/ public void focusGained(FocusEvent e) { ((JTextField) e.getSource()).selectAll(); } }); } return (T) tf; }
From source file:com.hexidec.ekit.EkitCore.java
public void focusGained(FocusEvent fe) { if (fe.getSource() == jtpMain) { setFormattersActive(true);/*from w w w. j ava 2 s .c o m*/ } else if (fe.getSource() == jtpSource) { setFormattersActive(false); } }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryFieldPanel.java
/** * @param iconSize//from w ww . j a v a2s .c om * @param returnWidths * @return */ protected int[] buildControlLayout(final IconManager.IconSize iconSize, final boolean returnWidths, final Component saveBtn) { FocusListener focusListener = new FocusListener() { /* * (non-Javadoc) * * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent) */ // @Override public void focusGained(FocusEvent e) { //Checking oppositeComponent to work around //weird behavior after addBtn is clicked which //causes top queryFieldPanel to be selected. if (ownerQuery.getAddBtn() != null && e.getOppositeComponent() != ownerQuery.getAddBtn()) { ownerQuery.selectQFP(QueryFieldPanel.this); } } /* * (non-Javadoc) * * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent) */ // @Override public void focusLost(FocusEvent e) { // nada } }; KeyListener enterListener = new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { //nuthin } @Override public void keyReleased(KeyEvent arg0) { //nuthin } @Override public void keyTyped(KeyEvent arg0) { if (arg0.getKeyChar() == KeyEvent.VK_ENTER && ownerQuery != null) { ownerQuery.doSearch(); } } }; comparators = getComparatorList(fieldQRI); //XXX need to build schemaItem for header panel too... if (schemaMapping != null) { schemaItemCBX = edu.ku.brc.ui.UIHelper.createComboBox(); schemaItemCBX.addItem("empty"); //to work around validator blow up for empty lists. DataChangeNotifier dcnsi = validator.hookupComponent(schemaItemCBX, "sicbx", UIValidator.Type.Changed, "", true); schemaItemCBX.addActionListener(dcnsi); schemaItemCBX.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (!QueryFieldPanel.this.ownerQuery.isUpdatingAvailableConcepts()) { if (e.getStateChange() == ItemEvent.SELECTED) { if (e.getItem() instanceof SpExportSchemaItem) { QueryFieldPanel.this.schemaItem = (SpExportSchemaItem) e.getItem(); } else { SpExportSchemaItemMapping m = QueryFieldPanel.this.getItemMapping(); SpExportSchemaItem si = QueryFieldPanel.this.schemaItem; String item = e.getItem().toString(); if (StringUtils.isNotBlank(item) && ownerQuery.isAvailableExportFieldName(QueryFieldPanel.this, item)) { if (m != null) { m.setExportedFieldName(e.getItem().toString()); } if (si != null) { si.setFieldName(e.getItem().toString()); } } else { if (StringUtils.isBlank(item)) { UIRegistry.displayErrorDlgLocalized( "QueryFieldPanel.ExportFieldNameInvalid", item); } else { UIRegistry.displayErrorDlgLocalized( "QueryFieldPanel.ExportFieldNameAlreadyUsed", item); } schemaItemCBX.setSelectedIndex(0); } } ownerQuery.updateAvailableConcepts(); } } } }); } else { schemaItemCBX = null; } iconLabel = new JLabel(icon); iconLabel.addFocusListener(focusListener); String fieldLabelText = fieldQRI != null ? fieldQRI.getTitle() : "WXYZ"; if (fieldQRI instanceof RelQRI) { DBRelationshipInfo.RelationshipType relType = ((RelQRI) fieldQRI).getRelationshipInfo().getType(); if (relType.equals(DBRelationshipInfo.RelationshipType.OneToMany) || relType.equals(DBRelationshipInfo.RelationshipType.ManyToMany)) { fieldLabelText += " " + UIRegistry.getResourceString("QB_AGGREGATED"); } else { fieldLabelText += " " + UIRegistry.getResourceString("QB_FORMATTED"); } } fieldLabel = createLabel(fieldLabelText); fieldLabel.addFocusListener(focusListener); fieldLabel.addKeyListener(enterListener); isNotCheckbox = createCheckBox("isNotCheckbox"); isNotCheckbox.addFocusListener(focusListener); isNotCheckbox.addKeyListener(enterListener); operatorCBX = createComboBox(comparators); operatorCBX.addFocusListener(focusListener); operatorCBX.addKeyListener(enterListener); boolean isBool = fieldQRI != null && fieldQRI.getDataClass().equals(Boolean.class); if (!isBool) { operatorCBX.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { criteria.setVisible(!operatorCBX.getSelectedItem().equals(SpQueryField.OperatorType.EMPTY)); } } }); } if (pickList == null) { boolean hasBetweenOp = false; for (int o = 0; o < comparators.length; o++) { if (comparators[o].equals(OperatorType.BETWEEN)) { hasBetweenOp = true; break; } } if (hasBetweenOp) { criteria = new CriteriaPair(enterListener); operatorCBX.addActionListener(this); } else { criteria = createTextField("1"); criteria.addKeyListener(enterListener); } } else { criteria = createPickList(saveBtn); if (!ownerQuery.isPromptMode()) { ((PickListCriteriaCombo) criteria) .setCurrentOp((SpQueryField.OperatorType) operatorCBX.getModel().getElementAt(0)); } criteria.addKeyListener(enterListener); operatorCBX.addItemListener(new ItemListener() { /* * (non-Javadoc) * * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) */ //@Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // System.out.println("setting curront op"); ((PickListCriteriaCombo) criteria) .setCurrentOp((SpQueryField.OperatorType) operatorCBX.getSelectedItem()); } } }); } //criteria.addFocusListener(focusListener); sortCheckbox = new MultiStateIconButon( new ImageIcon[] { IconManager.getImage("GrayDot", IconManager.IconSize.Std16), IconManager.getImage("UpArrow", IconManager.IconSize.Std16), IconManager.getImage("DownArrow", IconManager.IconSize.Std16) }); DataChangeNotifier dcn = validator.hookupComponent(sortCheckbox, "scb", UIValidator.Type.Changed, "", true); sortCheckbox.addFocusListener(focusListener); sortCheckbox.addActionListener(dcn); sortCheckbox.addKeyListener(enterListener); if (!this.ownerQuery.isPromptMode()) { isEnforcedCkbx = createCheckBox("isEnforcedCkbx"); dcn = validator.hookupComponent(isEnforcedCkbx, "iecb", UIValidator.Type.Changed, "", true); isEnforcedCkbx.addActionListener(dcn); isEnforcedCkbx.addFocusListener(focusListener); isEnforcedCkbx.addKeyListener(enterListener); } if (!this.ownerQuery.isPromptMode()) { isDisplayedCkbx = createCheckBox("isDisplayedCkbx"); dcn = validator.hookupComponent(isDisplayedCkbx, "idcb", UIValidator.Type.Changed, "", true); isDisplayedCkbx.addFocusListener(focusListener); isDisplayedCkbx.addKeyListener(enterListener); isDisplayedCkbx.addActionListener(dcn); isDisplayedCkbx.addActionListener(new ActionListener() { /* (non-Javadoc) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(ActionEvent arg0) { SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { sortCheckbox.setEnabled(isDisplayedCkbx.isSelected()); ownerQuery.changeNotification(QueryFieldPanel.this); } }); } }); isPromptCkbx = createCheckBox("isPromptCkbx"); dcn = validator.hookupComponent(isPromptCkbx, "ipcb", UIValidator.Type.Changed, "", true); isPromptCkbx.addActionListener(dcn); isPromptCkbx.addFocusListener(focusListener); isPromptCkbx.addKeyListener(enterListener); closeBtn = edu.ku.brc.ui.UIHelper.createIconBtn("Close", "QB_REMOVE_FLD", new ActionListener() { public void actionPerformed(ActionEvent ae) { boolean clearIt = schemaItem != null; ownerQuery.removeQueryFieldItem((QueryFieldPanel) ((JComponent) ae.getSource()).getParent()); if (clearIt) { setField(null, null); } } }); closeBtn.setEnabled(true); closeBtn.setFocusable(false); closeBtn.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { ((JButton) e.getSource()).setIcon(IconManager.getIcon("CloseHover")); super.mouseEntered(e); } @Override public void mouseExited(MouseEvent e) { ((JButton) e.getSource()).setIcon(IconManager.getIcon("Close")); super.mouseExited(e); } }); } else { isDisplayedCkbx = null; this.isPromptCkbx = null; this.isEnforcedCkbx = null; this.closeBtn = null; } JComponent[] qComps = { iconLabel, fieldLabel, isNotCheckbox, operatorCBX, criteria, sortCheckbox, isDisplayedCkbx, isPromptCkbx, isEnforcedCkbx, closeBtn, null }; JComponent[] sComps = { schemaItemCBX, iconLabel, fieldLabel, isNotCheckbox, operatorCBX, criteria, sortCheckbox, isDisplayedCkbx, isEnforcedCkbx, closeBtn, null }; // 0 1 2 3 4 5 6 7 8 9 if (schemaMapping == null) { comps = qComps; } else { comps = sComps; } StringBuilder sb = new StringBuilder(); Integer[] qFixedCmps = { 300 }; Integer[] sFixedCmps = { 268, 300 }; Integer[] fixedCmps; if (schemaMapping != null) { fixedCmps = sFixedCmps; } else { fixedCmps = qFixedCmps; } if (columnDefStr == null) { for (int i = 0; i < comps.length; i++) { sb.append(i == 0 ? "" : ","); if (isCenteredComp(i)) sb.append("c:"); if (i >= fixedCmps.length) { sb.append("p"); } else { sb.append(fixedCmps[i] + "px"); } if (isGrowComp(i)) sb.append(":g"); sb.append(",4px"); } } else { sb.append(columnDefStr); } PanelBuilder builder = new PanelBuilder(new FormLayout("3px, " + sb.toString() + ", 3px", "3px, p, 3px"), this); CellConstraints cc = new CellConstraints(); int col = 1; for (JComponent comp : comps) { if (comp != null) { builder.add(comp, cc.xy(col + 1, 2)); } col += 2; } if (fieldQRI != null) { icon = IconManager.getIcon(fieldQRI.getTableInfo().getName(), iconSize); setIcon(icon); } if (!ownerQuery.isPromptMode()) { isDisplayedCkbx.setSelected(true); isPromptCkbx.setSelected(!(fieldQRI instanceof RelQRI)); isEnforcedCkbx.setSelected(false); } if (fieldQRI == null && !returnWidths) { for (int c = 1; c < comps.length; c++) { if (comps[c] != null) { comps[c].setVisible(false); } } } else { // for now boolean isRel = fieldQRI != null && fieldQRI instanceof RelQRI; boolean isTreeLevel = fieldQRI instanceof TreeLevelQRI; isNotCheckbox.setVisible(!isRel || pickList != null); operatorCBX.setVisible(!isRel || pickList != null); criteria.setVisible((!isRel && !isBool) || pickList != null); if (schemaMapping != null) { this.sortCheckbox.setVisible(!(isTreeLevel || isRel)); } else { if (!isRel) { this.sortCheckbox.setVisible(true); } else { this.sortCheckbox.setVisible( ((RelQRI) fieldQRI).getRelationshipInfo().getType() != RelationshipType.OneToMany); } } if (!ownerQuery.isPromptMode()) { isDisplayedCkbx.setVisible(!isRel); isPromptCkbx.setVisible(!isRel); isEnforcedCkbx.setVisible(!isRel); } } validate(); doLayout(); int[] widths = null; if (returnWidths) { widths = new int[comps.length]; for (int i = 0; i < comps.length; i++) { widths[i] = comps[i] != null ? comps[i].getSize().width : 0; } if (this.schemaMapping == null) { widths[0] = iconSize.size(); widths[1] = 200; } else { widths[1] = iconSize.size(); widths[2] = 200; } } return widths; }
From source file:op.care.med.inventory.DlgNewStocks.java
private void txtMengeFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMengeFocusGained SYSTools.markAllTxt((JTextField) evt.getSource()); }