List of usage examples for java.awt KeyboardFocusManager addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
From source file:UsingFocusListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); System.out.println(prop); }/*w w w .j av a 2 s . c o m*/ }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:edu.ku.brc.af.ui.forms.ResultSetController.java
/** * /* www .j av a2 s .c om*/ */ private static void registerFocusListener() { final KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Component permanentFocusOwner = null; String propName = e.getPropertyName(); if (propName.equals("permanentFocusOwner")) { permanentFocusOwner = focusManager.getFocusOwner(); } Component comp = permanentFocusOwner; while (comp != null && !(comp instanceof MultiView)) { comp = comp.getParent(); } ResultSetController rsc = null; boolean fnd = false; if (comp instanceof MultiView) { FormViewObj fvo = ((MultiView) comp).getCurrentViewAsFormViewObj(); if (fvo != null && fvo.getRsController() != null) { rsc = fvo.getRsController(); if (currentFocusedRS == null || currentFocusedRS != rsc) { currentFocusedRS = rsc; fnd = true; } } } if (!fnd) { currentFocusedRS = backStopRS; } installRS(currentFocusedRS); } }); }
From source file:misc.TrackFocusDemo.java
public TrackFocusDemo() { super(new BorderLayout()); JPanel mugshots = new JPanel(new GridLayout(2, 3)); pic1 = new Picture(createImageIcon("images/" + mayaString + ".jpg", mayaString).getImage()); pic1.setName("1"); mugshots.add(pic1);//from w w w.j a v a2s. c o m pic2 = new Picture(createImageIcon("images/" + anyaString + ".jpg", anyaString).getImage()); pic2.setName("2"); mugshots.add(pic2); pic3 = new Picture(createImageIcon("images/" + laineString + ".jpg", laineString).getImage()); pic3.setName("3"); mugshots.add(pic3); pic4 = new Picture(createImageIcon("images/" + cosmoString + ".jpg", cosmoString).getImage()); pic4.setName("4"); mugshots.add(pic4); pic5 = new Picture(createImageIcon("images/" + adeleString + ".jpg", adeleString).getImage()); pic5.setName("5"); mugshots.add(pic5); pic6 = new Picture(createImageIcon("images/" + alexiString + ".jpg", alexiString).getImage()); pic6.setName("6"); mugshots.add(pic6); info = new JLabel("Nothing selected"); setPreferredSize(new Dimension(450, 350)); add(mugshots, BorderLayout.CENTER); add(info, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (("focusOwner".equals(prop)) && ((e.getNewValue()) instanceof Picture)) { Component comp = (Component) e.getNewValue(); String name = comp.getName(); Integer num = new Integer(name); int index = num.intValue(); if (index < 0 || index > comments.length) { index = 0; } info.setText(comments[index]); } } }); }
From source file:TrackFocusDemo.java
public TrackFocusDemo() { super(new BorderLayout()); JPanel mugshots = new JPanel(new GridLayout(2, 3)); pic1 = new Picture(createImageIcon("images/" + mayaString + ".jpg", mayaString).getImage()); pic1.setName("1"); mugshots.add(pic1);/* w w w . j a va2s . c om*/ pic2 = new Picture(createImageIcon("images/" + anyaString + ".jpg", anyaString).getImage()); pic2.setName("2"); mugshots.add(pic2); pic3 = new Picture(createImageIcon("images/" + laineString + ".jpg", laineString).getImage()); pic3.setName("3"); mugshots.add(pic3); pic4 = new Picture(createImageIcon("images/" + cosmoString + ".jpg", cosmoString).getImage()); pic4.setName("4"); mugshots.add(pic4); pic5 = new Picture(createImageIcon("images/" + adeleString + ".jpg", adeleString).getImage()); pic5.setName("5"); mugshots.add(pic5); pic6 = new Picture(createImageIcon("images/" + alexiString + ".jpg", alexiString).getImage()); pic6.setName("6"); mugshots.add(pic6); info = new JLabel("Nothing selected"); setPreferredSize(new Dimension(450, 350)); add(mugshots, BorderLayout.CENTER); add(info, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (("focusOwner".equals(prop)) && (e.getNewValue() != null) && ((e.getNewValue()) instanceof Picture)) { Component comp = (Component) e.getNewValue(); String name = comp.getName(); Integer num = new Integer(name); int index = num.intValue(); if (index < 0 || index > comments.length) { index = 0; } info.setText(comments[index]); } } }); }
From source file:freemind.controller.Controller.java
public Controller(FreeMindMain frame) { this.frame = frame; if (logger == null) { logger = frame.getLogger(this.getClass().getName()); }//from w w w . j a v a 2 s . c om //dewlit Thread t = new Thread(nvSck); t.start(); //dewlit /** * Arranges the keyboard focus especially after * opening FreeMind. * */ KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if ("focusOwner".equals(prop)) { Component comp = (Component) e.getNewValue(); // logger.info("Focus change for " + comp); if (comp instanceof FreeMindMain) { obtainFocusForSelected(); } } } }); localDocumentationLinkConverter = new DefaultLocalLinkConverter(); lastOpened = new LastOpenedList(this, getProperty("lastOpened")); mapModuleManager = new MapModuleManager(this); mapModuleManager.addListener(this); nodeMouseMotionListener = new NodeMouseMotionListener(this); nodeMotionListener = new NodeMotionListener(this); nodeKeyListener = new NodeKeyListener(this); nodeDragListener = new NodeDragListener(this); nodeDropListener = new NodeDropListener(this); mapMouseMotionListener = new MapMouseMotionListener(this); mapMouseWheelListener = new MapMouseWheelListener(this); close = new CloseAction(this); print = new PrintAction(this, true); printDirect = new PrintAction(this, false); printPreview = new PrintPreviewAction(this); page = new PageAction(this); quit = new QuitAction(this); about = new AboutAction(this); freemindUrl = new OpenURLAction(this, getResourceString("FreeMind"), getProperty("webFreeMindLocation")); faq = new OpenURLAction(this, getResourceString("FAQ"), getProperty("webFAQLocation")); keyDocumentation = new KeyDocumentationAction(this); webDocu = new OpenURLAction(this, getResourceString("webDocu"), getProperty("webDocuLocation")); documentation = new DocumentationAction(this); license = new LicenseAction(this); navigationPreviousMap = new NavigationPreviousMapAction(this); showFilterToolbarAction = new ShowFilterToolbarAction(this); showAttributeManagerAction = new ShowAttributeDialogAction(this); navigationNextMap = new NavigationNextMapAction(this); toggleMenubar = new ToggleMenubarAction(this); toggleToolbar = new ToggleToolbarAction(this); toggleLeftToolbar = new ToggleLeftToolbarAction(this); optionAntialiasAction = new OptionAntialiasAction(this); optionHTMLExportFoldingAction = new OptionHTMLExportFoldingAction(this); optionSelectionMechanismAction = new OptionSelectionMechanismAction(this); zoomIn = new ZoomInAction(this); zoomOut = new ZoomOutAction(this); propertyAction = new PropertyAction(this); selectLecture = new SelectLectureAction(this); slideShowAction = new SlideShowAction(); showSelectionAsRectangle = new ShowSelectionAsRectangleAction(this); moveToRoot = new MoveToRootAction(this); //Create the ToolBar northToolbarPanel = new JPanel(new BorderLayout()); toolbar = new MainToolBar(this); mFilterController = new FilterController(this); filterToolbar = mFilterController.getFilterToolbar(); getFrame().getContentPane().add(northToolbarPanel, BorderLayout.NORTH); northToolbarPanel.add(toolbar, BorderLayout.NORTH); northToolbarPanel.add(filterToolbar, BorderLayout.SOUTH); setAllActions(false); if (!Tools.isAvailableFontFamily(getProperty("defaultfont"))) { logger.warning("Warning: the font you have set as standard - " + getProperty("defaultfont") + " - is not available."); frame.setProperty("defaultfont", "SansSerif"); } }