Ejemplo n.º 1
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());
   }
 }
Ejemplo n.º 2
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);
   }
 }
Ejemplo n.º 3
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);
    }
 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);
   }
 }
Ejemplo n.º 5
0
 protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
   Graphics2D g2D = (Graphics2D) g;
   Object savedRenderingHint = null;
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
     g2D.setRenderingHint(
         RenderingHints.KEY_TEXT_ANTIALIASING,
         AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
   }
   if (menuItem.isSelected() && menuItem.isArmed()) {
     g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
   } else {
     g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
   }
   super.paintText(g, menuItem, textRect, text);
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
   }
 }
  /** Creates new form. */
  public PopupMenuTest() {
    initComponents();

    ActionListener a =
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            System.out.println(evt);
          }
        };

    JPopupMenu pm = new JPopupMenu();
    JMenu m;
    JMenuItem mi;
    JCheckBoxMenuItem cbmi;
    JRadioButtonMenuItem crmi;
    mi = new JMenuItem("Menu Item 1");
    mi.addActionListener(a);
    pm.add(mi);
    mi = new JMenuItem("Menu Item 2");
    mi.addActionListener(a);
    pm.add(mi);
    mi = new JMenuItem("Menu Item 3");
    mi.addActionListener(a);
    pm.add(mi);

    m = new JMenu("Menu 1");
    mi = new JMenuItem("Menu Item 1.1");
    mi.addActionListener(a);
    m.add(mi);
    mi = new JMenuItem("Menu Item 1.2");
    mi.addActionListener(a);
    m.add(mi);
    pm.add(m);

    pm.addSeparator();
    cbmi = new JCheckBoxMenuItem("Checkbox Menu Item");
    pm.add(cbmi);

    pm.addSeparator();
    ButtonGroup group = new ButtonGroup();
    crmi = new JRadioButtonMenuItem("Radio Menu Item 1");
    crmi.setSelected(true);
    group.add(crmi);
    pm.add(crmi);

    crmi = new JRadioButtonMenuItem("Radio Menu Item 2");
    group.add(crmi);
    pm.add(crmi);
    popupMenu = pm;

    /*
    //setComponentPopupMenu(pm);
    //jLabel1.setComponentPopupMenu(pm);
    JButton button = new JButton("Hi");
    // button.setComponentPopupMenu(pm);
    button.setInheritsPopupMenu(true);
    add(button, BorderLayout.SOUTH);
     */
    MouseAdapter popper1 =
        new MouseAdapter() {
          public void mousePressed(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              showPopupMenu(evt);
            }
          }

          public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              showPopupMenu(evt);
            }
          }

          protected void showPopupMenu(MouseEvent evt) {
            popupMenu.show((Component) evt.getSource(), evt.getX(), evt.getY());
          }
        };

    popupLabel1.addMouseListener(popper1);
    popupField.addMouseListener(popper1);

    MouseAdapter popper2 =
        new MouseAdapter() {
          public void mousePressed(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              showPopupMenu(evt);
            }
          }

          public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
              showPopupMenu(evt);
            }
          }

          protected void showPopupMenu(MouseEvent evt) {
            Dimension ps = popupMenu.getPreferredSize();
            popupMenu.show(popupLabel2, evt.getX() - ps.width / 2, evt.getY() - ps.height / 2);
          }
        };

    popupLabel2.addMouseListener(popper2);
  }