Пример #1
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   JMenuItem b = (JMenuItem) c;
   ButtonModel model = b.getModel();
   Color borderColorLo = AbstractLookAndFeel.getFrameColor();
   Color borderColorHi =
       ColorHelper.brighter(AbstractLookAndFeel.getMenuSelectionBackgroundColor(), 40);
   if (c.getParent() instanceof JMenuBar) {
     if (model.isArmed() || model.isSelected()) {
       g.setColor(borderColorLo);
       g.drawLine(x, y, x + w - 1, y);
       g.drawLine(x, y, x, y + h - 1);
       g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
       g.setColor(borderColorHi);
       g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
       g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
     }
   } else {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(borderColorLo);
       g.drawLine(x, y, x + w - 1, y);
       g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
       g.setColor(borderColorHi);
       g.drawLine(x, y + 1, x + w - 2, y + 1);
     }
   }
 }
Пример #2
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      JMenuItem b = (JMenuItem) c;
      ButtonModel model = b.getModel();

      g.translate(x, y);

      if (c.getParent() instanceof JMenuBar) {
        if (model.isArmed() || model.isSelected()) {
          g.setColor(MetalLookAndFeel.getControlDarkShadow());
          g.drawLine(0, 0, w - 2, 0);
          g.drawLine(0, 0, 0, h - 1);
          g.drawLine(w - 2, 2, w - 2, h - 1);

          g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
          g.drawLine(w - 1, 1, w - 1, h - 1);

          g.setColor(MetalLookAndFeel.getMenuBackground());
          g.drawLine(w - 1, 0, w - 1, 0);
        }
      } else {
        if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
          g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
          g.drawLine(0, 0, w - 1, 0);

          g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
          g.drawLine(0, h - 1, w - 1, h - 1);
        } else {
          g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
          g.drawLine(0, 0, 0, h - 1);
        }
      }

      g.translate(-x, -y);
    }
Пример #3
0
 protected void paintBackground(Graphics g, JComponent c, int x, int y, int w, int h) {
   JMenuItem b = (JMenuItem) c;
   ButtonModel model = b.getModel();
   if (c.getParent() instanceof JMenuBar) {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   } else {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     } else if (!AbstractLookAndFeel.getTheme().isMenuOpaque()) {
       Graphics2D g2D = (Graphics2D) g;
       Composite composite = g2D.getComposite();
       AlphaComposite alpha =
           AlphaComposite.getInstance(
               AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
       g2D.setComposite(alpha);
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
       g2D.setComposite(composite);
     } else {
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   }
   if (menuItem.isSelected() && menuItem.isArmed()) {
     g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
   } else {
     g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
   }
 }
  public void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
    ButtonModel model = menuItem.getModel();
    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();
    PlastikColorTheme colorTheme = PlastikLookAndFeel.getTheme().getColorTheme();

    Color oldColor = g.getColor();

    Color background =
        colorTheme.getColor(
            menuItem.getBackground(), PlastikColorTheme.MENU_ITEM | PlastikColorTheme.BACKGROUND);
    g.setColor(background);
    g.fillRect(0, 0, menuWidth, menuHeight);

    if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
      Color top =
          colorTheme.getColor(
              PlastikColorTheme.MENU_ITEM
                  | PlastikColorTheme.BACKGROUND
                  | PlastikColorTheme.ROLLOVER
                  | PlastikColorTheme.BRIGHTER);
      Color topGradient =
          colorTheme.getColor(
              PlastikColorTheme.MENU_ITEM
                  | PlastikColorTheme.BACKGROUND
                  | PlastikColorTheme.ROLLOVER
                  | PlastikColorTheme.BRIGHTER_GRADIENT);
      Color bottomGradient =
          colorTheme.getColor(
              PlastikColorTheme.MENU_ITEM
                  | PlastikColorTheme.BACKGROUND
                  | PlastikColorTheme.ROLLOVER
                  | PlastikColorTheme.DARKER_GRADIENT);
      Color bottom =
          colorTheme.getColor(
              PlastikColorTheme.MENU_ITEM
                  | PlastikColorTheme.BACKGROUND
                  | PlastikColorTheme.ROLLOVER
                  | PlastikColorTheme.DARKER);
      g.setColor(top);
      g.drawLine(0, 0, menuWidth - 1, 0);
      Gradients.drawBoxGradient(g, 0, 1, menuWidth, menuHeight - 2, topGradient, bottomGradient);
      g.setColor(bottom);
      g.drawLine(0, menuHeight - 1, menuWidth - 1, menuHeight - 1);
    }

    g.setColor(oldColor);
  }
 public void processMouseEvent(
     JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager) {
   Point p = e.getPoint();
   if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) {
     if (e.getID() == MouseEvent.MOUSE_RELEASED) {
       manager.clearSelectedPath();
       item.doClick(0);
       item.setArmed(false);
     } else manager.setSelectedPath(path);
   } else if (item.getModel().isArmed()) {
     MenuElement newPath[] = new MenuElement[path.length - 1];
     int i, c;
     for (i = 0, c = path.length - 1; i < c; i++) newPath[i] = path[i];
     manager.setSelectedPath(newPath);
   }
 }
