Example usage for java.awt KeyboardFocusManager getCurrentKeyboardFocusManager

List of usage examples for java.awt KeyboardFocusManager getCurrentKeyboardFocusManager

Introduction

In this page you can find the example usage for java.awt KeyboardFocusManager getCurrentKeyboardFocusManager.

Prototype

public static KeyboardFocusManager getCurrentKeyboardFocusManager() 

Source Link

Document

Returns the current KeyboardFocusManager instance for the calling thread's context.

Usage

From source file:eu.delving.sip.base.VisualFeedback.java

private static void acquireFocus() {
    Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (fo != null && fo.isShowing())
        fo.requestFocus();/*from w w  w. j  a  va 2 s. co m*/
}

From source file:umich.ms.batmass.filesupport.core.actions.importing.ImportFileByCategory.java

/**
 * Tries to find an appropriate component as a parent for the file chooser.
 * @return some Component: the focus owner, the active window or the app frame
 *//*from  ww w.  j a v a 2  s .  c  o m*/
private Component findDialogParent() {
    Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (parent == null) {
        parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    }
    if (parent == null) {
        Frame[] f = Frame.getFrames();
        parent = f.length == 0 ? null : f[f.length - 1];
    }
    return parent;
}

From source file:ru.codemine.pos.ui.MainWindow.java

private void setupKeyboard() {
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(keyDispatcher);
}

From source file:view.MainWindow.java

/**
 * Creates new form MainWindow// w  w  w .j  av a2s .  c  o  m
 */
public MainWindow() {
    initComponents();

    updateText();

    List<Image> icons = new ArrayList<>();
    icons.add(new ImageIcon(getClass().getResource("/image/aCCinaPDF_logo_icon32.png")).getImage());
    this.setIconImages(icons);

    setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
    workspacePanel.setParent((MainWindow) this);
    populateDriveComboBox();

    dmtn = new DefaultMutableTreeNode("0 " + Bundle.getBundle().getString("tn.documentsLoaded"));
    TreeModel tm = new DefaultTreeModel(dmtn);
    jtOpenedDocuments.setModel(tm);
    setupTreePopups();
    setupDropListener();

    DefaultTreeCellRenderer renderer1 = (DefaultTreeCellRenderer) jtOpenedDocuments.getCellRenderer();
    Icon closedIcon = new ImageIcon(MainWindow.class.getResource("/image/pdf_ico.jpg"));
    renderer1.setLeafIcon(closedIcon);
    DefaultTreeCellRenderer renderer2 = (DefaultTreeCellRenderer) jtExplorer.getCellRenderer();
    renderer2.setLeafIcon(closedIcon);
    tfProcurar.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            refreshTree(tfProcurar.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            refreshTree(tfProcurar.getText());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {

        }
    });

    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher((MainWindow) this);
    refreshTree(null);

    ctrl.setPrintMenuItem(menuItemPrint);
}

From source file:com.freedomotic.jfrontend.MainWindow.java

/**
 *
 * @param master//from   w  w w .  j  av a2s.co m
 */
public MainWindow(final JavaDesktopFrontend master) {
    this.i18n = master.getApi().getI18n();
    UIManager.put("OptionPane.yesButtonText", i18n.msg("yes"));
    UIManager.put("OptionPane.noButtonText", i18n.msg("no"));
    UIManager.put("OptionPane.cancelButtonText", i18n.msg("cancel"));
    this.master = master;
    this.api = master.getApi();
    this.auth = api.getAuth();
    ObjectEditor.setAPI(api);

    setWindowedMode();
    updateMenusPermissions();

    String defEnv = master.getApi().getConfig().getProperty("KEY_ROOM_XML_PATH");
    EnvironmentLogic env = api.environments()
            .findOne(defEnv.substring(defEnv.length() - 41, defEnv.length() - 5));
    setEnvironment(env);

    checkDeletableEnvironments();

    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new MyDispatcher());

}

From source file:PVGraph.java

