예제 #1
0
 private static int getAquaTabbedPaneBaseline(JTabbedPane tp, int height) {
   Font font = tp.getFont();
   FontMetrics metrics = tp.getFontMetrics(font);
   int ascent = metrics.getAscent();
   int offset;
   switch (tp.getTabPlacement()) {
     case JTabbedPane.TOP:
       offset = 5;
       if (tp.getFont().getSize() > 12) {
         offset = 6;
       }
       int yOffset = 20 - metrics.getHeight();
       yOffset /= 2;
       return offset + yOffset + ascent - 1;
     case JTabbedPane.BOTTOM:
       if (tp.getFont().getSize() > 12) {
         offset = 6;
       } else {
         offset = 4;
       }
       return height - (20 - ((20 - metrics.getHeight()) / 2 + ascent)) - offset;
     case JTabbedPane.LEFT:
     case JTabbedPane.RIGHT:
       // Aqua rotates left/right text, so that there isn't a good
       // baseline.
       return -1;
   }
   return -1;
 }
예제 #2
0
    public void paintComponent(Graphics g) {
      g.setColor(new Color(96, 96, 96));
      image.paintIcon(this, g, 1, 1);

      FontMetrics fm = g.getFontMetrics();

      String[] args = {jEdit.getVersion()};
      String version = jEdit.getProperty("about.version", args);
      g.drawString(version, (getWidth() - fm.stringWidth(version)) / 2, getHeight() - 5);

      g = g.create((getWidth() - maxWidth) / 2, TOP, maxWidth, getHeight() - TOP - BOTTOM);

      int height = fm.getHeight();
      int firstLine = scrollPosition / height;

      int firstLineOffset = height - scrollPosition % height;
      int lines = (getHeight() - TOP - BOTTOM) / height;

      int y = firstLineOffset;

      for (int i = 0; i <= lines; i++) {
        if (i + firstLine >= 0 && i + firstLine < text.size()) {
          String line = (String) text.get(i + firstLine);
          g.drawString(line, (maxWidth - fm.stringWidth(line)) / 2, y);
        }
        y += fm.getHeight();
      }
    }
예제 #3
0
  private void calcGraphInsets() {
    int top = titleFm.getHeight() + titleFm.getDescent() + 10;
    int left = (int) (2.5 * fm.getHeight());
    int bottom = 2 * fm.getHeight();
    int right = (int) (2.5 * fm.getHeight());

    graphInsets = new Insets(top, left, bottom, right);
  }
예제 #4
0
 void setPosition(int newX, int newY) {
   Insets insets = eNode.getContext().getInsets();
   FontMetrics metrics = getFontMetrics(getFont());
   int stringWidth = metrics.stringWidth(getText());
   int stringHeight = metrics.getHeight();
   setBounds(
       newX + insets.left + eNode.getWidth() + SEPARATION,
       newY + insets.top + eNode.getInsets().top,
       metrics.stringWidth(getText()),
       metrics.getHeight());
 }
예제 #5
0
  /**
   * The function prints out key to jumpshot data.
   */
  int print (Graphics g, int x, int y, int width, int height) {
    Font f = g.getFont ();
    FontMetrics fm = getToolkit ().getFontMetrics (f);
    
    int charW = fm.stringWidth (" "), charH = fm.getHeight ();
    int hgap1 = charW, hgap2 = 2 * charW, vgap = fm.getAscent ();
    int rectW = 30, rectH = charH; //Dimensions of state rectangles
    int xcord = x, ycord = y;
    
    Enumeration enum = parent.stateDefs.elements ();
    while (enum.hasMoreElements ()) {
      RecDef s = (RecDef)enum.nextElement ();
      
      if (s.stateVector.size () > 0) {
	int strW = fm.stringWidth (s.description);
	
	if ((xcord + rectW + hgap1 + strW) > (width + x)) {
          xcord = x; ycord += (charH + vgap);
        }
        
        g.setColor (s.color);
        g.fillRect (xcord, ycord, rectW, rectH);
        g.setColor (Color.black);
        g.drawRect (xcord, ycord, rectW - 1, rectH - 1);
        g.drawString( s.description,
                      xcord + rectW + hgap1,
                      ycord + rectH - fm.getDescent () - 1);
        xcord += (rectW + hgap1 + strW + hgap2);
      }
    }
    return (ycord - y + (2 * charH));
  }      
