Java Code Examples for java.awt.Font

The following are top voted examples for showing how to use java.awt.Font. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: Font2D.java   View source code 6 votes vote down vote up
protected void setStyle() {

        String fName = fullName.toLowerCase();

        for (int i=0; i < boldItalicNames.length; i++) {
            if (fName.indexOf(boldItalicNames[i]) != -1) {
                style = Font.BOLD|Font.ITALIC;
                return;
            }
        }

        for (int i=0; i < italicNames.length; i++) {
            if (fName.indexOf(italicNames[i]) != -1) {
                style = Font.ITALIC;
                return;
            }
        }

        for (int i=0; i < boldNames.length; i++) {
            if (fName.indexOf(boldNames[i]) != -1 ) {
                style = Font.BOLD;
                return;
            }
        }
    }
 
Example 2
Project: incubator-netbeans   File: SvnOptionsPanel.java   View source code 6 votes vote down vote up
/** Creates new form SvnOptionsPanel */
public SvnOptionsPanel() {
    initComponents();
    if(Utilities.isWindows()) {
        jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.windows.text"));
        jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.text"));
    } else {
        jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.unix.text"));
        jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.unix.text"));
    }
    Document doc = textPaneClient.getDocument();
    if (doc instanceof HTMLDocument) { // Issue 185505
        HTMLDocument htmlDoc = (HTMLDocument)doc;
        Font font = UIManager.getFont("Label.font"); // NOI18N
        String bodyRule = "body { font-family: " + font.getFamily() + "; " // NOI18N
            + "color: " + SvnUtils.getColorString(textPaneClient.getForeground()) + "; " //NOI18N
            + "font-size: " + font.getSize() + "pt; }"; // NOI18N
        htmlDoc.getStyleSheet().addRule(bodyRule);
    }
    textPaneClient.setOpaque(false);
    textPaneClient.setBackground(new Color(0,0,0,0)); // windows and nimbus workaround see issue 145826
}
 
Example 3
Project: OpenJSharp   File: TextLayout.java   View source code 6 votes vote down vote up
/**
 * Constructs a <code>TextLayout</code> from an iterator over styled text.
 * <p>
 * The iterator must specify a single paragraph of text because an
 * entire paragraph is required for the bidirectional
 * algorithm.
 * @param text the styled text to display
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(AttributedCharacterIterator text, FontRenderContext frc) {

    if (text == null) {
        throw new IllegalArgumentException("Null iterator passed to TextLayout constructor.");
    }

    int start = text.getBeginIndex();
    int limit = text.getEndIndex();
    if (start == limit) {
        throw new IllegalArgumentException("Zero length iterator passed to TextLayout constructor.");
    }

    int len = limit - start;
    text.first();
    char[] chars = new char[len];
    int n = 0;
    for (char c = text.first();
         c != CharacterIterator.DONE;
         c = text.next())
    {
        chars[n++] = c;
    }

    text.first();
    if (text.getRunLimit() == limit) {

        Map<? extends Attribute, ?> attributes = text.getAttributes();
        Font font = singleFont(chars, 0, len, attributes);
        if (font != null) {
            fastInit(chars, font, attributes, frc);
            return;
        }
    }

    standardInit(text, chars, frc);
}
 
Example 4
Project: jdk8u-jdk   File: HelvLtOblTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 5
Project: Logisim   File: InstanceTextField.java   View source code 6 votes vote down vote up
void update(Attribute<String> labelAttr, Attribute<Font> fontAttr, Attribute<Color> colorAttr, int x, int y,
		int halign, int valign) {
	boolean wasReg = shouldRegister();
	this.labelAttr = labelAttr;
	this.fontAttr = fontAttr;
	this.colorAttr = colorAttr;
	this.fieldX = x;
	this.fieldY = y;
	this.halign = halign;
	this.valign = valign;
	boolean shouldReg = shouldRegister();
	AttributeSet attrs = comp.getAttributeSet();
	if (!wasReg && shouldReg)
		attrs.addAttributeListener(this);
	if (wasReg && !shouldReg)
		attrs.removeAttributeListener(this);

	updateField(attrs);
}
 
Example 6
Project: LivroJavaComoProgramar10Edicao   File: CheckBoxFrame.java   View source code 6 votes vote down vote up
public CheckBoxFrame()
{
   super("JCheckBox Test");
   setLayout(new FlowLayout());

   // set up JTextField and set its font
   textField = new JTextField("Watch the font style change", 20);
   textField.setFont(new Font("Serif", Font.PLAIN, 14));
   add(textField); // add textField to JFrame

   boldJCheckBox = new JCheckBox("Bold"); 
   italicJCheckBox = new JCheckBox("Italic"); 
   add(boldJCheckBox); // add bold checkbox to JFrame
   add(italicJCheckBox); // add italic checkbox to JFrame

   // register listeners for JCheckBoxes
   CheckBoxHandler handler = new CheckBoxHandler();
   boldJCheckBox.addItemListener(handler);
   italicJCheckBox.addItemListener(handler);
}
 
Example 7
Project: jdk8u-jdk   File: StyledParagraph.java   View source code 6 votes vote down vote up
/**
 * Extract a GraphicAttribute or Font from the given attributes.
 * If attributes does not contain a GraphicAttribute, Font, or
 * Font family entry this method returns null.
 */
