@Override
  public void keyPressed(KeyEvent e) {
    //
    if (e.getKeyCode() == KeyEvent.VK_TAB) {
      if (checkValidity()) {
        backup = getText();
        if (e.getModifiersEx() == KeyEvent.SHIFT_DOWN_MASK) {
          index = index - 1;

        } else {
          index = index + 1;
        }
        if (index == capacity) {
          KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();
          return;
        }
        if (index == -1) {
          KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();
          return;
        }

      } else {
        setText(backup);
        Logger.getLogger(VectorTextField.class.getName()).log(Level.WARNING, "Invalid format");
      }
      findSelection(0);
    }
  }
  public boolean editCellAt(int index, EventObject e) {
    if (editor != null && !editor.stopCellEditing()) return false;

    if (index < 0 || index >= getModel().getSize()) return false;

    if (!isCellEditable(index)) return false;

    if (editorRemover == null) {
      KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      editorRemover = new CellEditorRemover(fm);
      fm.addPropertyChangeListener("permanentFocusOwner", editorRemover); // NOI18N
    }

    if (editor != null && editor.isCellEditable(e)) {
      editorComp = prepareEditor(index);
      if (editorComp == null) {
        removeEditor();
        return false;
      }
      editorComp.setBounds(getCellBounds(index, index));
      add(editorComp);
      editorComp.validate();

      editingIndex = index;
      editor.addCellEditorListener(this);

      return true;
    }
    return false;
  }
