public static FontMetrics getFontMetrics(JComponent c, Graphics g, Font f) {
   FontMetrics fm = null;
   if (getJavaVersion() >= 1.6) {
     try {
       Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2");
       Class classParams[] = {JComponent.class, Graphics.class, Font.class};
       Method m = swingUtilities2Class.getMethod("getFontMetrics", classParams);
       Object methodParams[] = {c, g, f};
       fm = (FontMetrics) m.invoke(null, methodParams);
     } catch (Exception ex) {
       // Nothing to do
     }
   }
   if (fm == null) {
     if (g == null) {
       if (c != null) {
         g = c.getGraphics();
       }
     }
     if (g != null) {
       if (f != null) {
         fm = g.getFontMetrics(f);
       } else {
         fm = g.getFontMetrics();
       }
     } else if (c != null) {
       if (f != null) {
         fm = c.getFontMetrics(f);
       } else {
         fm = c.getFontMetrics(c.getFont());
       }
     }
   }
   return fm;
 }
Example #2
0
  /**
   * Function: drawNode Pre: Takes a graphics object g to draw on. Also takes two ints (x_size,
   * y_size) defining the screen size Also takes a node radius r Post: Prints out this node to the
   * screen appropriately
   */
  public void drawNode(Graphics g, int x_size, int y_size, int r) {
    // Don't print nodes that aren't activated
    if (!activated) return;

    // First, get some stats based on the Graphics area size
    // In particular, the size of the Node
    int px = (int) (x_size * x) - r; // X & Y positions
    int py = (int) (y_size * y) - r;

    // Set the font to appropriate no matter what
    // int sizor;    //The size for the text, based on radius
    g.setFont(new Font("Serif", Font.BOLD, r));

    // Find the color for the text, it's used often... we'll do this later now
    // String textcol = getOtherTextColor(color);  MOOF!  UPDATE THIS LATER!
    // Make sure the color is correct no matter what... adjust also later!

    // Node insides... get this color correct later, moof!
    g.setColor(getMyJavaColor());
    // g.setColor(Color.white);
    g.fillOval(px, py, r * 2, r * 2);

    // Node border
    g.setColor(getJavaColor(getOtherNodeColor(color)));
    g.drawOval(px, py, r * 2, r * 2);

    // Text inside... set up to be centered
    py = py + r + (int) (g.getFontMetrics().getAscent() / 2.2);
    px = px + r - (g.getFontMetrics().stringWidth("" + cindex) / 2);
    g.drawString("" + cindex, px, py);
  }
 /**
  * Draws the Legend for the scatter plot
  *
  * @param g {@link Graphics}
  */
 private void drawLegend(Graphics g) {
   // set the color of the legend rectangle
   g.setColor(LEGEND_BACKGROUND);
   int lineHeight = g.getFontMetrics().getHeight() + 2; // height of a legend line
   // draw the legend rectangle
   g.fillRect(
       getWidth() - legendWidth - LENGEND_PAD - (LEGEND_INSET * 2),
       LENGEND_PAD,
       legendWidth + (LEGEND_INSET * 2),
       ((data.size() + 2) * lineHeight) + (LEGEND_INSET * 2));
   g.setColor(Colors.BLACK);
   g.drawRect(
       getWidth() - legendWidth - LENGEND_PAD - (LEGEND_INSET * 2),
       LENGEND_PAD,
       legendWidth + (LEGEND_INSET * 2),
       ((data.size() + 2) * lineHeight) + (LEGEND_INSET * 2));
   // search the position where to start the text of the legend
   Point p =
       new Point(
           getWidth() - legendWidth - LENGEND_PAD - LEGEND_INSET,
           LENGEND_PAD + LEGEND_INSET + g.getFontMetrics().getHeight());
   // draw the axis names
   g.drawString(X_AXIS_PREFIX + xAxis.getName(), p.x, p.y); // draw X-Axis legend
   g.drawString(Y_AXIS_PREFIX + yAxis.getName(), p.x, p.y + lineHeight); // draw Y-Axis legend
   // draw graph name legend
   for (int i = 0; i < data.size(); i++) {
     Color graphColor = data.get(i).getColor();
     String graphName = data.get(i).getName();
     g.setColor(graphColor);
     int yLine = p.y + ((i + 2) * lineHeight); // y position of the current line
     g.drawLine(p.x, yLine - 5, p.x + 25, yLine - 5); // draw a line with the color of the graph
     g.setColor(Colors.BLACK);
     g.drawString(graphName, p.x + 30, yLine); // draw the name of the graph
   }
 }
