Java Code Examples for java.awt.Font#MONOSPACED
The following examples show how to use
java.awt.Font#MONOSPACED .
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: SortPanel.java From SortingAlgorithmAnimations with MIT License | 6 votes |
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); //draw border g.setColor(Color.WHITE); g.drawRect(BORDER_WIDTH, BORDER_WIDTH, getWidth() - 2 * BORDER_WIDTH, getHeight() - 2 * BORDER_WIDTH); //draw title Font nameFont = new Font(Font.MONOSPACED, Font.BOLD, 18); FontMetrics nameFontMetrix = getFontMetrics(nameFont); g.setColor(Color.BLACK); g.fillRect((getWidth() - nameFontMetrix.stringWidth(name)) / 2, 0, nameFontMetrix.stringWidth(name), BORDER_WIDTH + nameFontMetrix.getAscent() / 3); g.setColor(Color.WHITE); g.setFont(nameFont); g.drawString(name, (getWidth() - nameFontMetrix.stringWidth(name)) / 2, BORDER_WIDTH + nameFontMetrix.getAscent() / 3); }
Example 2
Source File: GuiHelper.java From binnavi with Apache License 2.0 | 5 votes |
public static String getMonospaceFont() { final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); final Font[] allfonts = env.getAllFonts(); for (final Font font : allfonts) { if (font.getName().equals("Courier New")) { return "Courier New"; } } return Font.MONOSPACED; }
Example 3
Source File: Demo5.java From jexer with MIT License | 4 votes |
/** * Run two demo applications in separate panes. */ private void addApplications() { /* * In this demo we will create two swing panels with two * independently running applications, each with a different font * size. */ /* * First we create a panel to put it on. We need this to pass to * SwingBackend's constructor, so that it knows not to create a new * frame. */ JPanel app1Panel = new JPanel(); /* * Next, we create the Swing backend. The "listener" (second * argument, set to null) is what the backend wakes up on every event * received. Typically this is the TApplication. TApplication sets * it in its constructor, so we can pass null here and be fine. */ SwingBackend app1Backend = new SwingBackend(app1Panel, null, 80, 25, 16); // Now that we have the backend, construct the TApplication. app1 = new DemoApplication(app1Backend); /* * The second panel is the same sequence, except that we also change * the font from the default Terminus to JVM monospaced. */ JPanel app2Panel = new JPanel(); SwingBackend app2Backend = new SwingBackend(app2Panel, null, 80, 25, 18); app2 = new DemoApplication(app2Backend); Font font = new Font(Font.MONOSPACED, Font.PLAIN, 18); app2Backend.setFont(font); /* * Now that the applications are ready, spin them off on their * threads. */ (new Thread(app1)).start(); (new Thread(app2)).start(); /* * The rest of this is standard Swing. Set up a frame, a split pane, * put each of the panels on it, and make it visible. */ JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(this); JSplitPane mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, app1Panel, app2Panel); mainPane.setOneTouchExpandable(true); mainPane.setDividerLocation(500); mainPane.setDividerSize(6); mainPane.setBorder(null); frame.setContentPane(mainPane); frame.setTitle("Two Jexer Apps In One Swing UI"); frame.setSize(1000, 640); frame.setVisible(true); }
Example 4
Source File: SunFontManager.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Get a list of installed fonts in the requested {@link Locale}. * The list contains the fonts Family Names. * If Locale is null, the default locale is used. * * @param requestedLocale, if null the default locale is used. * @return list of installed fonts in the system. */ public String[] getInstalledFontFamilyNames(Locale requestedLocale) { if (requestedLocale == null) { requestedLocale = Locale.getDefault(); } if (allFamilies != null && lastDefaultLocale != null && requestedLocale.equals(lastDefaultLocale)) { String[] copyFamilies = new String[allFamilies.length]; System.arraycopy(allFamilies, 0, copyFamilies, 0, allFamilies.length); return copyFamilies; } TreeMap<String,String> familyNames = new TreeMap<String,String>(); // these names are always there and aren't localised String str; str = Font.SERIF; familyNames.put(str.toLowerCase(), str); str = Font.SANS_SERIF; familyNames.put(str.toLowerCase(), str); str = Font.MONOSPACED; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG_INPUT; familyNames.put(str.toLowerCase(), str); /* Platform APIs may be used to get the set of available family * names for the current default locale so long as it is the same * as the start-up system locale, rather than loading all fonts. */ if (requestedLocale.equals(getSystemStartupLocale()) && getFamilyNamesFromPlatform(familyNames, requestedLocale)) { /* Augment platform names with JRE font family names */ getJREFontFamilyNames(familyNames, requestedLocale); } else { loadFontFiles(); Font2D[] physicalfonts = getPhysicalFonts(); for (int i=0; i < physicalfonts.length; i++) { if (!(physicalfonts[i] instanceof NativeFont)) { String name = physicalfonts[i].getFamilyName(requestedLocale); familyNames.put(name.toLowerCase(requestedLocale), name); } } } // Add any native font family names here addNativeFontFamilyNames(familyNames, requestedLocale); String[] retval = new String[familyNames.size()]; Object [] keyNames = familyNames.keySet().toArray(); for (int i=0; i < keyNames.length; i++) { retval[i] = familyNames.get(keyNames[i]); } if (requestedLocale.equals(Locale.getDefault())) { lastDefaultLocale = requestedLocale; allFamilies = new String[retval.length]; System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length); } return retval; }
Example 5
Source File: CSS.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscript or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 6
Source File: SunFontManager.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Get a list of installed fonts in the requested {@link Locale}. * The list contains the fonts Family Names. * If Locale is null, the default locale is used. * * @param requestedLocale, if null the default locale is used. * @return list of installed fonts in the system. */ public String[] getInstalledFontFamilyNames(Locale requestedLocale) { if (requestedLocale == null) { requestedLocale = Locale.getDefault(); } if (allFamilies != null && lastDefaultLocale != null && requestedLocale.equals(lastDefaultLocale)) { String[] copyFamilies = new String[allFamilies.length]; System.arraycopy(allFamilies, 0, copyFamilies, 0, allFamilies.length); return copyFamilies; } TreeMap<String,String> familyNames = new TreeMap<String,String>(); // these names are always there and aren't localised String str; str = Font.SERIF; familyNames.put(str.toLowerCase(), str); str = Font.SANS_SERIF; familyNames.put(str.toLowerCase(), str); str = Font.MONOSPACED; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG_INPUT; familyNames.put(str.toLowerCase(), str); /* Platform APIs may be used to get the set of available family * names for the current default locale so long as it is the same * as the start-up system locale, rather than loading all fonts. */ if (requestedLocale.equals(getSystemStartupLocale()) && getFamilyNamesFromPlatform(familyNames, requestedLocale)) { /* Augment platform names with JRE font family names */ getJREFontFamilyNames(familyNames, requestedLocale); } else { loadFontFiles(); Font2D[] physicalfonts = getPhysicalFonts(); for (int i=0; i < physicalfonts.length; i++) { if (!(physicalfonts[i] instanceof NativeFont)) { String name = physicalfonts[i].getFamilyName(requestedLocale); familyNames.put(name.toLowerCase(requestedLocale), name); } } } // Add any native font family names here addNativeFontFamilyNames(familyNames, requestedLocale); String[] retval = new String[familyNames.size()]; Object [] keyNames = familyNames.keySet().toArray(); for (int i=0; i < keyNames.length; i++) { retval[i] = familyNames.get(keyNames[i]); } if (requestedLocale.equals(Locale.getDefault())) { lastDefaultLocale = requestedLocale; allFamilies = new String[retval.length]; System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length); } return retval; }
Example 7
Source File: CSS.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscirpt or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 8
Source File: SunFontManager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Get a list of installed fonts in the requested {@link Locale}. * The list contains the fonts Family Names. * If Locale is null, the default locale is used. * * @param requestedLocale, if null the default locale is used. * @return list of installed fonts in the system. */ public String[] getInstalledFontFamilyNames(Locale requestedLocale) { if (requestedLocale == null) { requestedLocale = Locale.getDefault(); } if (allFamilies != null && lastDefaultLocale != null && requestedLocale.equals(lastDefaultLocale)) { String[] copyFamilies = new String[allFamilies.length]; System.arraycopy(allFamilies, 0, copyFamilies, 0, allFamilies.length); return copyFamilies; } TreeMap<String,String> familyNames = new TreeMap<String,String>(); // these names are always there and aren't localised String str; str = Font.SERIF; familyNames.put(str.toLowerCase(), str); str = Font.SANS_SERIF; familyNames.put(str.toLowerCase(), str); str = Font.MONOSPACED; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG_INPUT; familyNames.put(str.toLowerCase(), str); /* Platform APIs may be used to get the set of available family * names for the current default locale so long as it is the same * as the start-up system locale, rather than loading all fonts. */ if (requestedLocale.equals(getSystemStartupLocale()) && getFamilyNamesFromPlatform(familyNames, requestedLocale)) { /* Augment platform names with JRE font family names */ getJREFontFamilyNames(familyNames, requestedLocale); } else { loadFontFiles(); Font2D[] physicalfonts = getPhysicalFonts(); for (int i=0; i < physicalfonts.length; i++) { if (!(physicalfonts[i] instanceof NativeFont)) { String name = physicalfonts[i].getFamilyName(requestedLocale); familyNames.put(name.toLowerCase(requestedLocale), name); } } } // Add any native font family names here addNativeFontFamilyNames(familyNames, requestedLocale); String[] retval = new String[familyNames.size()]; Object [] keyNames = familyNames.keySet().toArray(); for (int i=0; i < keyNames.length; i++) { retval[i] = (String)familyNames.get(keyNames[i]); } if (requestedLocale.equals(Locale.getDefault())) { lastDefaultLocale = requestedLocale; allFamilies = new String[retval.length]; System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length); } return retval; }
Example 9
Source File: HtmlPrintContainer.java From netbeans with Apache License 2.0 | 4 votes |
private String createStyle (String element, String selector, Font font, Color fg, Color bg, boolean useDefaults) { StringBuffer sb = new StringBuffer(); if (element != null) { sb.append (element); sb.append (WS); } if (selector != null) { sb.append (DOT); sb.append (selector); sb.append (WS); } sb.append (ST_BEGIN); boolean first = true; if ((!useDefaults || !fg.equals(getDefaultColor())) && fg != null) { sb.append (ST_COLOR); sb.append (getHtmlColor(fg)); first = false; } if ((!useDefaults || !bg.equals (getDefaultBackgroundColor())) && bg != null) { if (!first) { sb.append (ST_SEPARATOR); } sb.append (ST_BGCOLOR); sb.append (getHtmlColor(bg)); first = false; } if ((!useDefaults || !font.equals (getDefaultFont())) && font != null) { if (!first) { sb.append (ST_SEPARATOR); } sb.append (ST_FONT_FAMILY); switch(font.getFamily()) { case Font.MONOSPACED: sb.append (FF_MONOSPACE); break; case Font.SERIF: sb.append (FF_SERIF); break; case Font.SANS_SERIF: sb.append (FF_SANSSERIF); break; case Font.DIALOG: sb.append (FF_SANSSERIF); break; case Font.DIALOG_INPUT: sb.append (FF_MONOSPACE); break; default: sb.append (font.getFamily()); //TODO: Locale should go here } if (font.isBold()) { sb.append (ST_SEPARATOR); sb.append (ST_BOLD); } if (font.isItalic()) { sb.append (ST_SEPARATOR); sb.append (ST_ITALIC); } Font df = getDefaultFont(); if (df != null && df.getSize() != font.getSize()) { sb.append (ST_SEPARATOR); sb.append (ST_SIZE); sb.append (String.valueOf(font.getSize())); } } sb.append (ST_END); return sb.toString(); }
Example 10
Source File: CSS.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscirpt or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 11
Source File: SunFontManager.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Get a list of installed fonts in the requested {@link Locale}. * The list contains the fonts Family Names. * If Locale is null, the default locale is used. * * @param requestedLocale, if null the default locale is used. * @return list of installed fonts in the system. */ public String[] getInstalledFontFamilyNames(Locale requestedLocale) { if (requestedLocale == null) { requestedLocale = Locale.getDefault(); } if (allFamilies != null && lastDefaultLocale != null && requestedLocale.equals(lastDefaultLocale)) { String[] copyFamilies = new String[allFamilies.length]; System.arraycopy(allFamilies, 0, copyFamilies, 0, allFamilies.length); return copyFamilies; } TreeMap<String,String> familyNames = new TreeMap<String,String>(); // these names are always there and aren't localised String str; str = Font.SERIF; familyNames.put(str.toLowerCase(), str); str = Font.SANS_SERIF; familyNames.put(str.toLowerCase(), str); str = Font.MONOSPACED; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG_INPUT; familyNames.put(str.toLowerCase(), str); /* Platform APIs may be used to get the set of available family * names for the current default locale so long as it is the same * as the start-up system locale, rather than loading all fonts. */ if (requestedLocale.equals(getSystemStartupLocale()) && getFamilyNamesFromPlatform(familyNames, requestedLocale)) { /* Augment platform names with JRE font family names */ getJREFontFamilyNames(familyNames, requestedLocale); } else { loadFontFiles(); Font2D[] physicalfonts = getPhysicalFonts(); for (int i=0; i < physicalfonts.length; i++) { if (!(physicalfonts[i] instanceof NativeFont)) { String name = physicalfonts[i].getFamilyName(requestedLocale); familyNames.put(name.toLowerCase(requestedLocale), name); } } } // Add any native font family names here addNativeFontFamilyNames(familyNames, requestedLocale); String[] retval = new String[familyNames.size()]; Object [] keyNames = familyNames.keySet().toArray(); for (int i=0; i < keyNames.length; i++) { retval[i] = (String)familyNames.get(keyNames[i]); } if (requestedLocale.equals(Locale.getDefault())) { lastDefaultLocale = requestedLocale; allFamilies = new String[retval.length]; System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length); } return retval; }
Example 12
Source File: CSS.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscirpt or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 13
Source File: SunFontManager.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Get a list of installed fonts in the requested {@link Locale}. * The list contains the fonts Family Names. * If Locale is null, the default locale is used. * * @param requestedLocale, if null the default locale is used. * @return list of installed fonts in the system. */ public String[] getInstalledFontFamilyNames(Locale requestedLocale) { if (requestedLocale == null) { requestedLocale = Locale.getDefault(); } if (allFamilies != null && lastDefaultLocale != null && requestedLocale.equals(lastDefaultLocale)) { String[] copyFamilies = new String[allFamilies.length]; System.arraycopy(allFamilies, 0, copyFamilies, 0, allFamilies.length); return copyFamilies; } TreeMap<String,String> familyNames = new TreeMap<String,String>(); // these names are always there and aren't localised String str; str = Font.SERIF; familyNames.put(str.toLowerCase(), str); str = Font.SANS_SERIF; familyNames.put(str.toLowerCase(), str); str = Font.MONOSPACED; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG_INPUT; familyNames.put(str.toLowerCase(), str); /* Platform APIs may be used to get the set of available family * names for the current default locale so long as it is the same * as the start-up system locale, rather than loading all fonts. */ if (requestedLocale.equals(getSystemStartupLocale()) && getFamilyNamesFromPlatform(familyNames, requestedLocale)) { /* Augment platform names with JRE font family names */ getJREFontFamilyNames(familyNames, requestedLocale); } else { loadFontFiles(); Font2D[] physicalfonts = getPhysicalFonts(); for (int i=0; i < physicalfonts.length; i++) { if (!(physicalfonts[i] instanceof NativeFont)) { String name = physicalfonts[i].getFamilyName(requestedLocale); familyNames.put(name.toLowerCase(requestedLocale), name); } } } // Add any native font family names here addNativeFontFamilyNames(familyNames, requestedLocale); String[] retval = new String[familyNames.size()]; Object [] keyNames = familyNames.keySet().toArray(); for (int i=0; i < keyNames.length; i++) { retval[i] = (String)familyNames.get(keyNames[i]); } if (requestedLocale.equals(Locale.getDefault())) { lastDefaultLocale = requestedLocale; allFamilies = new String[retval.length]; System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length); } return retval; }
Example 14
Source File: Renderer.java From gpx-animator with Apache License 2.0 | 4 votes |
public void render(final RenderingContext rc) throws UserException { final List<Long[]> spanList = new ArrayList<>(); final TreeMap<Long, Point2D> wpMap = new TreeMap<>(); parseGPX(spanList, wpMap); final boolean userSpecifiedWidth = cfg.getWidth() != null; final int width = userSpecifiedWidth ? cfg.getWidth() : 800; final Integer zoom = calculateZoomFactor(rc, width); final double scale = calculateScaleFactor(width, zoom); minX -= cfg.getMargin() / scale; maxX += cfg.getMargin() / scale; minY -= cfg.getMargin() / scale; maxY += cfg.getMargin() / scale; if (userSpecifiedWidth) { final double ww = width - (maxX - minX) * scale; minX -= ww / scale / 2.0; maxX += ww / scale / 2.0; } if (cfg.getHeight() != null) { final double hh = cfg.getHeight() - (maxY - minY) * scale; minY -= hh / scale / 2.0; maxY += hh / scale / 2.0; } timePointMapListList.forEach((timePointMapList) -> timePointMapList .forEach((timePointMap) -> translateCoordinatesToZeroZero(scale, timePointMap))); translateCoordinatesToZeroZero(scale, wpMap); final String frameFilePattern = cfg.getOutput().toString(); //noinspection MagicCharacter final int dot = frameFilePattern.lastIndexOf('.'); final String ext = dot == -1 ? null : frameFilePattern.substring(dot + 1).toLowerCase(Locale.getDefault()); final boolean toImages = ext != null && (isEqual("png", ext) || isEqual("jpg", ext)); //NON-NLS final int realWidth = calculateRealWidth(userSpecifiedWidth, scale, toImages); final int realHeight = calculateRealHeight(scale, toImages); LOGGER.info("{}x{};{}", realWidth, realHeight, scale); final FrameWriter frameWriter = toImages ? new FileFrameWriter(frameFilePattern, ext, cfg.getFps()) : new VideoFrameWriter(cfg.getOutput(), cfg.getFps(), realWidth, realHeight); final BufferedImage bi = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_3BYTE_BGR); final Graphics2D ga = (Graphics2D) bi.getGraphics(); drawBackground(rc, zoom, bi, ga); if (cfg.getFontSize() > 0) { font = new Font(Font.MONOSPACED, Font.PLAIN, cfg.getFontSize()); // TODO https://github.com/zdila/gpx-animator/issues/154 fontMetrics = ga.getFontMetrics(font); } speedup = cfg.getTotalTime() == null ? cfg.getSpeedup() : 1.0 * (maxTime - minTime) / cfg.getTotalTime(); final int frames = (int) ((maxTime + cfg.getTailDuration() - minTime) * cfg.getFps() / (MS * speedup)); final Photos photos = new Photos(cfg.getPhotoDirectory()); float skip = -1f; for (int frame = 1; frame < frames; frame++) { if (rc.isCancelled1()) { return; } final Long time = getTime(frame); skip: if (cfg.isSkipIdle()) { for (final Long[] span : spanList) { if (span[0] <= time && span[1] >= time) { break skip; } } rc.setProgress1((int) (100.0 * frame / frames), String.format(resourceBundle.getString("renderer.progress.unusedframes"), frame, (frames - 1))); skip = 1f; continue; } final int pct = (int) (100.0 * frame / frames); rc.setProgress1(pct, String.format(resourceBundle.getString("renderer.progress.frame"), frame, (frames - 1))); paint(bi, frame, 0, null); final BufferedImage bi2 = Utils.deepCopy(bi); paint(bi2, frame, cfg.getTailDuration(), cfg.getTailColor()); drawWaypoints(bi2, frame, wpMap); final Point2D marker = drawMarker(bi2, frame); if (font != null) { drawInfo(bi2, frame, marker); drawAttribution(bi2, cfg.getAttribution()); } skip = renderFlashback(skip, bi2); frameWriter.addFrame(bi2); photos.render(time, cfg, bi2, frameWriter, rc, pct); } keepLastFrame(rc, frameWriter, bi, frames); frameWriter.close(); LOGGER.info("Done."); }
Example 15
Source File: CSS.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscirpt or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 16
Source File: CSS.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscirpt or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 17
Source File: SunFontManager.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Get a list of installed fonts in the requested {@link Locale}. * The list contains the fonts Family Names. * If Locale is null, the default locale is used. * * @param requestedLocale, if null the default locale is used. * @return list of installed fonts in the system. */ public String[] getInstalledFontFamilyNames(Locale requestedLocale) { if (requestedLocale == null) { requestedLocale = Locale.getDefault(); } if (allFamilies != null && lastDefaultLocale != null && requestedLocale.equals(lastDefaultLocale)) { String[] copyFamilies = new String[allFamilies.length]; System.arraycopy(allFamilies, 0, copyFamilies, 0, allFamilies.length); return copyFamilies; } TreeMap<String,String> familyNames = new TreeMap<String,String>(); // these names are always there and aren't localised String str; str = Font.SERIF; familyNames.put(str.toLowerCase(), str); str = Font.SANS_SERIF; familyNames.put(str.toLowerCase(), str); str = Font.MONOSPACED; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG_INPUT; familyNames.put(str.toLowerCase(), str); /* Platform APIs may be used to get the set of available family * names for the current default locale so long as it is the same * as the start-up system locale, rather than loading all fonts. */ if (requestedLocale.equals(getSystemStartupLocale()) && getFamilyNamesFromPlatform(familyNames, requestedLocale)) { /* Augment platform names with JRE font family names */ getJREFontFamilyNames(familyNames, requestedLocale); } else { loadFontFiles(); Font2D[] physicalfonts = getPhysicalFonts(); for (int i=0; i < physicalfonts.length; i++) { if (!(physicalfonts[i] instanceof NativeFont)) { String name = physicalfonts[i].getFamilyName(requestedLocale); familyNames.put(name.toLowerCase(requestedLocale), name); } } } // Add any native font family names here addNativeFontFamilyNames(familyNames, requestedLocale); String[] retval = new String[familyNames.size()]; Object [] keyNames = familyNames.keySet().toArray(); for (int i=0; i < keyNames.length; i++) { retval[i] = (String)familyNames.get(keyNames[i]); } if (requestedLocale.equals(Locale.getDefault())) { lastDefaultLocale = requestedLocale; allFamilies = new String[retval.length]; System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length); } return retval; }
Example 18
Source File: CSS.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscirpt or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 19
Source File: CSS.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns the font for the values in the passed in AttributeSet. * It is assumed the keys will be CSS.Attribute keys. * <code>sc</code> is the StyleContext that will be messaged to get * the font once the size, name and style have been determined. */ Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) { ss = getStyleSheet(ss); int size = getFontSize(a, defaultSize, ss); /* * If the vertical alignment is set to either superscirpt or * subscript we reduce the font size by 2 points. */ StringValue vAlignV = (StringValue)a.getAttribute (CSS.Attribute.VERTICAL_ALIGN); if ((vAlignV != null)) { String vAlign = vAlignV.toString(); if ((vAlign.indexOf("sup") >= 0) || (vAlign.indexOf("sub") >= 0)) { size -= 2; } } FontFamily familyValue = (FontFamily)a.getAttribute (CSS.Attribute.FONT_FAMILY); String family = (familyValue != null) ? familyValue.getValue() : Font.SANS_SERIF; int style = Font.PLAIN; FontWeight weightValue = (FontWeight) a.getAttribute (CSS.Attribute.FONT_WEIGHT); if ((weightValue != null) && (weightValue.getValue() > 400)) { style |= Font.BOLD; } Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE); if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) { style |= Font.ITALIC; } if (family.equalsIgnoreCase("monospace")) { family = Font.MONOSPACED; } Font f = sc.getFont(family, style, size); if (f == null || (f.getFamily().equals(Font.DIALOG) && ! family.equalsIgnoreCase(Font.DIALOG))) { family = Font.SANS_SERIF; f = sc.getFont(family, style, size); } return f; }
Example 20
Source File: RevokedCertsTableCellRend.java From portecle with GNU General Public License v2.0 | 2 votes |
/** * Creates a new revoked certificates table cell renderer. * * @param table Parent table */ public RevokedCertsTableCellRend(JTable table) { monospace = new Font(Font.MONOSPACED, Font.PLAIN, table.getFont().getSize()); }