Example #3
0
  public void createController() {
    controller = new MegaMekController();
    KeyboardFocusManager kbfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kbfm.addKeyEventDispatcher(controller);

    KeyBindParser.parseKeyBindings(controller);
  }
    public void actionPerformed(ActionEvent e) {
      final KeyboardFocusManager currentKeyboardFocusManager =
          KeyboardFocusManager.getCurrentKeyboardFocusManager();
      final Window activeWindow = currentKeyboardFocusManager.getActiveWindow();
      if (activeWindow instanceof JDialog
          && ((JDialog) activeWindow).isModal()
          && !SwingUtilities.isDescendingFrom(
              Controller.getCurrentController().getViewController().getMapView(), activeWindow)) {
        popup.hide();
        hideTimer.removeActionListener(this);
        hideTimer.stop();
      }

      if (tip.getMousePosition(true) != null || mouseOverComponent()) {
        hideTimer.restart();
        return;
      }
      final Component focusOwner = currentKeyboardFocusManager.getFocusOwner();
      if (focusOwner != null) {
        if (SwingUtilities.isDescendingFrom(focusOwner, tip)) {
          hideTimer.restart();
          return;
        }
      }

      popup.hide();
      hideTimer.removeActionListener(this);
      hideTimer.stop();
    }
    public void actionPerformed(ActionEvent e) {
      int selIndexBefore = getSelectedIndex();
      myDefaultAction.actionPerformed(e);
      int selIndexCurrent = getSelectedIndex();
      if (selIndexBefore != selIndexCurrent) {
        return;
      }
      if (myFocusNext && selIndexCurrent == 0) {
        return;
      }

      KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      Container container = kfm.getCurrentFocusCycleRoot();
      FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
      if (policy == null) {
        policy = kfm.getDefaultFocusTraversalPolicy();
      }
      Component next =
          myFocusNext
              ? policy.getComponentAfter(container, PaletteItemsComponent.this)
              : policy.getComponentBefore(container, PaletteItemsComponent.this);
      if (next instanceof PaletteGroupComponent) {
        clearSelection();
        next.requestFocus();
        ((PaletteGroupComponent) next).scrollRectToVisible(next.getBounds());
      }
    }
  void test3(Window owner, Window child1, Window child2) {
    System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);

    owner.setFocusableWindowState(true);
    owner.setVisible(true);

    child1.setFocusableWindowState(false);
    child1.setVisible(true);

    child2.setFocusableWindowState(true);
    child2.add(button);
    child2.setVisible(true);

    Util.waitTillShown(child2);

    Util.clickOnComp(button, robot);
    System.err.println(
        "focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
    if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
      throw new RuntimeException("Test failed.");
    }
    child1.dispose();
    child2.dispose();
    owner.dispose();
  }
  public ToolbarDragDrop(GuiTestApp parent) {
    this.parent = parent;

    KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    fm.addKeyEventDispatcher(
        new KeyEventDispatcher() {
          public boolean dispatchKeyEvent(KeyEvent e) {

            if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_TAB) {

              if (dragging) {

                Thread t =
                    new Thread() {
                      public void run() {
                        draggedTile.rotate();
                      }
                    };

                t.start();
              }
            }

            return false;
          }
        });
  }
 @Override
 public void actionPerformed(ActionEvent evt) {
   switch (command) {
     case TAB_OUT_FORWARD:
       KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();
       break;
     case TAB_OUT_BACK:
       KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();
       break;
     case EDIT_PLUGIN:
       int[] rows = table.getSelectedRows();
       Object[] state = new Object[rows.length];
       for (int i = 0; i < rows.length; i++) {
         state[i] = pluginModel.getValueAt(rows[i], 0);
       }
       for (int i = 0; i < rows.length; i++) {
         pluginModel.setValueAt(state[i].equals(Boolean.FALSE), rows[i], 0);
       }
       break;
     case CLOSE_PLUGIN_MANAGER:
       window.ok();
       break;
     default:
       throw new InternalError();
   }
 }
  public void focusGained(FocusEvent event) {
    QuaquaUtilities.repaintBorder((JComponent) event.getComponent());

    final JTextComponent tc = (JTextComponent) event.getSource();
    if (tc.isEditable() && tc.isEnabled()) {

      String uiProperty;
      if (tc instanceof JPasswordField) {
        uiProperty = "PasswordField.autoSelect";
      } else if (tc instanceof JFormattedTextField) {
        uiProperty = "FormattedTextField.autoSelect";
      } else {
        uiProperty = "TextField.autoSelect";
      }

      if (tc.getClientProperty("Quaqua.TextComponent.autoSelect") == Boolean.TRUE
          || tc.getClientProperty("Quaqua.TextComponent.autoSelect") == null
              && UIManager.getBoolean(uiProperty)) {
        if (event instanceof CausedFocusEvent) {
          CausedFocusEvent cfEvent = (CausedFocusEvent) event;
          if (cfEvent.getCause() == Cause.TRAVERSAL_FORWARD
              || cfEvent.getCause() == Cause.TRAVERSAL_BACKWARD) {
            tc.selectAll();
          }
        }
      }
    }
    if (KeyboardFocusManager.getCurrentKeyboardFocusManager()
        instanceof QuaquaKeyboardFocusManager) {
      QuaquaKeyboardFocusManager kfm =
          (QuaquaKeyboardFocusManager) KeyboardFocusManager.getCurrentKeyboardFocusManager();
      kfm.setLastKeyboardTraversingComponent(null);
    }
  }
 public void actionPerformed(ActionEvent e) {
   KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   Container container = kfm.getCurrentFocusCycleRoot();
   FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
   if (null == policy) policy = kfm.getDefaultFocusTraversalPolicy();
   Component next =
       moveDown
           ? policy.getComponentAfter(container, PaletteGroupHeader.this)
           : policy.getComponentBefore(container, PaletteGroupHeader.this);
   if (null != next && next instanceof PaletteComponentList) {
     final PaletteComponentList list = (PaletteComponentList) next;
     if (list.getModel().getSize() != 0) {
       list.takeFocusFrom(PaletteGroupHeader.this, list == myComponentList ? 0 : -1);
       return;
     } else {
       next =
           moveDown
               ? policy.getComponentAfter(container, next)
               : policy.getComponentBefore(container, next);
     }
   }
   if (null != next && next instanceof PaletteGroupHeader) {
     next.requestFocus();
   }
 }