private static Object getGraphicOrFont(
        Map<? extends Attribute, ?> attributes) {

    Object value = attributes.get(TextAttribute.CHAR_REPLACEMENT);
    if (value != null) {
        return value;
    }
    value = attributes.get(TextAttribute.FONT);
    if (value != null) {
        return value;
    }

    if (attributes.get(TextAttribute.FAMILY) != null) {
        return Font.getFont(attributes);
    }
    else {
        return null;
    }
}
 
Example 8
Project: Moenagade   File: BloxsEditor.java   View source code 6 votes vote down vote up
private void printHeaderFooter(Graphics g, PageFormat pageFormat, int page, String className)
{
    int origPage = page+1;

    // Add header
    g.setColor(Color.BLACK);
    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();
    
    // header text
    if(className!=null)
        g.drawString(className, xOffset, topOffset-10);
    // footer text
    g.drawString(pageString, xOffset+(int)pageFormat.getImageableWidth()-tw,bottom-2);
}
 
Example 9
Project: s-store   File: FontDialogSwing.java   View source code 6 votes vote down vote up
/**
 * Displays a color chooser and Sets the selected color.
 */
public static void setFontSize(String inFontSize) {

    // [email protected] 20050215 - Changed for Compatbilty fix for JDK 1.3
    // Convert Strng to float for deriveFont() call
    Float stageFloat = new Float(inFontSize);
    float fontSize   = stageFloat.floatValue();
    Font  fonttTree  = fOwner.tTree.getFont().deriveFont(fontSize);

    fOwner.tTree.setFont(fonttTree);

    Font fontTxtCommand =
        fOwner.txtCommand.getFont().deriveFont(fontSize);

    fOwner.txtCommand.setFont(fontTxtCommand);

    Font fontTxtResult = fOwner.txtResult.getFont().deriveFont(fontSize);

    fOwner.txtResult.setFont(fontTxtResult);
}
 
Example 10
Project: JuggleMasterPro   File: AnimationJFrame.java   View source code 6 votes vote down vote up
/**
 * Method description
 * 
 * @see
 */
final public void initBufferingAndFonts() {

	// Hardware double-buffering :
	RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
	this.setIgnoreRepaint(true);

	// Waiting for the frame to be displayed :
	while (!this.isVisible()) {
		Thread.yield();
	}

	// Images :
	final Graphics2D objLjuggleMasterProJFrameGraphics2D = (Graphics2D) this.getGraphics();

	this.initBounds();

	// Font metrics :
	this.objGnormalFont = objLjuggleMasterProJFrameGraphics2D.getFont();
	this.objGboldFont = this.objGnormalFont.deriveFont(Font.BOLD);
	Constants.objS_GRAPHICS_FONT_METRICS = objLjuggleMasterProJFrameGraphics2D.getFontMetrics();
	objLjuggleMasterProJFrameGraphics2D.dispose();
}
 
