public boolean setSingleSelection(boolean b) {
   if (choices == null) return false;
   if (b) {
     if (getSingleSelection()) return false;
     if (invisibleButton == null) invisibleButton = new JRadioButton();
     if (buttonGroup == null) {
       buttonGroup = new ButtonGroup();
     } else {
       clearButtonGroup(buttonGroup);
     }
     buttonGroup.add(invisibleButton);
     JRadioButton[] rb = new JRadioButton[choices.length];
     for (int i = 0; i < choices.length; i++) {
       rb[i] = new JRadioButton();
       rb[i].setFont(getFont());
       rb[i].setText(choices[i].getText());
       rb[i].setIcon(choices[i].getIcon());
       ActionListener[] al = choices[i].getActionListeners();
       if (al != null) {
         for (ActionListener x : al) rb[i].addActionListener(x);
       }
       ItemListener[] il = choices[i].getItemListeners();
       if (il != null) {
         for (ItemListener x : il) rb[i].addItemListener(x);
       }
       buttonGroup.add(rb[i]);
     }
     choices = rb;
     for (AbstractButton c : choices) {
       c.setBackground(getBackground());
       c.setOpaque(isOpaque());
     }
   } else {
     if (!getSingleSelection()) return false;
     JCheckBox[] cb = new JCheckBox[choices.length];
     for (int i = 0; i < choices.length; i++) {
       cb[i] = new JCheckBox();
       cb[i].setFont(getFont());
       cb[i].setText(choices[i].getText());
       cb[i].setIcon(choices[i].getIcon());
       ActionListener[] al = choices[i].getActionListeners();
       if (al != null) {
         for (ActionListener x : al) cb[i].addActionListener(x);
       }
       ItemListener[] il = choices[i].getItemListeners();
       if (il != null) {
         for (ItemListener x : il) cb[i].addItemListener(x);
       }
     }
     choices = cb;
     for (AbstractButton c : choices) {
       c.setBackground(getBackground());
       c.setOpaque(isOpaque());
     }
     clearButtonGroup(buttonGroup);
   }
   layChoices();
   return true;
 }
 @Override
 protected void installDefaults(AbstractButton b) {
   super.installDefaults(b);
   b.setContentAreaFilled(false);
   b.setOpaque(false);
   b.setBackground(new Color(250, 250, 250));
   initShape(b);
 }
 public void setOpaque(boolean b) {
   super.setOpaque(b);
   if (buttonPanel != null) buttonPanel.setOpaque(b);
   if (choicePanel != null) choicePanel.setOpaque(b);
   if (questionBody != null) questionBody.setOpaque(b);
   if (choices != null) {
     for (AbstractButton c : choices) c.setOpaque(b);
   }
 }
Example #4
0
  /**
   * Initializes the layout of this <code>GroupBox</code>.
   *
   * @param buttons The buttons to be shown at the top-left section of the group box
   * @param panes The panes to be shown as a group where a button is shown as a pane's title
   */
  protected void initializeLayout(AbstractButton[] buttons, JComponent[] panes) {
    checkIntegrity(buttons, panes);

    GridBagConstraints constraints = new GridBagConstraints();

    for (int index = 0; index < buttons.length; index++) {
      boolean paneWasAddedBefore = ((index > 0) && (panes[index - 1] != NO_PANE));

      // First add the button
      AbstractButton button = buttons[index];
      button.setOpaque(false); // Requires to paint the titled border properly
      button.setBorder(
          BorderFactory.createCompoundBorder(
              BorderFactory.createEmptyBorder(0, 5, 0, 0), button.getBorder()));

      if (panes[index] != NO_PANE) {
        button.addItemListener(buildRepainterHandler());
      }

      constraints.gridx = 0;
      constraints.gridy = index;
      constraints.gridwidth = 1;
      constraints.gridheight = 1;
      constraints.weightx = 0;
      constraints.weighty = 0;
      constraints.fill = GridBagConstraints.NONE;
      constraints.anchor = GridBagConstraints.FIRST_LINE_START;
      constraints.insets = new Insets(paneWasAddedBefore ? 5 : 0, 0, 0, 0);

      add(button, constraints);

      // Now add the pane if one is associated with the button
      JComponent pane = panes[index];

      if (pane != NO_PANE) {
        boolean fillVertical = shouldFillVertical(pane);
        int top = button.getPreferredSize().height / 2 - 6;

        pane.setBorder(
            BorderFactory.createCompoundBorder(createPaneBorder(button, pane), pane.getBorder()));

        constraints.gridx = 0;
        constraints.gridy = index;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = 1;
        constraints.weighty = fillVertical ? 1 : 0;
        constraints.fill = fillVertical ? GridBagConstraints.BOTH : GridBagConstraints.HORIZONTAL;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.insets = new Insets(paneWasAddedBefore ? top + 5 : top, 0, 0, 0);

        add(pane, constraints);
      }
    }
  }
Example #5
0
  /* (non-Javadoc)
   * @see javax.swing.plaf.basic.BasicButtonUI#installDefaults(javax.swing.AbstractButton)
   */
  protected void installDefaults(AbstractButton b) {
    super.installDefaults(b);
    b.setOpaque(false);

    if (!defaults_initialized) {
      String pp = getPropertyPrefix();
      dashedRectGapX = UIManager.getInt(pp + "dashedRectGapX");
      dashedRectGapY = UIManager.getInt(pp + "dashedRectGapY");
      dashedRectGapWidth = UIManager.getInt(pp + "dashedRectGapWidth");
      dashedRectGapHeight = UIManager.getInt(pp + "dashedRectGapHeight");
      focusColor = UIManager.getColor(pp + "focus");
      defaults_initialized = true;
    }

    //		BEXPStyle xp = BEXPStyle.getXP();
    //		if (xp != null)
    {
      b.setBorder(
          new XPEmptyBorder(new Insets(3, 3, 3, 3))); // xp.getBorder(b, getXPButtonType(b)));
      LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE);
    }
  }
Example #6
0
  @Override
  public void installUI(JComponent c) {
    AbstractButton button = (AbstractButton) c;

    ButtonInfo info = new ButtonInfo(button, this);
    button.putClientProperty(BUTTON_INFO_KEY, info);

    button.addMouseListener(info.basicListener);
    button.addMouseMotionListener(info.basicListener);
    button.addFocusListener(info.basicListener);
    button.addPropertyChangeListener(info.basicListener);
    button.addChangeListener(info.basicListener);
    button.addKeyListener(focusArrowListener);
    button.addComponentListener(componentListener);
    button.addKeyListener(keyArmingListener);
    button.setRequestFocusEnabled(false);
    button.setFocusable(true);
    button.addPropertyChangeListener(positionAndShapeListener);
    button.setOpaque(false);
    button.setRolloverEnabled(true);

    if (button.getIcon() != null) {
      Font font = UIManager.getFont("IconButton.font");
      if (font != null) button.setFont(font); // miniature-ish
    }

    super.installUI(c);

    updateLayout(button, info);

    if (button.getFont() == null) {
      Font font = UIManager.getFont("Button.font");
      if (font == null) {
        font = new Font("Default", 0, 13);
      }
      button.setFont(font);
    }
  }
Example #7
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);
  }
Example #8
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;
 }
Example #9
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();
  }
Example #10
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);
 }