Example #4
0
  public void paintComponent(Graphics g) {
    if (name == "" && serialport == "") {
      Map<String, String> boardPreferences = Base.getBoardPreferences();
      if (boardPreferences != null) setBoardName(boardPreferences.get("name"));
      else setBoardName("-");
      setSerialPort(Preferences.get("serial.port"));
    }
    g.setColor(background);
    Dimension size = getSize();
    g.fillRect(0, 0, size.width, size.height);

    g.setFont(font);
    g.setColor(foreground);
    int baseline = (high + g.getFontMetrics().getAscent()) / 2;
    g.drawString(text, 6, baseline);

    g.setColor(messageForeground);
    String tmp = name + " on " + serialport;

    Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null);

    g.drawString(tmp, size.width - (int) bounds.getWidth() - 20, baseline);

    if (Base.isMacOS()) {
      g.drawImage(resize, size.width - 20, 0, this);
    }
  }
Example #5
0
  public void paintFPS(int x, int y, Graphics g) {

    // Skip if not needed:
    if (usingMenu) {
      return;
    }

    if (showFPS) {

      // Update FPS count:
      if (--fpsCounter <= 0) {

        long ct = nes.getGui().getTimer().currentMicros();
        long frameT = (ct - prevFrameTime) / 45;
        if (frameT == 0) {
          fps = "FPS: -";
        } else {
          fps = "FPS: " + (1000000 / frameT);
        }
        fpsCounter = 45;
        prevFrameTime = ct;
      }

      // Draw FPS.
      gfx.setColor(Color.black);
      gfx.fillRect(
          x,
          y - gfx.getFontMetrics().getAscent(),
          gfx.getFontMetrics().stringWidth(fps) + 3,
          gfx.getFontMetrics().getHeight());
      gfx.setColor(Color.cyan);
      gfx.drawString(fps, x, y);
    }
  }
  public static void drawString(
      Graphics g,
      String str,
      int x,
      int y,
      HorizontalAlignment horizontalAlignment,
      VerticalAlignment verticalAlignment) {
    int textWidth = g.getFontMetrics().stringWidth(str);
    final int textHeight = g.getFontMetrics().getAscent();
    int resultX = x;
    int resultY = y;

    if (horizontalAlignment == HorizontalAlignment.left) resultX = x;
    else if (horizontalAlignment == HorizontalAlignment.center) resultX = x - textWidth / 2;
    else if (horizontalAlignment == HorizontalAlignment.right) resultX = x - textWidth;

    if (verticalAlignment == VerticalAlignment.top) resultY = y + textHeight;
    else if (verticalAlignment == VerticalAlignment.center) resultY = y + textHeight / 2 - 1;
    else if (verticalAlignment == VerticalAlignment.bottom) resultY = y;

    Color previousColor = g.getColor();
    g.setColor(new Color(1f, 1f, 1f, 0.7f));
    // g.setColor(new Color(0.7f, 0.7f, 1f, 0.7f)); //debug with this
    g.fillRect(resultX, resultY - textHeight + 1, textWidth, g.getFontMetrics().getHeight() - 1);
    g.setColor(previousColor);
    g.drawString(str, resultX, resultY);
  }
  protected void paintComponent(Graphics g) {
    g.setColor(GroupedElementsRenderer.POPUP_SEPARATOR_FOREGROUND);

    if (hasCaption()) {
      Rectangle viewR = new Rectangle(0, getVgap(), getWidth() - 1, getHeight() - getVgap() - 1);
      Rectangle iconR = new Rectangle();
      Rectangle textR = new Rectangle();
      String s =
          SwingUtilities.layoutCompoundLabel(
              g.getFontMetrics(),
              myCaption,
              null,
              CENTER,
              myCaptionCentered ? CENTER : LEFT,
              CENTER,
              myCaptionCentered ? CENTER : LEFT,
              viewR,
              iconR,
              textR,
              0);
      final int lineY = textR.y + textR.height / 2;
      if (s.equals(myCaption) && viewR.width - textR.width > 2 * getHgap()) {
        if (myCaptionCentered) {
          g.drawLine(0, lineY, textR.x - getHgap(), lineY);
        }
        g.drawLine(textR.x + textR.width + getHgap(), lineY, getWidth() - 1, lineY);
      }
      UIUtil.applyRenderingHints(g);
      g.setColor(GroupedElementsRenderer.POPUP_SEPARATOR_TEXT_FOREGROUND);
      g.drawString(s, textR.x, textR.y + g.getFontMetrics().getAscent());
    } else {
      g.drawLine(0, getVgap(), getWidth() - 1, getVgap());
    }
  }