Example #11
0
  public mainWindow(Controller c, RandomEventGenerator r, Safety s) {

    // use system look and feel
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      // do nothing
    }

    view = new ElevatorSimView();
    safety = s;
    controller = c;
    randomEventGen = r;
    simStarted = false;

    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    initComponents();

    setGUIEnabled(false);

    SimViewPanel.add(view.getCanvas(), BorderLayout.CENTER);
    this.validate();

    AlgorithmDescBox.setText(controller.getAlgorithmDesc(0));

    doc = MsgBox.getStyledDocument();

    Style style = MsgBox.addStyle("Faults", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setItalic(style, true);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Passengers", null);
    StyleConstants.setForeground(style, new Color(0, 204, 204));
    StyleConstants.setItalic(style, true);

    style = MsgBox.addStyle("Normal", null);

    style = MsgBox.addStyle("Elevators", null);
    StyleConstants.setForeground(style, new Color(51, 255, 0));
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Emergs", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Maintenance", null);
    StyleConstants.setForeground(style, Color.ORANGE);
    StyleConstants.setBold(style, true);

    // Hijack the keyboard manager
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyDispatcher(this));

    // add window listener
    this.addWindowListener(new mainWindowListener());
  }
Example #12
0
  /**
   * Returns whether the given component is "actively" shown in screen, that is, it or any of its
   * ancestors is focused.
   *
   * @param aComponent the component to determine whether it is actively shown on screen, may be
   *     <code>null</code>.
   * @return <code>true</code> if the given component is actively shown, <code>false</code>
   *     otherwise.
   */
  public static final boolean isActivelyShown(final Component aComponent) {
    final KeyboardFocusManager kbdFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    final Window owner = kbdFocusManager.getFocusedWindow();

    return ((aComponent != null)
        && (owner != null)
        && ((owner == aComponent) || owner.isAncestorOf(aComponent)));
  }
Example #13
0
 /**
  * Tries to find the current focused window.
  *
  * @return the current focused window, or <code>null</code> if no such window could be found.
  */
 public static final Window getCurrentWindow() {
   Window owner;
   final KeyboardFocusManager kbdFocusManager =
       KeyboardFocusManager.getCurrentKeyboardFocusManager();
   owner = kbdFocusManager.getFocusedWindow();
   if (owner == null) {
     owner = kbdFocusManager.getActiveWindow();
   }
   return owner;
 }
Example #14
0
 public void resetDefaultFocusTraversalKeys() {
   KeyboardFocusManager m = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   for (Integer each :
       Arrays.asList(
           KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
           KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
           KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,
           KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS)) {
     setFocusTraversalKeys(each, m.getDefaultFocusTraversalKeys(each));
   }
 }
  /** Provide appropriate LAF feedback when a filter error occurs. */
  public void provideErrorFeedback() {
    LookAndFeel laf = UIManager.getLookAndFeel();

    if (laf == null) {
      Toolkit.getDefaultToolkit().beep();
    } else {
      KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      Component component = fm.getFocusOwner();
      laf.provideErrorFeedback(component);
    }
  }
  private void tabBackward() {
    final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.focusPreviousComponent();

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            if (manager.getFocusOwner() instanceof JScrollBar) manager.focusPreviousComponent();
          }
        });
  }
  /*
   *  Create using the specified focus policy
   */
  public TabFocusHandler(JTabbedPane tabbedPane, int focusPolicy) {
    if (focusPolicy != RESET_FOCUS && focusPolicy != RETAIN_FOCUS)
      throw new IllegalArgumentException("Invalid focus policy");

    this.tabbedPane = tabbedPane;
    this.focusPolicy = focusPolicy;

    //  Add listeners to manage a tab change

    tabbedPane.addChangeListener(this);
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener("permanentFocusOwner", this);
  }
 /**
  * Inserts a new key processor at the top of the stack
  *
  * @param keyProc The key processor to insert
  */
 public void pushKeyProcessorStack(KeyEventPostProcessor keyProc) {
   if (null != this.m_CurrentActiveKeyProcessor) {
     KeyboardFocusManager.getCurrentKeyboardFocusManager()
         .removeKeyEventPostProcessor(this.m_CurrentActiveKeyProcessor);
   }
   m_KeyProcessorStack.add(this.m_CurrentActiveKeyProcessor);
   m_CurrentActiveKeyProcessor = null;
   if (null != keyProc) {
     m_CurrentActiveKeyProcessor = keyProc;
     KeyboardFocusManager.getCurrentKeyboardFocusManager()
         .addKeyEventPostProcessor(this.m_CurrentActiveKeyProcessor);
   }
 }
