List of usage examples for java.awt Graphics setFont
public abstract void setFont(Font font);
From source file:com.headswilllol.basiclauncher.Launcher.java
public void paintComponent(Graphics g) { super.paintComponent(g); g.setFont(font); if (updateMsg != null) { g.drawString("Update Available!", centerText(g, "Update Available!"), 50); g.setFont(smallFont);/* w w w.j a va2 s. com*/ g.drawString(updateMsg, centerText(g, updateMsg), 100); } else if (progress == null) g.drawString(NAME + " Launcher", centerText(g, NAME + " Launcher"), 50); else { g.drawString(progress, centerText(g, progress), height / 2); if (fail != null) g.drawString(fail, centerText(g, fail), height / 2 + 50); else { if (aSize != -1 && eSize != -1) { String s = (aSize * 8) + "/" + (int) (eSize * 8) + " B"; if (eSize * 8 >= 1024) if (eSize * 8 >= 1024 * 1024) s = String.format("%.2f", aSize * 8 / 1024 / 1024) + "/" + String.format("%.2f", eSize * 8 / 1024 / 1024) + " MiB"; else s = String.format("%.2f", aSize * 8 / 1024) + "/" + String.format("%.2f", eSize * 8 / 1024) + " KiB"; g.drawString(s, centerText(g, s), height / 2 + 40); String sp = "@" + (int) speed + " B/s"; if (speed >= 1024) if (speed >= 1024 * 1024) sp = "@" + String.format("%.2f", (speed / 1024 / 1024)) + " MiB/s"; else sp = "@" + String.format("%.2f", (speed / 1024)) + " KiB/s"; g.drawString(sp, centerText(g, sp), height / 2 + 80); int barWidth = 500; int barHeight = 35; g.setColor(Color.LIGHT_GRAY); g.drawRect(width / 2 - barWidth / 2, height / 2 + 100, barWidth, barHeight); g.setColor(Color.GREEN); g.fillRect(width / 2 - barWidth / 2 + 1, height / 2 + 100 + 1, (int) ((aSize / eSize) * (double) barWidth - 2), barHeight - 1); g.setColor(new Color(.2f, .2f, .2f)); int percent = (int) (aSize / (double) eSize * 100); g.drawString(percent + "%", centerText(g, percent + "%"), height / 2 + 128); } } } }
From source file:com.tinypace.mobistore.servlet.ValidateCodeServlet.java
private String createCharacter(Graphics g) { char[] codeSeq = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' }; String[] fontTypes = { "\u5b8b\u4f53", "\u65b0\u5b8b\u4f53", "\u9ed1\u4f53", "\u6977\u4f53", "\u96b6\u4e66" }; Random random = new Random(); StringBuilder s = new StringBuilder(); for (int i = 0; i < 4; i++) { String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10)); g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100))); g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)], Font.BOLD, 26)); g.drawString(r, 15 * i + 5, 19 + random.nextInt(8)); s.append(r);/*from w w w . ja v a2 s. c o m*/ } return s.toString(); }
From source file:apm.common.servlet.ValidateCodeServlet.java
private String createCharacter(Graphics g) { char[] codeSeq = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' }; String[] fontTypes = { "\u5b8b\u4f53", "\u65b0\u5b8b\u4f53", "\u9ed1\u4f53", "\u6977\u4f53", "\u96b6\u4e66" }; Random random = new Random(); StringBuilder s = new StringBuilder(); for (int i = 0; i < 4; i++) { String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10)); g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100))); g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)], Font.BOLD, 26)); g.drawString(r, 15 * i + 5, 19 + random.nextInt(8)); // g.drawString(r, i*w/4, h-5); s.append(r);/*from www.j a va2s.c om*/ } return s.toString(); }
From source file:com.aistor.common.servlet.ValidateCodeServlet.java
private String createCharacter(Graphics g) { char[] codeSeq = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; String[] fontTypes = { "\u5b8b\u4f53", "\u65b0\u5b8b\u4f53", "\u9ed1\u4f53", "\u6977\u4f53", "\u96b6\u4e66" }; Random random = new Random(); StringBuilder s = new StringBuilder(); for (int i = 0; i < 4; i++) { String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10)); g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100))); g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)], Font.BOLD, 26)); g.drawString(r, 15 * i + 5, 19 + random.nextInt(8)); // g.drawString(r, i*w/4, h-5); s.append(r);/* w w w . j a va 2 s . co m*/ } return s.toString(); }
From source file:CalIcon.java
/** paintIcon: draw the calendar page. */ public void paintIcon(Component c, Graphics g, int x, int y) { // Allow clock to get painted (voodoo magic) if (showTime) super.paint(g); // Outline it. g.setColor(Color.black);/*from w w w .jav a 2 s . c o m*/ g.draw3DRect(x, y, d.width - 2, d.height - 2, true); // Show the date: First, a white page with a drop shadow. g.setColor(Color.gray); g.fillRect(x + RBX + 3, y + RBY + 3, RBW, RBH); g.setColor(Color.white); g.fillRect(x + RBX, y + RBY, RBW, RBH); // g.setColor(getForeground()); g.setColor(Color.black); String s = days[myCal.get(Calendar.DAY_OF_WEEK) - 1]; g.setFont(dayNameFont); int w = dayNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 10); s = Integer.toString(myCal.get(Calendar.DAY_OF_MONTH)); g.setFont(dayNumbFont); w = dayNumbFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 25); s = mons[myCal.get(Calendar.MONTH)]; g.setFont(monNameFont); w = monNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 35); }
From source file:edu.ku.brc.specify.plugins.imgproc.ImageProcessorPanel.java
@Override public void paint(Graphics g) { ((Graphics2D) g).addRenderingHints(hints); super.paint(g); if (font == null) { font = (new JLabel()).getFont(); font = font.deriveFont(18.0f);// w w w .j av a 2 s. c om font = font.deriveFont(Font.BOLD); } String title = "Specify Image Processor"; g.setColor(new Color(32, 131, 155)); g.setFont(font); int w = g.getFontMetrics().stringWidth(title); int y = g.getFontMetrics().getHeight() - 5; int x = (getSize().width - w) / 2; g.drawString(title, x, y); }
From source file:org.fhaes.fhfilechecker.FrameViewOutput.java
@Override public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { try {/* w w w .j av a 2s. c om*/ // For catching IOException if (pageIndex != rememberedPageIndex) { // First time we've visited this page rememberedPageIndex = pageIndex; // If encountered EOF on previous page, done if (rememberedEOF) { return Printable.NO_SUCH_PAGE; } // Save current position in input file rememberedFilePointer = raf.getFilePointer(); } else { raf.seek(rememberedFilePointer); } g.setColor(Color.black); g.setFont(fnt); int x = (int) pf.getImageableX() + 10; int y = (int) pf.getImageableY() + 12; // Title line g.drawString("File: " + fileName + ", page: " + (pageIndex + 1), x, y); // Generate as many lines as will fit in imageable area y += 36; while (y + 12 < pf.getImageableY() + pf.getImageableHeight()) { String line = raf.readLine(); if (line == null) { rememberedEOF = true; break; } g.drawString(line, x, y); y += 12; } return Printable.PAGE_EXISTS; } catch (Exception e) { return Printable.NO_SUCH_PAGE; } }
From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java
public String generateScale(Dataset dataset, boolean clustColumn) { int W = 0;/* www . j a va 2s. co m*/ if (clustColumn) { W = (Math.min((upperTree.getWidth() + 21), 250)); } else { W = (Math.min((dataset.getColumnIds().length * 12 + 21), 250)); } BufferedImage nfo = new BufferedImage(W, 50, BufferedImage.TYPE_INT_ARGB); Graphics g = nfo.getGraphics(); g.setFont(getTableFont(9)); drawScale(g, new Point(0, 0), W, 30); return this.generateEncodedImg(nfo); }
From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java
public BufferedImage generateHeatMap(Dataset dataset, boolean clustColumn) { colorFactory = new HeatmapColorFactory(); heatMapImg = null;/* ww w . ja v a2s.co m*/ if (clustColumn) { heatMapImg = new BufferedImage((upperTree.getWidth() + squareW), (sideTree.getHeight()), BufferedImage.TYPE_INT_ARGB); } else { heatMapImg = new BufferedImage((dataset.getColumnIds().length * squareW + squareW), (sideTree.getHeight()), BufferedImage.TYPE_INT_ARGB); TopTreeWidth = dataset.getColumnIds().length * squareW + squareW; } Graphics g = heatMapImg.getGraphics(); g.setFont(getTableFont(12)); drawSquares(g, new Point(0, 0), null, dataset, clustColumn); return heatMapImg; }
From source file:org.underworldlabs.swing.plaf.base.AcceleratorToolTipUI.java
public void paint(Graphics g, JComponent c) { UIUtils.antialias(g);//from www. j av a 2s. c o m Font font = c.getFont(); FontMetrics metrics = c.getFontMetrics(font); Dimension size = c.getSize(); if (c.isOpaque()) { g.setColor(c.getBackground()); g.fillRect(0, 0, size.width + 20, size.height); } JToolTip toolTip = (JToolTip) c; String tipText = getTipText(toolTip); if (!MiscUtils.isNull(tipText)) { Insets insets = c.getInsets(); Rectangle paintTextR = new Rectangle(insets.left, insets.top, size.width - (insets.left + insets.right), size.height - (insets.top + insets.bottom)); Color foreground = c.getForeground(); g.setColor(foreground); g.setFont(font); g.drawString(tipText, paintTextR.x + 3, paintTextR.y + metrics.getAscent()); String acceleratorString = getAcceleratorStringForRender(toolTip); if (StringUtils.isNotBlank(acceleratorString)) { Font acceleratorFont = font.deriveFont(font.getSize() - 1f); g.setFont(acceleratorFont); g.setColor(GUIUtils.getSlightlyBrighter(foreground, 2.0f)); g.drawString(acceleratorString, paintTextR.x + 6 + metrics.stringWidth(tipText), paintTextR.y + metrics.getAscent()); } } }