Example 11
Project: Caritemere   File: Theme.java   View source code 6 votes vote down vote up
public static Theme getMedicalWhiteColorScheme() {
	Theme out = new Theme("Medical White");
	out.colors[COL_BACKGROUND] = new Color(0x888888);
	out.colors[COL_WINDOW_BACKGROUND] = new Color(0xbbbbbb);
	out.colors[COL_ACCENT] = new Color(0xbbbbbb);
	out.colors[COL_TEXT_PRIMARY] = new Color(0xffffff);
	out.colors[COL_TEXT_SECONDARY] = new Color(0xeeeeee);
	out.colors[COL_TEXT_TERTIARY] = new Color(0xdddddd);
	out.colors[COL_TEXT_STATUS] = new Color(0xdd9999);
	out.colors[COL_BUTTON] = new Color(0x555555);
	out.colors[COL_BUTTON_HOVER] = new Color(0xffffff);
	out.colors[COL_BUTTON_PRESS] = new Color(0xcccccc);
	out.colors[COL_INFO_WINDOW_BG] = new Color(0x666666);

	out.fonts[FONT_TITLE] = new Font("Mars Needs Cunnilingus", Font.BOLD, 45);
	return out;
}
 
Example 12
Project: AgentWorkbench   File: DynTableCellRenderEditor.java   View source code 6 votes vote down vote up
/**
 * Returns the JButton for a OntologyClassVisualsation like for TimeSeries or XyChart's.
 *
 * @param dynType the current DynType
 * @param startArgIndex the start argument index
 * @return the JButton for special class
 */
private JButton getJButtonOntologyClassVisualsation(DynType dynType) {
	
	final DynType dynTypeCurrent = dynType;
	 
	JButton jButtonSpecialClass = new JButton();
	jButtonSpecialClass.setFont(new Font("Arial", Font.BOLD, 11));
	jButtonSpecialClass.setText("Edit");
	jButtonSpecialClass.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			dynTable.setOntologyClassVisualsationVisible(dynTypeCurrent);
		}
	});
	return jButtonSpecialClass;
}
 
Example 13
Project: openjdk-jdk10   File: SunFontManager.java   View source code 6 votes vote down vote up
private static HashSet<String> getInstalledNames() {
    if (installedNames == null) {
       Locale l = getSystemStartupLocale();
       SunFontManager fontManager = SunFontManager.getInstance();
       String[] installedFamilies =
           fontManager.getInstalledFontFamilyNames(l);
       Font[] installedFonts = fontManager.getAllInstalledFonts();
       HashSet<String> names = new HashSet<String>();
       for (int i=0; i<installedFamilies.length; i++) {
           names.add(installedFamilies[i].toLowerCase(l));
       }
       for (int i=0; i<installedFonts.length; i++) {
           names.add(installedFonts[i].getFontName(l).toLowerCase(l));
       }
       installedNames = names;
    }
    return installedNames;
}
 
Example 14
Project: Logisim   File: PlaRom.java   View source code 6 votes vote down vote up
@Override
public void paintInstance(InstancePainter painter) {
	PlaRomData data = getPlaRomData(painter);
	Graphics g = painter.getGraphics();
	painter.drawRoundBounds(Color.WHITE);
	Bounds bds = painter.getBounds();
	g.setFont(new Font("sans serif", Font.BOLD, 11));
	GraphicsUtil.drawCenteredText(g, Strings.getter("PlaRomComponent").toString(), bds.getX() + bds.getWidth() / 2,
			bds.getY() + bds.getHeight() / 4);
	GraphicsUtil.drawCenteredText(g, data.getSizeString(), bds.getX() + bds.getWidth() / 2,
			bds.getY() + bds.getHeight() * 2 / 5);
	g.setColor(Color.WHITE);
	g.fillRect(bds.getX() + 4, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 11, 72, 16);
	g.setColor(Color.BLACK);
	g.drawRect(bds.getX() + 4, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 12, 72, 16);
	GraphicsUtil.drawCenteredText(g, com.cburch.logisim.gui.menu.Strings.get("editMenu"),
			bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() - bds.getHeight() / 4 - 6);
	painter.drawPort(0);
	painter.drawPort(1);
	g.setColor(Color.GRAY);
	painter.drawPort(2, Strings.get("ramClrLabel"), Direction.SOUTH);
	painter.drawPort(3, Strings.get("ramCSLabel"), Direction.NORTH);
}
 