Example #8
0
  @Override
  public void draw(Graphics g) {
    g.setFont(_textFont);
    if (_enabled) {
      if (_isHovered) {
        g.setColor(_hoverBackgroundColor);
      } else {
        g.setColor(_backgroundColor);
      }
    } else {
      g.setColor(new Color(150, 150, 150));
    }

    g.fillRect(_bounds.x, _bounds.y, _bounds.width, _bounds.height);
    g.setColor(Color.black);
    g.drawRect(_bounds.x, _bounds.y, _bounds.width, _bounds.height);

    int strPosX = _bounds.x + 1 + (_bounds.width - g.getFontMetrics().stringWidth(_text)) / 2;
    int strPosY =
        _bounds.y
            + (_bounds.height + g.getFontMetrics().getAscent() - g.getFontMetrics().getDescent())
                / 2;
    g.setColor(_fontColor);
    g.drawString(_text, strPosX, strPosY);
  }
  @Override
  public void draw(Graphics g, GamePanel parent) {
    int width = parent.getWidth() * 3 / 5;

    tgs.getOPS().draw(g, parent);
    g.setColor(new Color(255, 255, 255));
    g.setFont(new Font("Rockwell", 0, 32));
    g.fillRect(parent.getWidth() / 5, parent.getHeight() / 5, width, parent.getHeight() * 3 / 5);
    g.setColor(Color.BLACK);
    g.drawString(
        name,
        parent.getWidth() / 5 + width / 2 - g.getFontMetrics().stringWidth(name),
        parent.getHeight() / 5 + g.getFontMetrics().getHeight());
    for (int i = 0; i < abilities.length; i++) {

      if (abilities[i] != null) {
        g.drawString(
            abilities[i],
            parent.getWidth() / 5,
            parent.getHeight() / 5 + g.getFontMetrics().getHeight() * (8 + i));
      }
    }
    for (int i = 0; i < traits.length; i++) {
      if (i == currentIndex) {
        g.setColor(Color.RED);
      } else {
        g.setColor(Color.BLACK);
      }
      g.drawString(
          traits[i],
          parent.getWidth() / 5,
          parent.getHeight() / 5 + g.getFontMetrics().getHeight() * (2 + i));
    }
  }
Example #10
0
  /**
   * Ecrit le nom de l'element.
   *
   * @param g graphics
   * @param vueElement vue de l'element a dessiner
   * @param coordX abscisse de l'element
   * @param coordY ordonnee de l'element
   * @return vrai si le texte a ete ecrit en dessous de la forme representant l'element, faux sinon
   */
  private boolean dessineElementNom(Graphics g, VueElement<?> vueElement, int coordX, int coordY) {
    Rectangle rect = this.getBounds();

    // affiche au dessus du point ses informations
    String s = vueElement.getElement().getNom();
    int stringWidth = (int) g.getFontMetrics().getStringBounds(s, g).getWidth();
    int stringHeight = (int) g.getFontMetrics().getStringBounds(s, g).getHeight();
    int start = (stringWidth / 2) - (ELEMENT_SIZE / 2);

    // gestion du debordement des infos
    int coordXString = Math.max(coordX - start, 2);

    if (coordXString + stringWidth > rect.getWidth()) {
      coordXString = (int) (rect.getWidth() - 2 - stringWidth);
    }

    int coordYString = coordY - 10;
    boolean descendu = false;

    if (coordY < stringHeight) {
      coordYString = coordY + 29;
      descendu = true;
    }

    g.drawString(s, coordXString, coordYString);

    return descendu;
  }
