List of usage examples for java.awt Graphics setFont
public abstract void setFont(Font font);
From source file:com.jcraft.weirdx.DDXWindowImp.java
public final Graphics getGraphics(GC gc, int mask) { if (!isVisible()) { return null; }/* ww w.ja v a 2 s. c o m*/ if (offg == null) allocImage(); Graphics graphics = offg; if ((mask & GC.GCSubwindowMode) != 0 && (gc.attr & GC.IncludeInferiors) != 0) { graphics = getGraphics(); window.currentGC = null; } else { if (gc == window.currentGC && gc.time == window.gctime && (mask & ~window.gmask) == 0) { //System.out.println("DDXWindow skip"); return graphics; } window.gctime = gc.time; window.currentGC = gc; window.gmask = mask; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec != null) { graphics = offg; } if (rec == null || (rec.x == 0 && rec.y == 0 && rec.width == window.width && rec.height == window.height)) { // return graphics; } else { graphics.setClip(rec.x, rec.y, rec.width, rec.height); } } if ((mask & GC.GCFunction) != 0) { Color color = window.getColormap().getColor(gc.fgPixel); if (gc.function == GC.GXxor) { window.gmask &= ~GC.GCFunction; graphics.setXORMode(new Color((color.getRGB() ^ graphics.getColor().getRGB()) & 0xffffff)); } else if (gc.function == GC.GXinvert) { window.gmask &= ~GC.GCFunction; graphics.setXORMode(window.screen.defaultColormap.getColor(window.background.pixel)); } else { graphics.setColor(color); } } if ((mask & GC.GCFont) != 0) { XFont font = gc.font; graphics.setFont(font.getFont()); } if ((mask & GC.GCLineWidth) != 0 || (mask & GC.GCLineStyle) != 0 || (mask & GC.GCCapStyle) != 0 || (mask & GC.GCJoinStyle) != 0) { } return graphics; }
From source file:com.jcraft.weirdx.XPixmap.java
Graphics getGraphics(GC gc, int mask) { Graphics graphics = imgg; if (gc == currentGC && gc.time == gctime && (mask & ~gmask) == 0) { return graphics; }//from www.j a v a 2s . c om gctime = gc.time; currentGC = gc; gmask = mask; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { return graphics; } graphics.setClip(rec.x, rec.y, rec.width, rec.height); } if ((mask & GC.GCFunction) != 0) { Color color = getColormap().getColor(gc.fgPixel); if (gc.function == GC.GXxor) { gmask &= ~GC.GCFunction; graphics.setXORMode(new Color((color.getRGB() ^ graphics.getColor().getRGB()) & 0xffffff)); } else if (gc.function == GC.GXinvert) { //System.out.println("Pimxpa: GXinvert"); } else { graphics.setColor(color); } } if ((mask & GC.GCFont) != 0) { XFont font = gc.font; graphics.setFont(font.getFont()); } if ((mask & GC.GCLineWidth) != 0 || (mask & GC.GCLineStyle) != 0 || (mask & GC.GCCapStyle) != 0 || (mask & GC.GCJoinStyle) != 0) { } return graphics; }
From source file:com.cburch.logisim.gui.start.AboutCredits.java
@Override protected void paintComponent(Graphics g) { FontMetrics[] fms = new FontMetrics[font.length]; for (int i = 0; i < fms.length; i++) { fms[i] = g.getFontMetrics(font[i]); }/*from ww w .ja v a2s . com*/ if (linesHeight == 0) { int y = 0; int index = -1; for (CreditsLine line : lines) { index++; if (index == initialLines) initialHeight = y; if (line.type == 0) y += 10; FontMetrics fm = fms[line.type]; line.y = y + fm.getAscent(); y += fm.getHeight(); } linesHeight = y; } Paint[] paint = paintSteady; int yPos = 0; int height = getHeight(); int initY = Math.min(0, initialHeight - height + About.IMAGE_BORDER); int maxY = linesHeight - height - initY; int totalMillis = 2 * MILLIS_FREEZE + (linesHeight + height) * MILLIS_PER_PIXEL; int offs = scroll % totalMillis; if (offs >= 0 && offs < MILLIS_FREEZE) { // frozen before starting the credits scroll int a = 255 * (MILLIS_FREEZE - offs) / MILLIS_FREEZE; if (a > 245) { paint = null; } else if (a < 15) { paint = paintSteady; } else { paint = new Paint[colorBase.length]; for (int i = 0; i < paint.length; i++) { Color hue = colorBase[i]; paint[i] = new GradientPaint(0.0f, 0.0f, derive(hue, a), 0.0f, fadeStop, hue); } } yPos = initY; } else if (offs < MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) { // scrolling through credits yPos = initY + (offs - MILLIS_FREEZE) / MILLIS_PER_PIXEL; } else if (offs < 2 * MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) { // freezing at bottom of scroll yPos = initY + maxY; } else if (offs < 2 * MILLIS_FREEZE + (linesHeight - initY) * MILLIS_PER_PIXEL) { // scrolling bottom off screen yPos = initY + (offs - 2 * MILLIS_FREEZE) / MILLIS_PER_PIXEL; } else { // scrolling next credits onto screen int millis = offs - 2 * MILLIS_FREEZE - (linesHeight - initY) * MILLIS_PER_PIXEL; paint = null; yPos = -height + millis / MILLIS_PER_PIXEL; } int width = getWidth(); int centerX = width / 2; maxY = getHeight(); for (CreditsLine line : lines) { int y = line.y - yPos; if (y < -100 || y > maxY + 50) continue; int type = line.type; if (paint == null) { g.setColor(colorBase[type]); } else { ((Graphics2D) g).setPaint(paint[type]); } g.setFont(font[type]); int textWidth = fms[type].stringWidth(line.text); g.drawString(line.text, centerX - textWidth / 2, line.y - yPos); Image img = line.img; if (img != null) { int x = width - line.imgWidth - About.IMAGE_BORDER; int top = y - fms[type].getAscent(); g.drawImage(img, x, top, this); } } }
From source file:forge.toolbox.FSkin.java
public static void setGraphicsFont(final Graphics g, final SkinFont skinFont) { g.setFont(skinFont.font); }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Set the font on the graphics from the font defined on the node. * * @param g The graphics//from ww w . ja va 2s . com * @param node Node to get font info from */ private void setFont(Graphics g, Element node) { int fontSize = applyMacros(node, ATTR_FONTSIZE, 12); Font f = new Font(applyMacros(node, ATTR_FONTFACE, "dialog"), Font.PLAIN, fontSize); g.setFont(f); }
From source file:lu.fisch.unimozer.Diagram.java
private void printHeaderFooter(Graphics g, PageFormat pageFormat, int page, String className) { int origPage = page + 1; // Add header g.setColor(Color.BLACK);// w ww . j a v a2s.co m int xOffset = (int) pageFormat.getImageableX(); int topOffset = (int) pageFormat.getImageableY() + 20; int bottom = (int) (pageFormat.getImageableY() + pageFormat.getImageableHeight()); // header line g.drawLine(xOffset, topOffset - 8, xOffset + (int) pageFormat.getImageableWidth(), topOffset - 8); // footer line g.drawLine(xOffset, bottom - 11, xOffset + (int) pageFormat.getImageableWidth(), bottom - 11); g.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 10)); Graphics2D gg = (Graphics2D) g; String pageString = "Page " + origPage; int tw = (int) gg.getFont().getStringBounds(pageString, gg.getFontRenderContext()).getWidth(); // footer text g.drawString(pageString, xOffset + (int) pageFormat.getImageableWidth() - tw, bottom - 2); //System.err.println("Printing: "+directoryName); if (directoryName != null) { g.setFont(new Font(g.getFont().getFontName(), Font.ITALIC, 10)); String filename = directoryName; if (!className.equals("")) filename += System.getProperty("file.separator") + className + ".java"; // header text g.drawString(filename, xOffset, bottom - 2); File f = new File(filename); //System.err.println("Printing: "+filename); if (f.exists()) { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); java.util.Date date = new java.util.Date(); date.setTime(f.lastModified()); String myDate = dateFormat.format(date); int w = (int) gg.getFont().getStringBounds(myDate, gg.getFontRenderContext()).getWidth(); // header text g.drawString("File last modified on " + myDate, xOffset, topOffset - 10); } } }
From source file:com.lfv.lanzius.server.WorkspaceView.java
@Override protected void paintComponent(Graphics g) { int w = getWidth(); int h = getHeight(); Document doc = server.getDocument(); Color storedCol = g.getColor(); Font storedFont = g.getFont(); // Fill workspace area g.setColor(getBackground());/*w w w. j a v a 2s. c o m*/ g.fillRect(0, 0, w, h); // Should the cached version be updated? int updateDocumentVersion = server.getDocumentVersion(); boolean update = (documentVersion != updateDocumentVersion); // Check if we have cached the latest document version, otherwise cache the terminals if (update) { log.debug("Updating view to version " + updateDocumentVersion); terminalMap.clear(); groupList.clear(); if (doc != null) { synchronized (doc) { // Clear the visible attribute on all groups // except the started or paused ones Element egd = doc.getRootElement().getChild("GroupDefs"); Iterator iter = egd.getChildren().iterator(); while (iter.hasNext()) { Element eg = (Element) iter.next(); boolean isVisible = !DomTools.getAttributeString(eg, "state", "stopped", false) .equals("stopped"); eg.setAttribute("visible", String.valueOf(isVisible)); } // Gather information about terminals and cache it Element etd = doc.getRootElement().getChild("TerminalDefs"); iter = etd.getChildren().iterator(); while (iter.hasNext()) { Element et = (Element) iter.next(); int tid = DomTools.getAttributeInt(et, "id", 0, false); if (tid > 0) { // Create terminal and add it to list Terminal t = new Terminal(tid, DomTools.getAttributeInt(et, "x", 0, false), DomTools.getAttributeInt(et, "y", 0, false), DomTools.getChildText(et, "Name", "T/" + tid, false), DomTools.getAttributeBoolean(et, "online", false, false), DomTools.getAttributeBoolean(et, "selected", false, false)); terminalMap.put(tid, t); // Is the terminal monitored? t.isMonitored = DomTools.getAttributeBoolean(et, "monitored", false, false); // Examine the Player element under PlayerSetup t.groupColor = null; Element ep = DomTools.getElementFromSection(doc, "PlayerSetup", "terminalid", String.valueOf(tid)); // Has linked player for this terminal if (ep != null) { StringBuffer sb = new StringBuffer(); // Append player name sb.append(DomTools.getChildText(ep, "Name", "P/?", true)); sb.append(" ("); // Append role list boolean hasRoles = false; Element ers = ep.getChild("RoleSetup"); if (ers != null) { Iterator iterr = ers.getChildren().iterator(); while (iterr.hasNext()) { Element er = (Element) iterr.next(); String id = er.getAttributeValue("id"); er = DomTools.getElementFromSection(doc, "RoleDefs", "id", id); if (er != null) { sb.append(DomTools.getChildText(er, "Name", "R/" + id, false)); sb.append(", "); hasRoles = true; } } if (hasRoles) { // Trim last comma int len = sb.length(); sb.setLength(Math.max(len - 2, 0)); } sb.append(")"); } t.roles = sb.toString(); // Is the player relocated? t.isRelocated = DomTools.getAttributeBoolean(ep, "relocated", false, false); // Get group name and color Element eg = DomTools.getElementFromSection(doc, "GroupDefs", "id", DomTools.getAttributeString(ep, "groupid", "0", true)); t.groupColor = Color.lightGray; if (eg != null) { String sc = DomTools.getChildText(eg, "Color", null, false); if (sc != null) { try { t.groupColor = Color.decode(sc); } catch (NumberFormatException ex) { log.warn("Invalid color attribute on Group node, defaulting to grey"); } } //t.name += " "+DomTools.getChildText(eg, "Name", "G/"+eg.getAttributeValue("id"), false); t.groupName = DomTools.getChildText(eg, "Name", "G/" + eg.getAttributeValue("id"), false); // This group should now be visible eg.setAttribute("visible", "true"); } else log.warn("Invalid groupid attribute on Player node, defaulting to grey"); } } else log.error("Invalid id attribute on Terminal node, skipping"); } // Gather information about groups and cache it iter = egd.getChildren().iterator(); while (iter.hasNext()) { Element eg = (Element) iter.next(); if (DomTools.getAttributeBoolean(eg, "visible", false, false)) { int gid = DomTools.getAttributeInt(eg, "id", 0, true); if (gid > 0) { Group grp = new Group(gid, DomTools.getChildText(eg, "Name", "G/" + gid, false), DomTools.getAttributeBoolean(eg, "selected", false, false)); groupList.add(grp); // group color String sc = DomTools.getChildText(eg, "Color", null, false); if (sc != null) { try { grp.color = Color.decode(sc); } catch (NumberFormatException ex) { log.warn("Invalid color attribute on Group node, defaulting to grey"); } } // state color grp.stateColor = Color.red; String state = DomTools.getAttributeString(eg, "state", "stopped", false); if (state.equals("started")) grp.stateColor = Color.green; else if (state.equals("paused")) grp.stateColor = Color.orange; } } } } } } if (doc == null) { g.setColor(Color.black); String text = "No configuration loaded. Select 'Load configuration...' from the file menu."; g.drawString(text, (w - SwingUtilities.computeStringWidth(g.getFontMetrics(), text)) / 2, h * 5 / 12); } else { g.setFont(new Font("Dialog", Font.BOLD, 13)); Iterator<Terminal> itert = terminalMap.values().iterator(); while (itert.hasNext()) { Terminal t = itert.next(); // Draw box int b = t.isSelected ? SERVERVIEW_SELECTION_BORDER : 1; g.setColor(Color.black); g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER - b, t.y + SERVERVIEW_SELECTION_BORDER - b, SERVERVIEW_TERMINAL_WIDTH + 2 * b, SERVERVIEW_TERMINAL_HEIGHT + 2 * b); g.setColor(t.groupColor == null ? Color.white : t.groupColor); g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER, t.y + SERVERVIEW_SELECTION_BORDER, SERVERVIEW_TERMINAL_WIDTH, SERVERVIEW_TERMINAL_HEIGHT); // Inner areas Rectangle r = new Rectangle(t.x + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER, t.y + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER, SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER, g.getFontMetrics().getHeight() + 4); g.setColor(Color.white); g.fillRect(r.x, r.y, r.width, r.height); g.fillRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width, SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2); g.setColor(Color.black); g.drawRect(r.x, r.y, r.width, r.height); g.drawRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width, SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2); // Name of terminal and group if (server.isaClient(t.tid)) { g.drawImage(indicatorIsa.getImage(), r.x + r.width - 20, r.y + SERVERVIEW_TERMINAL_HEIGHT - 26, null); } g.drawString(t.name + " " + t.groupName, r.x + 4, r.y + r.height - 4); double px = r.x + 4; double py = r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 5; // Draw monitored indicator if (t.isMonitored) { g.drawImage(indicatorMonitored.getImage(), r.x + r.width - 9, r.y + 3, null); } // Draw relocated indicator if (t.isRelocated) { g.drawImage(indicatorRelocated.getImage(), r.x + r.width - 9, r.y + 13, null); } // Draw online indicator r.setBounds(r.x, r.y + r.height, r.width, 3); g.setColor(t.isOnline ? Color.green : Color.red); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(Color.black); g.drawRect(r.x, r.y, r.width, r.height); // Roles if (t.roles.length() > 0) { LineBreakMeasurer lbm = new LineBreakMeasurer(new AttributedString(t.roles).getIterator(), new FontRenderContext(null, false, true)); TextLayout layout; while ((layout = lbm .nextLayout(SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER)) != null) { if (py < t.y + SERVERVIEW_TERMINAL_HEIGHT) { py += layout.getAscent(); layout.draw((Graphics2D) g, (int) px, (int) py); py += layout.getDescent() + layout.getLeading(); } } } } // Draw group indicators int nbrGroupsInRow = w / (2 * Constants.SERVERVIEW_SELECTION_BORDER + 2 + Constants.SERVERVIEW_GROUP_WIDTH); if (nbrGroupsInRow < 1) nbrGroupsInRow = 1; int nbrGroupRows = (groupList.size() + nbrGroupsInRow - 1) / nbrGroupsInRow; int innerWidth = Constants.SERVERVIEW_GROUP_WIDTH; int innerHeight = g.getFontMetrics().getHeight() + 5; int outerWidth = innerWidth + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2; int outerHeight = innerHeight + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2; int x = 0; int y = h - outerHeight * nbrGroupRows; g.setColor(Color.white); g.fillRect(0, y, w, h - y); g.setColor(Color.black); g.drawLine(0, y - 1, w - 1, y - 1); Iterator<Group> iterg = groupList.iterator(); while (iterg.hasNext()) { Group grp = iterg.next(); // Group box grp.boundingRect.setBounds(x, y, outerWidth, outerHeight); int b = grp.isSelected ? Constants.SERVERVIEW_SELECTION_BORDER : 1; g.setColor(Color.black); g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER - b + 1, y + Constants.SERVERVIEW_SELECTION_BORDER - b + 1, innerWidth + 2 * b, innerHeight + 2 * b); g.setColor(grp.color); g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1, y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, innerHeight); g.setColor(Color.black); g.drawString(grp.name, x + Constants.SERVERVIEW_SELECTION_BORDER + 4, y + Constants.SERVERVIEW_SELECTION_BORDER + innerHeight - 4 + 1); // Draw started indicator g.setColor(grp.stateColor); g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1, y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, 2); g.setColor(Color.black); g.drawLine(x + Constants.SERVERVIEW_SELECTION_BORDER + 1, y + Constants.SERVERVIEW_SELECTION_BORDER + 3, x + Constants.SERVERVIEW_SELECTION_BORDER + 1 + innerWidth, y + Constants.SERVERVIEW_SELECTION_BORDER + 3); x += outerWidth; if ((x + outerWidth) > w) { x = 0; y += outerHeight; } } } // Store cached version documentVersion = updateDocumentVersion; g.setColor(storedCol); g.setFont(storedFont); }