예제 #6
0
  private BufferedImage generateFrame(GifFrame frame) {
    int width = frame.getColumns() * CELL_WIDTH;
    BufferedImage img =
        new BufferedImage(width, frame.getRows() * CELL_HEIGHT + TEXT_AREA_HEIGHT, IMAGE_TYPE_GIF);
    Graphics graphics = img.getGraphics();
    for (int row = 0; row < frame.getRows(); row++) {
      for (int col = 0; col < frame.getColumns(); col++) {
        ImageIcon icon =
            new ImageIcon(
                "site/images/" + frame.getBoard().get(row, col).getImageFilename() + ".png");
        graphics.drawImage(icon.getImage(), col * CELL_WIDTH, row * CELL_HEIGHT, null);
      }
    }

    for (BoxOverlay overlay : frame.getOverlays()) {
      graphics.setColor(overlay.getColor());
      Rectangle rect = overlay.getRectangle();
      int rect_x = rect.getLeft() * CELL_WIDTH - OVERLAY_PADDING;
      int rect_y = rect.getTop() * CELL_HEIGHT - OVERLAY_PADDING;
      int rect_width = (rect.getRight() - rect.getLeft() + 1) * CELL_WIDTH + 2 * OVERLAY_PADDING;
      int rect_height = (rect.getBottom() - rect.getTop() + 1) * CELL_HEIGHT + 2 * OVERLAY_PADDING;
      graphics.drawRect(rect_x, rect_y, rect_width, rect_height);
      graphics.drawRect(rect_x - 1, rect_y - 1, rect_width + 2, rect_height + 2);
    }

    graphics.setColor(FONT_COLOR);
    graphics.setFont(FONT);
    FontMetrics fm = graphics.getFontMetrics();
    graphics.drawString(
        frame.getText(),
        width / 2 - fm.stringWidth(frame.getText()) / 2,
        frame.getRows() * CELL_HEIGHT + TEXT_AREA_HEIGHT / 2 + fm.getHeight() / 2);

    return img;
  }
  public Rectangle getVisualBounds(JComponent c, int type, int width, int height) {
    Rectangle bounds = new Rectangle(0, 0, width, height);
    if (type == VisuallyLayoutable.CLIP_BOUNDS) {
      return bounds;
    }

    AbstractButton b = (AbstractButton) c;

    if (type == VisuallyLayoutable.COMPONENT_BOUNDS
        && b.getBorder() != null
        && b.isBorderPainted()) {
      Border border = b.getBorder();
      if (border instanceof BackgroundBorder) {
        border = ((BackgroundBorder) border).getBackgroundBorder();
        if (border instanceof VisualMargin) {
          InsetsUtil.subtractInto(((VisualMargin) border).getVisualMargin(c), bounds);
        } else if (border instanceof QuaquaButtonBorder) {
          InsetsUtil.subtractInto(((QuaquaButtonBorder) border).getVisualMargin(c), bounds);
        }
      }
      return bounds;
    }

    String text = b.getText();
    boolean isEmpty = (text == null || text.length() == 0);
    if (isEmpty) {
      text = " ";
    }
    Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return null;
    }

    FontMetrics fm = c.getFontMetrics(c.getFont());
    Insets insets = c.getInsets(viewInsets);

    viewR.x = insets.left;
    viewR.y = insets.top;
    viewR.width = width - (insets.left + insets.right);
    viewR.height = height - (insets.top + insets.bottom);

    iconR.x = iconR.y = iconR.width = iconR.height = 0;
    textR.x = textR.y = textR.width = textR.height = 0;

    String clippedText = layoutCL(b, fm, text, icon, viewR, iconR, textR);

    Rectangle textBounds = Fonts.getPerceivedBounds(text, c.getFont(), c);
    if (isEmpty) {
      textBounds.width = 0;
    }
    int ascent = fm.getAscent();
    textR.x += textBounds.x;
    textR.width = textBounds.width;
    textR.y += ascent + textBounds.y;
    textR.height -= fm.getHeight() - textBounds.height;

    bounds.setBounds(textR);
    return bounds;
  }
  @Override
  public void customizePainter(
      @NotNull JComponent component,
      @NotNull Collection<VcsRef> references,
      @Nullable VcsLogRefManager manager,
      @NotNull Color background,
      @NotNull Color foreground) {
    FontMetrics metrics = component.getFontMetrics(getReferenceFont());
    myHeight =
        metrics.getHeight()
            + RectanglePainter.TOP_TEXT_PADDING
            + RectanglePainter.BOTTOM_TEXT_PADDING;
    myWidth = 2 * PaintParameters.LABEL_PADDING;

    myLabels = ContainerUtil.newArrayList();
    if (manager == null) return;

    List<VcsRef> sorted = ContainerUtil.sorted(references, manager.getLabelsOrderComparator());

    for (Map.Entry<VcsRefType, Collection<VcsRef>> entry :
        ContainerUtil.groupBy(sorted, VcsRef::getType).entrySet()) {
      VcsRef ref = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(entry.getValue()));
      String text = ref.getName() + (entry.getValue().size() > 1 ? " +" : "");
      myLabels.add(Pair.create(text, entry.getKey().getBackgroundColor()));

      myWidth +=
          myLabelPainter.calculateSize(text, metrics).getWidth() + PaintParameters.LABEL_PADDING;
    }
  }
