List of usage examples for java.awt Font Font
private Font(String name, int style, float sizePts)
From source file:D20140128.ApacheXMLGraphicsTest.EPSExample1.java
/** * Creates an EPS file. The contents are painted using a Graphics2D * implementation that generates an EPS file. * * @param outputFile the target file/* w w w . j av a 2 s . co m*/ * @throws IOException In case of an I/O error */ public static void generateEPSusingJava2D(File outputFile) throws IOException { OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { //Instantiate the EPSDocumentGraphics2D instance EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); //Set up the document size g2d.setupDocument(out, 400, 200); //400pt x 200pt //Paint a bounding box g2d.drawRect(0, 0, 400, 200); //A few rectangles rotated and with different color Graphics2D copy = (Graphics2D) g2d.create(); int c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(0.0f, 1 - f, 0.0f); copy.setColor(col); copy.fillRect(70, 90, 50, 50); copy.rotate(-2 * Math.PI / (double) c, 70, 90); } copy.dispose(); //Some text g2d.rotate(-0.25); g2d.setColor(Color.RED); g2d.setFont(new Font("sans-serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 140); g2d.setColor(Color.RED.darker()); g2d.setFont(new Font("serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 180); //Cleanup g2d.finish(); } finally { IOUtils.closeQuietly(out); } }
From source file:Main.java
public Main() { setSize(500, 340);/*w w w . j a v a2 s .c o m*/ Date currentDate = new Date(); calendar.setTime(currentDate); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(4, 1)); JPanel p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Selected Date")); dateLabel = new JLabel(dateFormat.format(currentDate) + " "); dateLabel.setFont(new Font("Arial", Font.BOLD, 24)); p.add(dateLabel); p1.add(p); yearSlider.setPaintLabels(true); yearSlider.setMajorTickSpacing(5); yearSlider.setMinorTickSpacing(1); yearSlider.setPaintTicks(true); DateListener lst = new DateListener(); yearSlider.addChangeListener(lst); p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Year")); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(Box.createRigidArea(RIGID_DIMENSION)); p.add(yearSlider); p.add(Box.createRigidArea(RIGID_DIMENSION)); p1.add(p); String[] months = (new DateFormatSymbols()).getShortMonths(); hashTable = new Hashtable(12); for (int i = 0; i < 12; i++) hashTable.put(new Integer(i + 1), new JLabel(months[i], JLabel.CENTER)); monthSlider.setLabelTable(hashTable); monthSlider.setPaintLabels(true); monthSlider.setMajorTickSpacing(1); monthSlider.setPaintTicks(true); monthSlider.addChangeListener(lst); p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Month")); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(Box.createRigidArea(RIGID_DIMENSION)); p.add(monthSlider); p.add(Box.createRigidArea(RIGID_DIMENSION)); p1.add(p); int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); daySlider = new JSlider(JSlider.HORIZONTAL, 1, maxDays, calendar.get(Calendar.DAY_OF_MONTH)); daySlider.setPaintLabels(true); daySlider.setMajorTickSpacing(5); daySlider.setMinorTickSpacing(1); daySlider.setPaintTicks(true); daySlider.addChangeListener(lst); p = new JPanel(); p.setBorder(new TitledBorder(new EtchedBorder(), "Day")); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(Box.createRigidArea(RIGID_DIMENSION)); p.add(daySlider); p.add(Box.createRigidArea(RIGID_DIMENSION)); p1.add(p); getContentPane().add(p1, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); enableEvents(ComponentEvent.COMPONENT_RESIZED); setVisible(true); }
From source file:RadioButtonTest.java
public RadioButtonFrame() { setTitle("RadioButtonTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add the sample text label label = new JLabel("The quick brown fox jumps over the lazy dog."); label.setFont(new Font("Serif", Font.PLAIN, DEFAULT_SIZE)); add(label, BorderLayout.CENTER); // add the radio buttons buttonPanel = new JPanel(); group = new ButtonGroup(); addRadioButton("Small", 8); addRadioButton("Medium", 12); addRadioButton("Large", 18); addRadioButton("Extra large", 36); add(buttonPanel, BorderLayout.SOUTH); }
From source file:unusedClasses.MemoryUsageDemo.java
public MemoryUsageDemo(int paramInt) { super(new BorderLayout()); this.total.setMaximumItemAge(paramInt); this.free = new TimeSeries("Free Memory"); this.free.setMaximumItemAge(paramInt); TimeSeriesCollection localTimeSeriesCollection = new TimeSeriesCollection(); localTimeSeriesCollection.addSeries(this.total); localTimeSeriesCollection.addSeries(this.free); DateAxis localDateAxis = new DateAxis("Time"); NumberAxis localNumberAxis = new NumberAxis("Memory"); localDateAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); localNumberAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); localDateAxis.setLabelFont(new Font("SansSerif", 0, 14)); localNumberAxis.setLabelFont(new Font("SansSerif", 0, 14)); XYLineAndShapeRenderer localXYLineAndShapeRenderer = new XYLineAndShapeRenderer(true, false); localXYLineAndShapeRenderer.setSeriesPaint(0, Color.red); localXYLineAndShapeRenderer.setSeriesPaint(1, Color.green); localXYLineAndShapeRenderer.setSeriesStroke(0, new BasicStroke(3.0F, 0, 2)); localXYLineAndShapeRenderer.setSeriesStroke(1, new BasicStroke(3.0F, 0, 2)); XYPlot localXYPlot = new XYPlot(localTimeSeriesCollection, localDateAxis, localNumberAxis, localXYLineAndShapeRenderer); localDateAxis.setAutoRange(true);// ww w . ja v a 2s . c o m localDateAxis.setLowerMargin(0.0D); localDateAxis.setUpperMargin(0.0D); localDateAxis.setTickLabelsVisible(true); localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart localJFreeChart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), localXYPlot, true); ChartUtilities.applyCurrentTheme(localJFreeChart); ChartPanel localChartPanel = new ChartPanel(localJFreeChart, true); localChartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(localChartPanel); }
From source file:TextLayoutWithCarets.java
private void initialize(Graphics2D g2) { String s = "Java Source and Support."; // Create a plain and italic font. int fontSize = 32; Font font = new Font("Lucida Sans Regular", Font.PLAIN, fontSize); Font italicFont = new Font("Lucida Sans Oblique", Font.ITALIC, fontSize); // Create an Attributed String AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, font); as.addAttribute(TextAttribute.FONT, italicFont, 2, 5); // Get the iterator. AttributedCharacterIterator iterator = as.getIterator(); // Create a TextLayout. FontRenderContext frc = g2.getFontRenderContext(); mLayout = new TextLayout(iterator, frc); mHit = mLayout.getNextLeftHit(1);/*from w ww. j av a2 s . c o m*/ // Respond to left and right arrow keys. mInitialized = true; }
From source file:demo.BarChartDemo11.java
/** * Creates a sample chart.//from w ww .j av a 2 s . c om * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Open Source Projects By License", "License", "Percent", dataset); chart.removeLegend(); TextTitle source = new TextTitle( "Source: http://www.blackducksoftware.com/resources/data/top-20-licenses (as at 30 Aug 2013)", new Font("Dialog", Font.PLAIN, 9)); source.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(source); // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setDomainGridlinesVisible(true); plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(0.8f); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator("{1}: {2} percent", new DecimalFormat("0")); renderer.setBaseToolTipGenerator(tt); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.BLUE, 0.0f, 0.0f, new Color(0, 0, 64)); renderer.setSeriesPaint(0, gp0); return chart; }
From source file:charts.AceptadosRechazadosPie.java
private JFreeChart createChart(PieDataset dataset, String title) { JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false); // createBarChart(title, "Cantidades", "Estado de las trazas", dataset, PlotOrientation.VERTICAL, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 11)); plot.setNoDataMessage("no data"); plot.setCircular(false);//from www. jav a 2 s.co m plot.setLabelGap(0.02); return chart; }
From source file:net.sf.mzmine.chartbasics.chartthemes.ChartThemeFactory.java
public static EStandardChartTheme changeChartThemeForPrintOrPresentation(EStandardChartTheme theme, boolean forPrint) { if (forPrint) { // Fonts/* www . j a va 2s . c o m*/ theme.setExtraLargeFont(new Font("Arial", Font.BOLD, 16)); theme.setLargeFont(new Font("Arial", Font.BOLD, 11)); theme.setRegularFont(new Font("Arial", Font.PLAIN, 11)); theme.setSmallFont(new Font("Arial", Font.PLAIN, 11)); } else { // for presentation larger fonts // Fonts theme.setExtraLargeFont(new Font("Arial", Font.BOLD, 30)); theme.setLargeFont(new Font("Arial", Font.BOLD, 20)); theme.setRegularFont(new Font("Arial", Font.PLAIN, 16)); theme.setSmallFont(new Font("Arial", Font.PLAIN, 16)); } return theme; }
From source file:jmbench.plots.OverallRelativeAreaPlot.java
public OverallRelativeAreaPlot(String title, int sizes[]) { // createAreaChart chart = ChartFactory.createStackedAreaChart(title, // chart title "Size", // domain axis label "Relative Average Speed", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, false);// w w w. j a v a2 s. c om chart.addSubtitle(new TextTitle("Weighted by Operation Speed. Larger is Better.", new Font("SansSerif", Font.ITALIC, 12))); plot = chart.getCategoryPlot(); sizeNames = new String[sizes.length]; for (int i = 0; i < sizes.length; i++) { sizeNames[i] = Integer.toString(sizes[i]); } plot.setRangeGridlinePaint(Color.WHITE); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); }
From source file:org.jfree.chart.demo.CategoryMarkerDemo2.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createLineChart("Category Marker Demo 2", "Category", "Count", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setSeriesShapesVisible(0, true); lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setBaseFillPaint(Color.white); CategoryMarker categorymarker = new CategoryMarker("Category 4", new Color(0, 0, 255, 25), new BasicStroke(1.0F)); categorymarker.setDrawAsLine(false); categorymarker.setAlpha(1.0F);/*from w w w. j a va2 s . c o m*/ categorymarker.setLabel("Marker Label"); categorymarker.setLabelFont(new Font("Dialog", 0, 11)); categorymarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); categorymarker.setLabelOffset(new RectangleInsets(2D, 5D, 2D, 5D)); categoryplot.addDomainMarker(categorymarker, Layer.BACKGROUND); return jfreechart; }