Esempio n. 1
0
 public void mouseExited(MouseEvent e) {
   Component component = e.getComponent();
   if (component instanceof AbstractButton) {
     AbstractButton button = (AbstractButton) component;
     button.setBorderPainted(false);
   }
 }
 @Override
 public void mouseEntered(final MouseEvent e) {
   final Component component = e.getComponent();
   if (component instanceof AbstractButton) {
     final AbstractButton button = (AbstractButton) component;
     button.setBorderPainted(true);
   }
 }
 private static void removeButtonContentAreaAndBorder(AbstractButton button) {
   boolean canRemove = true;
   if (button instanceof JToggleButton) {
     canRemove = !button.isSelected();
   }
   if (canRemove) {
     button.setContentAreaFilled(false);
     button.setBorderPainted(false);
   }
 }
        public @Override void mouseEntered(MouseEvent evt) {
          Object src = evt.getSource();

          if (src instanceof AbstractButton) {
            AbstractButton button = (AbstractButton) evt.getSource();
            if (button.isEnabled()) {
              button.setContentAreaFilled(true);
              button.setBorderPainted(true);
            }
          }
        }
Esempio n. 5
0
  /**
   * Creates the new item.
   *
   * @param component the content of this item, not <code>null</code>
   */
  public ComponentItem(Component component) {
    if (component == null) {
      throw new IllegalArgumentException("component must not be null");
    }

    if (component instanceof AbstractButton) {
      ((AbstractButton) component).setBorderPainted(false);
    }

    this.component = component;
  }
Esempio n. 6
0
 @Override
 public void mouseEntered(MouseEvent e) {
   AbstractButton btn = (AbstractButton) e.getSource();
   if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == 0) {
     if (rolloverBorderPainted) {
       btn.setBorderPainted(true);
     }
     if (rolloverContentAreaFilled) {
       btn.setContentAreaFilled(true);
     }
   }
 }
Esempio n. 7
0
 public static AbstractButton makeToolBarButton(Command cmd) {
   AbstractButton b;
   if (cmd instanceof ToggleCommand) {
     b = new JToggleButton(cmd);
     b.setSelected(((ToggleCommand) cmd).isSelected());
   } else {
     b = new JButton(cmd);
   }
   b.setFocusable(false);
   b.setText(null);
   // b.setMargin(new Insets(2, 2, 2, 2));
   b.setBorderPainted(false);
   cmd.bind(b);
   return b;
 }
Esempio n. 8
0
  protected AbstractButton addButton(Action action) {
    boolean isToggle = action instanceof AbstractFXDToggleAction;
    Border buttonBorder = UIManager.getBorder("nb.tabbutton.border"); // NOI18N
    AbstractButton button;

    if (isToggle) {
      final JToggleButton tButton = new JToggleButton(action);
      action.addPropertyChangeListener(
          new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {
              if (AbstractFXDToggleAction.SELECTION_STATE.equals(evt.getPropertyName())) {
                tButton.setSelected(((Boolean) evt.getNewValue()).booleanValue());
                tButton.repaint();
              }
            }
          });
      Boolean state = (Boolean) action.getValue(AbstractFXDToggleAction.SELECTION_STATE);
      if (state != null) {
        tButton.setSelected(state.booleanValue());
      }
      button = tButton;
    } else {
      button = new JButton(action);
    }

    if (buttonBorder != null) {
      button.setBorder(buttonBorder);
    }
    GridBagConstraints constrains = new GridBagConstraints();
    constrains.anchor = GridBagConstraints.WEST;
    constrains.insets = new Insets(0, 3, 0, 2);

    button.setContentAreaFilled(true);
    button.setBorderPainted(true);
    if (button instanceof JButton) {
      button.addMouseListener(m_buttonListener);
    }
    // @inherited fix of issue #69642. Focus shouldn't stay in toolbar
    button.setFocusable(false);
    add(button, constrains);
    return button;
  }
  public void setUseFlatUI(boolean b) {
    main.setContentAreaFilled(!b);
    main.setFocusPainted(!b);
    main.setBorderPainted(!b);
    main.setMargin(new Insets(1, 1, 1, 1));

    popper.setContentAreaFilled(!b);
    popper.setFocusPainted(!b);
    popper.setBorderPainted(!b);
    popper.setMargin(new Insets(1, 1, 1, 1));

    setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    setOpaque(false);

    MouseAdapter ma =
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            main.setContentAreaFilled(true);
            main.setBackground(new Color(216, 240, 254));
            // m.getMainButton().setForeground( Color.black );
            setBorder(new LineBorder(new Color(200, 200, 200), 1));
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            popper.setBackground(new Color(242, 242, 242));
            popper.setContentAreaFilled(true);
            popper.setBorder(menu.getBorder());
          }

          public void mouseExited(MouseEvent e) {
            main.setContentAreaFilled(false);
            //	c.setForeground( Color.black );
            setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
            setCursor(Cursor.getDefaultCursor());

            popper.setContentAreaFilled(false);
            popper.setBorder(null);
          }
        };

    main.addMouseListener(ma);
    popper.addMouseListener(ma);
  }
