private void updateLook(JButton button) {
      ButtonModel model = button.getModel();
      boolean enabled = model.isEnabled();
      if (!enabled) {
        setLookNormal(button);
        return;
      }

      boolean pressed = model.isPressed();
      boolean selected = model.isSelected();
      if (pressed || selected) {
        setLookLowered(button);
        return;
      }

      if ((button == arrow) && popupVisible) {
        setLookLowered(button);
        return;
      }

      if (rollOver) {
        setLookRaised(button);
        return;
      }
      if (arrow.getModel().isSelected()) {
        setLookRaised(button);
        return;
      }
      setLookNormal(button);
    }
  /**
   * Resets the rollover state of all rollover components in the current cell except the component
   * given as a parameter.
   *
   * @param excludeComponent the component to exclude from the reset
   */
  public void resetRolloverState(Component excludeComponent) {
    if (!chatButton.equals(excludeComponent)) chatButton.getModel().setRollover(false);

    if (!callButton.equals(excludeComponent)) callButton.getModel().setRollover(false);

    if (!callVideoButton.equals(excludeComponent)) callVideoButton.getModel().setRollover(false);

    if (!desktopSharingButton.equals(excludeComponent))
      desktopSharingButton.getModel().setRollover(false);

    if (!addContactButton.equals(excludeComponent)) addContactButton.getModel().setRollover(false);

    if (customActionButtons != null) {
      Iterator<JButton> buttonsIter = customActionButtons.iterator();
      while (buttonsIter.hasNext()) {
        JButton button = buttonsIter.next();

        if (!button.equals(excludeComponent)) button.getModel().setRollover(false);
      }
    }

    if (customActionButtonsUIGroup != null) {
      Iterator<JButton> buttonsIter = customActionButtonsUIGroup.iterator();
      while (buttonsIter.hasNext()) {
        JButton button = buttonsIter.next();

        if (!button.equals(excludeComponent)) button.getModel().setRollover(false);
      }
    }
  }
  public static void renderSurface(
      Graphics g,
      Container c,
      Rectangle rect,
      boolean toSimulateRollover,
      boolean hasTopBorder,
      boolean hasBottomBorder) {
    CellRendererPane buttonRendererPane = new CellRendererPane();
    JButton rendererButton = new JButton("");
    rendererButton.getModel().setRollover(toSimulateRollover);

    buttonRendererPane.setBounds(rect.x, rect.y, rect.width, rect.height);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.clipRect(rect.x, rect.y, rect.width, rect.height);
    buttonRendererPane.paintComponent(
        g2d,
        rendererButton,
        c,
        rect.x - rect.width / 2,
        rect.y - rect.height / 2,
        2 * rect.width,
        2 * rect.height,
        true);

    g2d.setColor(FlamingoUtilities.getBorderColor());
    if (hasTopBorder) {
      g2d.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
    }
    if (hasBottomBorder) {
      g2d.drawLine(
          rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
    }
    g2d.dispose();
  }
Ejemplo n.º 4
0
 @Override
 public Component getListCellRendererComponent(
     JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) {
   label.setText(Objects.toString(value, ""));
   this.list = list;
   this.index = index;
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     label.setForeground(list.getSelectionForeground());
   } else {
     setBackground(index % 2 == 0 ? EVEN_COLOR : list.getBackground());
     label.setForeground(list.getForeground());
   }
   MutableComboBoxModel m = (MutableComboBoxModel) list.getModel();
   if (index < 0 || m.getSize() - 1 <= 0) {
     setOpaque(false);
     deleteButton.setVisible(false);
     label.setForeground(list.getForeground());
   } else {
     boolean f = index == rolloverIndex;
     setOpaque(true);
     deleteButton.setVisible(true);
     deleteButton.getModel().setRollover(f);
     deleteButton.setForeground(f ? Color.WHITE : list.getForeground());
   }
   return this;
 }
 /**
  * Sets the selected direction.
  *
  * @param direction
  */
 public void setSelectedDirection(int direction) {
   JButton button = getButton(direction);
   if (button != null) {
     button.getModel().setRollover(false);
   }
   setSelectedObject(direction);
 }
Ejemplo n.º 6
0
 private void resetButtonStatus() {
   for (JButton b : Arrays.asList(deleteButton, copyButton)) {
     ButtonModel m = b.getModel();
     m.setRollover(false);
     m.setArmed(false);
     m.setPressed(false);
     m.setSelected(false);
   }
 }
