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);
}
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);
}
}
}
}
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);
}
}
});
}
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);
}
}
}
}
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);
}
Aggregations