Example 15
Project: AutonomousCar   File: TextBox.java   View source code 6 votes vote down vote up
public TextBox(double x, double y, double width, double height, Background background, String text, Font font, boolean editable, Color textColor, double horizontalMargin, double verticalMargin, double lineSpacing, double cursorWidth, double spamDelay)
{
    super(x,y,width,height,background);
    setDefaultText(text);
    setEditable(editable);
    setTextColor(textColor);
    setFont(font);
    setText(text);
    setHorizontalMargin(horizontalMargin);
    setVerticalMargin(verticalMargin);
    setLineSpacing(lineSpacing);
    setCursorWidth(cursorWidth);
    setSpamDelay(spamDelay);
    
    cursor = newCursor();
    cursor.setLayer(getLayer() - 1);
    
    
}
 
Example 16
Project: openjdk-jdk10   File: XOpenTypeViewer.java   View source code 6 votes vote down vote up
public Component prepareRenderer(TableCellRenderer renderer,
        int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    Object o = ((DefaultTableModel) getModel()).getValueAt(row, column);
    if (column == 0) {
        String key = o.toString();
        renderKey(key, comp);
    } else {
        if (isClickableElement(o)) {
            comp.setFont(boldFont);
        } else {
            comp.setFont(normalFont);
        }
    }

    return comp;
}
 
Example 17
Project: Equella   File: ScriptTargetChooser.java   View source code 5 votes vote down vote up
private void createGUI()
{
	GridBagLayout gridbag = new GridBagLayout();
	GridBagConstraints c = new GridBagConstraints();

	setLayout(gridbag);
	setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));

	target = new JTextField();
	target.setEditable(false);
	target.setMinimumSize(new Dimension(150, 20));
	target.setPreferredSize(new Dimension(150, 20));
	target.setMaximumSize(new Dimension(150, 20));
	c.gridx = 0;
	c.weightx = 1;
	c.gridy = 0;
	c.fill = GridBagConstraints.HORIZONTAL;
	gridbag.setConstraints(target, c);
	add(target);

	JButton search = new JButton("..."); //$NON-NLS-1$
	search.setFont(new Font("Sans Serif", Font.PLAIN, 8)); //$NON-NLS-1$
	search.addActionListener(new SearchHandler());
	search.setMinimumSize(new Dimension(18, 20));
	search.setPreferredSize(new Dimension(18, 20));
	search.setMaximumSize(new Dimension(18, 20));
	c.gridx = 1;
	c.weightx = 0;
	gridbag.setConstraints(search, c);
	add(search);
}
 
Example 18
Project: hearthstone   File: Fontes.java   View source code 5 votes vote down vote up
public static Font getBelwe(int size) {
    try {
        Font font = Font.createFont(Font.TRUETYPE_FONT, Fontes.class.getResourceAsStream("/com/limagiran/hearthstone/util/belwe.ttf"));
        font = font.deriveFont(Font.BOLD, size);
        return font;
    } catch (Exception ex) {
    }
    return new Font("Tahoma", Font.BOLD, size);
}
 
Example 19
Project: oxygen-git-plugin   File: ToolbarPanel.java   View source code 5 votes vote down vote up
/**
* Create the "Push" button.
* 
* @return the "Push" button.
*/
private ToolbarButton createPushButton() {
  return new ToolbarButton(createPushAction(), false) {
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);

		String str = "";
		if (pushesAhead > 0) {
			str = "" + pushesAhead;
		}
		if (pushesAhead > 9) {
			pushButton.setHorizontalAlignment(SwingConstants.LEFT);
		} else {
			pushButton.setHorizontalAlignment(SwingConstants.CENTER);
		}
		g.setFont(g.getFont().deriveFont(Font.BOLD, 8.5f));
		FontMetrics fontMetrics = g.getFontMetrics(g.getFont());
		int stringWidth = fontMetrics.stringWidth(str);
		int stringHeight = fontMetrics.getHeight();
		g.setColor(new Color(255, 255, 255, 100));
		g.fillRect(pushButton.getWidth() - stringWidth - 1, pushButton.getHeight() - stringHeight, stringWidth,
				stringHeight);
		g.setColor(Color.BLACK);
		g.drawString(str, pushButton.getWidth() - stringWidth, pushButton.getHeight() - fontMetrics.getDescent());
	}
};
}
 