Пример #6
0
  /**
   * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla
   * en todas partes...
   */
  static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) {
    ButtonModel model = menuItem.getModel();
    Color oldColor = g.getColor();

    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();

    if (menuItem.isOpaque()) {
      g.setColor(menuItem.getBackground());
      g.fillRect(0, 0, menuWidth, menuHeight);
    }

    if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected())
        || model.isArmed()) {
      RoundRectangle2D.Float boton = new RoundRectangle2D.Float();
      boton.x = 1;
      boton.y = 0;
      boton.width = menuWidth - 3;
      boton.height = menuHeight - 1;
      boton.arcwidth = 8;
      boton.archeight = 8;

      GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu());

      Graphics2D g2D = (Graphics2D) g;
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(bgColor);
      g2D.fill(boton);

      g.setColor(bgColor.darker());
      g2D.draw(boton);

      g2D.setPaint(grad);
      g2D.fill(boton);

      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    }

    g.setColor(oldColor);
  }
Пример #7
0
  /**
   * This method is not being used to paint menu item since 6.0 This code left for compatibility
   * only. Do not use or override it, this will not cause any visible effect.
   */
  public static void paintMenuItem(
      Graphics g,
      JComponent c,
      Icon checkIcon,
      Icon arrowIcon,
      Color background,
      Color foreground,
      int defaultTextIconGap) {

    JMenuItem b = (JMenuItem) c;
    ButtonModel model = b.getModel();

    Dimension size = b.getSize();
    Insets i = c.getInsets();

    Rectangle viewRect = new Rectangle(size);

    viewRect.x += i.left;
    viewRect.y += i.top;
    viewRect.width -= (i.right + viewRect.x);
    viewRect.height -= (i.bottom + viewRect.y);

    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle acceleratorRect = new Rectangle();
    Rectangle checkRect = new Rectangle();
    Rectangle arrowRect = new Rectangle();

    Font holdf = g.getFont();
    Font f = c.getFont();
    g.setFont(f);
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
    FontMetrics fmAccel =
        SwingUtilities2.getFontMetrics(c, g, UIManager.getFont("MenuItem.acceleratorFont"));

    if (c.isOpaque()) {
      if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
        g.setColor(background);
      } else {
        g.setColor(c.getBackground());
      }
      g.fillRect(0, 0, size.width, size.height);
    }

    // get Accelerator text
    KeyStroke accelerator = b.getAccelerator();
    String acceleratorText = "";
    if (accelerator != null) {
      int modifiers = accelerator.getModifiers();
      if (modifiers > 0) {
        acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
        acceleratorText += "+";
      }
      acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
    }

    // layout the text and icon
    String text =
        layoutMenuItem(
            c,
            fm,
            b.getText(),
            fmAccel,
            acceleratorText,
            b.getIcon(),
            checkIcon,
            arrowIcon,
            b.getVerticalAlignment(),
            b.getHorizontalAlignment(),
            b.getVerticalTextPosition(),
            b.getHorizontalTextPosition(),
            viewRect,
            iconRect,
            textRect,
            acceleratorRect,
            checkRect,
            arrowRect,
            b.getText() == null ? 0 : defaultTextIconGap,
            defaultTextIconGap);

    // Paint the Check
    Color holdc = g.getColor();
    if (checkIcon != null) {
      if (model.isArmed() || (c instanceof JMenu && model.isSelected())) g.setColor(foreground);
      checkIcon.paintIcon(c, g, checkRect.x, checkRect.y);
      g.setColor(holdc);
    }

    // Paint the Icon
    if (b.getIcon() != null) {
      Icon icon;
      if (!model.isEnabled()) {
        icon = (Icon) b.getDisabledIcon();
      } else if (model.isPressed() && model.isArmed()) {
        icon = (Icon) b.getPressedIcon();
        if (icon == null) {
          // Use default icon
          icon = (Icon) b.getIcon();
        }
      } else {
        icon = (Icon) b.getIcon();
      }

      if (icon != null) {
        icon.paintIcon(c, g, iconRect.x, iconRect.y);
      }
    }

    // Draw the Text
    if (text != null && !text.equals("")) {
      // Once BasicHTML becomes public, use BasicHTML.propertyKey
      // instead of the hardcoded string below!
      View v = (View) c.getClientProperty("html");
      if (v != null) {
        v.paint(g, textRect);
      } else {
        int mnemIndex = b.getDisplayedMnemonicIndex();

        if (!model.isEnabled()) {
          // *** paint the text disabled
          g.setColor(b.getBackground().brighter());
          SwingUtilities2.drawStringUnderlineCharAt(
              b, g, text, mnemIndex, textRect.x, textRect.y + fmAccel.getAscent());
          g.setColor(b.getBackground().darker());
          SwingUtilities2.drawStringUnderlineCharAt(
              b, g, text, mnemIndex, textRect.x - 1, textRect.y + fmAccel.getAscent() - 1);

        } else {
          // *** paint the text normally
          if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
            g.setColor(foreground);
          } else {
            g.setColor(b.getForeground());
          }
          SwingUtilities2.drawStringUnderlineCharAt(
              b, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
        }
      }
    }

    // Draw the Accelerator Text
    if (acceleratorText != null && !acceleratorText.equals("")) {

      // Get the maxAccWidth from the parent to calculate the offset.
      int accOffset = 0;
      Container parent = b.getParent();
      if (parent != null && parent instanceof JComponent) {
        JComponent p = (JComponent) parent;
        Integer maxValueInt = (Integer) p.getClientProperty(MotifGraphicsUtils.MAX_ACC_WIDTH);
        int maxValue = maxValueInt != null ? maxValueInt.intValue() : acceleratorRect.width;

        // Calculate the offset, with which the accelerator texts will be drawn with.
        accOffset = maxValue - acceleratorRect.width;
      }

      g.setFont(UIManager.getFont("MenuItem.acceleratorFont"));
      if (!model.isEnabled()) {
        // *** paint the acceleratorText disabled
        g.setColor(b.getBackground().brighter());
        SwingUtilities2.drawString(
            c,
            g,
            acceleratorText,
            acceleratorRect.x - accOffset,
            acceleratorRect.y + fm.getAscent());
        g.setColor(b.getBackground().darker());
        SwingUtilities2.drawString(
            c,
            g,
            acceleratorText,
            acceleratorRect.x - accOffset - 1,
            acceleratorRect.y + fm.getAscent() - 1);
      } else {
        // *** paint the acceleratorText normally
        if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
          g.setColor(foreground);
        } else {
          g.setColor(b.getForeground());
        }
        SwingUtilities2.drawString(
            c,
            g,
            acceleratorText,
            acceleratorRect.x - accOffset,
            acceleratorRect.y + fmAccel.getAscent());
      }
    }

    // Paint the Arrow
    if (arrowIcon != null) {
      if (model.isArmed() || (c instanceof JMenu && model.isSelected())) g.setColor(foreground);
      if (!(b.getParent() instanceof JMenuBar)) arrowIcon.paintIcon(c, g, arrowRect.x, arrowRect.y);
    }

    g.setColor(holdc);
    g.setFont(holdf);
  }
