Example usage for java.awt.event FocusEvent getSource

List of usage examples for java.awt.event FocusEvent getSource

Introduction

In this page you can find the example usage for java.awt.event FocusEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:op.system.DlgLogin.java

private void txtUsernameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtUsernameFocusGained
    ((JTextField) evt.getSource()).selectAll();
}

From source file:op.tools.SYSCalendar.java

public static void handleDateFocusLost(FocusEvent evt, DateMidnight min, DateMidnight max) {
    DateTime dt;//from   ww  w  .  j a  va 2 s.co m
    if (max == null) {
        max = new DateMidnight();
    }
    try {
        dt = new DateTime(parseDate(((JTextField) evt.getSource()).getText()));
    } catch (NumberFormatException ex) {
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.wrongdate")));
        dt = new DateTime();
    }
    if (dt.isAfter(max)) {
        dt = new DateTime();
        DisplayMessage dm = new DisplayMessage(
                dt.isAfterNow() ? SYSTools.xx("misc.msg.futuredate") : SYSTools.xx("misc.msg.wrongdate"));
        OPDE.getDisplayManager().addSubMessage(dm);
    }
    if (dt.isBefore(min)) {
        dt = new DateTime();
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.DateTooOld")));
    }

    ((JTextField) evt.getSource()).setText(DateFormat.getDateInstance().format(dt.toDate()));
}

From source file:op.tools.SYSCalendar.java

public static void handleDateFocusLost(FocusEvent evt, LocalDate min, LocalDate max) {
    LocalDate dt;/*from  w  w w . ja  v a  2  s.  co  m*/
    if (max == null) {
        max = new LocalDate();
    }
    try {
        dt = new LocalDate(parseDate(((JTextField) evt.getSource()).getText()));
    } catch (NumberFormatException ex) {
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.wrongdate")));
        dt = new LocalDate();
    }
    if (dt.isAfter(max)) {
        dt = new LocalDate();
        DisplayMessage dm = new DisplayMessage(
                dt.isAfter(max) ? SYSTools.xx("misc.msg.futuredate") : SYSTools.xx("misc.msg.wrongdate"));
        OPDE.getDisplayManager().addSubMessage(dm);
    }
    if (dt.isBefore(min)) {
        dt = new LocalDate();
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.DateTooOld")));
    }

    ((JTextField) evt.getSource()).setText(DateFormat.getDateInstance().format(dt.toDate()));
}

From source file:op.tools.SYSTools.java

public static void handleIntegerFocusLost(FocusEvent evt, int min, int max, int def) {
    int myInt;//  ww  w.  j  a va  2s.c  om
    try {
        myInt = Integer.parseInt(((JTextField) evt.getSource()).getText());
    } catch (NumberFormatException ex) {
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.wrongentry")));
        myInt = def;
    }
    if (myInt < min) {
        myInt = min;
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.entryTooSmall")));
    }
    if (myInt > max) {
        myInt = max;
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.entryTooBig")));
    }

    ((JTextField) evt.getSource()).setText(Integer.toString(myInt));
}

From source file:op.tools.SYSTools.java

public static void handleBigDecimalFocusLost(FocusEvent evt, BigDecimal min, BigDecimal max, BigDecimal def) {
    BigDecimal myBD;/*from  w  w  w. j  av  a2s .com*/
    try {
        myBD = BigDecimal.valueOf(
                Double.parseDouble(assimilateDecimalSeparators(((JTextField) evt.getSource()).getText())));
    } catch (NumberFormatException ex) {
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.wrongentry")));
        myBD = def;
    }
    if (myBD.compareTo(min) < 0) {
        myBD = min;
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.entryTooSmall")));
    }
    if (myBD.compareTo(max) > 0) {
        myBD = max;
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.entryTooBig")));
    }

    ((JTextField) evt.getSource()).setText(myBD.setScale(2, RoundingMode.HALF_UP).toString());
}

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//from   w w w .j av  a  2  s.c om
    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:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java

public void focusGained(FocusEvent e) {

    if (e.getSource() == queryEditorTextComponent()) {

        scheduleListItemLoad();
    }

}

From source file:org.executequery.gui.editor.QueryEditorTextPane.java

/**
 * Updates the state of undo/redo ona focus gain.
 *///from   www.j ava2 s  .  c  o m
public void focusGained(FocusEvent e) {
    if (e.getSource() != this && editorPanel != null) {
        editorPanel.focusGained();
    }
}

From source file:org.jcurl.demo.tactics.BroomPromptSwingBean.java

public void focusGained(final FocusEvent e) {
    log.debug(e.getSource());
    if (e.getSource() == split2) {
        if (broom == null || broom.getSplitTimeMillis() == null)
            return;
        first = new SplitMemento(broom, broom.getSplitTimeMillis().getValue());
    } else/*from  ww w  . ja va 2 s.c om*/
        log.warn("Unprocessed event from " + e.getSource());
}

From source file:org.jcurl.demo.tactics.BroomPromptSwingBean.java

public void focusLost(final FocusEvent e) {
    if (e.getSource() == split2) {
        if (broom == null || broom.getSplitTimeMillis() == null)
            return;
        getChanger().undoable(first, new SplitMemento(broom, broom.getSplitTimeMillis().getValue()));
        first = null;/*from  ww  w. j  av  a 2  s . com*/
    } else
        log.warn("Unprocessed event from " + e.getSource());
}