List of usage examples for java.awt Font Font
private Font(String name, int style, float sizePts)
From source file:include.picture.MyBarChart.java
/** *? *///from ww w . j a v a2 s. co m public void paint() { try { check(); CategoryDataset dataset = getDataSet(series, category, data); JFreeChart chart = ChartFactory.createBarChart3D(title, axisXLabel, axisYLabel, dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.WHITE); BarRenderer3D renderer = new BarRenderer3D(); CategoryPlot plot = chart.getCategoryPlot(); renderer.setMaxBarWidth(0.01); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("", Font.PLAIN, 15)); renderer.setItemLabelsVisible(true); renderer.setItemMargin(0.1); plot.setRenderer(renderer); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(fileName); ChartUtilities.writeChartAsJPEG(fos_jpg, 1000, chart, width, height, null); } finally { try { fos_jpg.close(); } catch (Exception e) { } } } catch (Exception e) { e.printStackTrace(); } // end of try-catch }
From source file:components.SplitPaneDividerDemo.java
public SplitPaneDividerDemo() { super(new BorderLayout()); Font font = new Font("Serif", Font.ITALIC, 24); ImageIcon icon = createImageIcon("images/Cat.gif"); SizeDisplayer sd1 = new SizeDisplayer("left", icon); sd1.setMinimumSize(new Dimension(30, 30)); sd1.setFont(font);//w w w . ja v a 2 s .c o m icon = createImageIcon("images/Dog.gif"); SizeDisplayer sd2 = new SizeDisplayer("right", icon); sd2.setMinimumSize(new Dimension(60, 60)); sd2.setFont(font); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sd1, sd2); splitPane.setResizeWeight(0.5); splitPane.setOneTouchExpandable(true); splitPane.setContinuousLayout(true); add(splitPane, BorderLayout.CENTER); add(createControlPanel(), BorderLayout.PAGE_END); }
From source file:qmod.generator.MainWindow.java
@SuppressWarnings("unchecked") public MainWindow() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Quick Mod Generator"); JLabel lblAuthors = new JLabel("Authors:"); authorField1 = new JTextField(); authorField1.setColumns(25);/* w ww. jav a2s .c o m*/ JButton btnGenerateFile = new JButton("Generate File"); btnGenerateFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { writeFiles(); } }); authCombo1.setFont(new Font("Dialog", Font.BOLD, 8)); authCombo1.setModel( (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" })); authCombo1.setSelectedIndex(0); authCombo2.setFont(new Font("Dialog", Font.BOLD, 8)); authCombo2.setModel( (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" })); authCombo2.setSelectedIndex(0); authorField2 = new JTextField(); authorField2.setColumns(25); authCombo3.setFont(new Font("Dialog", Font.BOLD, 8)); authCombo3.setModel( (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" })); authCombo3.setSelectedIndex(0); authorField3 = new JTextField(); authorField3.setColumns(25); JLabel lblCategories = new JLabel("Categories:"); categoriesField = new JTextField(); categoriesField.setColumns(10); JLabel lblDescription = new JLabel("Description:"); JEditorPane descriptionField = new JEditorPane(); JLabel lblLicense = new JLabel("License:"); licenseField = new JTextField(); licenseField.setColumns(10); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createParallelGroup(Alignment.TRAILING).addComponent(btnGenerateFile) .addGroup(groupLayout.createSequentialGroup().addComponent(lblAuthors) .addPreferredGap(ComponentPlacement.RELATED).addGroup(groupLayout .createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createSequentialGroup() .addComponent( authCombo2, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) .addGap(6).addComponent(authorField2, GroupLayout.PREFERRED_SIZE, 192, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createSequentialGroup().addComponent( authCombo1, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE).addPreferredGap( ComponentPlacement.RELATED) .addComponent( authorField1, GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)) .addGroup(groupLayout.createSequentialGroup() .addComponent(authCombo3, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) .addGap(6).addGroup(groupLayout.createParallelGroup( Alignment.LEADING).addComponent( descriptionField) .addGroup(groupLayout .createParallelGroup( Alignment.LEADING, false) .addComponent(categoriesField) .addComponent( authorField3, GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)) .addGroup(groupLayout .createSequentialGroup() .addComponent(licenseField, GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE) .addPreferredGap( ComponentPlacement.RELATED))))))) .addComponent(lblCategories).addComponent(lblDescription)) .addGap(84)) .addGroup(groupLayout.createSequentialGroup().addComponent(lblLicense) .addContainerGap(377, Short.MAX_VALUE))))); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createSequentialGroup().addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblAuthors) .addComponent(authorField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(authCombo1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(authCombo2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGroup(groupLayout.createSequentialGroup().addGap(3).addComponent(authorField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(authCombo3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGroup(groupLayout.createSequentialGroup().addGap(3).addComponent(authorField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblCategories) .addComponent(categoriesField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblDescription) .addComponent(descriptionField, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addGap(9).addComponent(lblLicense)) .addGroup(groupLayout.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED) .addComponent(licenseField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED, 322, Short.MAX_VALUE).addComponent(btnGenerateFile) .addContainerGap())); getContentPane().setLayout(groupLayout); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('F'); menuBar.add(mnFile); JMenuItem mntmNew = new JMenuItem("New"); mntmNew.setMnemonic(KeyEvent.VK_N); mnFile.add(mntmNew); JMenuItem mntmOpen = new JMenuItem("Open"); mnFile.add(mntmOpen); JMenuItem mntmSave = new JMenuItem("Save"); mnFile.add(mntmSave); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); mntmExit.setMnemonic(KeyEvent.VK_X); mnFile.add(mntmExit); }
From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java
public static void readData(String inFile, File outdir, String xAxisLabel, String yAxisLabel) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); DefaultBoxAndWhiskerCategoryDataset scatterDataset = new DefaultBoxAndWhiskerCategoryDataset(); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = reader.readLine(); while ((line = reader.readLine()) != null) { String[] values = line.split("\\t"); XYSeries series = new XYSeries(values[2]); dataset.addSeries(series);//from w w w .ja va 2s . c om double average = Double.parseDouble(values[4]); int Q1 = Integer.parseInt(values[6]); ; int median = Integer.parseInt(values[7]); int Q3 = Integer.parseInt(values[8]); int pct_98 = Integer.parseInt(values[9]); int pct_2 = Integer.parseInt(values[10]); int minOutlier = 0; // we don't care about the outliers int maxOutlier = 0; // BoxAndWhiskerItem item = new BoxAndWhiskerItem(average, median, Q1, Q3, pct_2, pct_98, minOutlier, maxOutlier, new ArrayList()); scatterDataset.add(item, values[2], ""); } String title = new File(inFile).getName(); int index = title.indexOf("."); if (index != -1) { title = title.substring(0, index); } Font lableFont = new Font("Helvetica", Font.BOLD, 28); createBoxplot(scatterDataset, new PrintStream(new File(outdir, title + ".boxchart.png")), title, xAxisLabel, yAxisLabel, lableFont); }
From source file:CompositeEffects.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // fill the background g.setPaint(new Color(175, 175, 175)); g.fillRect(0, 0, getWidth(), getHeight()); // Set text attributes g.setColor(Color.black);//from w w w . j av a2 s.com g.setFont(new Font("SansSerif", Font.BOLD, 12)); // Draw the unmodified image g.translate(10, 10); g.drawImage(cover, 0, 0, this); g.drawString("SRC_OVER", 0, COVERHEIGHT + 15); // Draw the cover again, using AlphaComposite to make the opaque // colors of the image 50% translucent g.translate(COVERWIDTH + 10, 0); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); g.drawImage(cover, 0, 0, this); // Restore the pre-defined default Composite for the screen, so // opaque colors stay opaque. g.setComposite(AlphaComposite.SrcOver); // Label the effect g.drawString("SRC_OVER, 50%", 0, COVERHEIGHT + 15); // Now get an offscreen image to work with. In order to achieve // certain compositing effects, the drawing surface must support // transparency. Onscreen drawing surfaces cannot, so we have to do the // compositing in an offscreen image that is specially created to have // an "alpha channel", then copy the final result to the screen. BufferedImage offscreen = new BufferedImage(COVERWIDTH, COVERHEIGHT, BufferedImage.TYPE_INT_ARGB); // First, fill the image with a color gradient background that varies // left-to-right from opaque to transparent yellow Graphics2D osg = offscreen.createGraphics(); osg.setPaint(new GradientPaint(0, 0, Color.yellow, COVERWIDTH, 0, new Color(255, 255, 0, 0))); osg.fillRect(0, 0, COVERWIDTH, COVERHEIGHT); // Now copy the cover image on top of this, but use the DstOver rule // which draws it "underneath" the existing pixels, and allows the // image to show depending on the transparency of those pixels. osg.setComposite(AlphaComposite.DstOver); osg.drawImage(cover, 0, 0, this); // And display this composited image on the screen. Note that the // image is opaque and that none of the screen background shows through g.translate(COVERWIDTH + 10, 0); g.drawImage(offscreen, 0, 0, this); g.drawString("DST_OVER", 0, COVERHEIGHT + 15); // Now start over and do a new effect with the off-screen image. // First, fill the offscreen image with a new color gradient. We // don't care about the colors themselves; we just want the // translucency of the background to vary. We use opaque black to // transparent black. Note that since we've already used this offscreen // image, we set the composite to Src, we can fill the image and // ignore anything that is already there. osg.setComposite(AlphaComposite.Src); osg.setPaint(new GradientPaint(0, 0, Color.black, COVERWIDTH, COVERHEIGHT, new Color(0, 0, 0, 0))); osg.fillRect(0, 0, COVERWIDTH, COVERHEIGHT); // Now set the compositing type to SrcIn, so colors come from the // source, but translucency comes from the destination osg.setComposite(AlphaComposite.SrcIn); // Draw our loaded image into the off-screen image, compositing it. osg.drawImage(cover, 0, 0, this); // And then copy our off-screen image to the screen. Note that the // image is translucent and some of the image shows through. g.translate(COVERWIDTH + 10, 0); g.drawImage(offscreen, 0, 0, this); g.drawString("SRC_IN", 0, COVERHEIGHT + 15); // If we do the same thing but use SrcOut, then the resulting image // will have the inverted translucency values of the destination osg.setComposite(AlphaComposite.Src); osg.setPaint(new GradientPaint(0, 0, Color.black, COVERWIDTH, COVERHEIGHT, new Color(0, 0, 0, 0))); osg.fillRect(0, 0, COVERWIDTH, COVERHEIGHT); osg.setComposite(AlphaComposite.SrcOut); osg.drawImage(cover, 0, 0, this); g.translate(COVERWIDTH + 10, 0); g.drawImage(offscreen, 0, 0, this); g.drawString("SRC_OUT", 0, COVERHEIGHT + 15); // Here's a cool effect; it has nothing to do with compositing, but // uses an arbitrary shape to clip the image. It uses Area to combine // shapes into more complicated ones. g.translate(COVERWIDTH + 10, 0); Shape savedClip = g.getClip(); // Save current clipping region // Create a shape to use as the new clipping region. // Begin with an ellipse Area clip = new Area(new Ellipse2D.Float(0, 0, COVERWIDTH, COVERHEIGHT)); // Intersect with a rectangle, truncating the ellipse. clip.intersect(new Area(new Rectangle(5, 5, COVERWIDTH - 10, COVERHEIGHT - 10))); // Then subtract an ellipse from the bottom of the truncated ellipse. clip.subtract(new Area(new Ellipse2D.Float(COVERWIDTH / 2 - 40, COVERHEIGHT - 20, 80, 40))); // Use the resulting shape as the new clipping region g.clip(clip); // Then draw the image through this clipping region g.drawImage(cover, 0, 0, this); // Restore the old clipping region so we can label the effect g.setClip(savedClip); g.drawString("Clipping", 0, COVERHEIGHT + 15); }
From source file:FontDialog.java
public void updateFont() { Font font = new Font((String) style.getSelectedValue(), (bold.isSelected() ? Font.BOLD : 0) + (italic.isSelected() ? Font.ITALIC : 0), Integer.parseInt(size.getText())); sample.setFont(font);// ww w . j a va 2 s .c om repaint(); }
From source file:jesse.GA_ANN.DataVis.java
JFreeChart createChart()//Here Input MillSecond { total = new XYSeries[10]; XYSeriescollection = new XYSeriesCollection(); for (int i = 0; i < 10; i++) { total[i] = new XYSeries(i); XYSeriescollection.addSeries(total[i]); }//from w ww.ja v a 2 s .c o m dateaxis = new NumberAxis("Time"); NumberAxis Conaxis = new NumberAxis("z??"); dateaxis.setAutoRange(true); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); dateaxis.setTickLabelsVisible(true); xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.green); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1F, 0, 2)); xylineandshaperenderer.setFillPaint(new Color(30, 30, 220), true); Conaxis.setRange(-1, 1); Conaxis.setAutoRange(true); Conaxis.setAutoRangeIncludesZero(false); XYPlot xyplot = new XYPlot(XYSeriescollection, dateaxis, Conaxis, xylineandshaperenderer); JFreeChart jfreechart = new JFreeChart("time-z", new Font("Arial", 1, 24), xyplot, true); ChartUtilities.applyCurrentTheme(jfreechart); ChartPanel chartpanel = new ChartPanel(jfreechart, true); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); return jfreechart; }
From source file:com.orsonpdf.demo.PDFTimeSeriesChartDemo1.java
/** * Creates a chart.//from ww w . ja va 2 s . c o m * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", null, "US cents/lb", dataset, true, false, false); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.setRangeGridlinePaint(Color.red); plot.setDomainGridlinePaint(Color.red); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); // set the default stroke for all series renderer.setAutoPopulateSeriesStroke(false); renderer.setBaseStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, new Color(24, 123, 58)); renderer.setSeriesPaint(2, new Color(149, 201, 136)); renderer.setSeriesPaint(3, new Color(1, 62, 29)); renderer.setSeriesPaint(4, new Color(81, 176, 86)); renderer.setSeriesPaint(5, new Color(0, 55, 122)); renderer.setSeriesPaint(6, new Color(0, 92, 165)); } return chart; }
From source file:com.tencent.wstt.apt.chart.PieChart.java
private JFreeChart createChart() { this.dataset = new DefaultPieDataset(); final JFreeChart chart = ChartFactory.createPieChart("??", this.dataset, true, true, false); chart.getTitle().setFont(new Font("", Font.BOLD, 20)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}")); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false);/* w w w .ja v a 2s . c o m*/ plot.setLabelGap(0.02); return chart; }
From source file:CustomStrokes.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Get a shape to work with. Here we'll use the letter B Font f = new Font("Serif", Font.BOLD, 200); GlyphVector gv = f.createGlyphVector(g.getFontRenderContext(), "B"); Shape shape = gv.getOutline(); // Set drawing attributes and starting position g.setColor(Color.black);/* ww w.jav a 2s . com*/ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.translate(10, 175); // Draw the shape once with each stroke for (int i = 0; i < strokes.length; i++) { g.setStroke(strokes[i]); // set the stroke g.draw(shape); // draw the shape g.translate(140, 0); // move to the right } }