Example 20
Project: org.alloytools.alloy   File: Artist.java   View source code 5 votes vote down vote up
/** Draws the given string at (x,y) */
public void drawString(String text, int x, int y) {
	if (text.length() == 0)
		return;
	if (gr != null) {
		gr.drawString(text, x, y);
		return;
	}
	calc();
	Font font = (fontBoldness ? cachedBoldFont : cachedPlainFont);
	GlyphVector gv = font.createGlyphVector(new FontRenderContext(null, false, false), text);
	translate(x, y);
	draw(gv.getOutline(), true);
	translate(-x, -y);
}
 
Example 21
Project: trashjam2017   File: FontData.java   View source code 5 votes vote down vote up
/**
 * Get a styled version of a particular font family
 * 
 * @param familyName The name of the font family
 * @param style The style (@see java.awt.Font#PLAIN)
 * @return The styled font or null if no such font exists
 */
public static FontData getStyled(String familyName, int style) {
	boolean b = (style & Font.BOLD) != 0;
	boolean i = (style & Font.ITALIC) != 0;

	if (b & i) {
		return getBoldItalic(familyName);
	} else if (b) {
		return getBold(familyName);
	} else if (i) {
		return getItalic(familyName);
	} else {
		return getPlain(familyName);
	}
}
 
Example 22
Project: incubator-netbeans   File: ResultPanelOutput.java   View source code 5 votes vote down vote up
/**
 * Creates a new instance of ResultPanelOutput
 */
ResultPanelOutput(ResultDisplayHandler displayHandler) {
    super();
    if (LOG) {
        System.out.println("ResultPanelOutput.<init>");
    }
    
    textPane = new JEditorPane();
    textPane.setFont(new Font("monospaced", Font.PLAIN, getFont().getSize()));
    textPane.setEditorKit(new OutputEditorKit());
    textPane.setEditable(false);
    textPane.getCaret().setVisible(true);
    textPane.getCaret().setBlinkRate(0);
    textPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    setViewportView(textPane);

    /*
     * On GTK L&F, background of the text pane is gray, even though it is
     * white on a JTextArea. The following is a hack to fix it:
     */
    Color background = UIManager.getColor("TextPane.background");   //NOI18N
    if (background != null) {
        textPane.setBackground(background);
    }

    doc = textPane.getDocument();

    AccessibleContext ac = textPane.getAccessibleContext();
    ac.setAccessibleName(NbBundle.getMessage(getClass(),
                                            "ACSN_OutputTextPane"));//NOI18N
    ac.setAccessibleDescription(NbBundle.getMessage(getClass(),
                                            "ACSD_OutputTextPane"));//NOI18N
    
    this.displayHandler = displayHandler;
}
 
Example 23
Project: scorekeeperfrontend   File: SelectionBar.java   View source code 5 votes vote down vote up
public SelectionBar()
{
	super();

	Messenger.register(MT.TIMER_SERVICE_CONNECTION, this);
	Messenger.register(MT.SERIES_CHANGED, this);
	Messenger.register(MT.NEW_CHALLENGE, this);
	Messenger.register(MT.CHALLENGE_DELETED, this);

	setBorder(new BevelBorder(0));

	Font f = new Font(Font.DIALOG, Font.BOLD, 14);

	seriesLabel = new CurrentSeriesLabel();
	seriesLabel.setFont(f.deriveFont(Font.PLAIN));
	challengeSelect  = createCombo("challengeChange");
	eventSelect = createCombo("eventChange");
	
	connectLabel = new JLabel("Not Connected");
	connectLabel.setForeground(Color.RED);
	connectLabel.setFont(f);

	add(createLabel("Series:", f));
	add(seriesLabel);
	add(Box.createHorizontalStrut(40));

	add(createLabel("Event:", f));
	add(eventSelect);
	add(Box.createHorizontalStrut(40));

	add(createLabel("Challenge:", f));
	add(challengeSelect);
	add(Box.createHorizontalStrut(15));
	
	add(createLabel("Timer:", f));
	add(connectLabel);
}
 
Example 24
Project: jdk8u-jdk   File: AquaInternalFrameBorderMetrics.java   View source code 5 votes vote down vote up
@Override
protected AquaInternalFrameBorderMetrics getInstance() {
    return new AquaInternalFrameBorderMetrics() {
        protected void initialize() {
            font = new Font("Lucida Grande", Font.PLAIN, 13);
            titleBarHeight = 22;
            leftSidePadding = 8;
            buttonHeight = 15;
            buttonWidth = 15;
            buttonPadding = 6;
            downShift = 1;
        }
    };
}
 