public PVGraph(Calendar date, int initialViewIndex) {
    super(WINDOW_TITLE_PREFIX);
    this.date = date;
    synchronized (graphs) {
        graphs.add(this);
    }/*from ww  w.j a v a 2s .  c  o  m*/

    views = new PVGraphView[4];
    views[DAY_VIEW_INDEX] = new DayView();
    views[MONTH_VIEW_INDEX] = new MonthView();
    views[YEAR_VIEW_INDEX] = new YearView();
    views[YEARS_VIEW_INDEX] = new YearsView();

    tabPane = new JTabbedPane();
    for (PVGraphView v : views)
        tabPane.addTab(v.getTabLabel(), v.makePanel());
    tabPane.setSelectedIndex(initialViewIndex);
    setContentPane(tabPane);
    pack();
    try {
        java.net.URL url = getClass().getResource("sun.png");
        if (url != null)
            setIconImage(ImageIO.read(url));
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    ;
    setVisible(true);

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        public boolean dispatchKeyEvent(KeyEvent ke) {
            Object src = ke.getSource();
            if (src instanceof JComponent && ((JComponent) src).getRootPane().getContentPane() == tabPane) {
                if (ke.getID() == KeyEvent.KEY_TYPED) {
                    switch (ke.getKeyChar()) {
                    case 'd':
                        tabPane.setSelectedIndex(DAY_VIEW_INDEX);
                        return true;
                    case 'm':
                        tabPane.setSelectedIndex(MONTH_VIEW_INDEX);
                        return true;
                    case 'N' - 0x40:
                        new PVGraph((Calendar) PVGraph.this.date.clone(), tabPane.getSelectedIndex());
                        return true;
                    case 'Q' - 0x40:
                        dispatchEvent(new WindowEvent(PVGraph.this, WindowEvent.WINDOW_CLOSING));
                        return true;
                    case 'R' - 0x40:
                        loadProperties();
                        updateView();
                        return true;
                    case 'S':
                        try {
                            runSmatool();
                            updateView();
                        } catch (IOException ioe) {
                            System.err.println(ioe.getMessage());
                        }
                        return true;
                    case 'y':
                        tabPane.setSelectedIndex(YEAR_VIEW_INDEX);
                        return true;
                    case 'Y':
                        tabPane.setSelectedIndex(YEARS_VIEW_INDEX);
                        return true;
                    default:
                        return views[tabPane.getSelectedIndex()].handleKey(ke.getKeyChar());
                    }
                }
            }
            return false;
        }
    });
}

From source file:openlr.mapviewer.gui.MapViewerGui.java

/**
 * Prepare mouse listener.//from  www.j  av  a2 s  . c  om
 * 
 * @param mapHolder
 *            the map holder
 * @param sbar
 *            A reference to the status bar
 */
private void prepareMouseListener(final MapsHolder mapHolder, final StatusBar sbar) {
    MouseLineInfo mli = new MouseLineInfo(mapHolder, MapsHolder.MapIndex.FIRST_MAP, sbar);
    mapHolder.getMapPane(MapsHolder.MapIndex.FIRST_MAP).getToolManager().addMapMouseListener(mli);
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .addKeyEventDispatcher(new OpenLRMapPaneKeyDispatcher(mli, this));
    if (mapHolder.hasTwoMaps()) {
        MouseLineInfo mli2 = new MouseLineInfo(mapHolder, MapsHolder.MapIndex.SECOND_MAP, sbar);
        mapHolder.getMapPane(MapsHolder.MapIndex.SECOND_MAP).getToolManager().addMapMouseListener(mli2);
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
                .addKeyEventDispatcher(new OpenLRMapPaneKeyDispatcher(mli2, this));
    }
}

From source file:com.frostwire.gui.player.MediaPlayer.java

