@Override
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    final Graphics2D g2d = (Graphics2D) g;
    final Insets ins = getBorderInsets(c);
    final int yOff = (ins.top + ins.bottom) / 4;
    final boolean square = DarculaButtonUI.isSquare(c);
    int offset = JBUI.scale(square ? 1 : getOffset());
    if (c.hasFocus()) {
      DarculaUIUtil.paintFocusRing(g2d, offset, yOff, width - 2 * offset, height - 2 * yOff);
    } else {
      final GraphicsConfig config = new GraphicsConfig(g);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
      g2d.setPaint(
          UIUtil.getGradientPaint(
              width / 2,
              y + yOff + 1,
              Gray._80.withAlpha(90),
              width / 2,
              height - 2 * yOff,
              Gray._90.withAlpha(90)));
      // g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5);

      ((Graphics2D) g).setPaint(Gray._100.withAlpha(180));
      g.drawRoundRect(
          x + offset,
          y + yOff,
          width - 2 * offset,
          height - 2 * yOff,
          JBUI.scale(square ? 3 : 5),
          JBUI.scale(square ? 3 : 5));

      config.restore();
    }
  }
    @Override
    @SuppressWarnings("unchecked")
    public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
      JCheckBox cb = (JCheckBox) c;
      javax.swing.ButtonModel model = cb.getModel();

      if (ThemeManager.isLookAndFeelNimbus()) {
        icon.paintIcon(c, g, x, y);

        if (c.hasFocus()) {
          nimbusFocusBorder.paintBorder(g, x, y, iconWidth, iconHeight);
        }

        drawIndeterminateNimbusLine(g, x, y);
      } else {
        if (model.isEnabled()) {
          if (model.isPressed() && model.isArmed()) {
            g.setColor(MetalLookAndFeel.getControlShadow());
            g.fillRect(x, y, iconWidth - 1, iconHeight - 1);
            drawPressed3DBorder(g, x, y, iconWidth, iconHeight);
          } else {
            drawFlush3DBorder(g, x, y, iconWidth, iconHeight);
          }
          g.setColor(MetalLookAndFeel.getControlInfo());
        } else {
          g.setColor(MetalLookAndFeel.getControlShadow());
          g.drawRect(x, y, iconWidth - 1, iconHeight - 1);
        }

        drawIndeterminateLine(g, x, y);
      }
    }
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   if (comp.hasFocus() || focusLostTemporarily) {
     Color color = g.getColor();
     g.setColor(focusColor);
     BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
     g.setColor(color);
   }
 }
Esempio n. 4
0
 // These is some wierd problem such that sometimes, the vnmrj command
 // area gets the focus and these items in the login box do not get
 // the focus.  Even clicking in these items does not bring focus to
 // them.  Issuing requestFocus() does not bring focus to them.
 // I can however, determing if either the operator entry box or
 // the password box has focus and if neither does, I can unshow and
 // reshow the panel and that fixes the focus.  So, I have added this
 // to the mouseClicked action.  If neither has focus, it will
 // take focus with setVisible false then true.
 public void mouseClicked(MouseEvent e) {
   boolean pfocus = m_passwordField.hasFocus();
   boolean ofocus = comboTextField.hasFocus();
   if (!pfocus && !ofocus) {
     setVisible(false);
     setVisible(true);
   }
 }
Esempio n. 5
0
 /** Gives focus to a {@linkplain Component} by its name */
 protected static boolean focusByName(final String name)
     throws ComponentNotFoundException, MultipleComponentsFoundException {
   Component c = findByName(name);
   if (c.hasFocus()) return true;
   // try ordinary method
   if (c.requestFocusInWindow()) {
     while (!c.hasFocus()) guiSleep();
     return true;
   }
   // press tab until we have the correct focus
   for (int i = 0; i < 25 /* TODO proper number */; i++) {
     tester.keyStroke('\t');
     guiSleep();
     if (name.equals(AWT.getActiveWindow().getFocusOwner().getName())) return true;
   }
   // failed ...
   logger.warning("Could not give focus to component: " + name);
   return true;
 }
