Example usage for java.awt Font createFont

List of usage examples for java.awt Font createFont

Introduction

In this page you can find the example usage for java.awt Font createFont.

Prototype

public static Font createFont(int fontFormat, File fontFile)
        throws java.awt.FontFormatException, java.io.IOException 

Source Link

Document

Returns a new Font using the specified font type and the specified font file.

Usage

From source file:org.geoserver.wms.WMSLifecycleHandler.java

List<Font> loadFontsFromDataDirectory() {
    List<Font> result = new ArrayList<Font>();
    try {//from w ww. j  a  v a  2s  . 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:com.pronoiahealth.olhie.server.services.BookCoverImageService.java

/**
 * Initialize the various maps, fonts, etc..
 *//*from  w  w  w .  j  a v  a 2s  .c  o m*/
@PostConstruct
protected void postActivate() {
    try {
        // Init the coverMap and load the images
        coverMap = new HashMap<String, byte[]>();
        List<BookCover> covers = coverDisplayData.getCovers();
        for (BookCover cover : covers) {
            coverMap.put(cover.getCoverName(),
                    readResourceToByteArray("/" + cover.getImgUrl(), servletContext));
        }

        // Load needed fonts
        medulaOneRegularFont = Font.createFont(Font.TRUETYPE_FONT,
                servletContext.getResourceAsStream("/Olhie/font/MedulaOne-Regular.ttf"));
        medulaOneRegularFont48 = medulaOneRegularFont.deriveFont(new Float(48.0));
        arialBoldFont13 = new Font("Arial Bold", Font.BOLD, 13);
        arialBoldFont16 = new Font("Arial Bold", Font.ITALIC, 16);

        // Init font maps
        // author
        authorFontMap = new Hashtable<TextAttribute, Object>();
        authorFontMap.put(TextAttribute.FONT, arialBoldFont16);
        authorFontMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);

        // Title
        titleFontMap = new Hashtable<TextAttribute, Object>();
        titleFontMap.put(TextAttribute.FONT, medulaOneRegularFont48);
        titleFontMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);

        // Back cover title
        backTitleFontMap = new Hashtable<TextAttribute, Object>();
        backTitleFontMap.put(TextAttribute.FONT, arialBoldFont13);
        backTitleFontMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
        backTitleFontMap.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);

        // Build palette factory
        palFac = new PaletteFactory();

    } catch (Exception e) {
        log.log(Level.SEVERE, "Error occured during BookCoverImageService initialization.", e);
    }
}

From source file:PolyGlot.IOHandler.java

/**
 * Gets font from save file if possible, null otherwise
 *
 * @param _path The path of the PGD file
 * @return a Font object if the PGD file is both a zip archive and contains
 * a font//  w  ww . j a v a 2 s .  c  o  m
 * @throws java.io.IOException
 * @throws java.awt.FontFormatException
 */
public static Font getFontFrom(String _path) throws IOException, FontFormatException {
    Font ret = null;

    if (isFileZipArchive(_path)) {
        ZipFile zipFile = new ZipFile(_path);

        ZipEntry fontEntry = zipFile.getEntry(PGTUtil.fontFileName);

        if (fontEntry != null) {
            final File tempFile = File.createTempFile("stream2file", ".tmp");
            tempFile.deleteOnExit();

            FileOutputStream out = new FileOutputStream(tempFile);
            IOUtils.copy(zipFile.getInputStream(fontEntry), out);

            try {
                ret = Font.createFont(Font.TRUETYPE_FONT, tempFile);
            } catch (FontFormatException e) {
                throw new FontFormatException(
                        "Could not load language font. Possible incompatible font: " + e.getMessage());
            } catch (IOException e) {
                throw new FontFormatException("Could not load language font. I/O exception: " + e.getMessage());
            }
        }
    }

    return ret;
}

From source file:Citas.FrameCita.java