예제 #9
0
파일: HexEdit.java 프로젝트: khyuna/hyun
 @Override
 public void setFont(Font font) {
   FontMetrics fm = getFontMetrics(font);
   lineHeight = fm.getHeight();
   charWidth = fm.charWidth('0');
   super.setFont(font);
 }
예제 #10
0
  /** Initialise dialog. */
  public void initUI() {
    try {
      FontMetrics fontMetrics = getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());

      int minimumHeight = fontMetrics.getHeight() * 8 + HEIGHT_DELTA;
      int minimumWidth =
          Math.max(
                  fontMetrics.stringWidth(
                      controller.getLocaliser().getString("IssueAssetDialog.message")),
                  fontMetrics.stringWidth(
                      controller
                          .getLocaliser()
                          .getString(
                              "IssueAssetDialog.createdSuccessfullyShort", new Object[] {100})))
              + WIDTH_DELTA;
      setMinimumSize(new Dimension(minimumWidth, minimumHeight));
      positionDialogRelativeToParent(this, 0.5D, 0.47D);
    } catch (NullPointerException npe) {
      // FontSizer fail - probably headless in test - carry on.
    }

    issueAssetPanel = new IssueAssetPanel(this.bitcoinController, tradePanel, this);

    setLayout(new BorderLayout());
    add(issueAssetPanel, BorderLayout.CENTER);
  }
예제 #11
0
  public void drawVictory(Graphics g) {
    g.setColor(new Color(0, 0, 0, 200));
    g.fillRect(195, 220, 410, 110);
    g.setColor(new Color(255, 255, 255, 200));
    g.fillRect(200, 225, 400, 100);
    g.setColor(new Color(0, 0, 0, 200));
    g.setFont(new Font("Bell MT", Font.BOLD, 20));
    FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
    int hgt = metrics.getHeight();

    String initialMessage;
    String followupMessage;

    if (nextWindow) {
      initialMessage = "You have gotten stronger.";
      followupMessage = player.getName() + " is now level " + player.getLevel() + "!";
    } else {
      initialMessage = "You survived!";
      followupMessage = "You and your allies gain " + totalExperience + " experience!";
    }

    // Hgt = 26
    int adv = metrics.stringWidth(initialMessage);
    g.drawString(initialMessage, getWidth() / 2 - adv / 2, 234 + hgt);
    adv = metrics.stringWidth(followupMessage);
    g.drawString(followupMessage, getWidth() / 2 - adv / 2, 269 + hgt);
  }
