List of usage examples for java.awt GraphicsEnvironment registerFont
public boolean registerFont(Font font)
From source file:Main.java
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(new Font("New Font", Font.BOLD, 20)); }
From source file:net.team2xh.crt.gui.util.GUIToolkit.java
/** * Register a local font to the graphical environment. * * After registering a font, its font family can be used normally as if * the font was installed on the OS./* w w w.j ava2 s .co m*/ * * @param caller Caller instance for resource aquisition * @param path Font file path */ public static void registerFont(Object caller, String path) { try { URI uri = caller.getClass().getResource(path).toURI(); File fontFile = new File(uri); Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); } catch (FontFormatException | IOException | URISyntaxException e) { System.out.println(e.getMessage()); } }
From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java
/** * Creer camember3 d.// ww w . jav a2s.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; }
From source file:pcgen.system.Main.java
private static void initPrintPreviewFonts() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontDir = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fonts" + File.separator + "NotoSans" + File.separator; try {/*from w ww.j av a 2s . c om*/ ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Regular.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Bold.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Italic.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-BoldItalic.ttf"))); } catch (IOException | FontFormatException ex) { Logging.errorPrint("Unexpected exception loading fonts fo print p", ex); } }
From source file:net.technicpack.ui.lang.ResourceLoader.java
public Font getFontByName(String fontName) { Font font;// w ww. ja v a2s.c o m if (fontCache.containsKey(fontName)) return fontCache.get(fontName); if (launcherAssets == null) return fallbackFont; InputStream fontStream = null; try { String fullName = getString(fontName); fontStream = FileUtils.openInputStream(new File(launcherAssets, fullName)); if (fontStream == null) return fallbackFont; font = Font.createFont(Font.TRUETYPE_FONT, fontStream); GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); genv.registerFont(font); } catch (Exception e) { e.printStackTrace(); // Fallback return fallbackFont; } finally { if (fontStream != null) IOUtils.closeQuietly(fontStream); } fontCache.put(fontName, font); if (font == null) return fallbackFont; return font; }
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;// ww w . j a v a 2 s. c o m 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:cognitivej.vision.overlay.builder.ImageOverlayBuilder.java
private ImageOverlayBuilder(@NotNull BufferedImage bufferedImage) { this.bufferedImage = bufferedImage; try {/*w ww. j a va2s .co m*/ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/font/notosans/NotoSans-Bold.ttf"))); } catch (IOException | FontFormatException ignored) { } }
From source file:literarytermsquestionbank.AChristmasCarol.java
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened // Set window icon this.setIconImage(Toolkit.getDefaultToolkit() .getImage(getClass().getResource("/Resources/Images/book-icon_acc.png"))); // Set custom fonts try {//from w w w . java 2 s . c o m GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // Load Gill Sans from resources Font gillSansFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/GILLSANS.TTF")); ge.registerFont(gillSansFontFace); tabbedPane.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); questionLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); checkButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); youAreViewingLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); quoteIndexTextField.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 24f)); totalNumberLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 36f)); goButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f)); randomButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f)); backButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); clueLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); passageLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); exampleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); commentsLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); realAnswerLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); realAnswerTitleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); // Load the FreeStyle Script font from resources Font freeStyleFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/FREESCPT.TTF")); ge.registerFont(freeStyleFontFace); salutationLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f)); signatureLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f)); } catch (FontFormatException ex) { Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex); } JSONParser parser = new JSONParser(); try { // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package. Object quoteObj = parser .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json"))); // This casts the object to a JSONObject for future manipulation JSONObject jsonObject = (JSONObject) quoteObj; // This array holds all the quotes JSONArray quotesArray = (JSONArray) jsonObject.get("A Christmas Carol"); Iterator<JSONObject> iterator = quotesArray.iterator(); // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList while (iterator.hasNext()) { Collections.addAll(quotesList, iterator.next()); totalNumberOfQuotes++; } // Init randomizer Random rand = new Random(); // Generate a random integer between 1 and size of the ArrayList quoteIndex = rand.nextInt(quotesList.size()) + 1; generateQuote(quoteIndex); // This calls a method to generate a quote and display it } catch (Exception e) { // This means something went very wrong when starting the program System.out.println("Uh oh, something bad happened. Possible database corruption."); JOptionPane.showMessageDialog(null, "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } }
From source file:literarytermsquestionbank.RomeoAndJuliet.java
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened // Set custom icon this.setIconImage( Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/Images/book-icon_rj.png"))); // Set custom fonts try {/*from w ww . java2 s . c o m*/ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // Load Old English from resources Font englishFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/OLDENGL.TTF")); ge.registerFont(englishFontFace); actLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 30f)); sceneLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f)); lineNumberLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f)); // Load Matura Script font from resources Font maturaFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/MATURASC.TTF")); ge.registerFont(maturaFontFace); tabbedPane.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f)); questionLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f)); checkButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f)); stuckLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f)); rescueButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f)); answerLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f)); youAreViewingLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f)); quoteIndexTextField.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f)); totalNumberLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 36f)); goButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f)); randomButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f)); previousButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f)); nextButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f)); backButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f)); // Load Corsova font from resources Font corsovaFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/MTCORSVA.TTF")); ge.registerFont(corsovaFontFace); clueLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f)); passageLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f)); examplesLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f)); commentsLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 14f)); // Load Imprint font from resources Font imprintFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/IMPRISHA.TTF")); ge.registerFont(imprintFontFace); quoteTopLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f)); quoteBottomLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f)); } catch (FontFormatException ex) { Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex); } JSONParser parser = new JSONParser(); try { // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package. Object quoteObj = parser .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json"))); // This casts the object to a JSONObject for future manipulation JSONObject jsonObject = (JSONObject) quoteObj; // This array holds all the quotes JSONArray quotesArray = (JSONArray) jsonObject.get("Romeo and Juliet"); Iterator<JSONObject> iterator = quotesArray.iterator(); // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList while (iterator.hasNext()) { Collections.addAll(quotesList, iterator.next()); totalNumberOfQuotes++; } // Init randomizer Random rand = new Random(); // Generate a random integer between 1 and size of the ArrayList quoteIndex = rand.nextInt(quotesList.size()) + 1; generateQuote(quoteIndex); // This calls a method to generate a quote and display it } catch (Exception e) { // This means something went very wrong when starting the program System.out.println("Uh oh, something bad happened. Possible database corruption."); JOptionPane.showMessageDialog(null, "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } }
From source file:literarytermsquestionbank.ShortStories.java
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened // Set window icon this.setIconImage( Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/Images/book-icon_ss.png"))); // Set custom fonts try {//from www . j a va 2 s. co m GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // Load Great Vibes from resources Font bradleyFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/BRADHITC.TTF")); ge.registerFont(bradleyFontFace); questionLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f)); checkButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 36f)); stuckLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f)); rescueButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); answerLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); youAreViewingLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); quoteIndexTextField.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); totalNumberLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 36f)); goButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); randomButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); previousButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); nextButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); backButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f)); clueTitleLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f)); clueLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f)); passageLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f)); examplesLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f)); commentsLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f)); storyLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 20f)); tabbedPane.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); menuTitleLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f)); // Load and set Imprint font face Font imprintFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/IMPRISHA.TTF")); ge.registerFont(imprintFontFace); quoteTopLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f)); quoteBottomLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f)); } catch (FontFormatException ex) { Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex); } JSONParser parser = new JSONParser(); try { // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package. Object quoteObj = parser .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json"))); // This casts the object to a JSONObject for future manipulation JSONObject jsonObject = (JSONObject) quoteObj; // This array holds all the quotes JSONArray quotesArray = (JSONArray) jsonObject.get("Short Stories"); Iterator<JSONObject> iterator = quotesArray.iterator(); // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList while (iterator.hasNext()) { Collections.addAll(quotesList, iterator.next()); totalNumberOfQuotes++; } // Init randomizer Random rand = new Random(); // Generate a random integer between 1 and size of the ArrayList quoteIndex = rand.nextInt(quotesList.size()) + 1; generateQuote(quoteIndex); // This calls a method to generate a quote and display it } catch (Exception e) { // This means something went very wrong when starting the program System.out.println("Uh oh, something bad happened. Possible database corruption."); JOptionPane.showMessageDialog(null, "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } }