Example usage for java.awt KeyboardFocusManager getFocusOwner

List of usage examples for java.awt KeyboardFocusManager getFocusOwner

Introduction

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

Prototype

public Component getFocusOwner() 

Source Link

Document

Returns the focus owner, if the focus owner is in the same context as the calling thread.

Usage

From source file:edu.ku.brc.af.ui.forms.ResultSetController.java

/**
 * //from   ww w  . j av  a  2 s.  co  m
 */
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:ded.ui.DiagramController.java

/** The core of the paint routine, after we decide whether to interpose
  * another buffer. */// w  w  w  .  j  a  va  2  s.c o m
private void innerPaint(Graphics g) {
    super.paint(g);

    // I do not know the proper way to get a font set automatically
    // in a Graphics object.  Calling JComponent.setFont has gotten
    // me nowhere.  Setting it myself when I first get control
    // seems to work; but note that I have to do this *after*
    // calling super.paint().
    g.setFont(this.dedWindow.diagramFont);

    // Filename label.
    if (this.diagram.drawFileName && !this.fileName.isEmpty()) {
        String name = new File(this.fileName).getName();
        FontMetrics fm = g.getFontMetrics();
        LineMetrics lm = fm.getLineMetrics(name, g);
        int x = fileNameLabelMargin;
        int y = fileNameLabelMargin + (int) lm.getAscent();
        g.drawString(name, x, y);
        y += (int) lm.getUnderlineOffset() + 1 /*...*/;
        g.drawLine(x, y, x + fm.stringWidth(name), y);
    }

    // Controllers.
    for (Controller c : this.controllers) {
        if (c.isSelected()) {
            c.paintSelectionBackground(g);
        }
        c.paint(g);
    }

    // Lasso rectangle.
    if (this.mode == Mode.DCM_RECT_LASSO) {
        Rectangle r = this.getLassoRect();
        g.drawRect(r.x, r.y, r.width, r.height);
    }

    // Current focused Component.
    if (debugFocus) {
        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        Component fo = kfm.getFocusOwner();
        g.drawString("Focus: " + fo, 3, this.getHeight() - 22);
    }

    // Mode label.
    if (this.mode != Mode.DCM_SELECT) {
        g.drawString("Mode: " + this.mode.description, 3, this.getHeight() - 4);
    } else if (this.fpsMeasurementMode) {
        this.fpsFrameCount++;
        long current = System.currentTimeMillis();
        long millis = current - this.fpsStartMillis;
        if (millis > 1000) {
            // Update the FPS measurement with the results for this
            // interval.
            this.fpsSampleCount++;
            this.fpsMeasurement = "FPS: " + this.fpsFrameCount + " (millis=" + millis + ", samples="
                    + this.fpsSampleCount + ")";

            // Reset the counters.
            this.fpsStartMillis = current;
            this.fpsFrameCount = 0;
        }
        g.drawString(this.fpsMeasurement + " (Ctrl+G to stop)", 3, this.getHeight() - 4);
    }
}