예제 #12
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);
  }
예제 #13
0
  /**
   * Draws the title of the graph.
   *
   * @param g the graphics context.
   */
  private void drawTitle(Graphics g) {
    int stringWidth = titleFm.stringWidth(title);
    int stringHeight = titleFm.getHeight();

    g.setFont(titleFont);
    g.setColor(titleColor);
    g.drawString(title, plotRect.x + plotRect.width / 2 - stringWidth / 2, stringHeight);
  }
예제 #14
0
 public ColorPane() {
   super();
   Font font = new Font("Monospaced", Font.PLAIN, 12);
   FontMetrics fm = getFontMetrics(font);
   lineHeight = fm.getHeight();
   setFont(font);
   setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 }
  public Dimension getPreferredSize(JComponent c) {
    Dimension size;
    Insets border = progressBar.getInsets();
    FontMetrics fontSizer = progressBar.getFontMetrics(progressBar.getFont());

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      size = new Dimension(getPreferredInnerHorizontal());
      // Ensure that the progress string will fit
      if (progressBar.isStringPainted()) {
        // I'm doing this for completeness.
        String progString = progressBar.getString();
        int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer, progString);
        if (stringWidth > size.width) {
          size.width = stringWidth;
        }
        // This uses both Height and Descent to be sure that
        // there is more than enough room in the progress bar
        // for everything.
        // This does have a strange dependency on
        // getStringPlacememnt() in a funny way.
        int stringHeight = fontSizer.getHeight() + fontSizer.getDescent();
        if (stringHeight > size.height) {
          size.height = stringHeight;
        }
      }
    } else {
      size = new Dimension(getPreferredInnerVertical());
      // Ensure that the progress string will fit.
      if (progressBar.isStringPainted()) {
        String progString = progressBar.getString();
        int stringHeight = fontSizer.getHeight() + fontSizer.getDescent();
        if (stringHeight > size.width) {
          size.width = stringHeight;
        }
        // This is also for completeness.
        int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer, progString);
        if (stringWidth > size.height) {
          size.height = stringWidth;
        }
      }
    }

    size.width += border.left + border.right;
    size.height += border.top + border.bottom;
    return size;
  }
예제 #16
0
 @Override
 public int getBaseline() {
   FontMetrics fm = b.getFontMetrics(b.getFont());
   int border = (b.getPreferredSize().height - fm.getHeight()) / 2;
   int bestGuess = border + fm.getAscent();
   if (PlatformUtils.isMac()) bestGuess -= 1;
   return bestGuess;
 }
예제 #17
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   int width = getWidth();
   int height = getHeight();
   g.setFont(new Font("SansSerif", Font.BOLD, 14));
   FontMetrics fm = g.getFontMetrics();
   int i = 1;
   String newLine = "";
   do {
     g.drawString(newLine, 0, i * fm.getHeight());
     newLine = "";
     for (int j = 1; j <= i; j++) {
       newLine += " " + j;
     }
     i++;
   } while ((fm.stringWidth(newLine) <= width) && (fm.getHeight() * i <= height));
 }