Ejemplo n.º 7
0
 public void actionPerformed(ActionEvent e) {
   if (owner != null && SwingUtilities.getRootPane(owner) == root) {
     ButtonModel model = owner.getModel();
     if (press) {
       model.setArmed(true);
       model.setPressed(true);
     } else {
       model.setPressed(false);
     }
   }
 }
 public void actionPerformed(ActionEvent e) {
   if (button.isEnabled() && button.getModel().isArmed()) {
     int value = boundedRangeModel.getValue();
     if (button == forwardButton) {
       boundedRangeModel.setValue(
           value == boundedRangeModel.getMaximum() ? boundedRangeModel.getMinimum() : value + 1);
     } else {
       boundedRangeModel.setValue(
           value == boundedRangeModel.getMinimum() ? boundedRangeModel.getMaximum() : value - 1);
     }
   }
 }
  /** Resets the rollover state of all rollover components in the current cell. */
  public void resetRolloverState() {
    chatButton.getModel().setRollover(false);
    callButton.getModel().setRollover(false);
    callVideoButton.getModel().setRollover(false);
    desktopSharingButton.getModel().setRollover(false);
    addContactButton.getModel().setRollover(false);

    if (customActionButtons != null) {
      Iterator<JButton> buttonsIter = customActionButtons.iterator();
      while (buttonsIter.hasNext()) {
        JButton button = buttonsIter.next();
        button.getModel().setRollover(false);
      }
    }

    if (customActionButtonsUIGroup != null) {
      Iterator<JButton> buttonsIter = customActionButtonsUIGroup.iterator();
      while (buttonsIter.hasNext()) {
        JButton button = buttonsIter.next();
        button.getModel().setRollover(false);
      }
    }
  }
Ejemplo n.º 10
0
 @Override
 public Component getListCellRendererComponent(
     JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) {
   label.setText(Objects.toString(value, ""));
   this.index = index;
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     label.setForeground(list.getSelectionForeground());
   } else {
     setBackground(index % 2 == 0 ? EVEN_COLOR : list.getBackground());
     label.setForeground(list.getForeground());
   }
   resetButtonStatus();
   if (Objects.nonNull(button)) {
     if (index == pressedIndex) {
       button.getModel().setSelected(true);
       button.getModel().setArmed(true);
       button.getModel().setPressed(true);
     } else if (index == rolloverIndex) {
       button.getModel().setRollover(true);
     }
   }
   return this;
 }
Ejemplo n.º 11
0
 @Override
 public void mouseMoved(MouseEvent e) {
   // JList list = (JList) e.getComponent();
   Point pt = e.getPoint();
   int index = list.locationToIndex(pt);
   if (!list.getCellBounds(index, index).contains(pt)) {
     if (prevIndex >= 0) {
       listRepaint(list, list.getCellBounds(prevIndex, prevIndex));
     }
     index = -1;
     prevButton = null;
     return;
   }
   if (index >= 0) {
     JButton button = getButton(list, pt, index);
     ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer();
     renderer.button = button;
     if (Objects.isNull(button)) {
       renderer.rolloverIndex = -1;
       Rectangle r = null;
       if (prevIndex == index) {
         if (prevIndex >= 0 && Objects.nonNull(prevButton)) {
           r = list.getCellBounds(prevIndex, prevIndex);
         }
       } else {
         r = list.getCellBounds(index, index);
       }
       listRepaint(list, r);
       prevIndex = -1;
     } else {
       button.getModel().setRollover(true);
       renderer.rolloverIndex = index;
       if (!button.equals(prevButton)) {
         listRepaint(list, list.getCellBounds(prevIndex, index));
       }
     }
     prevButton = button;
   }
   prevIndex = index;
 }
Ejemplo n.º 12
0
 public boolean isEnabled() {
   return owner.getModel().isEnabled();
 }
