List of usage examples for java.awt Font getStyle
public int getStyle()
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Present the user with a font selection dialog and update the widgets if * the user chooses a font./*from w w w.ja v a2 s. c o m*/ */ private void configureFont() { FontChooser chooser; Font newFont; Color newColor; chooser = new FontChooser(this); chooser.setFont(getFontFromProperties()); chooser.setColor(getColorFromProperties()); LOGGER.debug("Font before choices: " + chooser.getNewFont()); chooser.setVisible(true); newFont = chooser.getNewFont(); newColor = chooser.getNewColor(); // Values will be null if user canceled request if (newFont != null && newColor != null) { properties.setProperty(ConfigurationProperty.FONT_NAME.key(), newFont.getName()); properties.setProperty(ConfigurationProperty.FONT_SIZE.key(), newFont.getSize() + ""); properties.setProperty(ConfigurationProperty.FONT_STYLE.key(), newFont.getStyle() + ""); properties.setProperty(ConfigurationProperty.FONT_COLOR.key(), newColor.getRGB() + ""); LOGGER.debug("Font after choices: " + newFont); setFont(newFont, newColor); } }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
/** * Renders this image/*from w ww . j a v a2 s . c o m*/ * * @return The image data */ private final byte[] render() throws IOException { Graphics2D gfx = (Graphics2D) this.image.getGraphics(); if (config.isFontAntialiasing()) gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int curWidth = config.getTextMarginLeft(); FontRenderContext ctx = new FontRenderContext(null, config.isFontAntialiasing(), false); for (int i = 0; i < charAttsList.size(); i++) { CharAttributes cf = (CharAttributes) charAttsList.get(i); TextLayout text = new TextLayout(cf.getChar() + "", getFont(cf.getName()), ctx); //gfx.getFontRenderContext()); AffineTransform textAt = new AffineTransform(); textAt.translate(curWidth, this.height - cf.getRise()); if (cf.getRotation() != 0) { textAt.rotate(cf.getRotation()); } if (cf.getShearX() > 0.0) textAt.shear(cf.getShearX(), cf.getShearY()); Shape shape = text.getOutline(textAt); curWidth += shape.getBounds().getWidth() + config.getTextSpacing(); if (config.isUseImageBackground()) gfx.setColor(Color.BLACK); else gfx.setXORMode(Color.BLACK); gfx.fill(shape); } if (config.isEffectsNoise()) { noiseEffects(gfx, image); } if (config.isUseTimestamp()) { if (config.isEffectsNoise()) gfx.setColor(Color.WHITE); else gfx.setColor(Color.BLACK); TimeZone tz = TimeZone.getTimeZone(config.getTimestampTZ()); Calendar cal = new GregorianCalendar(tz); SimpleDateFormat formatter; if (config.isUseTimestamp24hr()) formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z"); else formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a, z"); formatter.setTimeZone(tz); Font font = gfx.getFont(); Font newFont = new Font(font.getName(), font.getStyle(), config.getTimestampFontSize()); gfx.setFont(newFont); gfx.drawString(formatter.format(cal.getTime()), config.getTextMarginLeft() * 4, this.height - 1); } return toImageData(image); }
From source file:org.eclipse.wb.internal.swing.model.property.editor.font.DerivedFontInfo.java
public DerivedFontInfo(Font baseFont, String baseFontSource, String baseFontClipboardSource, String newFamily, Boolean newBold, Boolean newItalic, Integer deltaSize, Integer newSize) { m_baseFont = baseFont;//from www .j ava 2 s . c o m m_baseFontSource = baseFontSource; m_baseFontClipboardSource = baseFontClipboardSource; m_newFamily = newFamily; m_newBold = newBold; m_newItalic = newItalic; m_deltaSize = deltaSize; m_newSize = newSize; // create derived Font { String family = newFamily != null ? newFamily : baseFont.getFamily(); // style int style = baseFont.getStyle(); if (newBold != null) { if (newBold.booleanValue()) { style |= Font.BOLD; } else { style &= ~Font.BOLD; } } if (newItalic != null) { if (newItalic.booleanValue()) { style |= Font.ITALIC; } else { style &= ~Font.ITALIC; } } // size int size = baseFont.getSize(); if (deltaSize != null) { size += deltaSize.intValue(); } else if (newSize != null) { size = newSize.intValue(); } // create derived Font m_font = new Font(family, style, size); } }
From source file:org.eclipse.wb.tests.designer.swing.model.property.FontPropertyEditorTest.java
/** * Test for {@link DerivedFontInfo}.//from ww w . jav a 2 s.co m */ public void test_FontInfo_Derived() throws Exception { Font baseFont = new Font("Arial", Font.BOLD, 12); String baseFontSource = "button.getFont()"; String baseFontClipboardSource = "%this%.getFont()"; // no changes { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null, null, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("<no changes>, Arial 12 Bold", fontInfo.getText()); assertNull(fontInfo.getSource()); assertNull(fontInfo.getClipboardSource()); } // new family { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, "Tahoma", null, null, null, null); { Font font = fontInfo.getFont(); assertEquals("Tahoma", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("*Tahoma, Tahoma 12 Bold", fontInfo.getText()); assertEquals("new java.awt.Font(\"Tahoma\", button.getFont().getStyle(), button.getFont().getSize())", fontInfo.getSource()); assertEquals("new java.awt.Font(\"Tahoma\", %this%.getFont().getStyle(), %this%.getFont().getSize())", fontInfo.getClipboardSource()); } // new family +5 { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, "Tahoma", null, null, new Integer(5), null); { Font font = fontInfo.getFont(); assertEquals("Tahoma", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(17, font.getSize()); } assertEquals("*Tahoma +5, Tahoma 17 Bold", fontInfo.getText()); assertEquals( "new java.awt.Font(\"Tahoma\", button.getFont().getStyle(), button.getFont().getSize() + 5)", fontInfo.getSource()); assertEquals( "new java.awt.Font(\"Tahoma\", %this%.getFont().getStyle(), %this%.getFont().getSize() + 5)", fontInfo.getClipboardSource()); } // new family =20 { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, "Tahoma", null, null, null, new Integer(20)); { Font font = fontInfo.getFont(); assertEquals("Tahoma", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(20, font.getSize()); } assertEquals("*Tahoma 20, Tahoma 20 Bold", fontInfo.getText()); assertEquals("new java.awt.Font(\"Tahoma\", button.getFont().getStyle(), 20)", fontInfo.getSource()); } // +Bold { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, Boolean.TRUE, null, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("+Bold, Arial 12 Bold", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getStyle() | java.awt.Font.BOLD)", fontInfo.getSource()); } // -Bold { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, Boolean.FALSE, null, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.PLAIN, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("-Bold, Arial 12", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD)", fontInfo.getSource()); } // +Italic { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null, Boolean.TRUE, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD | Font.ITALIC, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("+Italic, Arial 12 Bold Italic", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getStyle() | java.awt.Font.ITALIC)", fontInfo.getSource()); } // -Italic { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null, Boolean.FALSE, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("-Italic, Arial 12 Bold", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.ITALIC)", fontInfo.getSource()); } // +Bold +Italic { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, Boolean.TRUE, Boolean.TRUE, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD | Font.ITALIC, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("+Bold +Italic, Arial 12 Bold Italic", fontInfo.getText()); assertEquals( "button.getFont().deriveFont(button.getFont().getStyle() | java.awt.Font.BOLD | java.awt.Font.ITALIC)", fontInfo.getSource()); } // -Bold +Italic { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, Boolean.FALSE, Boolean.TRUE, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.ITALIC, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("-Bold +Italic, Arial 12 Italic", fontInfo.getText()); assertEquals( "button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD | java.awt.Font.ITALIC)", fontInfo.getSource()); } // +Bold -Italic { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, Boolean.TRUE, Boolean.FALSE, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("+Bold -Italic, Arial 12 Bold", fontInfo.getText()); assertEquals( "button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.ITALIC | java.awt.Font.BOLD)", fontInfo.getSource()); } // -Bold -Italic { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, Boolean.FALSE, Boolean.FALSE, null, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.PLAIN, font.getStyle()); assertEquals(12, font.getSize()); } assertEquals("-Bold -Italic, Arial 12", fontInfo.getText()); assertEquals( "button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD & ~java.awt.Font.ITALIC)", fontInfo.getSource()); } // +5 { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null, null, +5, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(12 + 5, font.getSize()); } assertEquals("+5, Arial 17 Bold", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getSize() + 5f)", fontInfo.getSource()); } // -5 { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null, null, -5, null); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(12 - 5, font.getSize()); } assertEquals("-5, Arial 7 Bold", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getSize() - 5f)", fontInfo.getSource()); } // =20 { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null, null, null, 20); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(20, font.getSize()); } assertEquals("20, Arial 20 Bold", fontInfo.getText()); assertEquals("button.getFont().deriveFont(20f)", fontInfo.getSource()); } // -Bold =20 { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, Boolean.FALSE, null, null, 20); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.PLAIN, font.getStyle()); assertEquals(20, font.getSize()); } assertEquals("20 -Bold, Arial 20", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD, 20f)", fontInfo.getSource()); } // -Italic =20 { FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null, Boolean.FALSE, null, 20); { Font font = fontInfo.getFont(); assertEquals("Arial", font.getFamily()); assertEquals(Font.BOLD, font.getStyle()); assertEquals(20, font.getSize()); } assertEquals("20 -Italic, Arial 20 Bold", fontInfo.getText()); assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.ITALIC, 20f)", fontInfo.getSource()); } }
From source file:org.ecoinformatics.seek.ecogrid.EcogridPreferencesTab.java
private void initButtonPanel() { // remember default button font final Font defaultUIMgrButtonFont = (Font) UIManager.get("Button.font"); // now set our custom size, provided it's smaller than the default: int buttonFontSize = (defaultUIMgrButtonFont.getSize() < BUTTON_FONT_SIZE) ? defaultUIMgrButtonFont.getSize() : BUTTON_FONT_SIZE;// w w w . j ava2 s.c o m final Font BUTTON_FONT = new Font(defaultUIMgrButtonFont.getFontName(), defaultUIMgrButtonFont.getStyle(), buttonFontSize); UIManager.put("Button.font", BUTTON_FONT); refreshButton = new JButton(new ServicesRefreshAction( StaticResources.getDisplayString("preferences.data.refresh", "Refresh"), this)); refreshButton.setMinimumSize(EcogridPreferencesTab.BUTTONDIMENSION); refreshButton.setPreferredSize(EcogridPreferencesTab.BUTTONDIMENSION); refreshButton.setSize(EcogridPreferencesTab.BUTTONDIMENSION); // setMaximumSize was truncating label on osX. I don't know why. // It seems about the same as how SearchUIJPanel does things. -derik //refreshButton.setMaximumSize(EcogridPreferencesTab.BUTTONDIMENSION); keepExistingCheckbox = new JCheckBox( StaticResources.getDisplayString("preferences.data.keepExistingSources", "Keep existing sources")); keepExistingCheckbox.setSelected(false); JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS)); bottomPanel.add(refreshButton); bottomPanel.add(keepExistingCheckbox); newButtonPanel = new JPanel(); newButtonPanel.setLayout(new BorderLayout()); newButtonPanel.add(Box.createVerticalStrut(EcogridPreferencesTab.MARGINGSIZE), BorderLayout.NORTH); newButtonPanel.add(bottomPanel, BorderLayout.SOUTH); setButtonPanel(newButtonPanel); // restore default button font if (defaultUIMgrButtonFont != null) { UIManager.put("Button.font", defaultUIMgrButtonFont); } }
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. jav a 2 s . co m * @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:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java
public void setSelectedFont(Font selectedFont) { this.selectedFont = selectedFont; fontNameTextLabel.setText(selectedFont.getFamily()); fontSizeTextLabel.setText("" + selectedFont.getSize()); setFontStyleText(selectedFont.getStyle()); invalidate();/*from ww w . j a va 2 s.c o m*/ validate(); repaint(); }
From source file:org.notebook.gui.widget.LookAndFeelSelector.java
private static void fixFontBug() { int sizeOffset = 0; Enumeration keys = UIManager.getLookAndFeelDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof Font) { Font oldFont = (Font) value; // logger.info(oldFont.getName()); Font newFont = new Font("Dialog", oldFont.getStyle(), oldFont.getSize() + sizeOffset); UIManager.put(key, newFont); }/*from ww w. jav a 2 s .co m*/ } }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.ImportDialog.java
/** * Builds and lays out the component displaying the options for the * metadata.//from w w w . j av a 2s . c om * * @return See above. */ private JXTaskPane buildMetadataComponent() { JXTaskPane pane = new JXTaskPane(); Font font = pane.getFont(); pane.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2)); pane.setCollapsed(true); pane.setTitle(TEXT_METADATA_DEFAULTS); pane.add(buildPixelSizeComponent()); return pane; }
From source file:org.openmicroscopy.shoola.agents.fsimporter.util.FileImportComponent.java
/** Initializes the components. */ private void initComponents() { actionMenuButton = new JButton(); actionMenuButton.setVisible(false);//from ww w. j a v a 2s. c o m actionMenuButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { JPopupMenu popup = createActionMenu(); popup.show(actionMenuButton, 0, actionMenuButton.getHeight()); } }); adapter = new MouseAdapter() { /** * Views the image. * @see MouseListener#mousePressed(MouseEvent) */ public void mousePressed(MouseEvent e) { if (e.getClickCount() == 1) { launchFullViewer(); } } }; setLayout(new FlowLayout(FlowLayout.LEFT)); busyLabel = new JXBusyLabel(SIZE); busyLabel.setVisible(false); busyLabel.setBusy(false); cancelButton = new JButton("Cancel"); cancelButton.setForeground(UIUtilities.HYPERLINK_COLOR); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { cancelLoading(); } }); cancelButton.setVisible(true); namePane = new JPanel(); namePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); IconManager icons = IconManager.getInstance(); Icon icon; if (getFile().isFile()) icon = icons.getIcon(IconManager.IMAGE); else icon = icons.getIcon(IconManager.DIRECTORY); imageLabel = new ThumbnailLabel(icon); imageLabel.addPropertyChangeListener(this); imageLabels = new ArrayList<ThumbnailLabel>(); ThumbnailLabel label; for (int i = 0; i < MAX_THUMBNAILS; i++) { label = new ThumbnailLabel(); if (i == MAX_THUMBNAILS - 1) { Font f = label.getFont(); label.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2)); } label.setVisible(false); label.addPropertyChangeListener(this); imageLabels.add(label); } fileNameLabel = new JLabel(getFile().getName()); namePane.add(imageLabel); Iterator<ThumbnailLabel> j = imageLabels.iterator(); while (j.hasNext()) { namePane.add(j.next()); } namePane.add(Box.createHorizontalStrut(4)); namePane.add(fileNameLabel); namePane.add(Box.createHorizontalStrut(10)); resultLabel = new JLabel(); statusLabel = new StatusLabel(importable.getFile()); statusLabel.addPropertyChangeListener(this); image = null; refButton = cancelButton; refLabel = busyLabel; }