Search in sources :

Example 36 with FocusListener

use of java.awt.event.FocusListener in project qi4j-sdk by Qi4j.

the class Main method main.

public static void main(String[] args) throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(BoundPersonComposite.class);
            module.transients(AddressTransient.class);
            module.values(CityValue.class, CountryValue.class);
            new SwingBindingAssembler().assemble(module);
        }
    };
    module = assembler.module();
    Address address1 = createAddress("Vista Damai", "Jalan Tun Razak");
    Address address2 = createAddress("Mutiara", "Jalan Ceylon");
    TransientBuilder<BoundPersonComposite> builder = module.newTransientBuilder(BoundPersonComposite.class);
    PersonComposite prototype = builder.prototype();
    prototype.address().set(address1);
    prototype.firstName().set("Niclas");
    final BoundPersonComposite p1 = builder.newInstance();
    prototype.address().set(address2);
    prototype.firstName().set("Edward");
    final BoundPersonComposite p2 = builder.newInstance();
    final StateModel<BoundPersonComposite> model = module.newObject(StateModel.class, BoundPersonComposite.class);
    Form form = new Form<BoundPersonComposite>(model);
    JFrame frame = new JFrame("testing");
    frame.add(form, BorderLayout.CENTER);
    JPanel checkBoxPanel = new JPanel();
    checkBoxPanel.setFocusable(true);
    checkBoxPanel.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            System.out.println("Gained!");
        }

        public void focusLost(FocusEvent e) {
            System.out.println("LOst!");
        }
    });
    JCheckBox sw = new JCheckBox("Toggle");
    sw.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (((JCheckBox) e.getSource()).isSelected()) {
                model.use(p1);
                System.out.println(p1.firstName().get());
            } else {
                model.use(p2);
                System.out.println(p2.firstName().get());
            }
        }
    });
    checkBoxPanel.add(sw);
    frame.add(checkBoxPanel, BorderLayout.EAST);
    frame.pack();
    System.out.println(model);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
Also used : JPanel(javax.swing.JPanel) SwingBindingAssembler(org.qi4j.lib.swing.binding.SwingBindingAssembler) ActionEvent(java.awt.event.ActionEvent) FocusEvent(java.awt.event.FocusEvent) JCheckBox(javax.swing.JCheckBox) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) FocusListener(java.awt.event.FocusListener)

Example 37 with FocusListener

use of java.awt.event.FocusListener in project qi4j-sdk by Qi4j.

the class BoundAssociation method use.

public void use(Association<T> actualAssociation) {
    actual = actualAssociation;
    T value = null;
    if (actualAssociation != null) {
        value = actualAssociation.get();
    }
    stateModel.use(value);
    for (JComponent component : components) {
        SwingAdapter adapter = adapters.get(component.getClass());
        adapter.fromAssociationToSwing(component, actualAssociation);
        for (FocusListener listener : component.getFocusListeners()) {
            if (AssociationFocusLostListener.class.isInstance(listener)) {
                ((AssociationFocusLostListener) listener).use(adapter, actual);
            }
        }
    }
}
Also used : SwingAdapter(org.qi4j.lib.swing.binding.SwingAdapter) FocusListener(java.awt.event.FocusListener)

Example 38 with FocusListener

use of java.awt.event.FocusListener in project jadx by skylot.

the class AbstractCodeArea method addCaretActions.

private void addCaretActions() {
    Caret caret = getCaret();
    if (caret instanceof DefaultCaret) {
        ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    }
    this.addFocusListener(new FocusListener() {

        // fix caret missing bug.
        // when lost focus set visible to false,
        // and when regained set back to true will force
        // the caret to be repainted.
        @Override
        public void focusGained(FocusEvent e) {
            caret.setVisible(true);
        }

        @Override
        public void focusLost(FocusEvent e) {
            caret.setVisible(false);
        }
    });
    addCaretListener(new CaretListener() {

        int lastPos = -1;

        String lastText = "";

        @Override
        public void caretUpdate(CaretEvent e) {
            int pos = getCaretPosition();
            if (lastPos != pos) {
                lastPos = pos;
                lastText = highlightCaretWord(lastText, pos);
            }
        }
    });
}
Also used : CaretEvent(javax.swing.event.CaretEvent) CaretListener(javax.swing.event.CaretListener) DefaultCaret(javax.swing.text.DefaultCaret) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Caret(javax.swing.text.Caret) DefaultCaret(javax.swing.text.DefaultCaret) Point(java.awt.Point)