public FrameCita()
        throws ClientProtocolException, IOException, JSONException, ParseException, java.text.ParseException {

    initComponents();//from   w ww .ja  v  a  2s  .c o m
    this.getContentPane().setLayout(new GridBagLayout());
    rutasLeer = new Leer();
    rutasAdd = new Add();
    medico = new Medico(2, 0, 3, 30); //MEDICO EN SESIOOON
    citas = new Citas[medico.cantidadDeCitasxDia(10, 30)];

    try {
        font = Font.createFont(Font.TRUETYPE_FONT, new File("Sertig.otf"));
        font = font.deriveFont(Font.BOLD, 11);
    } catch (FontFormatException ex) {
        Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex);
    }

    setTitle("Citas");

    GridBagConstraints gbc = new GridBagConstraints();

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    gbc.weightx = 0.5;
    gbc.weighty = 0.5;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.BOTH;
    this.getContentPane().add(PanelCalendar, gbc);
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    gbc.weightx = 0.5;
    gbc.weighty = 1.0;
    this.getContentPane().add(PanelCita, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.gridheight = 2;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    this.getContentPane().add(PanelDetalle, gbc);

    ////////////////// PANEL DETALLES

    //Colores
    colorBackGround = new Color(hex("8FA8F6"));//Color de los BackGround 
    colorTextFields = new Color(hex("CDCBA6"));//Color de los JTextFields
    colorDelPapa = new Color(hex("2980b9"));//Color del backgorud del papa
    colorBotones = new Color(hex("2C3E50"));//Color d elos botonte
    colorActivo = new Color(hex("81CFE0"));//Color de los jTextFild cuando los activan
    //Colores

    //Inicializaciones

    this.setBackground(colorDelPapa);//Color del backgroud
    //BOTONES INICIALIZACION
    modificarB = new JButton("Modificar");
    eliminarB = new JButton("Eliminar");
    agregarB = new JButton("Agregar");
    atrasB = new JButton("Atras");
    buscarB = new JButton("Buscar");
    Botones = new JPanel(); //PAnel donde van los botones Agregar, Modificar y Eliminar
    BotonAtras = new JPanel(); //PAnel donde va el boton atras
    BotonBuscar = new JPanel(); //PAnel donde va el boton buscar
    agregarB.addActionListener(this);
    modificarB.addActionListener(this);
    eliminarB.addActionListener(this);
    atrasB.addActionListener(this);
    buscarB.addActionListener(this);
    // FIN BOTONES INICIALIZACION

    PanelCita.setLayout(new GridBagLayout());

    disenoBotones(modificarB);
    disenoBotones(eliminarB);
    disenoBotones(agregarB);
    disenoBotones(atrasB);
    disenoBotones(buscarB);
    PanelDetalle.setLayout(new GridBagLayout()); //Panel Pap (PanelDetalle)
    cambiarColorPanel(PanelCalendar, colorDelPapa);
    cambiarColorPanel(PanelCita, colorDelPapa);
    cambiarColorPanel(PanelDetalle, colorDelPapa);

    //LABELS
    horaCitas = new JLabel();
    fechaL = new JLabel("<HTML> Fecha &nbsp</HTML>");
    horaL = new JLabel("<HTML> Hora &nbsp</HTML>");
    nombreL = new JLabel("<HTML> Nombre &nbsp &nbsp </HTML>");
    apellidoL = new JLabel("<HTML> Apellido &nbsp &nbsp &nbsp</HTML>");
    cedulaL = new JLabel("<HTML> Cedula &nbsp &nbsp &nbsp &nbsp &nbsp</HTML>");
    direccionL = new JLabel("<HTML> Direccion &nbsp &nbsp</HTML>");
    motivosL = new JLabel("<HTML> Motivos &nbsp &nbsp &nbsp &nbsp</HTML>");
    telefonoCasaL = new JLabel("<HTML> Tlfn Casa&nbsp </HTML>");
    telefonoCelularL = new JLabel("<HTML> Tlfn Celular</HTML>");
    correoL = new JLabel("<HTML> Correo &nbsp &nbsp &nbsp</HTML>");

    font = font = font.deriveFont(Font.BOLD, 11);
    disenoLabel(horaCitas);
    disenoLabel(fechaL);
    disenoLabel(horaL);
    disenoLabel(nombreL);
    disenoLabel(apellidoL);
    disenoLabel(cedulaL);
    disenoLabel(direccionL);
    disenoLabel(motivosL);
    disenoLabel(telefonoCasaL);
    disenoLabel(telefonoCelularL);
    disenoLabel(correoL);

    //JTEXTFIELDS y TEXAREA

    fechaJ = new JTextField("");
    horaJ = new JTextField("");
    nombreJ = new JTextField("");
    apellidoJ = new JTextField("");
    cedulaJ = new JTextField("");
    direccionJ = new JTextField();
    motivosTA = new JTextArea("");
    telefonoCasaJ = new JTextField("");
    telefonoCelularJ = new JTextField("");
    correoJ = new JTextField("");
    //COLORES
    /*fechaJ.setBackground(colorTextFields);
    horaJ.setBackground(colorTextFields);
    nombreJ.setBackground(colorTextFields);
    apellidoJ.setBackground(colorTextFields);
    cedulaJ.setBackground(colorTextFields);
    direccionJ.setBackground(colorTextFields);
    motivosTA .setBackground(colorTextFields);
    telefonoCasaJ.setBackground(colorTextFields);
    telefonoCelularJ.setBackground(colorTextFields);
    correoJ.setBackground(colorTextFields);
    */
    //Aadir componentes al PanelDetalle
    GridBagConstraints constraints = new GridBagConstraints();

    //Caracteristicas globales del grid
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weighty = 1.0;
    constraints.insets.set(5, 0, 5, 10);
    //Fin Caracteristicas Globales del grid

    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(fechaL, constraints);

    constraints.gridx = 1; //Necesita estirarse
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(fechaJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(horaL, constraints);

    constraints.gridx = 1; //Necesita estirarse
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(horaJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 2;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(nombreL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 2;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(nombreJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(apellidoL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(apellidoJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 4;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(cedulaL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 4;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(cedulaJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 5;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(direccionL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 5;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(direccionJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 6;
    constraints.gridwidth = 1;
    constraints.gridheight = 2;
    constraints.weighty = 1.0;
    PanelDetalle.add(motivosL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 6;
    constraints.gridwidth = 1;
    constraints.gridheight = 2;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    PanelDetalle.add(motivosTA, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 8;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(telefonoCasaL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 8;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(telefonoCasaJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 9;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(telefonoCelularL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 9;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(telefonoCelularJ, constraints);
    constraints.weightx = 0.0;

    constraints.gridx = 0;
    constraints.gridy = 10;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    PanelDetalle.add(correoL, constraints);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 10;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1.0;
    PanelDetalle.add(correoJ, constraints);
    constraints.weightx = 0.0;

    //PANEL DE LOS BOTONES

    constraints.insets.set(30, 0, 10, 10);

    constraints.gridx = 1;//Necesita estirarse
    constraints.gridy = 11;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0.0;
    FlowLayout flowLayout1 = new FlowLayout();
    Botones.setLayout(flowLayout1);
    Botones.add(agregarB);
    Botones.add(modificarB);
    Botones.add(eliminarB);
    PanelDetalle.add(Botones, constraints);

    //Boton Buscar
    constraints.anchor = GridBagConstraints.NORTH;
    constraints.insets.set(10, 0, 0, 0);
    constraints.gridx = 2;//Necesita estirarse
    constraints.gridy = 4;
    constraints.gridwidth = 1;
    constraints.gridheight = 0;
    constraints.weightx = 0.0;
    BotonBuscar.setLayout(flowLayout1);
    BotonBuscar.add(buscarB);
    BotonBuscar.setBackground(colorBackGround);
    PanelDetalle.add(BotonBuscar, constraints);
    constraints.insets.set(30, 0, 10, 10);

    //BOTON ATRAS

    constraints.insets.set(30, 0, 10, 10);
    constraints.gridx = 2;//Necesita estirarse
    constraints.gridy = 11;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0.0;

    BotonAtras.setLayout(flowLayout1);
    BotonAtras.add(atrasB);

    PanelDetalle.add(BotonAtras, constraints);

    cambiarColorPanel(Botones, colorDelPapa);
    cambiarColorPanel(BotonBuscar, colorDelPapa);
    cambiarColorPanel(BotonAtras, colorDelPapa);

    PanelDetalle.setVisible(true);

    //////////////////////ULTIMAS MOTIFICACIONES PRIMER INCREMENTO
    atrasB.setEnabled(false);
    buscarB.setEnabled(false);
    modificarB.setEnabled(false);
    agregarB.setEnabled(false);
    eliminarB.setEnabled(false);
    fechaJ.setEditable(false);
    horaJ.setEditable(false);
    nombreJ.setEditable(false);
    apellidoJ.setEditable(false);
    cedulaJ.setEditable(false);
    direccionJ.setEditable(false);
    motivosTA.setEditable(false);
    telefonoCasaJ.setEditable(false);
    telefonoCelularJ.setEditable(false);
    correoJ.setEditable(false);

    /////////////////////FIN ULTIMAS MOTIFICACIONES PRIMER INCREMENTO

    /////////////////Para enero

    setCitas();
    dibujarPanelCita(medico);//Dibuja la "libreta" de las citas

    /////// fin para ENERO

    //jCalendar1.getDayChooser().addDateEvaluator(new DJFechasEspInv());//Pinta las Fechas ocupadas en rojo
    jCalendar1.addPropertyChangeListener("calendar", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            try {
                try {
                    setCitas();
                } catch (ClientProtocolException ex) {
                    Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ParseException ex) {
                    Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex);
                } catch (java.text.ParseException ex) {
                    Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (IOException ex) {
                Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JSONException ex) {
                Logger.getLogger(FrameCita.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

}

From source file:net.sf.jasperreports.engine.fonts.SimpleFontFace.java

public void loadFont() throws InvalidFontException {
    if (ttf != null && font == null) {
        if (log.isDebugEnabled()) {
            log.debug("Loading font " + ttf);
        }//from w  ww.  j a  v a2  s .  c  om

        String upperCaseTtf = ttf.trim().toUpperCase();
        if (upperCaseTtf.endsWith(".TTF") || upperCaseTtf.endsWith(".OTF")) {
            InputStream is = null;
            try {
                is = RepositoryUtil.getInstance(jasperReportsContext).getInputStreamFromLocation(ttf);
            } catch (JRException e) {
                throw new InvalidFontException(ttf, e);
            }

            try {
                font = Font.createFont(Font.TRUETYPE_FONT, is);
            } catch (FontFormatException e) {
                throw new InvalidFontException(ttf, e);
            } catch (IOException e) {
                throw new InvalidFontException(ttf, e);
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        } else {
            FontUtil.getInstance(jasperReportsContext).checkAwtFont(ttf,
                    JRPropertiesUtil.getInstance(jasperReportsContext)
                            .getBooleanProperty(JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT));

            font = new Font(ttf, Font.PLAIN, JRPropertiesUtil.getInstance(jasperReportsContext)
                    .getIntegerProperty(JRFont.DEFAULT_FONT_SIZE));
        }
    }
}

From source file:net.pms.util.CodecUtil.java

/**
 * Check the font file or font name if registered in the OS
 *
 * @param fontName font represented by font file or by the font name
 *
 * @return the registered font name or null when not found
 *///from w w  w  .  j a  v a2  s .c om
public static String isFontRegisteredInOS(String fontName) {
    if (isNotBlank(fontName)) {
        File fontFile = new File(fontName);
        if (fontFile.exists()) { // Test if the font is specified by the file.
            try {
                fontName = Font.createFont(Font.TRUETYPE_FONT, fontFile).getFontName();
            } catch (FontFormatException | IOException e) {
                LOGGER.debug("Exception when implementing the custom font: ", e.getMessage());
            }
        }

        // The font is specified by the name. Check if it is registered in the OS.
        String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        for (String font : fonts) {
            if (font.equals(fontName)) {
                return font;
            }
        }
    }

    LOGGER.debug("Font name not found. Check if it is properly specified or installed in the OS");
    return null;
}

From source file:org.jfree.eastwood.ChartServlet.java

private Font readFontResource(ServletContext ctx, String fontResourceParam, float fontSize)
        throws ServletException {

    if (!fontResourceParam.startsWith("/")) {
        fontResourceParam = "/" + fontResourceParam;
    }// w w w .ja va  2s .  com
    InputStream is = ctx.getResourceAsStream(fontResourceParam);
    if (is == null) {
        throw new ServletException("Font resource '" + fontResourceParam + "' not found");
    }
    try {
        return Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(fontSize);
    } catch (FontFormatException e) {
        throw new ServletException("Font resource '" + fontResourceParam + "' is not a truetype font", e);
    } catch (IOException e) {
        throw new ServletException("I/O error when reading font resource '" + fontResourceParam + "'", e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
        }
    }
}

From source file:org.apache.pdfbox.preflight.font.descriptor.Type1DescriptorHelper.java

/**
 * Try to load the font using the java.awt.font object. if the font is invalid, an exception will be pushed in the
 * font container//from  w  ww  .ja  v  a  2s.c o  m
 * 
 * @param fontDescriptor
 * @param fontFile
 */
protected void processFontFile1(PDFontDescriptorDictionary fontDescriptor, PDStream fontFile) {
    ByteArrayInputStream bis = null;
    try {
        bis = new ByteArrayInputStream(fontFile.getByteArray());
        Font.createFont(Font.TYPE1_FONT, bis);
        IOUtils.closeQuietly(bis);

        // Parse the Type1 Font program in order to extract Glyph Width
        COSStream streamObj = fontFile.getStream();
        int length1 = streamObj.getInt(COSName.LENGTH1);
        int length2 = streamObj.getInt(COSName.LENGTH2);
        bis = new ByteArrayInputStream(fontFile.getByteArray());
        Type1Parser parserForMetrics = Type1Parser.createParserWithEncodingObject(bis, length1, length2,
                font.getFontEncoding());
        Type1 parsedData = parserForMetrics.parse();

        this.fContainer.setType1Font(parsedData);

    } catch (IOException e) {
        this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, "The FontFile can't be read"));
    } catch (FontFormatException e) {
        this.fContainer.push(new ValidationError(ERROR_FONTS_TYPE1_DAMAGED, "The FontFile is damaged"));
    } finally {
        IOUtils.closeQuietly(bis);
    }
}

From source file:com.willwinder.universalgcodesender.uielements.panels.MachineStatusPanel.java

private void applyFont() {
    String fontPath = "/resources/";
    String fontName = "LED.ttf";
    InputStream is = getClass().getResourceAsStream(fontPath + fontName);
    Font font;//from w ww  . ja  v a  2  s .c  om
    Font big, small;

    try {
        font = Font.createFont(Font.TRUETYPE_FONT, is);
        big = font.deriveFont(Font.PLAIN, 30);
        small = font.deriveFont(Font.PLAIN, 18);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println(fontName + " not loaded.  Using serif font.");
        big = new Font("serif", Font.PLAIN, 24);
        small = new Font("serif", Font.PLAIN, 17);
    }

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.registerFont(big);
    ge.registerFont(small);

    this.machinePositionXValue.setFont(small);
    this.machinePositionXValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.machinePositionYValue.setFont(small);
    this.machinePositionYValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.machinePositionZValue.setFont(small);
    this.machinePositionZValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

    this.workPositionXValue.setFont(big);
    this.workPositionXValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.workPositionYValue.setFont(big);
    this.workPositionYValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.workPositionZValue.setFont(big);
    this.workPositionZValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
}

From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java

/**
 * Creer camember3 d./* w  w  w . jav a  2  s .c o m*/
 *
 * @param title
 *            the title
 * @param dataset
 *            the dataset
 * @param legend
 *            the legend
 * @param tooltips
 *            the tooltips
 * @param urls
 *            the urls
 * @return the j free chart
 * @throws FontFormatException
 *             the font format exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static JFreeChart creerCamember3D(final String title, final DefaultPieDataset dataset,
        final boolean legend, final boolean tooltips, final boolean urls)
        throws FontFormatException, IOException {

    dataset.sortByValues(SortOrder.DESCENDING);
    final JFreeChart jfreeChart = ChartFactory.createPieChart3D(title, dataset, legend, tooltips, urls);

    jfreeChart.setBackgroundPaint(Color.white);
    jfreeChart.setBorderVisible(true);
    jfreeChart.getLegend().setPosition(RectangleEdge.LEFT);
    final GraphicsEnvironment graph = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("hornet/framework/font/LiberationSans-Bold.ttf");
    final Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
    graph.registerFont(font);
    jfreeChart.getLegend().setItemFont(new Font("Liberation Sans", Font.BOLD, 11));
    jfreeChart.getLegend().setHeight(400);
    jfreeChart.getLegend().setBorder(0, 0, 0, 0);
    jfreeChart.setTitle(new TextTitle(title, new Font("Liberation Sans", Font.BOLD, 16)));
    final PiePlot piePlot = (PiePlot) jfreeChart.getPlot();

    final int nbData = dataset.getItemCount();
    int cptColor = 0;
    for (int x = 0; x < nbData; x++) {
        if (cptColor >= listColor.size()) {
            cptColor = 0;
        }
        piePlot.setSectionPaint(dataset.getKey(x), listColor.get(cptColor));

        cptColor++;

    }

    piePlot.setForegroundAlpha(0.5f);
    piePlot.setLabelFont(new Font("Liberation Sans", Font.BOLD, 12));
    piePlot.setLabelOutlineStroke(null);
    piePlot.setLabelLinkStroke(new BasicStroke(0.4f));
    piePlot.setLabelBackgroundPaint(Color.WHITE);
    piePlot.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
    piePlot.setBackgroundAlpha(0);
    piePlot.setOutlineVisible(false);
    piePlot.setForegroundAlpha(1); // transparence
    piePlot.setInteriorGap(0); // le camembert occupe plus de place
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}"));
    piePlot.setStartAngle(70);
    piePlot.setCircular(true); // force pour avoir un cercle et pas un oval
    piePlot.setMaximumLabelWidth(0.20);
    piePlot.setBaseSectionOutlinePaint(Color.BLACK); // bordure du camembert

    return jfreeChart;

}