Java Code Examples for java.awt.Font#decode()

The following examples show how to use java.awt.Font#decode() . 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: DefaultSyntaxKit.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Install the View on the given EditorPane.  This is called by Swing and
 * can be used to do anything you need on the JEditorPane control.  Here
 * I set some default Actions.
 *
 * @param editorPane
 */
@Override
public void install(JEditorPane editorPane) {
	super.install(editorPane);
	// get our font
	String fontName = getProperty("DefaultFont");
	Font font = DEFAULT_FONT;
	if (fontName != null) {
		font = Font.decode(fontName);
	}
	editorPane.setFont(font);
	Configuration conf = getConfig();
	Color caretColor = conf.getColor(CONFIG_CARETCOLOR, Color.BLACK);
	editorPane.setCaretColor(caretColor);
	Color selectionColor = getConfig().getColor(CONFIG_SELECTION, new Color(0x99ccff));
	editorPane.setSelectionColor(selectionColor);
	addActions(editorPane);
	addComponents(editorPane);
	addPopupMenu(editorPane);
}
 
Example 2
Source File: GamaFontType.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static GamaFont staticCast(final IScope scope, final Object obj, final boolean copy)
		throws GamaRuntimeException {
	if (obj instanceof Number) {
		final Number size = (Number) obj;
		final GamaFont font = DEFAULT_DISPLAY_FONT.getValue();
		return new GamaFont(font.getName(), font.getStyle(), size.intValue());
	}
	if (obj instanceof GamaFont) {
		if (copy) {
			return new GamaFont((Font) obj);
		} else {
			return (GamaFont) obj;
		}
	}
	if (obj instanceof String) { return new GamaFont(Font.decode((String) obj)); }
	return DEFAULT_DISPLAY_FONT.getValue();
}
 
Example 3
Source File: FontResource.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Do not use directly.
 *
 * @param resourceLocator The {@code URI} used when loading this
 *     resource.
 * @exception IOException if unable to read the font.
 */
public FontResource(URI resourceLocator) throws IOException {
    super(resourceLocator);
    font = null;
    try {
        if (resourceLocator.getPath() != null
            && resourceLocator.getPath().endsWith(".ttf")) {
            URL url = resourceLocator.toURL();
            font = Font.createFont(Font.TRUETYPE_FONT, url.openStream());
        } else {
            String name = resourceLocator.getSchemeSpecificPart();
            font = Font.decode(name.substring(SCHEME.length()));
        }
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .registerFont(font);

        logger.info("Loaded font: " + font.getFontName()
            + " from: " + resourceLocator);
    } catch (FontFormatException|IOException ex) {
        logger.log(Level.WARNING,
            "Failed loading font from: " + resourceLocator, ex);
        throw new IOException("Font load failed from: " + resourceLocator,
            ex);
    }
}
 
Example 4
Source File: PlotBox.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the label font, which is used for axis labels and legend labels.
 * The font names understood are those understood by
 * java.awt.Font.decode().
 *
 * @param name A font name.
 */

public synchronized void setLabelFont(String name) {
    // Changing legend means we need to repaint the offscreen buffer.
    _plotImage = null;

    _labelFont = Font.decode(name);
    _labelFontMetrics = getFontMetrics(_labelFont);
}
 
Example 5
Source File: CartesianType1.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 *  Set the label font, which is used for axis labels and legend labels. The
 *  font names understood are those understood by java.awt.Font.decode().
 *
 * @param  name  A font name.
 */
public void setLabelFont(String name) {
  if((name==null)||name.equals("")) { //$NON-NLS-1$
    return;
  }
  labelFont = Font.decode(name);
  // labelFontMetrics = getFontMetrics(labelFont);  FIX_ME
}
 
Example 6
Source File: EpsGraphics2D.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the Font to be used in future text.
 */