Example #11
0
 /**
  * handy little utility for determining the length in pixels the given string will use if drawn
  * into the given Graphics object. Note: perhaps belongs in some utility package.
  */
 public static Dimension stringSize(String str, Graphics g) {
   if (g instanceof Graphics2D) {
     java.awt.geom.Rectangle2D bounds =
         g.getFont().getStringBounds(str, ((Graphics2D) g).getFontRenderContext());
     return new Dimension((int) (bounds.getWidth() + .5), (int) (bounds.getHeight() + .5));
   } else
     return new Dimension(g.getFontMetrics().stringWidth(str), g.getFontMetrics().getHeight());
 }
    private void drawColumn(
        Graphics g, State state, EcoIdentity onGround, int x, int y, int cubeSize) {
      String label;
      int strWidth;
      EcoState ecoState;

      EcoIdentity entity = onGround;
      int yy = y - cubeSize;
      int strHeight = g.getFontMetrics().getHeight() / 2;

      Color backColor, frontColor;

      while (entity != null) {

        ecoState = state.ecoStates.get(entity);
        if (ecoState == null) {
          backColor = Color.DARK_GRAY;
          frontColor = Color.WHITE;
        } else {
          switch (ecoState) {
            case ESCAPING:
              backColor = Color.RED;
              frontColor = Color.BLACK;
              break;
            case ESCAPED:
              backColor = Color.PINK;
              frontColor = Color.BLACK;
              break;
            case SATISFACTING:
              backColor = Color.WHITE;
              frontColor = Color.BLACK;
              break;
            case SATISFACTED:
              backColor = Color.GREEN;
              frontColor = Color.BLACK;
              break;
            case INITIALIZED:
            case INITIALIZING:
            default:
              backColor = Color.DARK_GRAY;
              frontColor = Color.WHITE;
              break;
          }
        }

        g.setColor(backColor);
        g.fillRect(x, yy, cubeSize, cubeSize);
        g.setColor(frontColor);
        g.drawRect(x, yy, cubeSize, cubeSize);

        label = entity.toString();
        strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), label);
        g.drawString(label, x + (cubeSize - strWidth) / 2, yy + (cubeSize - strHeight) / 2);

        yy -= cubeSize;
        entity = state.map.get(entity);
      }
    }
  protected void paintComponent(Graphics g) {

    // Set up rendering hints to look as close to native as possible
    Graphics2D g2d = (Graphics2D) g;
    Object old = null;

    // First, try to use the rendering hint set that is "native".
    Map hints = (Map) getToolkit().getDesktopProperty("awt.font.desktophints");
    if (hints != null) {
      old = g2d.getRenderingHints();
      g2d.addRenderingHints(hints);
    }
    // If a "native" set isn't found, just turn on standard text AA.
    else {
      old = g2d.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
      g2d.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }

    //		if (jsc!=null) {
    //			setText(null); // Stop "Foobar" from being painted
    //		}

    // We never paint "selection" around the icon, to imitate Eclipse
    final int iconW = 18;
    int h = getHeight();
    if (!selected) {
      g.setColor(getBackground());
      g.fillRect(0, 0, getWidth(), h);
    } else {
      g.setColor(altBG != null && evenRow ? altBG : list.getBackground());
      g.fillRect(0, 0, iconW, h);
      g.setColor(getBackground()); // Selection color
      g.fillRect(iconW, 0, getWidth() - iconW, h);
    }
    if (getIcon() != null) {
      int y = (h - getIcon().getIconHeight()) / 2;
      getIcon().paintIcon(this, g, 0, y);
    }

    int x = getX() + iconW + 2;
    g.setColor(selected ? list.getSelectionForeground() : list.getForeground());
    if (jsc != null && !simpleText) {
      jsc.rendererText(g, x, g.getFontMetrics().getHeight(), selected);
    } else {
      Completion c = jsc != null ? (Completion) jsc : nonJavaCompletion;
      if (c != null) {
        g.drawString(c.toString(), x, g.getFontMetrics().getHeight());
      }
    }

    // Restore rendering hints appropriately.
    if (hints != null) {
      g2d.addRenderingHints((Map) old);
    } else {
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, old);
    }
  }
Example #14
0
  /**
   * @param g Graphics context.
   * @param ch The character.
   * @return the width of the character.
   */
  public int charWidth(Graphics g, char ch) {
    FontMetrics fm;
    if (g == null) return 0;

    if (font == null) fm = g.getFontMetrics();
    else fm = g.getFontMetrics(font);

    return fm.charWidth(ch);
  }
