List of usage examples for java.awt Font TRUETYPE_FONT
int TRUETYPE_FONT
To view the source code for java.awt Font TRUETYPE_FONT.
Click Source Link
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 va 2 s .co m*/ 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:com.netsteadfast.greenstep.action.CommonMeterChartAction.java
private void fillChart(String title, float value, int lowerBound, int upperBound) throws Exception { DefaultValueDataset dataset = new DefaultValueDataset(); dataset.setValue(value);// w ww. ja v a 2s . com DialPlot plot = new DialPlot(); plot.setView(0.0d, 0.0d, 1.0d, 1.0d); plot.setDataset(0, dataset); StandardDialFrame frame = new StandardDialFrame(); plot.setDialFrame(frame); DialBackground dialBackground = new DialBackground(); dialBackground.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(dialBackground); DialTextAnnotation textAnnotation = new DialTextAnnotation(title); textAnnotation.setRadius(0.555555555555555555D); plot.addLayer(textAnnotation); DialValueIndicator valueIndicator = new DialValueIndicator(0); plot.addLayer(valueIndicator); StandardDialScale scale1 = new StandardDialScale(); scale1.setLowerBound(lowerBound); scale1.setUpperBound(upperBound); scale1.setStartAngle(-140); // -120 scale1.setExtent(-260D); // -300D scale1.setTickRadius(0.88D); scale1.setTickLabelOffset(0.14999999999999999D); scale1.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 14)); plot.addScale(0, scale1); StandardDialRange standarddialrange0 = new StandardDialRange(lowerBound, (upperBound * 0.6), Color.red); standarddialrange0.setInnerRadius(0.52000000000000002D); standarddialrange0.setOuterRadius(0.55000000000000004D); plot.addLayer(standarddialrange0); StandardDialRange standarddialrange1 = new StandardDialRange((upperBound * 0.6), (upperBound * 0.8), Color.orange); standarddialrange1.setInnerRadius(0.52000000000000002D); standarddialrange1.setOuterRadius(0.55000000000000004D); plot.addLayer(standarddialrange1); StandardDialRange standarddialrange2 = new StandardDialRange((upperBound * 0.8), upperBound, Color.green); standarddialrange2.setInnerRadius(0.52000000000000002D); standarddialrange2.setOuterRadius(0.55000000000000004D); plot.addLayer(standarddialrange2); Pointer pointer = new Pointer(0); pointer.setFillPaint(new Color(144, 196, 246)); plot.addPointer(pointer); plot.mapDatasetToScale(0, 0); DialCap dialcap = new DialCap(); dialcap.setRadius(0.0700000000000001D); plot.setCap(dialcap); this.chart = new JFreeChart(plot); //this.chart.setBackgroundPaint(new Color(234, 244, 253)); this.chart.setBackgroundPaint(Color.white); }
From source file:org.jfree.eastwood.ChartServlet.java
private Font readFontResource(ServletContext ctx, String fontResourceParam, float fontSize) throws ServletException { if (!fontResourceParam.startsWith("/")) { fontResourceParam = "/" + fontResourceParam; }// www . j a v a 2s. c o m 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: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 w w. j ava2 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 ww . j av a2s . c om*/ * * @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:org.jfree.eastwood.ChartServlet.java
private Font readFontFile(String fontFileParam, float fontSize) throws ServletException { File f = new File(fontFileParam); if (!f.exists()) { throw new ServletException("Font file '" + f + "' doesn't exist"); }//from w w w . j a v a2 s . co m try { FileInputStream fis = new FileInputStream(f); Font font = Font.createFont(Font.TRUETYPE_FONT, fis).deriveFont(fontSize); fis.close(); return font; } catch (FontFormatException e) { throw new ServletException("Font file '" + f + "' is not a truetype font", e); } catch (IOException e) { throw new ServletException("I/O error when reading font file '" + f + "'", e); } }
From source file:view.AppearanceSettingsDialog.java
/** * Creates new form NewJDialog//from w ww .j ava2s . c o m * * @param parent * @param modal * @param signatureSettings */ public AppearanceSettingsDialog(java.awt.Frame parent, boolean modal, CCSignatureSettings signatureSettings) { super(parent, modal); initComponents(); this.signatureSettings = signatureSettings; updateText(); // Pastas conforme o SO ArrayList<String> dirs = new ArrayList<>(); if (SystemUtils.IS_OS_WINDOWS) { dirs.add(System.getenv("windir") + File.separator + "fonts"); } else if (SystemUtils.IS_OS_LINUX) { dirs.add("/usr/share/fonts/truetype/"); dirs.add("/usr/X11R6/lib/X11/fonts/"); } else if (SystemUtils.IS_OS_MAC_OSX) { dirs.add("/Library/Fonts"); dirs.add("/System/Library/Fonts"); } dirs.add("extrafonts"); // Hashmap com fonts hmFonts = getAllFonts(dirs); ArrayList<com.itextpdf.text.Font> alFonts = new ArrayList<>(hmFonts.keySet()); Collections.sort(alFonts, new Comparator<com.itextpdf.text.Font>() { @Override public int compare(com.itextpdf.text.Font f1, com.itextpdf.text.Font f2) { return f1.getFamilyname().compareToIgnoreCase(f2.getFamilyname()); } }); DefaultComboBoxModel dcbm = new DefaultComboBoxModel(); for (com.itextpdf.text.Font font : alFonts) { dcbm.addElement(font.getFamilyname()); } cbFontType.setModel(dcbm); String fontLocation = signatureSettings.getAppearance().getFontLocation(); boolean italic = signatureSettings.getAppearance().isItalic(); boolean bold = signatureSettings.getAppearance().isBold(); boolean showName = signatureSettings.getAppearance().isShowName(); boolean showLocation = signatureSettings.getAppearance().isShowLocation(); boolean showReason = signatureSettings.getAppearance().isShowReason(); boolean showDate = signatureSettings.getAppearance().isShowDate(); int align = signatureSettings.getAppearance().getAlign(); switch (align) { case 0: cbAlign.setSelectedIndex(0); break; case 1: cbAlign.setSelectedIndex(1); break; case 2: cbAlign.setSelectedIndex(2); break; default: cbAlign.setSelectedIndex(0); } previewPanel1.setReason(signatureSettings.getReason()); previewPanel1.setShowDate(showDate); if (signatureSettings.getCcAlias() != null) { previewPanel1.setAliasName(signatureSettings.getCcAlias().getName()); } else { previewPanel1.setAliasName(Bundle.getBundle().getString("name")); } if (!signatureSettings.getLocation().isEmpty()) { previewPanel1.setLocation(signatureSettings.getLocation()); cbShowLocation.setSelected(showLocation); previewPanel1.setShowLocation(showLocation); } else { cbShowLocation.setEnabled(false); cbShowLocation.setSelected(false); } cbShowName.setSelected(showName); previewPanel1.setShowName(showName); if (!signatureSettings.getReason().isEmpty()) { previewPanel1.setReason(signatureSettings.getReason()); cbShowReason.setSelected(showReason); previewPanel1.setShowReason(showReason); } else { cbShowReason.setEnabled(false); cbShowReason.setSelected(false); } previewPanel1.setText(signatureSettings.getText()); previewPanel1.setAlign(align); colorChooser.setPreviewPanel(new JPanel()); Color color = signatureSettings.getAppearance().getFontColor(); colorChooser.setColor(color); lblSampleText.setForeground(color); cbShowReason.setSelected(showReason); cbShowLocation.setSelected(showLocation); cbShowDateTime.setSelected(showDate); ColorSelectionModel model = colorChooser.getSelectionModel(); ChangeListener changeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent changeEvent) { Color newForegroundColor = colorChooser.getColor(); lblSampleText.setForeground(newForegroundColor); } }; model.addChangeListener(changeListener); if (fontLocation.contains("aCCinaPDF" + File.separator + "extrafonts")) { try { Font newFont = Font.createFont(Font.TRUETYPE_FONT, new File(fontLocation)); Font font = null; if (italic && bold) { font = newFont.deriveFont(Font.ITALIC + Font.BOLD, 36); } else if (italic && !bold) { font = newFont.deriveFont(Font.ITALIC, 36); } else if (!italic && bold) { font = newFont.deriveFont(Font.BOLD, 36); } else { font = newFont.deriveFont(Font.PLAIN, 36); } lblSampleText.setFont(font); } catch (FontFormatException | IOException ex) { } } else { if (italic && bold) { lblSampleText.setFont(new Font(fontLocation, Font.ITALIC + Font.BOLD, 36)); } else if (italic && !bold) { lblSampleText.setFont(new Font(fontLocation, Font.ITALIC, 36)); } else if (!italic && bold) { lblSampleText.setFont(new Font(fontLocation, Font.BOLD, 36)); } else { lblSampleText.setFont(new Font(fontLocation, Font.PLAIN, 36)); } } cbBold.setSelected(bold); cbItalic.setSelected(italic); updateSettings(fontLocation, bold, italic); previewPanel1.repaint(); }
From source file:net.technicpack.launcher.lang.ResourceLoader.java
public Font getFont(String name, float size, int style) { Font font;//from ww w. j a va2s . c o m try { font = Font .createFont(Font.TRUETYPE_FONT, ResourceLoader.class.getResourceAsStream(getResourcePath("/fonts/" + getString(name)))) .deriveFont(size).deriveFont(style); } catch (Exception e) { e.printStackTrace(); // Fallback font = new Font("Arial", Font.PLAIN, 12); } return font; }
From source file:virgil.meanback.HistoryInfo.java
public void printChart(Stock stock, List<String[]> list, int days) throws Exception { //?/*from w w w. j av a 2 s . c o m*/ StandardChartTheme standardChartTheme = new StandardChartTheme("CN"); // standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20)); // standardChartTheme.setRegularFont(new Font("", Font.BOLD, 12)); //? standardChartTheme.setLargeFont(new Font("", Font.BOLD, 18)); //? ChartFactory.setChartTheme(standardChartTheme); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = list.size() - 1; i >= 0; i--) { String[] s = (String[]) list.get(i); dataSet.addValue(Double.parseDouble(s[1]), days + "", s[0]); dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "", s[0]); float sub = Float.parseFloat(s[2]); float error = Float.parseFloat(s[3]); if (sub > error * 2) { dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "??", s[0]); } } //?????Legend //???? //??URL JFreeChart chart = ChartFactory.createLineChart( stock.getName() + "(" + stock.getCode() + ") ", "", "", dataSet, PlotOrientation.VERTICAL, true, true, false); CategoryPlot cp = chart.getCategoryPlot(); cp.setBackgroundPaint(ChartColor.WHITE); // CategoryAxis categoryAxis = cp.getDomainAxis(); // Lable 90 Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 10); categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); categoryAxis.setTickLabelFont(labelFont);//X?? ValueAxis yAxis = cp.getRangeAxis(); yAxis.setAutoRange(true); double[] d = getAxiasThresold(stock, list); yAxis.setLowerBound(d[0] - 0.15); yAxis.setUpperBound(d[1] + 0.15); LineAndShapeRenderer lasp = (LineAndShapeRenderer) cp.getRenderer(); lasp.setBaseFillPaint(ChartColor.RED); lasp.setDrawOutlines(true); lasp.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D)); LineAndShapeRenderer renderer = (LineAndShapeRenderer) cp.getRenderer(1);//? DecimalFormat decimalformat1 = new DecimalFormat("##.##");//??? renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); //???? renderer.setItemLabelsVisible(true);// renderer.setBaseItemLabelsVisible(true);// //????? renderer.setShapesFilled(Boolean.TRUE);//?? renderer.setShapesVisible(true);//? ChartFrame chartFrame = new ChartFrame("??", chart, true); //chart?JavaChartFramejavaJframe???? chartFrame.pack(); //?? chartFrame.setVisible(true);//??? }
From source file:Util.PacketGenerator.java
public static void GenerateGraph() { try {//from w w w.j a v a2s. c om for (int j = 6; j <= 6; j++) { File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\Real.csv"); for (int k = 1; k <= 4; k++) { File simu = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".csv"); FileInputStream simuFIS = new FileInputStream(simu); DataInputStream simuDIS = new DataInputStream(simuFIS); BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS)); FileInputStream realFIS = new FileInputStream(real); DataInputStream realDIS = new DataInputStream(realFIS); BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS)); String lineSimu = simuBR.readLine(); String lineReal = realBR.readLine(); XYSeries matrix = new XYSeries("Matriz", false, true); while (lineSimu != null && lineReal != null) { lineSimu = lineSimu.replaceAll(",", "."); String[] simuMatriz = lineSimu.split(";"); String[] realMatriz = lineReal.split(";"); for (int i = 0; i < simuMatriz.length; i++) { try { Integer valorReal = Integer.parseInt(realMatriz[i]); Float valorSimu = Float.parseFloat(simuMatriz[i]); matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0); } catch (NumberFormatException ex) { } } lineSimu = simuBR.readLine(); lineReal = realBR.readLine(); } simuFIS.close(); simuDIS.close(); simuBR.close(); realFIS.close(); realDIS.close(); realBR.close(); double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1; XYSeries middle = new XYSeries("Referncia"); ; middle.add(0, 0); middle.add(maxPlot, maxPlot); XYSeries max = new XYSeries("Superior 20%"); max.add(0, 0); max.add(maxPlot, maxPlot * 1.2); XYSeries min = new XYSeries("Inferior 20%"); min.add(0, 0); min.add(maxPlot, maxPlot * 0.8); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(middle); dataset.addSeries(matrix); dataset.addSeries(max); dataset.addSeries(min); JFreeChart chart; if (k == 4) { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset); } else { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset); } chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13)); chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10)); chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getDomainAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getRangeAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0.1f }, 0.0f)); renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesPaint(1, Color.BLACK); renderer.setSeriesPaint(2, Color.BLACK); renderer.setSeriesPaint(3, Color.BLACK); int width = (int) (192 * 1.5f); /* Width of the image */ int height = (int) (144 * 1.5f); /* Height of the image */ File XYChart = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".jpeg"); ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height); } } } catch (Exception e) { e.printStackTrace(); } }