List of usage examples for java.awt Font getName
public String getName()
From source file:org.kalypso.commons.java.util.StringUtilities.java
/** * Converts a font to a string. Format is defined in {@link StringUtilities#stringToFont(String)} * /*from w w w. j a va 2s . c om*/ * @param f * @throws IllegalArgumentException * if f is null */ public static String fontToString(final Font f) { if (f == null) throw new IllegalArgumentException( Messages.getString("org.kalypso.commons.java.util.StringUtilities.5")); //$NON-NLS-1$ final StringBuffer buf = new StringBuffer(); buf.append(f.getName()).append(";").append(f.getStyle()).append(";").append(f.getSize()); //$NON-NLS-1$ //$NON-NLS-2$ return buf.toString(); }
From source file:Main.java
public void paint(Graphics g) { Font f = g.getFont(); String fontName = f.getName(); String fontFamily = f.getFamily(); int fontSize = f.getSize(); int fontStyle = f.getStyle(); String msg = "Family: " + fontName; msg += ", Font: " + fontFamily; msg += ", Size: " + fontSize + ", Style: "; if ((fontStyle & Font.BOLD) == Font.BOLD) msg += "Bold "; if ((fontStyle & Font.ITALIC) == Font.ITALIC) msg += "Italic "; if ((fontStyle & Font.PLAIN) == Font.PLAIN) msg += "Plain "; g.drawString(msg, 4, 16);//from w w w .j av a 2 s. c o m }
From source file:util.ui.UiUtilities.java
/** * Creates a Html EditorPane that holds a HTML-Help Text. * * Add a Listener if you want to have clickable Links * * @param html/*from w w w .ja v a 2 s . com*/ * HTML-Text to display * @param listener * Link-Listener for this HelpText * @param background The color for the background. * @return EditorPane that holds a Help Text * @since 2.7.2 */ public static JEditorPane createHtmlHelpTextArea(String html, HyperlinkListener listener, Color background) { // Quick "hack". Remove HTML-Code and replace it with Code that includes the // correct Font if (html.indexOf("<html>") >= 0) { html = StringUtils.substringBetween(html, "<html>", "</html>"); } JLabel label = new JLabel(); Font font = label.getFont(); html = "<html><div style=\"color:" + UiUtilities.getHTMLColorCode(label.getForeground()) + ";font-family:" + font.getName() + "; font-size:" + font.getSize() + ";background-color:rgb(" + background.getRed() + "," + background.getGreen() + "," + background.getBlue() + ");\">" + html + "</div></html>"; final JEditorPane pane = new JEditorPane("text/html", html); pane.setBorder(BorderFactory.createEmptyBorder()); pane.setEditable(false); pane.setFont(font); pane.setOpaque(false); pane.setFocusable(false); if (listener != null) { pane.addHyperlinkListener(listener); } return pane; }
From source file:org.bitstrings.maven.plugins.splasher.DrawingContext.java
public Font getFont(String name, int style, int size) { Font font = getResource(name, Font.class); return new Font((font == null ? name : font.getName()), style, size); }
From source file:net.sourceforge.atunes.kernel.modules.state.FontBean.java
/** * @param font//from ww w .j av a 2 s . com */ public FontBean(final Font font) { this.name = font.getName(); this.style = font.getStyle(); this.size = font.getSize(); }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithPieChart.java
public void setLabelFontSize(int labelFontSize) { Font labelFont = ((PiePlot) getPlot()).getLabelFont(); Font newFont = new Font(labelFont.getName(), labelFont.getStyle(), labelFontSize); ((PiePlot) getPlot()).setLabelFont(newFont); }
From source file:net.sf.jasperreports.customizers.marker.CategoryMarkerCustomizer.java
protected CategoryMarker createMarker(JRChart jrc) { Comparable<?> value = getProperty(PROPERTY_CATEGORY); if (value == null) { return null; }//from w w w. ja v a2s . c om CategoryMarker marker = new CategoryMarker(value); configureMarker(marker); configureStroke(marker); Boolean drawAsLine = getBooleanProperty(PROPERTY_DRAW_AS_LINE); if (drawAsLine != null) { marker.setDrawAsLine(drawAsLine); } //Setup the font Font font = marker.getLabelFont(); String fontName = getProperty(PROPERTY_FONT_NAME); if (fontName == null) { fontName = font.getName(); } Float fontSize = getFloatProperty(PROPERTY_FONT_SIZE); if (fontSize == null) { fontSize = Float.valueOf(font.getSize()); } int fontStyle = Font.PLAIN; Boolean isBold = getBooleanProperty(PROPERTY_FONT_BOLD); if (isBold != null) { fontStyle = fontStyle | Font.BOLD; } Boolean isItalic = getBooleanProperty(PROPERTY_FONT_ITALIC); if (isItalic != null) { fontStyle = fontStyle | Font.ITALIC; } marker.setLabelFont(FontUtil.getInstance(filler.getJasperReportsContext()).getAwtFontFromBundles(fontName, fontStyle, fontSize, filler.getFillContext().getMasterLocale(), true)); return marker; }
From source file:com.codedx.burp.security.InvalidCertificateDialogStrategy.java
@Override public CertificateAcceptance checkAcceptance(Certificate genericCert, CertificateException certError) { if (genericCert instanceof X509Certificate && defaultHostVerifier instanceof DefaultHostnameVerifier) { X509Certificate cert = (X509Certificate) genericCert; DefaultHostnameVerifier verifier = (DefaultHostnameVerifier) defaultHostVerifier; JPanel message = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = 2;/*from w ww . ja v a 2 s. co m*/ gbc.insets = new Insets(0, 0, 10, 0); gbc.anchor = GridBagConstraints.WEST; message.add( new JLabel("Unable to establish a secure connection because the certificate is not trusted"), gbc); gbc = new GridBagConstraints(); gbc.gridy = 2; gbc.insets = new Insets(2, 0, 2, 0); gbc.anchor = GridBagConstraints.WEST; JLabel issuer = new JLabel("Issuer: "); Font defaultFont = issuer.getFont(); Font bold = new Font(defaultFont.getName(), Font.BOLD, defaultFont.getSize()); issuer.setFont(bold); message.add(issuer, gbc); gbc.gridx = 1; message.add(new JLabel(cert.getIssuerDN().toString()), gbc); try { JLabel fingerprint = new JLabel("Thumbprint: "); fingerprint.setFont(bold); gbc.gridx = 0; gbc.gridy += 1; message.add(fingerprint, gbc); gbc.gridx = 1; message.add(new JLabel(toHexString(getSHA1(cert.getEncoded()), " ")), gbc); } catch (CertificateEncodingException e) { // this shouldn't actually ever happen } try { verifier.verify(host, cert); } catch (SSLException e) { String cn = getCN(cert); JLabel mismatch = new JLabel("Host Mismatch: "); mismatch.setFont(bold); gbc.gridx = 0; gbc.gridy += 1; message.add(mismatch, gbc); String msg; if (cn != null) { msg = String.format("Expected '%s', but the certificate is for '%s'.", host, cn); } else { msg = e.getMessage(); } gbc.gridx = 1; message.add(new JLabel(msg), gbc); } // Open the dialog, and return its result int choice = JOptionPane.showOptionDialog(burpExtender.getUiComponent(), message, dialogTitle, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, dialogButtons, null); switch (choice) { case (0): return CertificateAcceptance.REJECT; case (1): return CertificateAcceptance.ACCEPT_TEMPORARILY; case (2): return CertificateAcceptance.ACCEPT_PERMANENTLY; } } return CertificateAcceptance.REJECT; }
From source file:org.geoserver.wms.WMSLifecycleHandler.java
List<Font> loadFontsFromDataDirectory() { List<Font> result = new ArrayList<Font>(); try {//from w w w . ja v a 2 s . c om Collection<File> files = FileUtils.listFiles(data.findStyleDir(), new String[] { "ttf", "TTF" }, true); for (File file : files) { try { final Font font = Font.createFont(Font.TRUETYPE_FONT, file); result.add(font); LOGGER.log(Level.INFO, "Loaded font file " + file + ", loaded font '" + font.getName() + "' in family '" + font.getFamily() + "'"); } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to load font file " + file, e); } } } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to scan style directory for fonts", e); } return result; }
From source file:piramide.interaction.reasoner.FuzzyReasonerWizardFacade.java
private BufferedImage createErrorMessagesImage(String text) { final Font font = TextTitle.DEFAULT_FONT; final Font bigBold = new Font(font.getName(), Font.BOLD, 24); final FontRenderContext frc = new FontRenderContext(null, true, false); final TextLayout layout = new TextLayout(text, bigBold, frc); final Rectangle2D bounds = layout.getBounds(); final int w = (int) Math.ceil(bounds.getWidth()); final int h = (int) Math.ceil(bounds.getHeight()); final BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final Graphics2D g = image.createGraphics(); g.setColor(Color.WHITE);//from w w w. j a v a2 s. c om g.fillRect(0, 0, w, h); g.setColor(Color.RED); g.setFont(bigBold); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g.drawString(text, (float) -bounds.getX(), (float) -bounds.getY()); g.dispose(); return image; }