List of usage examples for java.awt FontMetrics getHeight
public int getHeight()
From source file:FontPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); Font f = new Font("SansSerif", Font.BOLD, 14); Font fi = new Font("SansSerif", Font.BOLD + Font.ITALIC, 14); FontMetrics fm = g.getFontMetrics(f); FontMetrics fim = g.getFontMetrics(fi); String s1 = "Java "; String s2 = "Source and Support"; String s3 = " at www.java2s.com"; int width1 = fm.stringWidth(s1); int width2 = fim.stringWidth(s2); int width3 = fm.stringWidth(s3); Dimension d = getSize();//w ww . j ava2s . c o m int cx = (d.width - width1 - width2 - width3) / 2; int cy = (d.height - fm.getHeight()) / 2 + fm.getAscent(); g.setFont(f); g.drawString(s1, cx, cy); cx += width1; g.setFont(fi); g.drawString(s2, cx, cy); cx += width2; g.setFont(f); g.drawString(s3, cx, cy); }
From source file:com.t3.client.ui.ChatTypingNotification.java
/** * This component is only made visible when there are notifications to be displayed. That means the first couple of * IF statements in this method are redundant since paintComponent() will not be called unless the component is * visible, and it will only be visible when there are notifications... *//*w w w.j a va 2 s . co m*/ @Override protected void paintComponent(Graphics g) { // System.out.println("Chat panel is painting itself..."); if (AppPreferences.getTypingNotificationDuration() != 0) { LinkedMap<String, Long> chatTypers = TabletopTool.getFrame().getChatNotificationTimers() .getChatTypers(); if (chatTypers == null || chatTypers.isEmpty()) { return; } Boolean showBackground = AppPreferences.getChatNotificationShowBackground(); Graphics2D statsG = (Graphics2D) g.create(); Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD); Font font = AppStyle.labelFont; FontMetrics valueFM = g.getFontMetrics(font); FontMetrics keyFM = g.getFontMetrics(boldFont); int PADDING7 = 7; int PADDING3 = 3; int PADDING2 = 2; BufferedImage img = AppStyle.panelTexture; int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight()); setBorder(null); int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin(); int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin(); statsG.setFont(font); SwingUtil.useAntiAliasing(statsG); Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(), height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width, getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin() + PADDING2); int y = bounds.y + rowHeight; rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight()); setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin())); if (showBackground) { g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this); AppStyle.miniMapBorder.paintAround(statsG, bounds); } Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7, AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(), AppStyle.chatImage.getHeight()); Set<?> keySet = chatTypers.keySet(); @SuppressWarnings("unchecked") Set<String> playerTimers = (Set<String>) keySet; Color c1 = new Color(249, 241, 230, 140); Color c2 = new Color(175, 163, 149); for (String playerNamer : playerTimers) { if (showBackground) { statsG.setColor(c1); statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); statsG.setColor(c2); statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); } g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(), (int) rightRow.getHeight(), this); // Values statsG.setColor(TabletopTool.getFrame().getChatTypingLabelColor()); statsG.setFont(boldFont); statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer), bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5); y += PADDING2 + rowHeight; } if (showBackground) { AppStyle.shadowBorder.paintWithin(statsG, bounds); } else { setOpaque(false); } } }
From source file:ChartPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); if (values == null || values.length == 0) return;//from www . j av a 2s.com double minValue = 0; double maxValue = 0; for (int i = 0; i < values.length; i++) { if (minValue > values[i]) minValue = values[i]; if (maxValue < values[i]) maxValue = values[i]; } Dimension d = getSize(); int clientWidth = d.width; int clientHeight = d.height; int barWidth = clientWidth / values.length; Font titleFont = new Font("SansSerif", Font.BOLD, 20); FontMetrics titleFontMetrics = g.getFontMetrics(titleFont); Font labelFont = new Font("SansSerif", Font.PLAIN, 10); FontMetrics labelFontMetrics = g.getFontMetrics(labelFont); int titleWidth = titleFontMetrics.stringWidth(title); int y = titleFontMetrics.getAscent(); int x = (clientWidth - titleWidth) / 2; g.setFont(titleFont); g.drawString(title, x, y); int top = titleFontMetrics.getHeight(); int bottom = labelFontMetrics.getHeight(); if (maxValue == minValue) return; double scale = (clientHeight - top - bottom) / (maxValue - minValue); y = clientHeight - labelFontMetrics.getDescent(); g.setFont(labelFont); for (int i = 0; i < values.length; i++) { int valueX = i * barWidth + 1; int valueY = top; int height = (int) (values[i] * scale); if (values[i] >= 0) valueY += (int) ((maxValue - values[i]) * scale); else { valueY += (int) (maxValue * scale); height = -height; } g.setColor(Color.red); g.fillRect(valueX, valueY, barWidth - 2, height); g.setColor(Color.black); g.drawRect(valueX, valueY, barWidth - 2, height); int labelWidth = labelFontMetrics.stringWidth(names[i]); x = i * barWidth + (barWidth - labelWidth) / 2; g.drawString(names[i], x, y); } }
From source file:BenchmarkApplet.java
public void init() { tgroup = Thread.currentThread().getThreadGroup(); Font font = new Font("Courier", Font.PLAIN, 10); FontMetrics fm = getFontMetrics(font); int lines = Math.max(10, size().height / fm.getHeight() - 4); out = new TextArea(lines, spaces.length() + Benchmark.resolutionName.length()); out.setFont(font);/*from w ww . jav a2 s. c o m*/ out.setEditable(false); add(out); boolean toobig; do { testList = new List(--lines, true); add(testList, 0); validate(); if (toobig = testList.size().height - out.size().height > 2) remove(testList); } while (toobig); for (int ii = 0; ii < tests.length; ii++) testList.addItem(tests[ii].getName()); testList.select(0); // Calibration benchmark testList.select(1); // Mixed benchmark timeEstimate = new Label(getTimeEstimate()); add(timeEstimate); add(doit = new Button("Run Benchmark")); add(abort = new Button("Stop")); add(clear = new Button("Clear")); abort.disable(); clear.disable(); add(console = new Checkbox("Console")); validate(); }
From source file:org.squidy.designer.zoom.NavigationShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { super.paintShapeZoomedIn(paintContext); Graphics2D g = (Graphics2D) paintContext.getGraphics(); if (showNavigation) {// && !isHierarchicalZoomInProgress()) { PBounds bounds = getBoundsReference(); int x = (int) bounds.getX(); int y = (int) bounds.getY(); int width = (int) bounds.getWidth(); int height = (int) bounds.getHeight(); g.setColor(Constants.Color.COLOR_SHAPE_BACKGROUND); if (isRenderPrimitiveRect()) g.fillRect(x, y, width, 60); else {/*from w ww.j av a 2s.c o m*/ g.clearRect(x, y, width, 60); g.fillRoundRect(x, y, width, 60, 25, 25); } g.setColor(Constants.Color.COLOR_SHAPE_BORDER); if (isRenderPrimitiveRect()) g.drawRect(x, y, width, 60); else g.drawRoundRect(x, y, width, 60, 25, 25); g.setFont(fontBreadcrumb); if (titleBounds == null) { FontMetrics fm = g.getFontMetrics(); titleBounds = new Rectangle2D.Double(bounds.getX() + 455 + titleGap, bounds.getY() + 25 - fm.getHeight(), FontUtils.getWidthOfText(fm, getTitle()) + 10, fm.getHeight() + 5); } // Font font = internalFont.deriveFont(3.2f); for (int i = 0; i < 3; i++) { if (isRenderPrimitiveRect()) g.fillRect((int) (bounds.getX() + 430), (int) bounds.getY() + i * 15 + 10, 5, 10); else g.fillOval((int) (bounds.getX() + 430), (int) bounds.getY() + i * 15 + 10, 5, 10); } if (!ShapeUtils.isApparent(titleInputWrapper)) { g.drawString(getTitle(), (int) (bounds.getX() + 460 + titleGap), (int) (bounds.getY() + 25)); } if (croppedBreadcrumb == null) { croppedBreadcrumb = FontUtils.createCroppedLabelIfNecessary(g.getFontMetrics(), getBreadcrumb(), (int) bounds.getWidth() * 10 - 450); } g.drawString(croppedBreadcrumb, (int) (bounds.getX() + 460), (int) (bounds.getY() + 50)); } }
From source file:uk.co.modularaudio.mads.base.oscilloscope.ui.OscilloscopeDisplayUiJComponent.java
private void drawScale(final Graphics g, final int height, final float maxMag, final int xOffset) { final FontMetrics fm = g.getFontMetrics(); // Do zero, and plus and minus maximum final int middle = height / 2; final int halfFontHeight = fm.getAscent() / 2; g.drawString("0.0", xOffset, middle + halfFontHeight); final int top = 0 + fm.getHeight(); // Only re-create the string when we need to if (previousPositiveMagStr == null || previousPositiveMag != maxMag) { previousPositiveMagStr = MathFormatter.fastFloatPrint(maxMag, 2, true); previousPositiveMag = maxMag;//from w w w. j a va2 s .c om } g.drawString(previousPositiveMagStr, xOffset, top); if (previousNegativeMagStr == null || previousNegativeMag != -maxMag) { previousNegativeMagStr = MathFormatter.fastFloatPrint(-maxMag, 2, true); previousNegativeMag = -maxMag; } final int bottom = height - halfFontHeight; g.drawString(previousNegativeMagStr, xOffset, bottom); }
From source file:org.evors.rs.ui.sandpit.TrialViewer.java
public void drawText(Graphics2D g2, String text) { FontMetrics fm = g2.getFontMetrics(); List<String> strings = Splitter.on("\n").splitToList(text); float x1 = 40, y = 40; int dx = 0;//from w w w . ja v a 2 s .com for (String s : strings) { int width = fm.stringWidth(s); if (width > dx) { dx = width; } } g2.setColor(new Color(0.6f, 0.6f, 0.6f, 0.6f)); g2.fillRect((int) x1, (int) y - fm.getHeight(), dx + 5, fm.getHeight() * strings.size() + 5); g2.setColor(Color.red); for (String s : strings) { g2.drawString(s, 40, y); y += fm.getHeight(); } }
From source file:com.celements.photo.image.GenerateThumbnail.java
private void drawCopyright(String copyright, Graphics2D g2d, int width, int height) { int bottomSpace = 5; //space between copyright and bottom border. int rightSpace = 5; //space between copyright and right border. int hSpacing = 3; //horizontal space between background and string. int vSpacing = 2; //vertical space between background and string. int rounding = 5; //rounding of the rect. FontMetrics metrics = calcCopyrightFontSize(copyright, width, g2d); g2d.setFont(metrics.getFont());/*www.ja v a2 s. com*/ int stringHeight = metrics.getHeight(); drawBackground(copyright, width, height, bottomSpace, rightSpace, vSpacing, hSpacing, rounding, stringHeight, metrics, g2d); drawString(copyright, width, height, bottomSpace, rightSpace, vSpacing, hSpacing, metrics, g2d); }
From source file:FormattedTextFieldExample.java
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException { a = adjustAllocation(a);//from w w w .jav a 2 s.c o m Rectangle r = new Rectangle(a.getBounds()); FontMetrics fm = getFontMetrics(); r.height = fm.getHeight(); int oldCount = contentBuff.count; if (pos < offsets.length) { contentBuff.count = offsets[pos]; } else { // Beyond the end: point to the location // after the last model position. contentBuff.count = offsets[offsets.length - 1] + 1; } int offset = Utilities.getTabbedTextWidth(contentBuff, metrics, 0, this, element.getStartOffset()); contentBuff.count = oldCount; r.x += offset; r.width = 1; return r; }
From source file:org.squidy.designer.zoom.impl.SourceCodeShape.java
/** * /* w ww . ja v a 2 s. co m*/ */ void computeHeightOfCodePane() { if (codePane != null) { int lineCount = FontUtils.getLineCount(codePane.getText(), CODE_PANE_WIDTH); FontMetrics fm = codePane.getFontMetrics(codePane.getFont()); codePane.setPreferredSize(new Dimension(CODE_PANE_WIDTH, lineCount * fm.getHeight())); } }