Java Code Examples for java.awt.Graphics#drawChars()
The following examples show how to use
java.awt.Graphics#drawChars() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NervousText.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 2
Source File: NervousText.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 3
Source File: NervousText.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 4
Source File: NervousText.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 5
Source File: NervousText.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 6
Source File: NervousText.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 7
Source File: NervousText.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 8
Source File: NervousText.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 9
Source File: NervousText.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public void paint(Graphics g) { int length = bannerChars.length; for (int i = 0, x = 0; i < length; i++) { int wd, ht; if (attributes[i] == '^') { wd = SMALL_WD; ht = SMALL_HT; g.setFont(smallFont); } else { wd = REGULAR_WD; ht = REGULAR_HT; g.setFont(regularFont); } int px = (int) (10 * Math.random() + x); int py = (int) (10 * Math.random() + ht); g.drawChars(bannerChars, i, 1, px, py); x += wd; } }
Example 10
Source File: TextRenderTests.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { TextContext tctx = (TextContext)ctx; Graphics g = tctx.graphics; char[] chars = tctx.chars; g.setFont(tctx.font); do { g.drawChars(chars, 0, chars.length, 40, 40); } while (--numReps >= 0); }
Example 11
Source File: BasicOIA.java From tn5250j with GNU General Public License v2.0 | 5 votes |
private void paintInhibited(Graphics g, Rectangle clip) { if (inhibitedRectangle.intersects(clip)) { if (oia.getInhibitedText() != null) System.out.println(oia.getInhibitedText()); System.out.println("xsystem " + oia.getLevel() + "," + oia.getInputInhibited()); g.setColor(BasicTerminalUI.DFT_FOREGROUND); int cy = (inhibitedRectangle.y + rowHeight - (metrics.getDescent() + metrics.getLeading())); int value = oia.getInputInhibited(); String stext = oia.getInhibitedText(); g.setColor(Color.black); g.fillRect(inhibitedRectangle.x,inhibitedRectangle.x,inhibitedRectangle.width, inhibitedRectangle.height); switch (oia.getLevel()) { case 1: if (value == 1) { g.setColor(Color.white); if (stext != null) { g.drawChars(stext.toCharArray(),0, oia.getInhibitedText().length(),inhibitedRectangle.x,cy); } else { g.drawChars("X - System".toCharArray(),0, "X - System".length(),inhibitedRectangle.x,cy); } } break; } } }
Example 12
Source File: TextRenderTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { TextContext tctx = (TextContext)ctx; Graphics g = tctx.graphics; char[] chars = tctx.chars; g.setFont(tctx.font); do { g.drawChars(chars, 0, chars.length, 40, 40); } while (--numReps >= 0); }
Example 13
Source File: TextRenderTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { TextContext tctx = (TextContext)ctx; Graphics g = tctx.graphics; char[] chars = tctx.chars; g.setFont(tctx.font); do { g.drawChars(chars, 0, chars.length, 40, 40); } while (--numReps >= 0); }
Example 14
Source File: TextRenderTests.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { TextContext tctx = (TextContext)ctx; Graphics g = tctx.graphics; char[] chars = tctx.chars; g.setFont(tctx.font); do { g.drawChars(chars, 0, chars.length, 40, 40); } while (--numReps >= 0); }
Example 15
Source File: TextRenderTests.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { TextContext tctx = (TextContext)ctx; Graphics g = tctx.graphics; char[] chars = tctx.chars; g.setFont(tctx.font); do { g.drawChars(chars, 0, chars.length, 40, 40); } while (--numReps >= 0); }
Example 16
Source File: TextRenderTests.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { TextContext tctx = (TextContext)ctx; Graphics g = tctx.graphics; char[] chars = tctx.chars; g.setFont(tctx.font); do { g.drawChars(chars, 0, chars.length, 40, 40); } while (--numReps >= 0); }
Example 17
Source File: TextRenderTests.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { TextContext tctx = (TextContext)ctx; Graphics g = tctx.graphics; char[] chars = tctx.chars; g.setFont(tctx.font); do { g.drawChars(chars, 0, chars.length, 40, 40); } while (--numReps >= 0); }
Example 18
Source File: SwingUtilities2.java From Bytecoder with Apache License 2.0 | 4 votes |
public static float drawChars(JComponent c, Graphics g, char[] data, int offset, int length, float x, float y, boolean useFPAPI) { if ( length <= 0 ) { //no need to paint empty strings return x; } float nextX = x + getFontCharsWidth(data, offset, length, getFontMetrics(c, g), useFPAPI); if (isPrinting(g)) { Graphics2D g2d = getGraphics2D(g); if (g2d != null) { FontRenderContext deviceFontRenderContext = g2d. getFontRenderContext(); FontRenderContext frc = getFontRenderContext(c); if (frc != null && !isFontRenderContextPrintCompatible (deviceFontRenderContext, frc)) { String text = new String(data, offset, length); TextLayout layout = new TextLayout(text, g2d.getFont(), deviceFontRenderContext); String trimmedText = trimTrailingSpaces(text); if (!trimmedText.isEmpty()) { float screenWidth = (float)g2d.getFont(). getStringBounds(trimmedText, frc).getWidth(); // If text fits the screenWidth, then do not need to justify if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(), trimmedText) > screenWidth) { layout = layout.getJustifiedLayout(screenWidth); } /* Use alternate print color if specified */ Color col = g2d.getColor(); if (col instanceof PrintColorUIResource) { g2d.setColor(((PrintColorUIResource)col).getPrintColor()); } layout.draw(g2d,x,y); g2d.setColor(col); } return nextX; } } } // Assume we're not printing if we get here, or that we are invoked // via Swing text printing which is laid out for the printer. Object aaHint = (c == null) ? null : c.getClientProperty(KEY_TEXT_ANTIALIASING); if (!(g instanceof Graphics2D)) { g.drawChars(data, offset, length, (int) x, (int) y); return nextX; } Graphics2D g2 = (Graphics2D) g; if (aaHint != null) { Object oldContrast = null; Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING); if (aaHint != null && aaHint != oldAAValue) { g2.setRenderingHint(KEY_TEXT_ANTIALIASING, aaHint); } else { oldAAValue = null; } Object lcdContrastHint = c.getClientProperty(KEY_TEXT_LCD_CONTRAST); if (lcdContrastHint != null) { oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST); if (lcdContrastHint.equals(oldContrast)) { oldContrast = null; } else { g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, lcdContrastHint); } } g2.drawString(new String(data, offset, length), x, y); if (oldAAValue != null) { g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue); } if (oldContrast != null) { g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast); } } else { g2.drawString(new String(data, offset, length), x, y); } return nextX; }
Example 19
Source File: PCheckBox.java From PolyGlot with MIT License | 4 votes |
@Override public void paint(Graphics g) { boolean enabled = this.isEnabled(); Color selected = VisualStyleManager.getCheckBoxSelected(enabled, nightMode); Color backGround = VisualStyleManager.getCheckBoxBG(enabled, nightMode); Color outline = VisualStyleManager.getCheckBoxOutline(enabled, nightMode); Color hover = VisualStyleManager.getCheckBoxHover(enabled, nightMode); Color click = VisualStyleManager.getCheckBoxClicked(enabled, nightMode); Color fieldBack = VisualStyleManager.getCheckBoxFieldBack(enabled, nightMode); int rounding = PGTUtil.CHECKBOX_ROUNDING; int thisHeight = this.getHeight(); if (this.hasFocus()) { g.setColor(selected); g.drawRect(0, 0, this.getWidth() - 1, thisHeight - 1); } ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (enabled) { if (mouseOver) { g.setColor(hover); g.drawRoundRect(3, 3, thisHeight - 6, thisHeight - 6, rounding, rounding); } if (clicked) { backGround = click; } } g.setColor(outline); g.drawRoundRect(4, 4, thisHeight - 8, thisHeight - 8, rounding, rounding); g.setColor(backGround); g.drawRoundRect(5, 5, thisHeight - 10, thisHeight - 10, rounding, rounding); g.setColor(fieldBack); g.fillRect(6, 6, thisHeight - 11, thisHeight - 11); g.setColor(selected); if (this.isSelected()) { g.fillRect(7, 7, thisHeight - 14, thisHeight - 14); } g.setColor(outline); char[] text = getText().toCharArray(); FontMetrics fm = g.getFontMetrics(getFont()); Rectangle2D rec = fm.getStringBounds(getText(), g); int stringH = (int) Math.round(rec.getHeight()); g.drawChars(text, 0, text.length, thisHeight, thisHeight/2 + stringH/3); }
Example 20
Source File: PButton.java From PolyGlot with MIT License | 4 votes |
@Override public void paintComponent(Graphics g) { boolean enabled = isEnabled(); Color bgColor; Color fontColor; final int thisHeight = getHeight(); final int thisWidth = getWidth(); if (!enabled) { bgColor = PGTUtil.COLOR_DISABLED_BG; fontColor = PGTUtil.COLOR_DISABLED_FOREGROUND; } else if (mousePressed && mouseEntered) { bgColor = PGTUtil.COLOR_SELECTED_BG; fontColor = getForeground(); } else { bgColor = PGTUtil.COLOR_ENABLED_BG; fontColor = getForeground(); } if (activeSelected) { g.setColor(Color.black); g.fillRect(0, 0, getWidth(), getHeight()); } // turn on anti-alias mode Graphics2D antiAlias = (Graphics2D) g; antiAlias.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(bgColor); g.fillRect(2, 2, thisWidth - 4, thisHeight - 4); // draw black border on mouseover if button enabled if (mouseEntered && enabled) { g.setColor(PGTUtil.COLOR_MOUSEOVER_BORDER); g.drawRect(1, 1, thisWidth - 3, thisHeight - 3); } g.setColor(fontColor); g.setFont(getFont()); char[] text = getText().toCharArray(); FontMetrics fm = g.getFontMetrics(getFont()); Rectangle2D rec = fm.getStringBounds(getText(), g); int stringW = (int) Math.round(rec.getWidth()); int stringH = (int) Math.round(rec.getHeight()); g.drawChars(text, 0, text.length, (thisWidth/2) - (stringW/2), thisHeight/2 + stringH/4); Icon icon = this.getIcon(); if (icon != null) { icon.paintIcon(this, g, (thisWidth -icon.getIconWidth())/2, (thisHeight - icon.getIconHeight())/2); } }