Example 39 with FocusListener

use of java.awt.event.FocusListener in project antlrworks by antlr.

the class XJUndoEngine method unregisterUndo.

public void unregisterUndo(XJUndoDelegate delegate) {
    for (JTextPane tp : new HashSet<JTextPane>(undos.keySet())) {
        XJUndo undo = undos.get(tp);
        if (undo.delegate == delegate) {
            undo.close();
            undos.remove(tp);
            for (FocusListener fl : tp.getFocusListeners()) {
                tp.removeFocusListener(fl);
            }
        }
    }
}
Also used : FocusListener(java.awt.event.FocusListener) HashSet(java.util.HashSet)

Example 40 with FocusListener

use of java.awt.event.FocusListener in project cayenne by apache.

the class EjbqlQueryScriptsTab method initView.

private void initView() {
    scriptArea = new JUndoableCayenneTextPane(new EJBQLSyntaxConstant());
    scriptArea.getDocument().addDocumentListener(this);
    scriptArea.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            try {
                String text = scriptArea.getDocument().getText(e.getOffset(), 1);
                if (text.equals(" ") || text.equals("\n") || text.equals("\t")) {
                    getQuery().setEjbql(scriptArea.getDocumentTextDirect());
                    validateEJBQL();
                }
            } catch (BadLocationException ex) {
                logger.warn("Error reading document", ex);
            }
        }

        public void removeUpdate(DocumentEvent e) {
            getQuery().setEjbql(scriptArea.getDocumentTextDirect());
            validateEJBQL();
        }
    });
    scriptArea.getPane().addFocusListener(new FocusListener() {

        EJBQLValidationThread thread;

        public void focusGained(FocusEvent e) {
            thread = new EJBQLValidationThread();
            thread.start();
        }

        public void focusLost(FocusEvent e) {
            thread.terminate();
        }
    });
    scriptArea.getPane().addKeyListener(new KeyListener() {

        boolean pasteOrCut;

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_END || e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_UNDO) {
                getQuery().setEjbql(scriptArea.getText());
                validateEJBQL();
            }
            if ((e.getKeyCode() == KeyEvent.VK_V || e.getKeyCode() == KeyEvent.VK_X) && e.isControlDown()) {
                pasteOrCut = true;
            }
        }

        public void keyReleased(KeyEvent e) {
            if ((pasteOrCut && e.getKeyCode() == KeyEvent.VK_CONTROL) || e.getKeyCode() == KeyEvent.VK_DELETE) {
                scriptArea.removeHighlightText();
                getQuery().setEjbql(scriptArea.getText());
                validateEJBQL();
                pasteOrCut = false;
            }
        }

        public void keyTyped(KeyEvent e) {
        }
    });
    setLayout(new BorderLayout());
    add(scriptArea, BorderLayout.WEST);
    add(scriptArea.getScrollPane(), BorderLayout.CENTER);
    setVisible(true);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) DocumentEvent(javax.swing.event.DocumentEvent) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) JUndoableCayenneTextPane(org.apache.cayenne.modeler.util.JUndoableCayenneTextPane) KeyListener(java.awt.event.KeyListener) EJBQLSyntaxConstant(org.apache.cayenne.swing.components.textpane.syntax.EJBQLSyntaxConstant) FocusListener(java.awt.event.FocusListener) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

FocusListener (java.awt.event.FocusListener)87 FocusEvent (java.awt.event.FocusEvent)80 ActionEvent (java.awt.event.ActionEvent)24 ActionListener (java.awt.event.ActionListener)23 JLabel (javax.swing.JLabel)20 JTextField (javax.swing.JTextField)17 Dimension (java.awt.Dimension)16 JPanel (javax.swing.JPanel)16 JButton (javax.swing.JButton)15 KeyEvent (java.awt.event.KeyEvent)12 JComboBox (javax.swing.JComboBox)11 BorderLayout (java.awt.BorderLayout)9 Component (java.awt.Component)9 MouseEvent (java.awt.event.MouseEvent)9 KeyListener (java.awt.event.KeyListener)8 JCheckBox (javax.swing.JCheckBox)8 ChangeListener (javax.swing.event.ChangeListener)8 Color (java.awt.Color)7 GridBagConstraints (java.awt.GridBagConstraints)7 MouseAdapter (java.awt.event.MouseAdapter)7