Java Code Examples for java.awt.Font#getSize()
The following examples show how to use
java.awt.Font#getSize() .
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: EPSGraphics.java From opt4j with MIT License | 6 votes |
@Override public void setFont(Font font) { if (font == null) { return; } int size = font.getSize(); boolean bold = font.isBold(); if (bold) { _buffer.append("/Helvetica-Bold findfont\n"); } else { _buffer.append("/Helvetica findfont\n"); } _buffer.append("" + size + " scalefont setfont\n"); _currentFont = font; }
Example 2
Source File: HTMLLabel.java From visualvm with GNU General Public License v2.0 | 5 votes |
public void setText(String value) { txt = value; Font font = getFont(); Color fgColor = getForeground(); Color bgColor = getBackground(); value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N String alignText = null; switch (halign) { case SwingConstants.CENTER: alignText = "center"; //NOI18N break; case SwingConstants.RIGHT: case SwingConstants.TRAILING: alignText = "right"; //NOI18N break; } String bodyFlags = "text=\"" + fgText + "\""; //NOI18N if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N }
Example 3
Source File: InjectedParameterPlaceholderLabel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public InjectedParameterPlaceholderLabel(ConnectionParameterModel param) { super(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); JLabel icon = new JLabel("", INJECTED_ICON, JLabel.LEFT); add(icon, gbc); Font font = icon.getFont(); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); editorPane.setOpaque(false); editorPane.setBorder(null); editorPane.setEditable(false); editorPane.addHyperlinkListener(event -> { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getURL() != null) { RMUrlHandler.openInBrowser(event.getURL()); } }); gbc.insets.left = icon.getIconTextGap(); gbc.weightx = 1; gbc.fill = GridBagConstraints.HORIZONTAL; add(editorPane, gbc); valueProviderChanged = (i, o, n) -> updateText(param); valueProviderParameterChanged = c -> { while (c.next()) { for (ValueProviderParameterModel valueProviderParameterModel : c.getAddedSubList()) { valueProviderParameterModel.valueProperty().removeListener(valueProviderChanged); valueProviderParameterModel.valueProperty().addListener(valueProviderChanged); } } updateText(param); }; param.injectorNameProperty().addListener((i, o, n) -> registerListener(param)); registerListener(param); }
Example 4
Source File: HTMLLabel.java From netbeans with Apache License 2.0 | 5 votes |
public void setText(String value) { txt = value; Font font = getFont(); Color fgColor = getForeground(); Color bgColor = getBackground(); value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N String alignText = null; switch (halign) { case SwingConstants.CENTER: alignText = "center"; //NOI18N break; case SwingConstants.RIGHT: case SwingConstants.TRAILING: alignText = "right"; //NOI18N break; } String bodyFlags = "text=\"" + fgText + "\""; //NOI18N if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N }
Example 5
Source File: OptionsMap.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Converts the value to string using {@link Strings#toString(Object)} * method and then stores it. * There is get methods for values that are a String, an Integer, a Boolean, * a Font, a List of String and a Map of String*String. */ @Override public Object put(Object key, Object value) { if(value instanceof Font){ Font font = (Font)value; String family = font.getFamily(); int size = font.getSize(); boolean italic = font.isItalic(); boolean bold = font.isBold(); value = family + "#" + size + "#" + italic + "#" + bold; } return super.put(key.toString(), Strings.toString(value)); }
Example 6
Source File: NotesPanel.java From osrsclient with GNU General Public License v2.0 | 5 votes |
public void actionPerformed(ActionEvent e){ Font f = notewindow.getFont(); if(f.getSize() < 30){ Font f2 = new Font(f.getFontName(), f.getStyle(), f.getSize() + 2); notewindow.setFont(f2); } }
Example 7
Source File: Utils.java From visualvm with GNU General Public License v2.0 | 5 votes |
static int getDefaultFontSize() { Integer customFontSize = (Integer)UIManager.get("customFontSize"); // NOI18N if (customFontSize != null) { return customFontSize.intValue(); } else { Font systemDefaultFont = UIManager.getFont("TextField.font"); // NOI18N return (systemDefaultFont != null) ? systemDefaultFont.getSize() : 12; } }
Example 8
Source File: OptionType.java From ghidra with Apache License 2.0 | 5 votes |
@Override String objectToString(Object object) { Font font = (Font) object; String fontName = font.getFamily(); int style = font.getStyle(); int size = font.getSize(); StringBuffer buf = new StringBuffer(); buf.append(fontName); buf.append("-"); buf.append(STYLES[style]); buf.append("-"); buf.append(size); return buf.toString(); }
Example 9
Source File: LizzieFrame.java From lizzie with GNU General Public License v3.0 | 5 votes |
private void drawCommandString(Graphics2D g) { if (userAlreadyKnowsAboutCommandString) return; int maxSize = (int) (min(mainPanel.getWidth(), mainPanel.getHeight()) * 0.98); Font font = new Font(Lizzie.config.fontName, Font.PLAIN, (int) (maxSize * 0.03)); String commandString = resourceBundle.getString("LizzieFrame.prompt.showControlsHint"); int strokeRadius = Lizzie.config.showBorder ? 2 : 0; int showCommandsHeight = (int) (font.getSize() * 1.1); int showCommandsWidth = g.getFontMetrics(font).stringWidth(commandString) + 4 * strokeRadius; int showCommandsX = mainPanel.getInsets().left; int showCommandsY = mainPanel.getHeight() - showCommandsHeight - mainPanel.getInsets().bottom; g.setColor(new Color(0, 0, 0, 130)); g.fillRect(showCommandsX, showCommandsY, showCommandsWidth, showCommandsHeight); if (Lizzie.config.showBorder) { g.setStroke(new BasicStroke(2 * strokeRadius)); g.setColor(new Color(0, 0, 0, 60)); g.drawRect( showCommandsX + strokeRadius, showCommandsY + strokeRadius, showCommandsWidth - 2 * strokeRadius, showCommandsHeight - 2 * strokeRadius); } g.setStroke(new BasicStroke(1)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.WHITE); g.setFont(font); g.drawString(commandString, showCommandsX + 2 * strokeRadius, showCommandsY + font.getSize()); }
Example 10
Source File: BaseSectionNodeInnerPanel.java From netbeans with Apache License 2.0 | 5 votes |
private int scaledWidth(int width) { Font f = getFont(); if(f != null) { int fs = f.getSize(); if(fs > 12) { width = width * fs / 12; } } return width; }
Example 11
Source File: JThermometer.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Increases or decreases the tick font size. * * @param delta the change in size. */ public void changeTickFontSize(int delta) { Font f = getTickLabelFont(); String fName = f.getFontName(); Font newFont = new Font(fName, f.getStyle(), (f.getSize() + delta)); setTickLabelFont(newFont); }
Example 12
Source File: PatchedHtmlRenderer.java From netbeans with Apache License 2.0 | 5 votes |
/** * Workaround for Apple bug 3644261 - after using form editor, all boldface * fonts start showing up with incorrect metrics, such that all boldface * fonts in the entire IDE are displayed 12px below where they should be. * Embarrassing and awful. */ private static final Font deriveFont(Font f, int style) { // return f.deriveFont(style); // see #49973 for details. Font result = Utilities.isMac() ? new Font(f.getName(), style, f.getSize()) : f.deriveFont(style); return result; }
Example 13
Source File: Fonts.java From gcs with Mozilla Public License 2.0 | 4 votes |
public Info(Font font) { mName = font.getName(); mStyle = FontStyle.from(font); mSize = font.getSize(); }
Example 14
Source File: TextSettingsPanel.java From Pixelitor with GNU General Public License v3.0 | 4 votes |
private JPanel createFontPanel(TextSettings settings) { JPanel fontPanel = new JPanel(); fontPanel.setBorder(createTitledBorder("Font")); fontPanel.setLayout(new GridBagLayout()); var gbh = new GridBagHelper(fontPanel); int maxFontSize = 1000; Font font = settings.getFont(); int defaultFontSize = font.getSize(); if (maxFontSize < defaultFontSize) { // can get here if the canvas is downsized // after the text layer creation maxFontSize = defaultFontSize; } gbh.addLabel("Font Size:", 0, 0); RangeParam fontSizeParam = new RangeParam("", 1, defaultFontSize, maxFontSize); fontSizeSlider = SliderSpinner.from(fontSizeParam); fontSizeSlider.setName("fontSize"); fontSizeParam.setAdjustmentListener(this); gbh.addLastControl(fontSizeSlider); gbh.addLabel("Font Type:", 0, 1); String[] availableFonts = Utils.getAvailableFontNames(); fontFamilyChooserCB = new JComboBox<>(availableFonts); // it is important to use Font.getName(), and not Font.getFontName(), // otherwise it might not be in the combo box String fontName = font.getName(); fontFamilyChooserCB.setSelectedItem(fontName); fontFamilyChooserCB.addActionListener(this); gbh.addLastControl(fontFamilyChooserCB); boolean defaultBold = font.isBold(); boolean defaultItalic = font.isItalic(); setAttributeMapFromFontSettings(font); gbh.addLabel("Bold:", 0, 2); boldCB = createCheckBox("boldCB", gbh, defaultBold); gbh.addLabel(" Italic:", 2, 2); italicCB = createCheckBox("italicCB", gbh, defaultItalic); JButton showAdvancedSettingsButton = new JButton("Advanced..."); showAdvancedSettingsButton.addActionListener(e -> onAdvancedSettingsClick()); gbh.addLabel(" ", 4, 2); gbh.addControl(showAdvancedSettingsButton); return fontPanel; }
Example 15
Source File: BriefAppDescriptionBuilder.java From raccoon4 with Apache License 2.0 | 4 votes |
@Override protected JPanel assemble() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); JLabel appNameLabel = new JLabel(doc.getTitle(), SwingConstants.CENTER); Font font = appNameLabel.getFont(); Font boldFont = new Font(font.getFontName(), Font.BOLD, font.getSize() + 2); appNameLabel.setFont(boldFont); appNameLabel.setToolTipText(doc.getTitle()); Dimension tmp = appNameLabel.getPreferredSize(); tmp.width = 150; appNameLabel.setPreferredSize(tmp); JLabel vendorNameLabel = new JLabel(doc.getCreator(), SwingConstants.CENTER); tmp = vendorNameLabel.getPreferredSize(); tmp.width = 150; vendorNameLabel.setPreferredSize(tmp); vendorNameLabel.setToolTipText(doc.getCreator()); button = new JButton(); button.addActionListener(this); button.setIcon(SPINNER); globals.get(ImageLoaderService.class).request(this, DocUtil.getAppIconUrl(doc)); JPanel stars = new StarPanel(5, doc.getAggregateRating().getStarRating() / 5); DecimalFormat df = new DecimalFormat("#.## \u2605"); stars.setToolTipText(df.format(doc.getAggregateRating().getStarRating())); gbc.gridx = 0; gbc.gridy = 0; gbc.insets.bottom = 10; panel.add(button, gbc); gbc.insets.bottom = 0; gbc.gridy++; panel.add(appNameLabel, gbc); gbc.gridy++; panel.add(vendorNameLabel, gbc); gbc.gridy++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets.top = 10; gbc.insets.left = 15; gbc.insets.right = 15; gbc.insets.bottom = 15; panel.add(stars, gbc); return panel; }
Example 16
Source File: FontStrikeDesc.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static int getAAHintIntVal(Font2D font2D, Font font, FontRenderContext frc) { Object aa = frc.getAntiAliasingHint(); if (aa == VALUE_TEXT_ANTIALIAS_OFF || aa == VALUE_TEXT_ANTIALIAS_DEFAULT) { return INTVAL_TEXT_ANTIALIAS_OFF; } else if (aa == VALUE_TEXT_ANTIALIAS_ON) { return INTVAL_TEXT_ANTIALIAS_ON; } else if (aa == VALUE_TEXT_ANTIALIAS_GASP) { /* FRC.isIdentity() would have been useful */ int ptSize; AffineTransform tx = frc.getTransform(); if (tx.isIdentity() && !font.isTransformed()) { ptSize = font.getSize(); } else { /* one or both transforms is not identity */ float size = font.getSize2D(); if (tx.isIdentity()) { tx = font.getTransform(); tx.scale(size, size); } else { tx.scale(size, size); if (font.isTransformed()) { tx.concatenate(font.getTransform()); } } double shearx = tx.getShearX(); double scaley = tx.getScaleY(); if (shearx != 0) { scaley = Math.sqrt(shearx * shearx + scaley * scaley); } ptSize = (int)(Math.abs(scaley)+0.5); } if (font2D.useAAForPtSize(ptSize)) { return INTVAL_TEXT_ANTIALIAS_ON; } else { return INTVAL_TEXT_ANTIALIAS_OFF; } } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_HRGB || aa == VALUE_TEXT_ANTIALIAS_LCD_HBGR) { return INTVAL_TEXT_ANTIALIAS_LCD_HRGB; } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_VRGB || aa == VALUE_TEXT_ANTIALIAS_LCD_VBGR) { return INTVAL_TEXT_ANTIALIAS_LCD_VRGB; } else { return INTVAL_TEXT_ANTIALIAS_OFF; } }
Example 17
Source File: WindowsLookAndFeel.java From JDKSourceCode1.8 with MIT License | 4 votes |
protected Object configureValue(Object value) { if (value instanceof Font) { Font font = (Font)value; if ("MS Sans Serif".equals(font.getName())) { int size = font.getSize(); // 4950968: Workaround to mimic the way Windows maps the default // font size of 6 pts to the smallest available bitmap font size. // This happens mostly on Win 98/Me & NT. int dpi; try { dpi = Toolkit.getDefaultToolkit().getScreenResolution(); } catch (HeadlessException ex) { dpi = 96; } if (Math.round(size * 72F / dpi) < 8) { size = Math.round(8 * dpi / 72F); } Font msFont = new FontUIResource("Microsoft Sans Serif", font.getStyle(), size); if (msFont.getName() != null && msFont.getName().equals(msFont.getFamily())) { font = msFont; } else if (size != font.getSize()) { font = new FontUIResource("MS Sans Serif", font.getStyle(), size); } } if (FontUtilities.fontSupportsDefaultEncoding(font)) { if (!(font instanceof UIResource)) { font = new FontUIResource(font); } } else { font = FontUtilities.getCompositeFontUIResource(font); } return font; } return super.configureValue(value); }
Example 18
Source File: IDLExporter.java From ramus with GNU General Public License v3.0 | 4 votes |
private Object toSize(Font font) { double size = font.getSize(); size *= 0.8; return ((int) size) * 10; }
Example 19
Source File: WindowsLookAndFeel.java From hottub with GNU General Public License v2.0 | 4 votes |
protected Object configureValue(Object value) { if (value instanceof Font) { Font font = (Font)value; if ("MS Sans Serif".equals(font.getName())) { int size = font.getSize(); // 4950968: Workaround to mimic the way Windows maps the default // font size of 6 pts to the smallest available bitmap font size. // This happens mostly on Win 98/Me & NT. int dpi; try { dpi = Toolkit.getDefaultToolkit().getScreenResolution(); } catch (HeadlessException ex) { dpi = 96; } if (Math.round(size * 72F / dpi) < 8) { size = Math.round(8 * dpi / 72F); } Font msFont = new FontUIResource("Microsoft Sans Serif", font.getStyle(), size); if (msFont.getName() != null && msFont.getName().equals(msFont.getFamily())) { font = msFont; } else if (size != font.getSize()) { font = new FontUIResource("MS Sans Serif", font.getStyle(), size); } } if (FontUtilities.fontSupportsDefaultEncoding(font)) { if (!(font instanceof UIResource)) { font = new FontUIResource(font); } } else { font = FontUtilities.getCompositeFontUIResource(font); } return font; } return super.configureValue(value); }
Example 20
Source File: FontGlyphReader.java From jts with GNU Lesser General Public License v2.1 | 2 votes |
/** * Converts text rendered in the given {@link Font} to a {@link Geometry} * using a standard flatness factor. * * @param text the text to render * @param font the font to render with * @param geomFact the geometryFactory to use to create the result * @return a polygonal geometry representing the rendered text */ public static Geometry read(String text, Font font, GeometryFactory geomFact) { double flatness = font.getSize() / FLATNESS_FACTOR; return read(text, font, flatness, geomFact); }