예제 #18
0
 /**
  * Creates a new instance of ColorText Inputs: p -- reference to the Panel where you want to draw
  * the text text -- the text you wish to appear (for example, 'CS15 is awesome!') color -- the
  * java.awt.Color that you wish your text to have posX -- the x position of where the upper left
  * corner of the text should be placed posY -- the y position of where the upper left corner of
  * the text should be placed
  */
 public ColorText(JPanel p, String text, Color color, int posX, int posY) {
   _text = text;
   _font = new Font("SansSerif", Font.PLAIN, 20);
   _color = color;
   _posX = posX;
   _posY = posY;
   FontMetrics fm = p.getFontMetrics(_font);
   _size = new Dimension(fm.stringWidth(_text), fm.getHeight());
 }
예제 #19
0
  // Cette fonction pourrait etre optimisee en calculant le deplacement directement
  // Pas besoin de boucler
  void LightCalendar_MousePress(java.awt.event.MouseEvent event) {
    int x = 1;
    int y = drawMonthName ? 2 * (fm.getHeight() + 2) : (fm.getHeight());
    int w = getSize().width - 2;
    int h = getSize().height - y + 5;

    Rectangle r = new Rectangle(x, y, w, h);

    if (r.contains(event.getPoint())) {
      int caseWidth = w / 7;
      int caseHeight = h / 7;

      Calendar cal = Calendar.getInstance();
      cal.setTime(dateDebutMois);

      int nbJoursVides = cal.get(Calendar.DAY_OF_WEEK) - 1;
      int iJoursVides = 0;
      // int iJour = 1;

      Cases:
      for (int iRow = 0; iRow < 6; iRow++) {
        for (int iCol = 0; iCol < 7; iCol++) {
          // int day = cal.get( Calendar.DATE );
          if (iJoursVides < nbJoursVides) iJoursVides++;
          else if (cal.get(Calendar.MONTH) == mois) {
            int xCase = 1 + (iCol * caseWidth);
            int yCase = y + (iRow * caseHeight);
            Rectangle rCase = new Rectangle(xCase, yCase + 5, caseWidth, caseHeight);

            if (rCase.contains(event.getPoint())) {
              selectedDate = cal.getTime();
              selectedRow = iRow;
              selectedCol = iCol;
              parent.currentDate = selectedDate;
              repaint();
              break Cases;
            }

            cal.add(Calendar.DATE, 1);
          }
        }
      }
    }
  }
예제 #20
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   int x = 20, y = 30;
   String ch1 = "bonjour";
   String ch2 = "monsieur";
   g.drawString(ch1, x, y);
   FontMetrics fm = g.getFontMetrics();
   y += fm.getHeight();
   g.drawString(ch2, x, y);
 }
예제 #21
0
 private void adjustCanvasStuff() {
   Font f = parent.frameFont;
   setFont(f);
   fm = getToolkit().getFontMetrics(f);
   lineSize = fm.getHeight();
   rulerHt = 3 * lineSize;
   zLockStrW = fm.stringWidth("Zoom Lock");
   elTimeStrW = fm.stringWidth("Elapsed Time");
   fDescent = fm.getDescent();
   dpi = getToolkit().getScreenResolution();
 }
  private Dimension getPreferredFontSize() {
    if (hasCaption()) {
      FontMetrics fm = getFontMetrics(getFont());
      int preferredHeight = fm.getHeight();
      int preferredWidth = getPreferredWidth(fm);

      return new Dimension(preferredWidth, preferredHeight + getVgap() * 2);
    }

    return new Dimension(0, getVgap() * 2 + 1);
  }
    private int computeHeight() {
      FontMetrics fm = myRootPane.getFontMetrics(getFont());
      int fontHeight = fm.getHeight();
      fontHeight += 7;
      int iconHeight = 0;
      if (getWindowDecorationStyle() == JRootPane.FRAME) {
        iconHeight = IMAGE_HEIGHT;
      }

      return Math.max(Math.max(fontHeight, iconHeight), JBUI.scale(myIdeMenu == null ? 28 : 36));
    }