public void setFont(Font font) {
  if(font==null) {
    font = Font.decode(null);
  }
  _font = font;
  if(!getAccurateTextMode()) {
    append("/"+_font.getPSName()+" findfont "+(_font.getSize())+" scalefont setfont"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
}
 
Example 7
Source File: FontLibrary.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a default {@code Font} set on initialization of the GUI.
 * 
 * @param fontName Can be used to choose a different font from a
 *     user-provided name.
 * @param scaleFactor The applied scale factor.
 * @return The new {@code Font}.
 */
static Font createMainFont(String fontName, float scaleFactor) {
    final float defaultSize = 12f * scaleFactor;
    mainFont = null;
    if (fontName != null) {
        Font font = Font.decode(fontName);
        mainFont = font = font.deriveFont(defaultSize);
        return font;
    }
    return ResourceManager.getFont("font.normal").deriveFont(defaultSize);
}
 
Example 8
Source File: PlotBox.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the title font.
 * The font names understood are those understood by
 * java.awt.Font.decode().
 *
 * @param name A font name.
 */

public synchronized void setTitleFont(String name) {
    // Changing legend means we need to repaint the offscreen buffer.
    _plotImage = null;

    _titleFont = Font.decode(name);
    _titleFontMetrics = getFontMetrics(_titleFont);
}
 
Example 9
Source File: Attributes.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Font parse(String value) {
	return Font.decode(value);
}
 
Example 10
Source File: TSNEDemo.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	chart = ChartFactory.createScatterPlot("", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);

	final XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true) {
		private static final long serialVersionUID = 1L;

		@Override
		public ItemLabelPosition getPositiveItemLabelPosition(int row, int column) {
			return new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_LEFT);
		}
	};
	final Font font = Font.decode("Helvetica Neue-22");
	renderer.setBaseItemLabelFont(font);
	chart.getXYPlot().setRenderer(renderer);
	// chart.getXYPlot().getDomainAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getDomainAxis().setTickLabelFont(font);
	// chart.getXYPlot().getDomainAxis().setTickUnit(new NumberTickUnit(1))
	// chart.getXYPlot().getRangeAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getRangeAxis().setTickLabelFont(font);
	// chart.getXYPlot().getRangeAxis().setTickUnit(new NumberTickUnit(1))

	chart.getXYPlot().getRenderer().setBaseItemLabelGenerator(new StandardXYItemLabelGenerator() {
		private static final long serialVersionUID = 1L;

		@Override
		public String generateLabel(XYDataset ds, int series, int item) {
			return ((Dataset) ds).getLabel(series, item);
		};
	});
	chart.getXYPlot().getRenderer().setBaseItemLabelsVisible(true);

	chartPanel = new ChartPanel(chart);
	chart.setBackgroundPaint(new java.awt.Color(255, 255, 255, 255));
	chart.getXYPlot().setBackgroundPaint(java.awt.Color.WHITE);
	chart.getXYPlot().setRangeGridlinePaint(java.awt.Color.GRAY);
	chart.getXYPlot().setDomainGridlinePaint(java.awt.Color.GRAY);

	chartPanel.setSize(width, height - 50);
	chartPanel.setPreferredSize(chartPanel.getSize());
	base.add(chartPanel);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run t-SNE");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	iterLabel = new JLabel("                         ");
	final Dimension size = iterLabel.getPreferredSize();
	iterLabel.setMinimumSize(size);
	iterLabel.setPreferredSize(size);
	controls.add(iterLabel);

	updateImage();

	return base;
}
 
Example 11
Source File: MDSDemo.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	chart = ChartFactory.createScatterPlot("", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);

	final XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true) {
		private static final long serialVersionUID = 1L;

		@Override
		public ItemLabelPosition getPositiveItemLabelPosition(int row, int column) {
			return new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_LEFT);
		}
	};
	final Font font = Font.decode("Helvetica Neue-22");
	renderer.setBaseItemLabelFont(font);
	chart.getXYPlot().setRenderer(renderer);
	// chart.getXYPlot().getDomainAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getDomainAxis().setTickLabelFont(font);
	// chart.getXYPlot().getDomainAxis().setTickUnit(new NumberTickUnit(1))
	// chart.getXYPlot().getRangeAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getRangeAxis().setTickLabelFont(font);
	// chart.getXYPlot().getRangeAxis().setTickUnit(new NumberTickUnit(1))

	chart.getXYPlot().getRenderer().setBaseItemLabelGenerator(new StandardXYItemLabelGenerator() {
		private static final long serialVersionUID = 1L;

		@Override
		public String generateLabel(XYDataset ds, int series, int item) {
			return ((Dataset) ds).getLabel(series, item);
		};
	});
	chart.getXYPlot().getRenderer().setBaseItemLabelsVisible(true);

	chartPanel = new ChartPanel(chart);
	chart.setBackgroundPaint(new java.awt.Color(255, 255, 255, 255));
	chart.getXYPlot().setBackgroundPaint(java.awt.Color.WHITE);
	chart.getXYPlot().setRangeGridlinePaint(java.awt.Color.GRAY);
	chart.getXYPlot().setDomainGridlinePaint(java.awt.Color.GRAY);

	chartPanel.setSize(width, height - 50);
	chartPanel.setPreferredSize(chartPanel.getSize());
	base.add(chartPanel);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	controls.add(new JLabel("Distance:"));

	distCombo = new JComboBox<String>();
	distCombo.addItem("Euclidean");
	distCombo.addItem("1-Pearson");
	distCombo.addItem("1-Cosine");
	controls.add(distCombo);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run MDS");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	iterLabel = new JLabel("                         ");
	final Dimension size = iterLabel.getPreferredSize();
	iterLabel.setMinimumSize(size);
	iterLabel.setPreferredSize(size);
	controls.add(iterLabel);

	updateImage();

	return base;
}
 
Example 12
Source File: FontChooserTest.java    From ganttproject with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  myBaseFont = Font.decode("Dialog 10");
}
 
Example 13
Source File: FontHelper.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public static Font stringToFont(String fontString) {
    return Font.decode(fontString);
}
 