Esempio n. 10
0
  /**
   * Adds the given NamedMediaType.
   *
   * <p>Marks the 'Any Type' as selected.
   */
  private void addMediaType(NamedMediaType type, String toolTip) {
    Icon icon = type.getIcon();
    Icon disabledIcon = null;
    Icon rolloverIcon = null;
    AbstractButton button = new JRadioButton(type.getName());
    button.putClientProperty(MEDIA, type);
    button.putClientProperty(SELECTED, icon);
    if (icon != null) {
      disabledIcon = ImageManipulator.darken(icon);
      rolloverIcon = ImageManipulator.brighten(icon);
    }
    button.putClientProperty(DESELECTED, disabledIcon);
    button.setIcon(disabledIcon);
    button.setRolloverIcon(rolloverIcon);
    button.addItemListener(HIGHLIGHTER);
    button.setBorderPainted(false);
    button.setFocusPainted(false);
    button.setContentAreaFilled(false);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setOpaque(false);
    button.addMouseListener(CLICK_FORWARDER);
    button.setPreferredSize(new Dimension(100, 22));
    if (toolTip != null) {
      button.setToolTipText(toolTip);
    }
    GROUP.add(button);

    DitherPanel panel = new DitherPanel(DITHERER);
    panel.setDithering(false);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 7, 1));
    panel.add(button);
    panel.addMouseListener(CLICK_FORWARDER);
    panel.setBackground(UIManager.getColor("TabbedPane.background"));
    SCHEMAS.add(panel);

    if (type.getMediaType() == MediaType.getAnyTypeMediaType()) button.setSelected(true);
    else button.setSelected(false);
  }
Esempio n. 11
0
 private JToolBar createToolBar() {
   ActionMap actionMap = context.getActionMap(this);
   final JToolBar toolbar = new JToolBar();
   toolbar.setFloatable(false);
   toolbar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.GRAY));
   toolbar.setRollover(true);
   toolbar.add(actionMap.get("openProject"));
   toolbar.addSeparator();
   toolbar.add(application.getAction(NewRvConnection.COMMAND));
   toolbar.addSeparator();
   toolbar.add(application.getAction(ClearLedger.COMMAND));
   toolbar.addSeparator();
   toolbar.add(application.getAction(PauseAllConnections.COMMAND));
   final Component[] components = toolbar.getComponents();
   for (int i = 0, imax = components.length; i < imax; ++i) {
     Component component = components[i];
     if (component instanceof AbstractButton) {
       ((AbstractButton) component).setBorderPainted(false);
       ((AbstractButton) component).setOpaque(false);
     }
   }
   return toolbar;
 }
