Esempio n. 1
0
  public void paint(java.awt.Graphics g) {
    if (element != null) {
      Rectangle bounds = element.jGetBounds();
      Graphics2D g2 = (Graphics2D) g;

      g2.setFont(font);

      int mitteX = bounds.x + (bounds.width) / 2;
      int mitteY = bounds.y + (bounds.height) / 2;

      int distanceY = 10;

      g2.setColor(new Color(204, 204, 255));
      g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);
      g2.setColor(Color.BLACK);
      g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);

      String caption = "dec(" + variable.getValue() + ")";

      FontMetrics fm = g2.getFontMetrics();
      Rectangle2D r = fm.getStringBounds(caption, g2);

      g2.setColor(Color.BLACK);
      g.drawString(
          caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3);
    }
    super.paint(g);
  }
Esempio n. 2
0
 /** Draws a message centered in the window. */
 private void drawMessage(Graphics2D g2, String message) {
   g2.setColor(Color.WHITE);
   g2.setFont(new Font("serif", Font.PLAIN, 72));
   // Calculate the size of the text so we can center it in the window
   FontMetrics metrics = g2.getFontMetrics();
   Rectangle2D textBounds = metrics.getStringBounds(message, g2);
   g2.drawString(
       message,
       windowWidth / 2 - (int) textBounds.getCenterX(),
       windowHeight / 2 - (int) textBounds.getCenterY());
 }
Esempio n. 3
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));
  }