Example 25
Project: MapAnalyst   File: Style.java   View source code 5 votes vote down vote up
public Style(Color color, Color backColor, Stroke stroke, Font font) {
    super();
    this.color = color;
    this.backColor = backColor;
    this.stroke = stroke;
    this.font = font;
}
 
Example 26
Project: kettle_support_kettle8.0   File: Captcha.java   View source code 5 votes vote down vote up
/**
 * 随机生成字体、文字大小
 */
public static Font getRandomFont() {
	String[] fonts = { "Verdana", "Tahoma", "Time News Roman", "Quantzite",
			"Astarisborn", "WishfulWaves" };
	int fontIndex = (int) Math.round(Math.random() * (fonts.length - 1));
	int fontSize = (int) Math.round(Math.random() * 4 + 18);
	return new Font(fonts[fontIndex], Font.PLAIN, fontSize);
}
 
Example 27
Project: openjdk-jdk10   File: TextSourceLabel.java   View source code 5 votes vote down vote up
public AffineTransform getBaselineTransform() {
    Font font = source.getFont();
    if (font.hasLayoutAttributes()) {
        return AttributeValues.getBaselineTransform(font.getAttributes());
    }
    return null;
}
 
Example 28
Project: NotifyTools   File: AwtFontPersistenceDelegate.java   View source code 5 votes vote down vote up
@Override
protected Expression instantiate(Object oldInstance, Encoder enc) {
    Font font = (Font) oldInstance;
    return new Expression(oldInstance, oldInstance.getClass(),
            BeansUtils.NEW, new Object[] { font.getFontName(),
                    font.getStyle(), font.getSize() });
}
 
Example 29
Project: VASSAL-src   File: CounterDetailViewer.java   View source code 5 votes vote down vote up
protected void drawLabel(Graphics g, Point pt, String label, int hAlign, int vAlign) {

    if (label != null) {
      Color labelFgColor = fgColor == null ? Color.black : fgColor;
      Graphics2D g2d = ((Graphics2D) g);
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
      Labeler.drawLabel(g, label, pt.x, pt.y, new Font("Dialog", Font.PLAIN, fontSize), hAlign, vAlign, labelFgColor, bgColor, labelFgColor);
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }
  }
 
Example 30
Project: Servlet_Applet_Communication   File: LoginApplet.java   View source code 5 votes vote down vote up
@Override
public void init() {
this.setVisible(true);
this.setSize(500, 500);
this.setBackground(Color.green);
this.setLayout(new FlowLayout());

l1 = new Label("User Name");
l2 = new Label("Password");
tf1 = new TextField(20);
tf2 = new TextField(20);
tf2.setEchoChar('*');
b = new Button("Login");
b.addActionListener(this);

Font font = new Font("arial", Font.BOLD, 25);
l1.setFont(font);
l2.setFont(font);
tf1.setFont(font);
tf2.setFont(font);
b.setFont(font);

this.add(l1);
this.add(tf1);
this.add(l2);
this.add(tf2);
this.add(b);

}
 
Example 31
Project: myster   File: PreferencesDialogBox.java   View source code 5 votes vote down vote up
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(new Color(150, 150, 150));
    g.drawLine(10, YDEFAULT - 45, XDEFAULT - 20, YDEFAULT - 45);
    if (header.getFont().getSize() != 24) {
        header.setFont(new Font(getFont().getName(), Font.BOLD, 24));
    }
}
 
Example 32
Project: OpenJSharp   File: StandardGlyphVector.java   View source code 5 votes vote down vote up
private void init(Font font, char[] text, int start, int count,
                  FontRenderContext frc, int flags) {

    if (start < 0 || count < 0 || start + count > text.length) {
        throw new ArrayIndexOutOfBoundsException("start or count out of bounds");
    }

    this.font = font;
    this.frc = frc;
    this.flags = flags;

    if (getTracking(font) != 0) {
        addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
    }

    // !!! change mapper interface?
    if (start != 0) {
        char[] temp = new char[count];
        System.arraycopy(text, start, temp, 0, count);
        text = temp;
    }

    initFontData(); // sets up font2D

    // !!! no layout for now, should add checks
    // !!! need to support creating a StandardGlyphVector from a TextMeasurer's info...
    glyphs = new int[count]; // hmmm
    /* Glyphs obtained here are already validated by the font */
    userGlyphs = glyphs;
    font2D.getMapper().charsToGlyphs(count, text, glyphs);
}
 
