/** * 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)); }
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(); } }
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); }
// 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); } }
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(); }
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()); }
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); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { textLabel.setFont(table.getFont()); textLabel.setText(Objects.toString(value, "")); textLabel.setBorder(hasFocus ? focusCellHighlightBorder : noFocusBorder); FontMetrics fm = table.getFontMetrics(table.getFont()); Insets i = textLabel.getInsets(); int swidth = iconLabel.getPreferredSize().width + fm.stringWidth(textLabel.getText()) + i.left + i.right; int cwidth = table.getColumnModel().getColumn(column).getWidth(); dim.width = swidth > cwidth ? cwidth : swidth; if (isSelected) { textLabel.setOpaque(true); textLabel.setForeground(table.getSelectionForeground()); textLabel.setBackground(table.getSelectionBackground()); iconLabel.setIcon(sicon); } else { textLabel.setOpaque(false); textLabel.setForeground(table.getForeground()); textLabel.setBackground(table.getBackground()); iconLabel.setIcon(nicon); } return panel; }
/** * This is called to paint within the EditCanvas * * @param g Graphics * @param c DisplayCanvas to paint on. */ public void paint(Graphics g, DisplayCanvas c) { Rectangle nb = transformOutput(c, getBounds()); if (!getActive()) { Rectangle r = getBounds(); g.setColor(Color.lightGray); g.fillRect(r.x, r.y, r.width, r.height); } draw((Graphics2D) g, nb.x, nb.y, nb.width, nb.height); if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).getShowParams()) { int xoff = 0; FontMetrics fm = g.getFontMetrics(); g.setColor(Color.black); for (int i = 0; i < paramIds.length; i++) { String s = paramIds[i]; if (i > 0) { s = ", " + s; } g.drawString(s, nb.x + xoff, nb.y + nb.height + fm.getMaxDescent() + fm.getMaxAscent() + 4); xoff += fm.stringWidth(s); } } if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).shouldShowAlignmentPoints()) { paintRectPoint(g, c); } }
void drawRoiLabel(Graphics g, int index, Roi roi) { Rectangle r = roi.getBounds(); int x = screenX(r.x); int y = screenY(r.y); double mag = getMagnification(); int width = (int) (r.width * mag); int height = (int) (r.height * mag); int size = width > 40 && height > 40 ? 12 : 9; if (font != null) { g.setFont(font); size = font.getSize(); } else if (size == 12) g.setFont(largeFont); else g.setFont(smallFont); boolean drawingList = index >= LIST_OFFSET; if (drawingList) index -= LIST_OFFSET; String label = "" + (index + 1); if (drawNames && roi.getName() != null) label = roi.getName(); FontMetrics metrics = g.getFontMetrics(); int w = metrics.stringWidth(label); x = x + width / 2 - w / 2; y = y + height / 2 + Math.max(size / 2, 6); int h = metrics.getAscent() + metrics.getDescent(); if (bgColor != null) { g.setColor(bgColor); g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5); } if (!drawingList && labelRects != null && index < labelRects.length) labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h); g.setColor(labelColor); g.drawString(label, x, y - 2); g.setColor(defaultColor); }
public void paint(Graphics g) { m_fm = g.getFontMetrics(); g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); g.setColor(getForeground()); g.setFont(getFont()); m_insets = getInsets(); int x = m_insets.left; int y = m_insets.top + m_fm.getAscent(); StringTokenizer st = new StringTokenizer(getText(), "\t"); while (st.hasMoreTokens()) { String sNext = st.nextToken(); g.drawString(sNext, x, y); x += m_fm.stringWidth(sNext); if (!st.hasMoreTokens()) break; int index = 0; while (x >= getTab(index)) index++; x = getTab(index); } }
/** * Write the given text string in the current font, right-aligned at (x, y). * * @param x the x-coordinate of the text * @param y the y-coordinate of the text * @param s the text */ public static void textRight(double x, double y, String s) { offscreen.setFont(font); FontMetrics metrics = offscreen.getFontMetrics(); double xs = scaleX(x); double ys = scaleY(y); int ws = metrics.stringWidth(s); int hs = metrics.getDescent(); offscreen.drawString(s, (float) (xs - ws), (float) (ys + hs)); draw(); }
/** * Query the font width used in calculating line indenting. * * @return fontWidth to use to calculate line indenting. */ public int getFontWidth() { int retval = fontWidth; if (fontWidth < 0) { final FontMetrics fontMetrics = getFontMetrics(getFont()); retval = fontMetrics.stringWidth("_"); setFontWidth(retval); } return retval; }
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()
/** This internal method begins a new page and prints the header. */ protected void newpage() { page = job.getGraphics(); // Begin the new page linenum = 0; charnum = 0; // Reset line and char number pagenum++; // Increment page number page.setFont(headerfont); // Set the header font. page.drawString(jobname, x0, headery); // Print job name left justified String s = "- " + pagenum + " -"; // Print the page number centered. int w = headermetrics.stringWidth(s); page.drawString(s, x0 + (this.width - w) / 2, headery); w = headermetrics.stringWidth(time); // Print date right justified page.drawString(time, x0 + width - w, headery); // Draw a line beneath the header int y = headery + headermetrics.getDescent() + 1; page.drawLine(x0, y, x0 + width, y); // Set the basic monospaced font for the rest of the page. page.setFont(font); }
/** * Compute all the instance variables necessary for displaying the message. If the total width * of the message in pixels would be more than 280, break it up into several lines. */ private void makeStringList() { messageStrings = new Vector(); font = new Font("Dialog", Font.PLAIN, 12); FontMetrics fm = getFontMetrics(font); lineHeight = fm.getHeight() + 3; fontAscent = fm.getAscent(); int totalWidth = fm.stringWidth(message); if (totalWidth <= 280) { messageStrings.addElement(message); messageWidth = 280; messageHeight = lineHeight; } else { if (totalWidth > 1800) messageWidth = Math.min(500, totalWidth / 6); else messageWidth = 300; int actualWidth = 0; String line = " "; String word = ""; message += " "; // this forces word == "" after the following for loop ends. for (int i = 0; i < message.length(); i++) { if (message.charAt(i) == ' ') { if (fm.stringWidth(line + word) > messageWidth + 8) { messageStrings.addElement(line); actualWidth = Math.max(actualWidth, fm.stringWidth(line)); line = ""; } line += word; if (line.length() > 0) line += ' '; word = ""; } else { word += message.charAt(i); } } if (line.length() > 0) { messageStrings.addElement(line); actualWidth = Math.max(actualWidth, fm.stringWidth(line)); } messageHeight = lineHeight * messageStrings.size() - fm.getLeading(); messageWidth = Math.max(280, actualWidth); } }
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; }
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); }
public void centerText(String s1, String s2, Graphics g, Color c, int x, int y, int w, int h) { // locs[0].centerText(s1, s2, this.getGraphics(), // Color.white, 400,0,200,50); // g.setXORMode(unselected_color); // centerText("pic" + im, null, g, Color.black, x, y, w, h); Font f = g.getFont(); FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f); int ascent = fm.getAscent(); int height = fm.getHeight(); int width1 = 0, width2 = 0, x0 = 0, x1 = 0, y0 = 0, y1 = 0; width1 = fm.stringWidth(s1); if (s2 != null) width2 = fm.stringWidth(s2); x0 = x + (w - width1) / 2; x0 = x + (w - width2) / 2; if (s2 == null) y0 = y + (h - height) / 2 + ascent; else { y0 = y + (h - (int) (height * 2.2)) / 2 + ascent; y1 = y0 + (int) (height * 1.2); } g.setColor(c); g.drawString(s1, x0, y0); if (s2 != null) g.drawString(s2, x1, y1); }
public void paintComponent(Graphics g) { super.paintComponent(g); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Dimension theSize = getSize(); if (mColorListMode == VisualizationColor.cColorListModeCategories) { int categories = mCategoryColorList.length; if (categories <= cMaxEditableColors) { int fieldWidth = (theSize.width - 2 * cBorder + cSpacing) / categories - cSpacing; mRect = new Rectangle[categories]; for (int i = 0; i < categories; i++) { mRect[i] = new Rectangle( cBorder + i * (fieldWidth + cSpacing), cBorder, fieldWidth, theSize.height - 2 * cBorder); drawColorButton(g, i); } } else { final String message = "<too many colors to edit>"; g.setColor(Color.GRAY); g.setFont(new Font("Arial", Font.BOLD, 13)); FontMetrics m = g.getFontMetrics(); g.drawString( message, (theSize.width - m.stringWidth(message)) / 2, (theSize.height + m.getHeight()) / 2 - m.getDescent()); } } else { int size = theSize.height - 2 * cBorder; int x1 = 2 * cBorder + size; int x2 = theSize.width - 2 * cBorder - size; mRect = new Rectangle[3]; mRect[0] = new Rectangle(cBorder, cBorder, size, size); mRect[1] = new Rectangle( theSize.width - size - cBorder, theSize.height - size - cBorder, size, size); mRect[cColorWedgeButton] = new Rectangle(x1, cBorder, x2 - x1, size); drawColorButton(g, 0); drawColorButton(g, 1); drawColorButton(g, cColorWedgeButton); } }
public void paintComponent(Graphics gr) { Graphics2D g = (Graphics2D) gr; Object oldHints = QuaquaUtilities.beginGraphics((Graphics2D) g); g.drawImage(crayonsImage, 0, 0, this); if (selectedCrayon != null) { /* g.setColor(new Color(0x60ffffff & selectedCrayon.color.getRGB(),true)); g.fill(selectedCrayon.shape); */ g.setColor(getForeground()); FontMetrics fm = g.getFontMetrics(); int nameWidth = fm.stringWidth(selectedCrayon.name); g.drawString( selectedCrayon.name, (crayonsImage.getWidth(this) - nameWidth) / 2, fm.getAscent() + 1); } QuaquaUtilities.endGraphics((Graphics2D) g, oldHints); }
AboutPanel() { setFont(UIManager.getFont("Label.font")); fm = getFontMetrics(getFont()); setForeground(new Color(96, 96, 96)); image = new ImageIcon(getClass().getResource("/org/gjt/sp/jedit/icons/about.png")); setBorder(new MatteBorder(1, 1, 1, 1, Color.gray)); text = new Vector(50); StringTokenizer st = new StringTokenizer(jEdit.getProperty("about.text"), "\n"); while (st.hasMoreTokens()) { String line = st.nextToken(); text.addElement(line); maxWidth = Math.max(maxWidth, fm.stringWidth(line) + 10); } scrollPosition = -250; thread = new AnimationThread(); }
/** * Called to paint the outline. * * @param g graphics object to paint. */ public void paint(final Graphics g) { final FontMetrics fontMetrics = getFontMetrics(getFont()); setFontWidth(fontMetrics.stringWidth("_")); setFontHeight(fontMetrics.getHeight()); if (firstTime) { firstTime = false; setVisible("Outline".equalsIgnoreCase(djvuBean.properties.getProperty("navpane"))); } if (!isVisible()) { getParent().setVisible(false); invalidate(); djvuBean.recursiveRevalidate(); } else { synchronized (activeVector) { paintItem(0, g, getBookmark(0)); paintCheckbox(0, g, getBookmark(0)); } } }
@Override public void paintComponent(final Graphics g) { super.paintComponent(g); final Runtime rt = Runtime.getRuntime(); final long max = rt.maxMemory(); final long total = rt.totalMemory(); final long used = total - rt.freeMemory(); final int ww = getWidth(); final int hh = getHeight(); // draw memory box g.setColor(Color.white); g.fillRect(0, 0, ww - 3, hh - 3); g.setColor(GRAY); g.drawLine(0, 0, ww - 4, 0); g.drawLine(0, 0, 0, hh - 4); g.drawLine(ww - 3, 0, ww - 3, hh - 3); g.drawLine(0, hh - 3, ww - 3, hh - 3); // show total memory usage g.setColor(color1); g.fillRect(2, 2, Math.max(1, (int) (total * (ww - 6) / max)), hh - 6); // show current memory usage final boolean full = used * 6 / 5 > max; g.setColor(full ? colormark4 : color3); g.fillRect(2, 2, Math.max(1, (int) (used * (ww - 6) / max)), hh - 6); // print current memory usage final FontMetrics fm = g.getFontMetrics(); final String mem = Performance.format(used, true); final int fw = (ww - fm.stringWidth(mem)) / 2; final int h = fm.getHeight() - 3; g.setColor(full ? colormark3 : DGRAY); g.drawString(mem, fw, h); }
/** Draw the line numbers */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); // Determine the width of the space available to draw the line number FontMetrics fontMetrics = component.getFontMetrics(component.getFont()); Insets insets = getInsets(); int availableWidth = getSize().width - insets.left - insets.right; // Determine the rows to draw within the clipped bounds. Rectangle clip = g.getClipBounds(); int rowStartOffset = component.viewToModel(new Point(0, clip.y)); int endOffset = component.viewToModel(new Point(0, clip.y + clip.height)); while (rowStartOffset <= endOffset) { try { if (isCurrentLine(rowStartOffset)) g.setColor(getCurrentLineForeground()); else g.setColor(getForeground()); // Get the line number as a string and then determine the // "X" and "Y" offsets for drawing the string. String lineNumber = getTextLineNumber(rowStartOffset); int stringWidth = fontMetrics.stringWidth(lineNumber); int x = getOffsetX(availableWidth, stringWidth) + insets.left; int y = getOffsetY(rowStartOffset, fontMetrics); g.drawString(lineNumber, x, y); // Move to the next row rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1; } catch (Exception e) { } } }
public void draw( Graphics2D g, Color stringColor, Color foreground, Color background, String info, double x, double y) { FontMetrics fm = g.getFontMetrics(); int h = fm.getHeight(); int w = fm.stringWidth(info); r1.setRect( x - w / 2 - in.left, y - in.top - h / 2, w + in.right + in.left, h + in.bottom + in.top); g.setColor(background); g.fill(r1); g.setColor(stringColor); g.draw(r1); g.setColor(foreground); r2.setRect(r1.getX() + 1, r1.getY() + 1, r1.getWidth() - 2, r1.getHeight() - 2); g.draw(r2); g.setColor(stringColor); g.drawString( info, (float) (r2.getX() + in.left), (float) (r2.getY() + h - (r2.getHeight() - h) / 2)); }
public void paint(Graphics g) // function that puts everything on the screen { Graphics2D scene = (Graphics2D) g; // Not really sure what this is. Blame Victor // use scene to draw the background scene.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.clearRect(0, 0, SCREENWIDTH, SCREENHEIGHT); // Clears the screen Font q = new Font( "Source Sans Pro", Font.PLAIN, 40); // Makes the font we use for options and story text g.setFont(q); // Sets the default font g.setColor(Color.white); if (state == 1) // Story text { drawTag(g); g.drawImage(textBox, 0, 0, null); // draw the story boxes Font n = new Font("Source Sans Pro", Font.BOLD, 48); // Makes the font for the names g.setFont(n); // Sets the name font scene.drawString(nameC, 53, 435); // Draws the current name g.setFont(q); // sets the quote font fm = g.getFontMetrics(); ArrayList<String> lines = new ArrayList<String>(); String line = ""; for (int i = 0; i < quoteC.length(); i++) { line += quoteC.charAt(i); if (fm.stringWidth(line) > 1180) { String lineCopy = line; line = line.substring(0, lineCopy.lastIndexOf(' ')); i -= lineCopy.length() - lineCopy.lastIndexOf(' ') - 1; lines.add(line); line = ""; } } lines.add(line); for (int i = 0; i < lines.size(); i++) { scene.drawString(lines.get(i), 40, 535 + 65 * i); } } else if (state == 2) // Draws the options { scene.drawImage(bg, screenShakeX, screenShakeY, null); scene.drawImage(obox, screenShakeX, screenShakeY, null); // options thing scene.drawString(options.get(0), 220, 255); scene.drawString(options.get(1), 220, 375); scene.drawString(options.get(2), 220, 495); } else if (state == 3) // Game is over { scene.drawImage(oldbg, screenShakeX, screenShakeY, null); float opacity = fadeCounter / FADETIMELIMIT; if (opacity > 1.0f) opacity = 1.0f; scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); scene.drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); scene.drawString("The end", 40, 520); // End screen } }
protected int getWidth(String s) { FontMetrics fm = getFontMetrics(getFont()); if (fm == null) return 0; else return fm.stringWidth(s); }
public void ellipsifyValues(int width) { int maxKeyWidth = 0; int[] maxAdditionalColumnsWidth = new int[additionalColumns]; for (JComponent keyComp : keyKeyComponentMap.values()) { maxKeyWidth = Math.max(maxKeyWidth, keyComp.getPreferredSize().width); } for (String k : keyValueComponentMap.keySet()) { for (int i = 0; i < additionalColumns; i++) { JComponent extraComp = getAdditionalColumn(k, i); if (extraComp != null) { maxAdditionalColumnsWidth[i] = Math.max(maxAdditionalColumnsWidth[i], extraComp.getPreferredSize().width); } } } width -= maxKeyWidth; for (int i : maxAdditionalColumnsWidth) { width -= i; } for (String k : keyValueComponentMap.keySet()) { JComponent comp = getComponent(k); if (comp != null) { int avail = width; /*for (int i = 0; i < additionalColumns; i++) { JComponent extraComp = getAdditionalColumn(k, i); if (extraComp != null) { avail -= extraComp.getPreferredSize().width; } }*/ if (comp instanceof JLabel) { while (avail < comp.getPreferredSize().width) { String text = ((JLabel) comp).getText(); if (text.endsWith("…")) { if (text.length() > 2) { // Already truncated. text = text.substring(0, text.length() - 2); } else { break; // As short as we can get. Can't truncate any more. } } else { // Reasonable first truncation is to trim off the last word. int spacePos = text.lastIndexOf(' '); if (spacePos > 0) { text = text.substring(0, spacePos); } else { FontMetrics fm = comp.getFontMetrics(comp.getFont()); while (fm.stringWidth(text + "…") > avail) { // causes StringIndexOutOfBoundsException if text is empty. if (text == null || text.length() < 2) { LOG.info("Text is null or empty in KeyValuePairPanel"); break; } text = text.substring(0, text.length() - 2); } // text = text + "…"; // text = text.substring(0, text.length() - 1); } } ((JLabel) comp).setText(text + "…"); } } else { // Can't truncate, but we can force the preferred size. comp.setMaximumSize(new Dimension(avail, comp.getPreferredSize().height)); } } } }
private boolean recalcPositions(Graphics g) { Font f = g.getFont(); if (f != oldFont || !(StringUtil.stringsEqual(oldText, text))) { FontMetrics fm = g.getFontMetrics(f); sw = MesquiteInteger.maximum(fm.stringWidth("888"), fm.stringWidth(tf.getText())); sh = fm.getMaxAscent() + fm.getMaxDescent(); } oldText = text; oldFont = f; if (oldTextBoxWidth < sw + MesquiteModule.textEdgeCompensationWidth - 1 || oldTextBoxHeight < sh + MesquiteModule.textEdgeCompensationHeight - 1) { textBoxWidth = sw + MesquiteModule.textEdgeCompensationWidth; // 34 textBoxHeight = sh + MesquiteModule.textEdgeCompensationHeight; // 18 oldTextBoxWidth = textBoxWidth; oldTextBoxHeight = textBoxHeight; if (horizontal) { if (stacked) { totalWidth = textBoxWidth + EnterButton.MIN_DIMENSION + 2; totalHeight = textBoxHeight + 20; setSize(totalWidth, totalHeight); tf.setSize(textBoxWidth, textBoxHeight); tf.setLocation(0, 0); decrementButton.setLocation(2, textBoxHeight + 4); incrementButton.setLocation(totalWidth - 20, textBoxHeight + 4); } else { totalWidth = textBoxWidth + 36 + EnterButton.MIN_DIMENSION + 2; totalHeight = textBoxHeight + 4; setSize(totalWidth, totalHeight); tf.setSize(textBoxWidth, textBoxHeight); decrementButton.setLocation(0, 2); tf.setLocation( decrementButton.getBounds().x + decrementButton.getBounds().width + 1, 0); // 1 added to x incrementButton.setLocation( tf.getBounds().x + tf.getBounds().width + EnterButton.MIN_DIMENSION + 2, 2); // 1 added to x } enterButton.setLocation(tf.getBounds().x + tf.getBounds().width + 1, 2); } else { if (stacked) { totalWidth = textBoxWidth + EnterButton.MIN_DIMENSION + 2; totalHeight = textBoxHeight + 20; setSize(totalWidth, totalHeight); tf.setSize(textBoxWidth, textBoxHeight); tf.setLocation(0, 0); decrementButton.setLocation(2, textBoxHeight + 4); incrementButton.setLocation(totalWidth - 22, textBoxHeight + 4); enterButton.setLocation(tf.getBounds().x + tf.getBounds().width + 1, 2); } else { totalWidth = textBoxWidth; // should be 0 totalHeight = textBoxHeight + 36 + EnterButton.MIN_DIMENSION + 2; setSize(totalWidth, totalHeight); tf.setSize(textBoxWidth, textBoxHeight); incrementButton.setLocation(1, 2); tf.setLocation(0, incrementButton.getBounds().height + 3); decrementButton.setLocation( 1, tf.getBounds().y + tf.getBounds().height + EnterButton.MIN_DIMENSION + 2); enterButton.setLocation(1, tf.getBounds().y + tf.getBounds().height + 1); } } incrementButton.repaint(); decrementButton.repaint(); enterButton.repaint(); repaint(); getParent().repaint(); return true; } if (checkBackground()) { repaint(); return true; } /* if (!getBackground().equals(getParent().getBackground())) { bg =getParent().getBackground(); setBackground(bg); //setBackground(Color.green); tf.setBackground(bg); decrementButton.setBackground(bg); incrementButton.setBackground(bg); enterButton.setBackground(bg); repaint(); return true; }*/ return false; }