Example #19
0
 public void removeNotify() {
   final KeyboardFocusManager keyboardFocusManager =
       KeyboardFocusManager.getCurrentKeyboardFocusManager();
   //noinspection HardCodedStringLiteral
   keyboardFocusManager.removePropertyChangeListener("permanentFocusOwner", myEditorRemover);
   //noinspection HardCodedStringLiteral
   keyboardFocusManager.removePropertyChangeListener("focusOwner", myEditorRemover);
   super.removeNotify();
   if (myBusyIcon != null) {
     remove(myBusyIcon);
     Disposer.dispose(myBusyIcon);
     myBusyIcon = null;
   }
 }
  /*
   * The method maps the list of the active windows to the window's AppContext,
   * then the method registers ActiveWindowListener, GuiDisposedListener listeners;
   * it executes the initilialization only once per AppContext.
   */
  @SuppressWarnings("unchecked")
  private static void initActiveWindowsTracking(Window w) {
    AppContext appContext = AppContext.getAppContext();
    synchronized (appContext) {
      List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY);
      if (l == null) {
        l = new LinkedList<WWindowPeer>();
        appContext.put(ACTIVE_WINDOWS_KEY, l);
        appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener);

        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        kfm.addPropertyChangeListener("activeWindow", activeWindowListener);
      }
    }
  }
Example #21
0
  protected void redispatchKeyEvents(final JTextComponent textComponent, KeyEvent firstKeyEvent) {
    if (textComponent.hasFocus()) {
      return;
    }
    final KeyboardFocusManager currentKeyboardFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    class KeyEventQueue implements KeyEventDispatcher, FocusListener {
      LinkedList events = new LinkedList();

      public boolean dispatchKeyEvent(KeyEvent e) {
        events.add(e);
        return true;
      }

      public void focusGained(FocusEvent e) {
        e.getComponent().removeFocusListener(this);
        currentKeyboardFocusManager.removeKeyEventDispatcher(this);
        final Iterator iterator = events.iterator();
        while (iterator.hasNext()) {
          final KeyEvent ke = (KeyEvent) iterator.next();
          ke.setSource(textComponent);
          textComponent.dispatchEvent(ke);
        }
      }

      public void focusLost(FocusEvent e) {}
    };
    final KeyEventQueue keyEventDispatcher = new KeyEventQueue();
    currentKeyboardFocusManager.addKeyEventDispatcher(keyEventDispatcher);
    textComponent.addFocusListener(keyEventDispatcher);
    if (firstKeyEvent == null) {
      return;
    }
    if (firstKeyEvent.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
      switch (firstKeyEvent.getKeyCode()) {
        case KeyEvent.VK_HOME:
          textComponent.setCaretPosition(0);
          break;
        case KeyEvent.VK_END:
          textComponent.setCaretPosition(textComponent.getDocument().getLength());
          break;
      }
    } else {
      textComponent.selectAll(); // to enable overwrite
      // redispath all key events
      textComponent.dispatchEvent(firstKeyEvent);
    }
  }