Ejemplo n.º 13
0
  /**
   * Create a toolbar containing the given tools (if any).
   *
   * @param template Conta
   */
  protected void changeToolBar(JComponent[] template, IControlCenterPlugin selplugin) {
    // Setup the tool bar.
    if (toolbar == null) {
      toolbar = new JToolBar("Main Toolbar");
      getContentPane().add(BorderLayout.NORTH, toolbar);
      // Add standard entries (after gap).
      toolbar.add(Box.createGlue());
      toolcnt++;
      toolbar.addSeparator();
      toolcnt++;

      // ButtonGroup bg = new ButtonGroup();
      IControlCenterPlugin[] plugins = controlcenter.getPlugins();
      for (int i = 0; i < plugins.length; i++) {
        final IControlCenterPlugin plugin = plugins[i];
        // final JToggleButton button = new JToggleButton(new PluginAction(plugins[i]));
        final JButton button = new JButton(new PluginAction(plugins[i]));
        Icon ic = plugin.getToolIcon(selplugin.getName().equals(plugins[i].getName()));
        if (ic != null) button.setIcon(ic);
        else button.setText(plugins[i].getName());
        button.setText("A");
        button.putClientProperty("plugin", plugins[i]);
        button.setBorder(null);
        button.setText(null);
        button.setMinimumSize(BUTTON_DIM);
        button.setHorizontalAlignment(SwingConstants.CENTER);
        button.setVerticalAlignment(SwingConstants.CENTER);
        button.setToolTipText(plugins[i].getName());
        button
            .getModel()
            .addItemListener(
                new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                    // System.out.println(plugin.getName()+" :"+button.isSelected());
                    button.setIcon(plugin.getToolIcon(button.isSelected()));
                  }
                });
        //	            if(plugins[i].getHelpID()!=null)
        //	            	SHelp.setupHelp(button, plugins[i].getHelpID());

        // bg.add(button);
        toolbar.add(button);
        toolcnt++;
      }
      toolbar.addSeparator();
      toolcnt++;
      toolbar.add(new JadexLogoButton(toolbar));
      toolcnt++;
    } else {
      while (toolbar.getComponentCount() > toolcnt) {
        //				Component	comp	= toolbar.getComponent(0);
        toolbar.remove(0);
        // if(lasttoolbar!=null)
        //	lasttoolbar.add(comp);
      }
    }

    for (int i = 0; template != null && i < template.length; i++) toolbar.add(template[i], i);
    // lasttoolbar	= template;

    // Select plugins
    for (int i = 0; i < toolbar.getComponentCount(); i++) {
      JComponent comp = (JComponent) toolbar.getComponent(i);
      if (comp.getClientProperty("plugin") != null) {
        IControlCenterPlugin pl = (IControlCenterPlugin) comp.getClientProperty("plugin");
        ((JButton) comp).setIcon(pl.getToolIcon(pl.equals(selplugin)));
        // ((JToggleButton)comp).setSelected(pluginname.equals(comp.getClientProperty("pluginname")));
      }
    }

    toolbar.validate();
    toolbar.repaint();

    // If toolbar has been dropped out -> pack the window (hack???).
    Container root = toolbar;
    while (root.getParent() != null && !(root instanceof Window)) root = root.getParent();
    if (root != null && !(root instanceof JFrame)) {
      ((Window) root).pack();
    }
  }