Esempio n. 6
0
  public void paintBorder(Component component, Graphics g, int x, int y, int w, int h) {
    g.setColor(Color.black);
    g.drawRect(x + dist / 2, y + dist / 2, w - dist, h - dist);

    if (component.hasFocus()) {

      for (int i = 0; i < locations.length; i++) {
        Rectangle rect = getRectangle(x, y, w, h, locations[i]);
        g.setColor(Color.WHITE);
        g.fillRect(rect.x, rect.y, rect.width - 1, rect.height - 1);
        g.setColor(Color.BLACK);
        g.drawRect(rect.x, rect.y, rect.width - 1, rect.height - 1);
      }
    }
  }
 public void addPseudoclassListener(
     DefaultStyleable styleable, String pseudoclass, final PseudoclassListener listener)
     throws StylesheetException {
   final PseudoclassEvent event = new PseudoclassEvent(styleable, pseudoclass);
   Component component = (Component) styleable.getBaseObject();
   if (pseudoclass.equals("focused") || pseudoclass.equals("unfocused")) {
     boolean inverse = pseudoclass.equals("unfocused");
     if (component.hasFocus() != inverse) listener.pseudoclassAdded(event);
     component.addFocusListener(getFocusListener(listener, event, inverse));
   } else if (pseudoclass.equals("mouseover") || pseudoclass.equals("mouseout")) {
     boolean inverse = pseudoclass.equals("mouseout");
     if (inverse) listener.pseudoclassAdded(event);
     component.addMouseListener(getMouseOverListener(listener, event, inverse));
   } else if (pseudoclass.equals("mousedown") || pseudoclass.equals("mouseup")) {
     boolean inverse = pseudoclass.equals("mouseup");
     if (inverse) listener.pseudoclassAdded(event);
     component.addMouseListener(getMouseDownListener(listener, event, inverse));
   } else super.addPseudoclassListener(styleable, pseudoclass, listener);
 }
  /**
   * @return <code>true</code> if and only if the passed event is already dispatched by the <code>
   *     IdeMouseEventDispatcher</code> and there is no need for any other processing of the event.
   *     If the method returns <code>false</code> then it means that the event should be delivered
   *     to normal event dispatching.
   */
  public boolean dispatchMouseEvent(MouseEvent e) {
    Component c = e.getComponent();

    // frame activation by mouse click
    if (e.getID() == MOUSE_PRESSED && c instanceof IdeFrame && !c.hasFocus()) {
      IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
      if (focusManager instanceof FocusManagerImpl) {
        Component at = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
        if (at != null && at.isFocusable()) {
          ((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation((IdeFrame) c, at);
        }
      }
    }

    if (SystemInfo.isXWindow && e.isPopupTrigger() && e.getButton() != 3) {
      // we can do better than silly triggering popup on everything but left click
      resetPopupTrigger(e);
    }

    boolean ignore = false;
    if (!(e.getID() == MouseEvent.MOUSE_PRESSED
        || e.getID() == MouseEvent.MOUSE_RELEASED
        || e.getID() == MOUSE_CLICKED)) {
      ignore = true;
    }

    patchClickCount(e);

    if (e.isConsumed()
        || e.isPopupTrigger()
        || (e.getButton() > 3 ? e.getID() != MOUSE_PRESSED : e.getID() != MOUSE_RELEASED)
        || e.getClickCount() < 1
        || e.getButton() == MouseEvent.NOBUTTON) { // See #16995. It did happen
      ignore = true;
    }

    int modifiers = e.getModifiers();
    int modifiersEx = e.getModifiersEx();
    if (e.getID() == MOUSE_PRESSED) {
      myPressedModifiersStored = true;
      myModifiers = modifiers;
      myModifiersEx = modifiersEx;
    } else if (e.getID() == MOUSE_RELEASED) {
      if (myPressedModifiersStored) {
        myPressedModifiersStored = false;
        modifiers = myModifiers;
        modifiersEx = myModifiersEx;
      }
    }

    final JRootPane root = findRoot(e);
    if (root != null) {
      BlockState blockState = myRootPane2BlockedId.get(root);
      if (blockState != null) {
        if (SWING_EVENTS_PRIORITY.indexOf(blockState.currentEventId)
            < SWING_EVENTS_PRIORITY.indexOf(e.getID())) {
          blockState.currentEventId = e.getID();
          if (blockState.blockMode == IdeEventQueue.BlockMode.COMPLETE) {
            return true;
          } else {
            ignore = true;
          }
        } else {
          myRootPane2BlockedId.remove(root);
        }
      }
    }

    if (c == null) {
      throw new IllegalStateException("component cannot be null");
    }
    c = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());

    if (c instanceof IdeGlassPaneImpl) {
      c = ((IdeGlassPaneImpl) c).getTargetComponentFor(e);
    }

    if (c == null) { // do nothing if component doesn't contains specified point
      return false;
    }

    if (isHorizontalScrolling(c, e)) {
      boolean done = doHorizontalScrolling(c, (MouseWheelEvent) e);
      if (done) return true;
    }

    if (ignore) return false;

    // avoid "cyclic component initialization error" in case of dialogs shown because of component
    // initialization failure
    if (!KeymapManagerImpl.ourKeymapManagerInitialized) {
      return false;
    }

    final MouseShortcut shortcut = new MouseShortcut(e.getButton(), modifiersEx, e.getClickCount());
    fillActionsList(c, shortcut, IdeKeyEventDispatcher.isModalContext(c));
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    if (actionManager != null) {
      AnAction[] actions = myActions.toArray(new AnAction[myActions.size()]);
      for (AnAction action : actions) {
        DataContext dataContext = DataManager.getInstance().getDataContext(c);
        Presentation presentation = myPresentationFactory.getPresentation(action);
        AnActionEvent actionEvent =
            new AnActionEvent(
                e,
                dataContext,
                ActionPlaces.MAIN_MENU,
                presentation,
                ActionManager.getInstance(),
                modifiers);
        action.beforeActionPerformedUpdate(actionEvent);

        if (presentation.isEnabled()) {
          actionManager.fireBeforeActionPerformed(action, dataContext, actionEvent);
          final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);

          if (context != null && !context.isShowing()) continue;

          action.actionPerformed(actionEvent);
          e.consume();
        }
      }
      if (actions.length > 0 && e.isConsumed()) return true;
    }
    return e.getButton() > 3;
  }