Example #22
0
  public boolean editCellAt(final int row, final int column, final EventObject e) {
    if (cellEditor != null && !cellEditor.stopCellEditing()) {
      return false;
    }

    if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
      return false;
    }

    if (!isCellEditable(row, column)) {
      return false;
    }

    if (myEditorRemover == null) {
      final KeyboardFocusManager keyboardFocusManager =
          KeyboardFocusManager.getCurrentKeyboardFocusManager();
      myEditorRemover = new MyCellEditorRemover();
      //noinspection HardCodedStringLiteral
      keyboardFocusManager.addPropertyChangeListener("focusOwner", myEditorRemover);
      //noinspection HardCodedStringLiteral
      keyboardFocusManager.addPropertyChangeListener("permanentFocusOwner", myEditorRemover);
    }

    final TableCellEditor editor = getCellEditor(row, column);
    if (editor != null && editor.isCellEditable(e)) {
      editorComp = prepareEditor(editor, row, column);
      // ((JComponent)editorComp).setBorder(null);
      if (editorComp == null) {
        removeEditor();
        return false;
      }
      editorComp.setBounds(getCellRect(row, column, false));
      add(editorComp);
      editorComp.validate();

      IdeFocusManager.findInstanceByComponent(this).requestFocus(editorComp, false);

      setCellEditor(editor);
      setEditingRow(row);
      setEditingColumn(column);
      editor.addCellEditorListener(this);
      if (isTypeAhead) {
        JTableCellEditorHelper.typeAhead(this, e, row, column);
      }
      return true;
    }
    return false;
  }
  private boolean paintPlaceholderText(Graphics2D g) {
    CharSequence hintText = myEditor.getPlaceholder();
    EditorComponentImpl editorComponent = myEditor.getContentComponent();
    if (myDocument.getTextLength() > 0
        || hintText == null
        || hintText.length() == 0
        || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == editorComponent
            && !myEditor.getShowPlaceholderWhenFocused()) {
      return false;
    }

    hintText =
        SwingUtilities.layoutCompoundLabel(
            g.getFontMetrics(),
            hintText.toString(),
            null,
            0,
            0,
            0,
            0,
            editorComponent.getBounds(),
            new Rectangle(),
            new Rectangle(),
            0);
    g.setColor(myEditor.getFoldingModel().getPlaceholderAttributes().getForegroundColor());
    g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN));
    g.drawString(hintText.toString(), 0, myView.getAscent());
    return true;
  }
  static void subscribeTo(NavBarPanel panel) {
    if (panel.getClientProperty(LISTENER) != null) {
      unsubscribeFrom(panel);
    }

    final NavBarListener listener = new NavBarListener(panel);
    final Project project = panel.getProject();
    panel.putClientProperty(LISTENER, listener);
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener);
    FileStatusManager.getInstance(project).addFileStatusListener(listener);
    PsiManager.getInstance(project).addPsiTreeChangeListener(listener);
    WolfTheProblemSolver.getInstance(project).addProblemListener(listener);
    ActionManager.getInstance().addAnActionListener(listener);

    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
    connection.subscribe(NavBarModelListener.NAV_BAR, listener);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
    panel.putClientProperty(BUS, connection);
    panel.addKeyListener(listener);

    if (panel.isInFloatingMode()) {
      final Window window = SwingUtilities.windowForComponent(panel);
      if (window != null) {
        window.addWindowFocusListener(listener);
      }
    }
  }
  public static void init(Window window) {
    /* running in java 7 ? */
    if (java7 == true) return;

    if (instance == null) instance = new BDKeyboardFocusManagerPeer();
    instance.focusOwner = null;
    instance.window = window;

    /* replace default keyboard focus manager peer */
    Field kbPeer;
    try {
      Class c = Class.forName("java.awt.KeyboardFocusManager");
      kbPeer = c.getDeclaredField("peer");
      kbPeer.setAccessible(true);
    } catch (ClassNotFoundException e) {
      throw new Error("java.awt.KeyboardFocusManager not found");
    } catch (SecurityException e) {
      throw new Error("java.awt.KeyboardFocusManager not accessible");
    } catch (NoSuchFieldException e) {
      throw new Error("java.awt.KeyboardFocusManager.peer not found");
    }
    try {
      kbPeer.set(KeyboardFocusManager.getCurrentKeyboardFocusManager(), instance);
    } catch (java.lang.IllegalAccessException e) {
      throw new Error("java.awt.KeyboardFocusManager.peer not accessible:" + e);
    }
  }
    public void propertyChange(PropertyChangeEvent e) {
      boolean isDisposed = (Boolean) e.getNewValue();
      if (isDisposed != true) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
          log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED ");
        }
      }
      AppContext appContext = AppContext.getAppContext();
      synchronized (appContext) {
        appContext.remove(ACTIVE_WINDOWS_KEY);
        appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this);

        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        kfm.removePropertyChangeListener("activeWindow", activeWindowListener);
      }
    }
 static boolean shouldOpenDialog(Collection hints) {
   if (hints.contains(DiffTool.HINT_SHOW_MODAL_DIALOG)) return true;
   if (hints.contains(DiffTool.HINT_SHOW_NOT_MODAL_DIALOG)) return true;
   if (hints.contains(DiffTool.HINT_SHOW_FRAME)) return false;
   return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow()
       instanceof JDialog;
 }
  /**
   * Constructs a new AlgebraicValueEditor.
   *
   * @param valueEditorHierarchyManager
   */
  public AlgebraicValueEditor(ValueEditorHierarchyManager valueEditorHierarchyManager) {
    super(valueEditorHierarchyManager);

    setFocusCycleRoot(true);
    setLayout(new BorderLayout());
    setResizable(true);
    add(contentScrollPane, BorderLayout.CENTER);

    contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));

    contentScrollPane.getHorizontalScrollBar().setCursor(Cursor.getDefaultCursor());
    contentScrollPane.getVerticalScrollBar().setCursor(Cursor.getDefaultCursor());

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener("permanentFocusOwner", focusChangeListener);
  }