protected MediaPlayer() {
    lastRandomFiles = new LinkedList<MediaSource>();
    playExecutor = ExecutorsHelper.newProcessingQueue("AudioPlayer-PlayExecutor");

    String playerPath;/*from  www . j  a v  a  2s. c o m*/
    playerPath = getPlayerPath();

    MPlayer.initialise(new File(playerPath));
    mplayer = new MPlayer();
    mplayer.addPositionListener(new PositionListener() {
        public void positionChanged(float currentTimeInSecs) {
            notifyProgress(currentTimeInSecs);
        }
    });
    mplayer.addStateListener(new StateListener() {
        public void stateChanged(MediaPlaybackState newState) {
            if (newState == MediaPlaybackState.Closed) { // This is the case
                                                         // mplayer is
                                                         // done with the
                                                         // current file
                playNextMedia();
            }
        }
    });
    mplayer.addIcyInfoListener(new IcyInfoListener() {
        public void newIcyInfoData(String data) {
            notifyIcyInfo(data);
        }
    });

    repeatMode = RepeatMode.values()[PlayerSettings.LOOP_PLAYLIST.getValue()];
    shuffle = PlayerSettings.SHUFFLE_PLAYLIST.getValue();
    playNextMedia = true;
    volume = PlayerSettings.PLAYER_VOLUME.getValue();
    notifyVolumeChanged();

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_SPACE) {
                Object s = e.getComponent();
                if (!(s instanceof JTextField)
                        && !(s instanceof JTable && ((JTable) s).isEditing() && !(s instanceof JCheckBox))) {
                    togglePause();
                    return true;
                }
            }
            return false;
        }
    });

    // prepare to receive UI events
    MPlayerUIEventHandler.instance().addListener(this);
}

From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfControlPanel.java

/**
 * Builds and answer the control tab for the given layout.
 *
 * @param errors List of errors.//from  ww  w .j  a  va2s  . co  m
 * @return the control tab.
 */
protected JComponent buildEditorPanel(List<String> errors) {
    // Checks and initialize the errors list.
    if (errors == null) {
        errors = new ArrayList<String>(0);
    } else if (Utilities.isDev && errors.size() > 0) {
        LOG.info("Errors in form:");
        for (String error : errors) {
            LOG.info(error);
        }
    }

    // Define the layaout for the form.
    FormLayout layout = new FormLayout("right:max(50dlu;p), 4dlu, 100dlu, 7dlu, right:p, 4dlu, 100dlu",
            EDITOR_ROW_SPEC);
    layout.setColumnGroups(new int[][] { { 1, 3, 5, 7 } });

    // Construct the panel.
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setDefaultDialogBorder();

    CellConstraints cc = new CellConstraints(); // Constraints for the cells;

    // First row of the panel.
    builder = this.buildEntityTypeText(builder, cc);

    // Second row is the panel.
    builder = buildMainPanel(builder, cc);

    builder.addSeparator("", cc.xyw(1, this.rowNb, 7));
    setNextRow();
    JButton previousTabBtn = new ButtonTab(labels.getString("eaccpf.commons.previousTab"));
    builder.add(previousTabBtn, cc.xy(1, rowNb));
    previousTabBtn.addActionListener(new PreviousTabBtnAction(this.eaccpf, this.tabbedPane, this.model));

    // Row for exit and save buttons.
    setNextRow();
    JButton exitBtn = new ButtonTab(this.labels.getString("eaccpf.commons.exit"));
    builder.add(exitBtn, cc.xy(1, this.rowNb));
    exitBtn.addActionListener(new ExitBtnAction(this.eaccpf, this.tabbedPane, this.model));

    JButton saveBtn = new ButtonTab(labels.getString("eaccpf.commons.save"));
    builder.add(saveBtn, cc.xy(5, this.rowNb));
    saveBtn.addActionListener(new SaveBtnAction(this.eaccpf, this.tabbedPane, this.model));

    // Define the change tab listener.
    this.removeChangeListener();
    this.tabbedPane.addChangeListener(new ChangeTabListener(this.eaccpf, this.tabbedPane, this.model, 3));

    JPanel panel = builder.getPanel();
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .addPropertyChangeListener(new FocusManagerListener(panel));
    return panel;
}

From source file:Utilities.java

/**
 * Finds out the monitor where the user currently has the input focus.
 * This method is usually used to help the client code to figure out on
 * which monitor it should place newly created windows/frames/dialogs.
 *
 * @return the GraphicsConfiguration of the monitor which currently has the
 * input focus//from  ww  w  . j  a v  a2 s . c  o  m
 */
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focusOwner != null) {
        Window w = SwingUtilities.getWindowAncestor(focusOwner);
        if (w != null) {
            return w.getGraphicsConfiguration();
        }
    }

    return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}