Example 14
Source File: AbstractChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  // Misc Properties
  final TextTitle chartTitle = chart.getTitle();
  if ( chartTitle != null ) {
    final Font titleFont = Font.decode( getTitleFont() );
    chartTitle.setFont( titleFont );
  }

  if ( isAntiAlias() == false ) {
    chart.setAntiAlias( false );
  }

  chart.setBorderVisible( isShowBorder() );

  final Color backgroundColor = parseColorFromString( getBackgroundColor() );
  if ( backgroundColor != null ) {
    chart.setBackgroundPaint( backgroundColor );
  }

  if ( plotBackgroundColor != null ) {
    chart.getPlot().setBackgroundPaint( plotBackgroundColor );
  }
  chart.getPlot().setBackgroundAlpha( plotBackgroundAlpha );
  chart.getPlot().setForegroundAlpha( plotForegroundAlpha );
  final Color borderCol = parseColorFromString( getBorderColor() );
  if ( borderCol != null ) {
    chart.setBorderPaint( borderCol );
  }

  //remove legend if showLegend = false
  if ( !isShowLegend() ) {
    chart.removeLegend();
  } else { //if true format legend
    final LegendTitle chLegend = chart.getLegend();
    if ( chLegend != null ) {
      final RectangleEdge loc = translateEdge( legendLocation.toLowerCase() );
      if ( loc != null ) {
        chLegend.setPosition( loc );
      }
      if ( getLegendFont() != null ) {
        chLegend.setItemFont( Font.decode( getLegendFont() ) );
      }
      if ( !isDrawLegendBorder() ) {
        chLegend.setBorder( BlockBorder.NONE );
      }
      if ( legendBackgroundColor != null ) {
        chLegend.setBackgroundPaint( legendBackgroundColor );
      }
      if ( legendTextColor != null ) {
        chLegend.setItemPaint( legendTextColor );
      }
    }

  }

  final Plot plot = chart.getPlot();
  plot.setNoDataMessageFont( Font.decode( getLabelFont() ) );

  final String message = getNoDataMessage();
  if ( message != null ) {
    plot.setNoDataMessage( message );
  }

  plot.setOutlineVisible( isChartSectionOutline() );

  if ( backgroundImage != null ) {
    if ( plotImageCache != null ) {
      plot.setBackgroundImage( plotImageCache );
    } else {
      final ExpressionRuntime expressionRuntime = getRuntime();
      final ProcessingContext context = expressionRuntime.getProcessingContext();
      final ResourceKey contentBase = context.getContentBase();
      final ResourceManager manager = context.getResourceManager();
      try {
        final ResourceKey key = createKeyFromString( manager, contentBase, backgroundImage );
        final Resource resource = manager.create( key, null, Image.class );
        final Image image = (Image) resource.getResource();
        plot.setBackgroundImage( image );
        plotImageCache = image;
      } catch ( Exception e ) {
        logger.error( "ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e ); //$NON-NLS-1$
        throw new IllegalStateException( "Failed to process chart" );
      }
    }
  }
}
 
Example 15
Source File: OptionType.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
Object stringToObject(String string) {
	return Font.decode(string);
}
 
Example 16
Source File: PlotBox.java    From opt4j with MIT License 3 votes vote down vote up
/**
 * Set the title font. The font names understood are those understood by
 * java.awt.Font.decode().
 * 
 * @param name
 *            A font name.
 */
public synchronized void setTitleFont(String name) {
	// Changing legend means we need to repaint the offscreen buffer.
	_plotImage = null;
	_titleFont = Font.decode(name);
	_titleFontMetrics = getFontMetrics(_titleFont);
}
 
Example 17
Source File: PlotBox.java    From opt4j with MIT License 3 votes vote down vote up
/**
 * Set the label font, which is used for axis labels and legend labels. The
 * font names understood are those understood by java.awt.Font.decode().
 * 
 * @param name
 *            A font name.
 */
public synchronized void setLabelFont(String name) {
	// Changing legend means we need to repaint the offscreen buffer.
	_plotImage = null;
	_labelFont = Font.decode(name);
	_labelFontMetrics = getFontMetrics(_labelFont);
}
 
Example 18
Source File: FontValueConverter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Converts a string to a property value.
 *
 * @param s
 *          the string.
 * @return a property value.
 * @throws BeanException
 *           if there was an error during the conversion.
 */
public Object toPropertyValue( final String s ) throws BeanException {
  if ( s == null ) {
    throw new NullPointerException();
  }
  return Font.decode( s );
}
 
Example 19
Source File: FontResource.java    From freecol with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets a font of last resort, as finding fonts must not fail!
 * Currently using the default Java font, not matter how ugly.
 *
 * @return The default Java font.
 */
public static Font getEmergencyFont() {
    logger.warning("Using emergency font");
    return Font.decode(null);
}
 
Example 20
Source File: XYAxis.java    From osp with GNU General Public License v3.0 2 votes vote down vote up
/**
 *  Set the title font. The font names understood are those understood by
 *  java.awt.Font.decode().
 *
 * @param  name  A font name.
 */
public void setTitleFont(String name) {
  if((name!=null)&&!name.equals("")) { //$NON-NLS-1$
    titleFont = Font.decode(name);
  }
}