Ejemplo n.º 14
0
  /**
   * The class constructor.
   *
   * @param owner the GuiKeyboardInstance class instance
   * @param space plugin dimension
   */
  public GUI(final ButtonGridInstance owner, final Dimension space) {
    this.owner = owner;

    final JButton buttons[] = new JButton[owner.NUMBER_OF_KEYS];
    panel = new JPanel();

    setLayout(new BorderLayout());

    int labelHeight;

    if (owner.getCaption().length() > 0) {
      JLabel label = new JLabel(owner.getCaption(), 0);
      add(label, BorderLayout.NORTH);
      labelHeight = (int) getPreferredSize().getHeight();
    } else {
      labelHeight = 0;
    }

    for (int i = 0; i < owner.NUMBER_OF_KEYS; i++) {
      buttons[i] = new JButton();
      String caption = owner.getButtonCaption(i);
      buttons[i].setText(caption);
      if ("".equalsIgnoreCase(caption)) {
        buttons[i].setEnabled(false);
        buttons[i].setVisible(false);
      } else {
        numberOfKeys = numberOfKeys + 1;
        buttons[i].setEnabled(true);
        buttons[i].setVisible(true);

        final JButton b = buttons[i];

        // final Border raisedBevelBorder = BorderFactory.createRaisedBevelBorder();
        // final Insets insets = raisedBevelBorder.getBorderInsets(buttons[i]);
        // final EmptyBorder emptyBorder = new EmptyBorder(insets);
        // b.setBorder(emptyBorder);
        // b.setOpaque(false);
        // b.setContentAreaFilled(false);

        if (owner.propBorderColor != USE_DEFAULT_COLOR)
          b.setBorder(
              BorderFactory.createLineBorder(
                  getColorProperty(owner.propBorderColor), owner.propBorderThickness));

        b.setFocusPainted(false);
        if (!("".equalsIgnoreCase(owner.getToolTip(i)))) b.setToolTipText(owner.getToolTip(i));

        if (owner.propBackgroundColor != USE_DEFAULT_COLOR)
          b.setBackground(getColorProperty(owner.propBackgroundColor));

        if (owner.propTextColor != USE_DEFAULT_COLOR)
          b.setForeground(getColorProperty(owner.propTextColor));

        if (owner.propSelectionFrameColor != USE_DEFAULT_COLOR) {
          b.getModel()
              .addChangeListener(
                  new ChangeListener() {
                    @Override
                    public void stateChanged(ChangeEvent e) {
                      ButtonModel model = (ButtonModel) e.getSource();
                      if (model.isRollover()) {
                        // b.setBorder(raisedBevelBorder);
                        b.setBorder(
                            BorderFactory.createLineBorder(
                                getColorProperty(owner.propSelectionFrameColor),
                                owner.propSelectionFrameThickness));
                      } else {
                        // b.setBorder(emptyBorder);
                        b.setBorder(
                            BorderFactory.createLineBorder(
                                getColorProperty(owner.propBorderColor),
                                owner.propBorderThickness));
                      }
                    }
                  });
        }
      }

      final int y = i;

      buttons[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              if (colSav == null) colSav = buttons[y].getBackground();
              if (owner.propSelectionFrameColor == USE_DEFAULT_COLOR)
                buttons[y].setBackground(Color.RED);
              else buttons[y].setBackground(getColorProperty(owner.propSelectionFrameColor));
              owner.etpKeyArray[y].raiseEvent();

              AstericsThreadPool.instance.execute(
                  new Runnable() {
                    public void run() {
                      try {
                        Thread.sleep(250);
                        buttons[y].setBackground(colSav);
                      } catch (InterruptedException e) {
                      }
                    }
                  });
            }
          });
    }

    if (numberOfKeys > 0) {

      Dimension buttonDimension;
      Dimension panelDimension;

      if (owner.propHorizontalOrientation == true) {
        buttonDimension = new Dimension(space.width / numberOfKeys, ((space.height - labelHeight)));

        panelDimension =
            new Dimension(numberOfKeys * buttonDimension.width, buttonDimension.height);
      } else {
        buttonDimension = new Dimension(space.width, ((space.height - labelHeight) / numberOfKeys));

        panelDimension = new Dimension(space.width, numberOfKeys * buttonDimension.height);
      }

      panel.setMaximumSize(panelDimension);
      panel.setPreferredSize(panelDimension);
      panel.setMinimumSize(panelDimension);
      panel.setVisible(true);

      if (owner.propHorizontalOrientation == true) {
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
      } else {
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
      }

      for (int i = 0; i < owner.NUMBER_OF_KEYS; i++) {
        buttons[i].setPreferredSize(buttonDimension);
        buttons[i].setMinimumSize(buttonDimension);
        buttons[i].setMaximumSize(buttonDimension);
        // panel.add(buttons[i]);
      }

      float maxFontSize = fontSizeMax;
      float maxFontSizeTable[] = new float[owner.NUMBER_OF_KEYS];

      Rectangle buttonRectangle = new Rectangle();

      for (int i = 0; i < owner.NUMBER_OF_KEYS; i++) {
        float fontSize = 0;
        boolean finish = false;
        maxFontSizeTable[i] = 0;
        if (owner.getButtonCaption(i).length() > 0) {
          do {

            fontSize = fontSize + fontIncrementStep;

            buttons[i].setMargin(new Insets(2, 2, 2, 2));

            Font font = buttons[i].getFont();
            font = font.deriveFont(fontSize);
            FontMetrics fontMetrics = buttons[i].getFontMetrics(font);
            Rectangle2D tmpFontSize =
                fontMetrics.getStringBounds(owner.getButtonCaption(i), buttons[i].getGraphics());

            Insets insets = buttons[i].getMargin();

            double height = tmpFontSize.getHeight();
            double width = tmpFontSize.getWidth();
            double buttonHeightSpace =
                buttonDimension.getHeight()
                    - (double) insets.bottom
                    - (double) insets.top
                    - verticalOffset;
            double buttonWidthSpace =
                buttonDimension.getWidth()
                    - (double) insets.left
                    - (double) insets.right
                    - horizontalOffset;

            if ((height >= buttonHeightSpace) || (width >= buttonWidthSpace)) {
              finish = true;
              maxFontSizeTable[i] = fontSize - 1;
            } else {

              if (fontSize > fontSizeMax) {
                finish = true;
                maxFontSizeTable[i] = fontSize;
              }
            }

          } while (!finish);
        }
      }

      for (int i = 0; i < owner.NUMBER_OF_KEYS; i++) {
        if ((maxFontSizeTable[i] > 0) && (maxFontSizeTable[i] < maxFontSize)) {
          maxFontSize = maxFontSizeTable[i];
        }
      }

      for (int i = 0; i < owner.NUMBER_OF_KEYS; i++) {
        Font font = buttons[i].getFont();
        font = font.deriveFont(maxFontSize);
        buttons[i].setFont(font);
      }
    }

    for (int i = 0; i < owner.NUMBER_OF_KEYS; i++) {
      panel.add(buttons[i]);
    }

    add(panel, BorderLayout.CENTER);
    setBorder(BorderFactory.createLineBorder(Color.BLACK));
  }