Пример #8
0
 @Override
 protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
   JMenu menu = (JMenu) menuItem;
   ButtonModel buttonmodel = menu.getModel();
   if (menu.isTopLevelMenu()) {
     this.selectionForeground = Colors.getBlack();
   } else {
     this.selectionForeground = Colors.getWhite();
   }
   int w = menu.getWidth();
   int h = menu.getHeight();
   Color oldColor = g.getColor();
   if (!menu.isContentAreaFilled() || !menu.isOpaque()) {
     // do nothing
   } else {
     if (menu.isTopLevelMenu()) {
       if (buttonmodel.isSelected()) {
         CashedPainter.drawMenuBackground(menuItem, g, 0, 0, w, h);
       } else if (buttonmodel.isRollover() && buttonmodel.isEnabled()) {
         g.setColor(new ColorUIResource(252, 252, 252));
         g.fillRect(1, 1, w - 2, h - 2);
         g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[0]);
         g.drawLine(2, 0, w - 3, 0);
         g.drawLine(2, h - 1, w - 3, h - 1);
         g.drawLine(0, 2, 0, h - 3);
         g.drawLine(w - 1, 2, w - 1, h - 3);
         g.drawLine(1, 1, 1, 1);
         g.drawLine(w - 2, 1, w - 2, 1);
         g.drawLine(1, h - 2, 1, h - 2);
         g.drawLine(w - 2, h - 2, w - 2, h - 2);
         g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[8]);
         g.drawLine(0, 1, 1, 0);
         g.drawLine(w - 1, 1, w - 2, 0);
         g.drawLine(1, h - 1, 0, h - 2);
         g.drawLine(w - 1, h - 2, w - 2, h - 1);
         g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[7]);
         g.drawLine(1, 2, 2, 1);
         g.drawLine(w - 2, 2, w - 3, 1);
         g.setColor(RapidLookTools.getColors().getToolbarButtonColors()[6]);
         g.drawLine(2, h - 2, 1, h - 3);
         g.drawLine(w - 2, h - 3, w - 3, h - 2);
         g.setColor(new ColorUIResource(252, 252, 252));
         g.drawLine(0, 0, 0, 0);
         g.drawLine(w - 1, 0, w - 1, 0);
         g.setColor(new ColorUIResource(232, 232, 232));
         g.drawLine(0, h - 1, 0, h - 1);
         g.drawLine(w - 1, h - 1, w - 1, h - 1);
       } else {
         if (menuItem.getParent() instanceof JMenuBar) {
           ((MenuBarUI) ((JMenuBar) menuItem.getParent()).getUI()).update(g, menuItem);
         }
       }
     } else {
       if (!menuItem.getModel().isSelected()) {
         CashedPainter.drawMenuItemFading(menuItem, g);
       } else {
         RapidLookTools.drawMenuItemBackground(g, menuItem);
       }
     }
   }
   g.setColor(oldColor);
 }