Example #15
0
 public void paint(Graphics g) {
   g.drawImage(logo, 0, 0, this);
   int h = logo.getHeight(this) + 20;
   g.drawString(about1 + " v" + version + " (" + build + ")", 0, h);
   h += g.getFontMetrics().getHeight();
   g.drawString(about2, 0, h);
   h += g.getFontMetrics().getHeight();
   g.drawString(about3, 0, h);
 }
  @Override
  public void paintComponent(final Graphics g) {
    super.paintComponent(g);

    // draw entire component white
    g.setColor(Color.white);
    g.fillRect(0, 0, getWidth(), getHeight());

    // yellow circle
    g.setColor(Color.yellow);
    g.fillOval(0, 0, 240, 240);

    // magenta circle
    g.setColor(Color.magenta);
    g.fillOval(160, 160, 240, 240);

    // paint the icon below blue sqaure
    int w = java2sLogo.getIconWidth();
    int h = java2sLogo.getIconHeight();
    java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2));

    // paint the icon below red sqaure
    java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2));

    // transparent red square
    g.setColor(m_tRed);
    g.fillRect(60, 220, 120, 120);

    // transparent green circle
    g.setColor(m_tGreen);
    g.fillOval(140, 140, 120, 120);

    // transparent blue square
    g.setColor(m_tBlue);
    g.fillRect(220, 60, 120, 120);

    g.setColor(Color.black);

    g.setFont(monoFont);
    FontMetrics fm = g.getFontMetrics();
    w = fm.stringWidth("Java Source");
    h = fm.getAscent();
    g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4));

    g.setFont(sanSerifFont);
    fm = g.getFontMetrics();
    w = fm.stringWidth("and");
    h = fm.getAscent();
    g.drawString("and", 200 - (w / 2), 200 + (h / 4));

    g.setFont(serifFont);
    fm = g.getFontMetrics();
    w = fm.stringWidth("Support.");
    h = fm.getAscent();
    g.drawString("Support.", 280 - (w / 2), 280 + (h / 4));
  }
Example #17
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Dimension sz = getSize();
    int top = Math.max(0, (sz.height - tableHeight) / 2);
    int left = Math.max(0, (sz.width - tableWidth) / 2);
    Model model = getModel();
    if (model == null) return;
    Selection sel = model.getSelection();
    int columns = sel.size();
    if (columns == 0) {
      g.setFont(BODY_FONT);
      GraphicsUtil.drawCenteredText(
          g, Strings.get("tableEmptyMessage"), sz.width / 2, sz.height / 2);
      return;
    }

    g.setColor(Color.GRAY);
    int lineY = top + cellHeight + HEADER_SEP / 2;
    g.drawLine(left, lineY, left + tableWidth, lineY);

    g.setColor(Color.BLACK);
    g.setFont(HEAD_FONT);
    FontMetrics headerMetric = g.getFontMetrics();
    int x = left;
    int y = top + headerMetric.getAscent() + 1;
    for (int i = 0; i < columns; i++) {
      x = paintHeader(sel.get(i).toShortString(), x, y, g, headerMetric);
    }

    g.setFont(BODY_FONT);
    FontMetrics bodyMetric = g.getFontMetrics();
    Rectangle clip = g.getClipBounds();
    int firstRow = Math.max(0, (clip.y - y) / cellHeight - 1);
    int lastRow = Math.min(rowCount, 2 + (clip.y + clip.height - y) / cellHeight);
    int y0 = top + cellHeight + HEADER_SEP;
    x = left;
    for (int col = 0; col < columns; col++) {
      SelectionItem item = sel.get(col);
      ValueLog log = model.getValueLog(item);
      int radix = item.getRadix();
      int offs = rowCount - log.size();
      y = y0 + Math.max(offs, firstRow) * cellHeight;
      for (int row = Math.max(offs, firstRow); row < lastRow; row++) {
        Value val = log.get(row - offs);
        String label = val.toDisplayString(radix);
        int width = bodyMetric.stringWidth(label);
        g.drawString(label, x + (cellWidth - width) / 2, y + bodyMetric.getAscent());
        y += cellHeight;
      }
      x += cellWidth + COLUMN_SEP;
    }
  }
 public void origenEscalas(Graphics g) {
   cAlto = g.getFontMetrics().getHeight();
   cAncho = g.getFontMetrics().stringWidth("0");
   wAncho = getSize().width;
   wAlto = getSize().height;
   orgX = 12 * 4 * cAncho;
   orgXX = 4 * cAncho;
   orgY = (7 * wAlto) / 10;
   escalaY = (double) wAlto / (double) 500;
   escalaX = (double) (wAncho - orgX) / (double) 20;
 }
  @Override
  public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {
    Rectangle r0 = null, r1 = null;
    try {
      r0 = c.modelToView(p0);
      r1 = c.modelToView(p1);
    } catch (BadLocationException ex) {
      // Nothing
    }

    if (r0 != null && r1 != null) {
      if (c instanceof JTextField) {
        g.setColor(color);
        g.fillRect(r0.x, r0.y, r1.x - r0.x, r0.height);
        g.setColor(Color.black);
        g.drawString(c.getText().substring(p0, p1), r0.x, r0.y + r0.height - 2);
      } else if (c instanceof JTextArea) {
        String str = c.getText().substring(p0, p1);
        int strMeasure = g.getFontMetrics().stringWidth(str);
        if (r0.x + strMeasure > c.getWidth() - 12) {
          int posX = r0.x, posY = r0.y + r0.height - 3;
          double countLine = 1;

          for (char ch : str.toCharArray()) {
            int chMeasure = g.getFontMetrics().charWidth(ch);
            if (posX + chMeasure > c.getWidth() - 12) {

              Double d1 = new Double(posX + "");
              Double d2 = new Double(strMeasure + "");
              Double d3 = new Double(c.getWidth() + "");

              if ((d1 + d2) / d3 > countLine) {
                posX = 6;
                posY += r0.height;
                countLine += 1.0d;
              }
            }
            g.setColor(color);
            g.fillRect(posX, posY - r0.height - 3, chMeasure, r0.height);
            g.setColor(Color.black);
            g.drawString(ch + "", posX, posY);
            posX += chMeasure;
          }
        } else {
          int RX = r1.x - r0.x < 0 ? strMeasure : r1.x - r0.x;
          g.setColor(color);
          g.fillRect(r0.x, r0.y, RX, r0.height);
          g.setColor(Color.black);
          g.drawString(str, r0.x, r0.y + r0.height - 3);
        }
      }
    }
  }
 public void displayMetrics(Graphics g) {
   leading = g.getFontMetrics().getLeading();
   ascent = g.getFontMetrics().getAscent();
   descent = g.getFontMetrics().getDescent();
   height = g.getFontMetrics().getHeight();
   g.drawString(movieQuote, x, y += height);
   g.drawString("Leading is " + leading, x, y += height);
   g.drawString("Ascent is " + ascent, x, y += height);
   g.drawString("Descent is " + descent, x, y += height);
   g.drawString("Height is " + height, x, y += height);
   y += height * 2;
 }
 public void paint(Graphics g) {
   g.setColor(new Color(0xFFFFFF));
   g.fillRect(0, 0, g.getClipBounds().width, g.getClipBounds().height);
   g.setColor(new Color(0x000000));
   int width = g.getFontMetrics().stringWidth("Launching Elusiva Everywhere session...");
   int x = (int) (g.getClipBounds().getWidth() / 2) - (width / 2);
   int y = (int) (g.getClipBounds().getHeight() / 2);
   if (!redirectOutput) g.drawString("Launching Elusiva Everywhere session...", x, y);
   width = g.getFontMetrics().stringWidth("Connect to:" + getParameter("server"));
   x = (int) (g.getClipBounds().getWidth() / 2) - (width / 2);
   y = (int) (g.getClipBounds().getHeight() / 2) + 20;
   if (!redirectOutput) g.drawString("Connecting to:" + getParameter("server"), x, y);
 }
