Пример #1
0
 protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
   if (menuItem.isOpaque()) {
     int w = menuItem.getWidth();
     int h = menuItem.getHeight();
     paintBackground(g, menuItem, 0, 0, w, h);
   }
 }
  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);
   }
 }
Пример #4
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);
  }