예제 #24
0
  private void gameOverMessage(Graphics g)
        // Center the game-over message in the panel.
      {
    String msg = "Game Over. Your score: " + score;

    int x = (PWIDTH - metrics.stringWidth(msg)) / 2;
    int y = (PHEIGHT - metrics.getHeight()) / 2;
    g.setColor(Color.black);
    g.setFont(msgsFont);
    g.drawString(msg, x, y);
  } // end of gameOverMessage()
예제 #25
0
  // Draws the Battle Menu
  public void drawMenu(Graphics g) {
    if (scene == BATTLE) {
      // Background
      g.setColor(new Color(0, 100, 0));
      g.fillRect(0, 450, 800, 150);
      g.setColor(Color.BLACK);
      g.fillRect(10, 460, 780, 130);

      // Player
      // Health
      g.setColor(Color.WHITE);
      g.setFont(new Font("Bell MT", Font.BOLD, 20));
      FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
      int hgt = metrics.getHeight();
      // Hgt = 26
      int adv = metrics.stringWidth(player.getHealth() + "/" + player.getMaxHealth(0));
      g.setColor(Color.DARK_GRAY);
      g.fillRect(getWidth() - 170, 470, 150, hgt - 6);
      if ((double) player.getHealth() / player.getMaxHealth(0) > .25) g.setColor(Color.RED);
      else g.setColor(player.getLowHealth());
      g.drawString(
          player.getHealth() + "/" + player.getMaxHealth(0), getWidth() - adv - 180, 461 + hgt);
      g.fillRect(
          getWidth() - 167,
          473,
          (int) (144 * player.getHealth() / player.getMaxHealth(0)),
          hgt - 12);

      // Stamina
      g.setColor(Color.DARK_GRAY);
      g.fillRect(getWidth() - 170, 500, 150, hgt - 6);
      adv = metrics.stringWidth((int) player.getStamina() + "%");
      if (player.getStamina() < 33.3) g.setColor(Color.WHITE);
      else if (player.getStamina() == 100) g.setColor(Color.GREEN);
      else g.setColor(Color.CYAN);

      g.drawString((int) player.getStamina() + "%", getWidth() - adv - 180, 491 + hgt);
      g.fillRect(getWidth() - 167, 503, (int) (144 * player.getStamina() / 100), hgt - 12);

      // Basic Attack
      adv = metrics.stringWidth("Kick Dirt");
      g.setColor(Color.DARK_GRAY);
      g.fillRect(20, 470, adv + 10, 30);
      g.setColor(Color.WHITE);
      g.drawString("Kick Dirt", 25, 492);

      // Spell 1
      adv = metrics.stringWidth("Hurl Pebble");
      g.setColor(Color.DARK_GRAY);
      g.fillRect(20, 510, adv + 10, 30);
      g.setColor(Color.WHITE);
      g.drawString("Hurl Pebble", 25, 532);
    }
  }
예제 #26
0
 private void measure() {
   FontMetrics fontmetrics = getFontMetrics(getFont());
   if (fontmetrics == null) return;
   line_height = fontmetrics.getHeight();
   line_ascent = fontmetrics.getAscent();
   max_width = 0;
   for (int i = 0; i < num_lines; i++) {
     line_widths[i] = fontmetrics.stringWidth(lines[i]);
     if (line_widths[i] > max_width) max_width = line_widths[i];
   }
   max_width += 2 * btnMarginWidth;
   max_height = num_lines * line_height + 2 * btnMarginHeight;
 }
예제 #27
0
 void setPosition(int newX, int newY) {
   Insets insets = getContext().getInsets();
   insets = getContext().getInsets();
   FontMetrics metrics = getFontMetrics(getFont());
   int stringWidth = metrics.stringWidth(getText());
   int stringHeight = metrics.getHeight();
   setBounds(
       newX + insets.left,
       newY + insets.top,
       stringWidth + getInsets().left + getInsets().right,
       stringHeight + insets.top + insets.bottom + VERTICAL_PAD);
   if (rightLabel != null) rightLabel.setPosition(newX, newY);
 }