Example #29
0
  /**
   * Creates a swing applet instance.
   *
   * <p>This constructor sets the component's locale property to the value returned by <code>
   * JComponent.getDefaultLocale</code>.
   *
   * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true.
   * @see java.awt.GraphicsEnvironment#isHeadless
   * @see JComponent#getDefaultLocale
   */
  public JApplet() throws HeadlessException {
    super();
    // Check the timerQ and restart if necessary.
    TimerQueue q = TimerQueue.sharedInstance();
    if (q != null) {
      synchronized (q) {
        if (!q.running) q.start();
      }
    }

    /* Workaround for bug 4155072.  The shared double buffer image
     * may hang on to a reference to this applet; unfortunately
     * Image.getGraphics() will continue to call JApplet.getForeground()
     * and getBackground() even after this applet has been destroyed.
     * So we ensure that these properties are non-null here.
     */
    setForeground(Color.black);
    setBackground(Color.white);

    setLocale(JComponent.getDefaultLocale());
    setLayout(new BorderLayout());
    setRootPane(createRootPane());
    setRootPaneCheckingEnabled(true);

    // This code should be changed after the RFE 4719336 is resolved
    // to not make the applet a FocusCycleRoot, but set it's
    // FocusTraversalPolicy only.
    setFocusCycleRoot(true);
    setFocusTraversalPolicy(
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy());

    enableEvents(AWTEvent.KEY_EVENT_MASK);
  }
  public static boolean isFocused(@Nullable Component[] components) {
    if (components == null) return false;

    Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

    if (owner == null) return false;

    Window wnd;
    if (owner instanceof Window) {
      wnd = (Window) owner;
    } else {
      wnd = SwingUtilities.getWindowAncestor(owner);
    }

    for (Component each : components) {
      if (each != null && SwingUtilities.isDescendingFrom(owner, each)) {
        Window eachWindow =
            each instanceof Window ? (Window) each : SwingUtilities.getWindowAncestor(each);
        if (eachWindow == wnd) {
          return true;
        }
      }
    }

    return false;
  }