Example 33
Project: Tarski   File: OurConsole.java   View source code 5 votes vote down vote up
/** This helper method constructs a JTextPane with the given settings. */
private static JTextPane do_makeTextPane(boolean editable, int topMargin, int bottomMargin, int otherMargin) {
   JTextPane x = OurAntiAlias.pane(Color.BLACK, Color.WHITE, new Font("Verdana", Font.PLAIN, 14));
   x.setEditable(editable);
   x.setAlignmentX(0);
   x.setAlignmentY(0);
   x.setCaretPosition(0);
   x.setMargin(new Insets(topMargin, otherMargin, bottomMargin, otherMargin));
   return x;
}
 
Example 34
Project: OpenJSharp   File: FontPanel.java   View source code 5 votes vote down vote up
public void setFontParams(String name, float size,
                          int style, int transform) {
    boolean fontModified = false;
    if ( !name.equals( fontName ) || style != fontStyle )
      fontModified = true;

    fontName = name;
    fontSize = size;
    fontStyle = style;
    fontTransform = transform;

    /// Recreate the font as specified
    testFont = new Font(fontName, fontStyle, (int)fontSize);
    if ((float)((int)fontSize) != fontSize) {
        testFont = testFont.deriveFont(fontSize);
    }

    if ( fontTransform != NONE ) {
        AffineTransform at = getAffineTransform( fontTransform );
        testFont = testFont.deriveFont( at );
    }
    updateBackBuffer = true;
    updateFontMetrics = true;
    fc.repaint();
    if ( fontModified ) {
        /// Tell main panel to update the font info
        updateFontInfo();
        f2dt.fireUpdateFontInfo();
    }
}
 
Example 35
Project: gate-core   File: OptionsMap.java   View source code 5 votes vote down vote up
/**
 * 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 36
Project: OpenJSharp   File: PhysicalStrike.java   View source code 5 votes vote down vote up
public PhysicalStrike(Font font, FontFamily family, FontStyle style, FontRenderContext frc){
    this.font = font;
    this.family = family;
    this.style = style;
    this.frc = frc;
    this.size2D = font.getNetFont().get_Size();
    this.factor = size2D / family.GetEmHeight(style);
}
 
Example 37
Project: OpenJSharp   File: SunGraphics2D.java   View source code 5 votes vote down vote up
public FontInfo getGVFontInfo(Font font, FontRenderContext frc) {
    if (glyphVectorFontInfo != null &&
        glyphVectorFontInfo.font == font &&
        glyphVectorFRC == frc) {
        return glyphVectorFontInfo;
    } else {
        glyphVectorFRC = frc;
        return glyphVectorFontInfo =
            checkFontInfo(glyphVectorFontInfo, font, frc);
    }
}
 
Example 38
Project: AgentWorkbench   File: ProjectResources.java   View source code 5 votes vote down vote up
/**
 * This method initializes jListResources
 * @return javax.swing.JList
 */
private JList<ProjectResource2Display> getJListBinResources() {
	if (jListBinResources == null) {
		jListBinResources = new JList<ProjectResource2Display>();
		jListBinResources.setFont(new Font("Dialog", Font.PLAIN, 12));
	}
	return jListBinResources;
}
 
Example 39
Project: parabuild-ci   File: JThermometer.java   View source code 5 votes vote down vote up
/**
 * Sets the tick font style.
 *
 * @param style  the style.
 */
public void setTickFontStyle(int style) {
    Font f = getTickLabelFont();
    String fName = f.getFontName();
    Font newFont = new Font(fName, style, f.getSize());
    setTickLabelFont(newFont);
}
 
Example 40
Project: OpenJSharp   File: Font2D.java   View source code 5 votes vote down vote up
public FontStrike getStrike(Font font) {
    FontStrike strike = (FontStrike)lastFontStrike.get();
    if (strike != null) {
        return strike;
    } else {
        return getStrike(font, DEFAULT_FRC);
    }
}