예제 #28
0
 public Dimension getPreferredSize(JComponent c) {
   Dimension size = super.getPreferredSize(c);
   if (comboBox.getGraphics() != null) {
     FontMetrics fm =
         Utilities.getFontMetrics(comboBox, comboBox.getGraphics(), comboBox.getFont());
     size.height = fm.getHeight() + 2;
     if (UIManager.getLookAndFeel() instanceof BaseLookAndFeel) {
       BaseLookAndFeel laf = (BaseLookAndFeel) UIManager.getLookAndFeel();
       size.height =
           Math.max(size.height, laf.getIconFactory().getDownArrowIcon().getIconHeight() + 2);
     }
   }
   return new Dimension(size.width + 2, size.height + 2);
 }
예제 #29
0
 private static int getPanelBaseline(JPanel panel, int height) {
   Border border = panel.getBorder();
   if (border instanceof TitledBorder) {
     TitledBorder titledBorder = (TitledBorder) border;
     if (titledBorder.getTitle() != null && !"".equals(titledBorder.getTitle())) {
       Font font = titledBorder.getTitleFont();
       if (font == null) {
         font = panel.getFont();
         if (font == null) {
           font = new Font("Dialog", Font.PLAIN, 12);
         }
       }
       Border border2 = titledBorder.getBorder();
       Insets borderInsets;
       if (border2 != null) {
         borderInsets = border2.getBorderInsets(panel);
       } else {
         borderInsets = EMPTY_INSETS;
       }
       FontMetrics fm = panel.getFontMetrics(font);
       int fontHeight = fm.getHeight();
       int descent = fm.getDescent();
       int ascent = fm.getAscent();
       int y = EDGE_SPACING;
       int h = height - EDGE_SPACING * 2;
       int diff;
       switch (((TitledBorder) border).getTitlePosition()) {
         case TitledBorder.ABOVE_TOP:
           diff = ascent + descent + (Math.max(EDGE_SPACING, TEXT_SPACING * 2) - EDGE_SPACING);
           return y + diff - (descent + TEXT_SPACING);
         case TitledBorder.TOP:
         case TitledBorder.DEFAULT_POSITION:
           diff = Math.max(0, ((ascent / 2) + TEXT_SPACING) - EDGE_SPACING);
           return (y + diff - descent) + (borderInsets.top + ascent + descent) / 2;
         case TitledBorder.BELOW_TOP:
           return y + borderInsets.top + ascent + TEXT_SPACING;
         case TitledBorder.ABOVE_BOTTOM:
           return (y + h) - (borderInsets.bottom + descent + TEXT_SPACING);
         case TitledBorder.BOTTOM:
           h -= fontHeight / 2;
           return ((y + h) - descent) + ((ascent + descent) - borderInsets.bottom) / 2;
         case TitledBorder.BELOW_BOTTOM:
           h -= fontHeight;
           return y + h + ascent + TEXT_SPACING;
       }
     }
   }
   return -1;
 }
예제 #30
0
 public void drawDefeat(Graphics g) {
   g.setColor(new Color(0, 0, 0, 200));
   g.fillRect(195, 220, 410, 110);
   g.setColor(new Color(255, 255, 255, 200));
   g.fillRect(200, 225, 400, 100);
   g.setColor(new Color(0, 0, 0, 200));
   g.setFont(new Font("Bell MT", Font.BOLD, 20));
   FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
   int hgt = metrics.getHeight();
   // Hgt = 26
   int adv = metrics.stringWidth("You all fainted.");
   g.drawString("You all fainted.", getWidth() / 2 - adv / 2, 234 + hgt);
   adv = metrics.stringWidth("Defenseless, you are all eaten.");
   g.drawString("Defenseless, you are all eaten.", getWidth() / 2 - adv / 2, 269 + hgt);
 }