Example #22
0
 /**
  * Helper method for redraw to draw screen during phase of maze generation, screen is hard coded
  * only attribute percentdone is dynamic
  *
  * @param gc graphics is the off screen image
  */
 void redrawGenerating(Graphics gc) {
   gc.setColor(Color.yellow);
   gc.fillRect(0, 0, Constants.VIEW_WIDTH, Constants.VIEW_HEIGHT);
   gc.setFont(largeBannerFont);
   FontMetrics fm = gc.getFontMetrics();
   gc.setColor(Color.red);
   centerString(gc, fm, "Building maze", 150);
   gc.setFont(smallBannerFont);
   fm = gc.getFontMetrics();
   gc.setColor(Color.black);
   centerString(gc, fm, maze.getPercentDone() + "% completed", 200);
   centerString(gc, fm, "Hit escape to stop", 300);
 }
Example #23
0
 private static java.awt.geom.Rectangle2D getTextBounds(String text, java.awt.Font font) {
   if (text != null) {
     java.awt.Graphics g = edu.cmu.cs.dennisc.java.awt.GraphicsUtilities.getGraphics();
     java.awt.FontMetrics fm;
     if (font != null) {
       fm = g.getFontMetrics(font);
     } else {
       fm = g.getFontMetrics();
     }
     return fm.getStringBounds(text, g);
   } else {
     return new java.awt.geom.Rectangle2D.Float(0, 0, 0, 0);
   }
 }
Example #24
0
 /**
  * Draws a progress bar using the co-ordinates, dimensions and skill provided. This also displays
  * current level in the skill, percent till the next level & exp needed to reach the next level
  *
  * @param g An instance of Graphics to paintType to.
  * @param skill The number of the skill wanting to display. E.g Skills.MAGIC
  * @param x The "x" co-ordinate.
  * @param y The "y" co-ordinate.
  * @param w The width of the progress bar.
  * @param h The height of the progress bar.
  * @param hover If you want extra info to be displayed (Usually for when the skill is "Hovered")
  * @author Rudday, UberMouse
  */
 public void drawProgressBar(Graphics g, int skill, int x, int y, int w, int h, boolean hover) {
   Graphics2D g2 = (Graphics2D) g;
   Paint p = g2.getPaint();
   GradientPaint grad1 =
       new GradientPaint(x, y, scheme.firstGradient1, x, y + h + 3, scheme.firstGradient2);
   GradientPaint grad2 =
       new GradientPaint(x, y, scheme.secondGradient1, x, y + h + 3, scheme.secondGradient2);
   g2.setPaint(grad1);
   g2.fillRect(x, y, w, h);
   g2.setPaint(grad2);
   g2.fillRect(x, y, (int) (w * (UberSkills.getPercentToNextLevel(skill) / 100.0)), h);
   g2.setColor(scheme.text);
   g2.drawRect(x, y, w, h);
   g2.setFont(new Font("Arial", 0, 9));
   String progress =
       UberSkills.getPercentToNextLevel(skill)
           + "% to "
           + ((UberSkills.getRealLevel(skill) + 1 <= 120)
               ? UberSkills.getRealLevel(skill) + 1
               : 120)
           + " "
           + name
           + " | "
           + UberSkills.getExpToNextLevel(skill)
           + " XPTL";
   g2.drawString(
       progress,
       x + ((w - (g.getFontMetrics().stringWidth(progress))) / 2),
       (int) (y + ((g.getFontMetrics().getHeight() / 2) + (h / 4) * 1.75)));
   g2.setPaint(p);
   if (hover) {
     g2.setColor(scheme.hover);
     g2.fillRect(x, y - (height + 2), width, height);
     g2.setColor(scheme.text);
     g2.drawRect(x, y - (height + 2), width, height);
     progress =
         "TTL: "
             + skillInfo.timeToLevel()
             + " XPG: "
             + skillInfo.xpGained()
             + " XPPH: "
             + skillInfo.xpPH()
             + " LG: "
             + skillInfo.levelsGained();
     g2.drawString(
         progress,
         x + ((w - (g.getFontMetrics().stringWidth(progress))) / 2),
         (int) ((y - (height + 2)) + ((g.getFontMetrics().getHeight() / 2) + (h / 4) * 1.75)));
   }
 }
Example #25
0
 /**
  * Helper method for redraw to draw final screen, screen is hard coded
  *
  * @param gc graphics is the off screen image
  */
 void redrawFinish(Graphics gc) {
   gc.setColor(Color.blue);
   gc.fillRect(0, 0, Constants.VIEW_WIDTH, Constants.VIEW_HEIGHT);
   gc.setFont(largeBannerFont);
   FontMetrics fm = gc.getFontMetrics();
   gc.setColor(Color.yellow);
   centerString(gc, fm, "You won!", 100);
   gc.setColor(Color.orange);
   gc.setFont(smallBannerFont);
   fm = gc.getFontMetrics();
   centerString(gc, fm, "Congratulations!", 160);
   gc.setColor(Color.white);
   centerString(gc, fm, "Hit any key to restart", 300);
 }