Esempio n. 12
0
  public TrayIconPopup(TrayExtension trayExtension) {
    super();
    this.extension = trayExtension;
    // resizecomps = new ArrayList<AbstractButton>();
    setVisible(false);
    setLayout(new MigLayout("ins 0", "[grow,fill]", "[grow,fill]"));
    addMouseListener(this);
    this.setUndecorated(true);
    // initEntryPanel();
    // initQuickConfigPanel();
    // initBottomPanel();
    // initExitPanel();
    JPanel content = new JPanel(new MigLayout("ins 5, wrap 1", "[fill]", "[]5[]"));
    add(content);
    JButton header;
    content.add(
        header = new JButton("<html><b>" + JDUtilities.getJDTitle(0) + "</b></html>"),
        "align center");
    header.setBorderPainted(false);
    header.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            JDGui.getInstance().setWindowToTray(false);
            dispose();
          }
        });
    AbstractButton ab;
    // System.out.println(this.getColConstraints(list.length));
    MenuItemData last = null;
    for (final MenuItemData menudata : MenuManagerTrayIcon.getInstance().getMenuData().getItems()) {
      AbstractButton bt = null;
      AppAction action;
      try {
        if (!menudata.isVisible()) {
          continue;
        }
        if (menudata instanceof SeparatorData) {
          if (last != null && last instanceof SeparatorData) {
            // no separator dupes
            continue;
          }
          content.add(new JSeparator(SwingConstants.HORIZONTAL), "growx,spanx");
          last = menudata;
          continue;
        }
        if (menudata._getValidateException() != null) {
          continue;
        }

        if (menudata.getType()
            == org.jdownloader.controlling.contextmenu.MenuItemData.Type.CONTAINER) {

          bt =
              new JToggleButton() {

                protected void paintComponent(Graphics g) {

                  super.paintComponent(g);

                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint(
                      RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                  g2.setRenderingHint(
                      RenderingHints.KEY_INTERPOLATION,
                      RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                  g2.setRenderingHint(
                      RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
                  g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                  g2.setColor(Color.BLACK);
                  g2.fillPolygon(
                      new int[] {getWidth() - 5, getWidth() - 5 - 6, getWidth() - 5 - 6},
                      new int[] {getHeight() / 2, getHeight() / 2 - 4, getHeight() / 2 + 4},
                      3);
                }
              };

          bt.setText(menudata.getName());
          bt.setOpaque(false);
          bt.setContentAreaFilled(false);
          bt.setBorderPainted(false);
          bt.addActionListener(
              new ActionListener() {
                private ExtPopupMenu root = null;

                public void actionPerformed(ActionEvent e) {
                  hideThreadrunning = false;
                  if (root != null && root.isShowing()) {
                    return;
                  }
                  root = new ExtPopupMenu();

                  new MenuBuilder(
                      MenuManagerMainToolbar.getInstance(), root, (MenuContainer) menudata) {
                    protected void addAction(
                        final JComponent root, final MenuItemData inst, int index, int size)
                        throws InstantiationException, IllegalAccessException,
                            InvocationTargetException, ClassNotFoundException,
                            NoSuchMethodException, ExtensionNotLoadedException {
                      final JComponent ret = inst.addTo(root);
                      if (ret instanceof AbstractButton) {
                        ((AbstractButton) ret)
                            .addActionListener(
                                new ActionListener() {
                                  public void actionPerformed(ActionEvent evt) {
                                    ((AbstractButton) ret).getAction().actionPerformed(evt);
                                    TrayIconPopup.this.dispose();
                                  }
                                });
                      }
                    }
                  }.run();
                  Object src = e.getSource();
                  if (e.getSource() instanceof Component) {
                    Component button = (Component) e.getSource();
                    Dimension prefSize = root.getPreferredSize();
                    int[] insets = LAFOptions.getInstance().getPopupBorderInsets();
                    root.show(button, button.getWidth(), -insets[0]);
                  }
                }
              });
          bt.setIcon(MenuItemData.getIcon(menudata.getIconKey(), ICON_SIZE));
          bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          bt.setFocusPainted(false);
          bt.setHorizontalAlignment(JButton.LEFT);
          bt.setIconTextGap(5);
          bt.addMouseListener(new HoverEffect(bt));
          final AbstractButton finalBt = bt;
          bt.addMouseListener(
              new MouseListener() {

                private Timer timer;

                @Override
                public void mouseReleased(MouseEvent e) {
                  if (timer != null) {
                    timer.stop();
                    timer = null;
                  }
                }

                @Override
                public void mousePressed(MouseEvent e) {
                  if (timer != null) {
                    timer.stop();
                    timer = null;
                  }
                }

                @Override
                public void mouseExited(MouseEvent e) {
                  if (timer != null) {
                    timer.stop();
                    timer = null;
                  }
                }

                @Override
                public void mouseEntered(MouseEvent e) {

                  timer =
                      new Timer(
                          500,
                          new ActionListener() {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                              finalBt.doClick();
                            }
                          });
                  timer.setRepeats(false);
                  timer.start();
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                  if (timer != null) {
                    timer.stop();
                    timer = null;
                  }
                }
              });
          content.add(bt);

          continue;
        } else if (menudata instanceof MenuLink) {
          final JComponent item = menudata.createItem();
          if (StringUtils.isNotEmpty(menudata.getIconKey())) {
            if (item instanceof AbstractButton) {
              ((AbstractButton) item)
                  .setIcon(MenuItemData.getIcon(menudata.getIconKey(), ICON_SIZE));
            }
          }
          content.add(item, "");

        } else if (menudata.getActionData() != null) {

          action = menudata.createAction();
          if (!action.isVisible()) {
            continue;
          }
          if (StringUtils.isNotEmpty(menudata.getShortcut())
              && KeyStroke.getKeyStroke(menudata.getShortcut()) != null) {
            action.setAccelerator(KeyStroke.getKeyStroke(menudata.getShortcut()));
          } else if (MenuItemData.isEmptyValue(menudata.getShortcut())) {
            action.setAccelerator(null);
          }
          content.add(getMenuEntry(action));
          last = menudata;
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    // content.add(new JSeparator(), "growx, spanx");
    // content.add(entryPanel);
    // content.add(new JSeparator(), "growx, spanx");
    // content.add(quickConfigPanel);
    // content.add(new JSeparator(), "growx, spanx");
    // content.add(bottomPanel, "pushx,growx");
    // content.add(new JSeparator(), "growx, spanx");
    // content.add(exitPanel);
    //

    content.setBorder(BorderFactory.createLineBorder(content.getBackground().darker()));
    // Dimension size = new Dimension(getPreferredSize().width,
    // resizecomps.get(0).getPreferredSize().height);
    // for (AbstractButton c : resizecomps) {
    // c.setPreferredSize(size);
    // c.setMinimumSize(size);
    // c.setMaximumSize(size);
    // }
    setAlwaysOnTop(true);
    pack();
    hideThread =
        new Thread() {
          /*
           * this thread handles closing of popup because enter/exit/move events are too slow and can miss the exitevent
           */
          public void run() {
            while (true && hideThreadrunning) {
              try {
                sleep(500);
              } catch (InterruptedException e) {
              }
              if (enteredPopup && hideThreadrunning) {
                PointerInfo mouse = MouseInfo.getPointerInfo();
                Point current = TrayIconPopup.this.getLocation();
                if (mouse.getLocation().x < current.x
                    || mouse.getLocation().x > current.x + TrayIconPopup.this.getSize().width) {
                  dispose();
                  break;
                } else if (mouse.getLocation().y < current.y
                    || mouse.getLocation().y > current.y + TrayIconPopup.this.getSize().height) {
                  dispose();
                  break;
                }
              }
            }
          }
        };
    hideThreadrunning = true;
    hideThread.start();
  }
Esempio n. 13
0
 @Override
 public void mouseExited(MouseEvent e) {
   AbstractButton btn = (AbstractButton) e.getSource();
   btn.setBorderPainted(false);
   btn.setContentAreaFilled(false);
 }
Esempio n. 14
0
 /**
  * This method is invoked upon adding a button to the toolbar. It can be overriden to provide
  * another look or feel.
  *
  * <p>Default settings are :
  *
  * <ul>
  *   <li>setRolloverEnabled(true)
  *   <li>setContentAreaFilled(false);
  *   <li>setOpaque(false)
  *   <li>setBorderPainted(false)
  * </ul>
  */
 public static void configureButton(AbstractButton button) {
   button.setRolloverEnabled(true);
   button.setContentAreaFilled(false);
   button.setOpaque(false);
   button.setBorderPainted(false);
 }