Example #26
0
  @Override
  protected void paintComponent(Graphics g) {
    measures.ensureComputed(g);

    Rectangle clip = g.getClipBounds();
    if (isOpaque()) {
      g.setColor(getBackground());
      g.fillRect(clip.x, clip.y, clip.width, clip.height);
    }

    long addr0 = model.getFirstOffset();
    long addr1 = model.getLastOffset();

    long xaddr0 = measures.toAddress(0, clip.y);
    if (xaddr0 == addr0) xaddr0 = measures.getBaseAddress(model);
    long xaddr1 = measures.toAddress(getWidth(), clip.y + clip.height) + 1;
    highlighter.paint(g, xaddr0, xaddr1);

    g.setColor(getForeground());
    Font baseFont = g.getFont();
    FontMetrics baseFm = g.getFontMetrics(baseFont);
    Font labelFont = baseFont.deriveFont(Font.ITALIC);
    FontMetrics labelFm = g.getFontMetrics(labelFont);
    int cols = measures.getColumnCount();
    int baseX = measures.getBaseX();
    int baseY = measures.toY(xaddr0) + baseFm.getAscent() + baseFm.getLeading() / 2;
    int dy = measures.getCellHeight();
    int labelWidth = measures.getLabelWidth();
    int labelChars = measures.getLabelChars();
    int cellWidth = measures.getCellWidth();
    int cellChars = measures.getCellChars();
    for (long a = xaddr0; a < xaddr1; a += cols, baseY += dy) {
      String label = toHex(a, labelChars);
      g.setFont(labelFont);
      g.drawString(
          label, baseX - labelWidth + (labelWidth - labelFm.stringWidth(label)) / 2, baseY);
      g.setFont(baseFont);
      long b = a;
      for (int j = 0; j < cols; j++, b++) {
        if (b >= addr0 && b <= addr1) {
          String val = toHex(model.get(b), cellChars);
          int x = measures.toX(b) + (cellWidth - baseFm.stringWidth(val)) / 2;
          g.drawString(val, x, baseY);
        }
      }
    }

    caret.paintForeground(g, xaddr0, xaddr1);
  }
Example #27
0
 private Dimension getContainerDimensions(Graphics g, steps.array.bucket.Container c) {
   int spacingWidth =
       (int) g.getFontMetrics(g.getFont()).getStringBounds(CONTAINER_VALUE_SPACING, g).getHeight();
   int totalWidth = spacingWidth;
   int totalHeight = 0;
   for (int i = 0; i < c.theValues.length; i++) {
     totalHeight =
         (int) g.getFontMetrics(g.getFont()).getStringBounds("" + c.theValues[0], g).getHeight()
             * 2;
     totalWidth +=
         (int) g.getFontMetrics(g.getFont()).getStringBounds("" + c.theValues[i], g).getWidth();
     totalWidth += spacingWidth;
   }
   return new Dimension(totalWidth, totalHeight);
 }
Example #28
0
  /*
   * Draws menu header (logo and particles)
   */
  private void drawMenuHeader(Graphics g) {
    g.setFont(Fonts.largefont);
    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.YELLOW);
    // Draw logo
    Image img = game.imgs[0];
    g.drawImage(img, (winSize.width - img.getWidth(null)) / 2, 30, null);
    g.setFont(Fonts.smallfont);
    fm = g.getFontMetrics();
    g.drawString("by Ben Homer", 10, winSize.height - 20);

    if (DBClient.loggedIn) {
      g.drawString("Logged in as: " + DBClient.getName(), 10, 30);
    }
  }
 protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) {
   JButtonLinkA bn = (JButtonLinkA) com;
   ButtonModel bnModel = bn.getModel();
   Color color = bn.getForeground();
   Object obj = null;
   if (bnModel.isEnabled()) {
     if (bnModel.isPressed()) bn.setForeground(bn.getActiveLinkColor());
     else if (bn.isLinkVisited()) bn.setForeground(bn.getVisitedLinkColor());
     else bn.setForeground(bn.getLinkColor());
   } else {
     if (bn.getDisabledLinkColor() != null) bn.setForeground(bn.getDisabledLinkColor());
   }
   super.paintText(g, com, rect, s);
   int behaviour = bn.getLinkBehavior();
   boolean drawLine = false;
   if (behaviour == JButtonLinkA.HOVER_UNDERLINE) {
     if (bnModel.isRollover()) drawLine = true;
   } else if (behaviour == JButtonLinkA.ALWAYS_UNDERLINE
       || behaviour == JButtonLinkA.SYSTEM_DEFAULT) drawLine = true;
   if (!drawLine) return;
   FontMetrics fm = g.getFontMetrics();
   int x = rect.x + getTextShiftOffset();
   int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1;
   if (bnModel.isEnabled()) {
     g.setColor(bn.getForeground());
     g.drawLine(x, y, (x + rect.width) - 1, y);
   } else {
     g.setColor(bn.getBackground().brighter());
     g.drawLine(x, y, (x + rect.width) - 1, y);
   }
 }
Example #30
0
 /**
  * @param font where to get the descent
  * @return the descent of the font
  */
 private int getDescent(Font font) {
   Graphics g = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).createGraphics();
   g.setFont(font);
   int d = (int) (g.getFontMetrics().getDescent() + 0.99f);
   g.dispose();
   return d;
 }