List of usage examples for java.awt Font Font
private Font(String name, int style, float sizePts)
From source file:com.limegroup.gnutella.gui.init.LanguagePanel.java
/** * Constructs a LanguagePanel that will notify the given listener when the * language changes.//from w w w . j a va 2s . c o m */ public LanguagePanel(ActionListener actionListener) { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.actionListener = actionListener; this.languageLabel = new JLabel(); languageOptions = new JComboBox<Object>(); Font font = new Font("Dialog", Font.PLAIN, 11); languageOptions.setFont(font); Locale[] locales = LanguageUtils.getLocales(font); languageOptions.setModel(new DefaultComboBoxModel<Object>(locales)); languageOptions.setRenderer(LanguageFlagFactory.getListRenderer()); Locale locale = guessLocale(locales); languageOptions.setSelectedItem(locale); applySettings(false); // It is important that the listener is added after the selected item // is set. Otherwise the listener will call methods that are not ready // to be called at this point. languageOptions.addItemListener(new StateListener()); add(languageLabel); add(Box.createHorizontalStrut(5)); add(languageOptions); }
From source file:com.liusoft.dlog4j.servlet.DLOG_RandomImageServlet.java
/** * ???,,?16,/*from w w w. j av a 2 s .co m*/ * @param num ?? * @param out ? * @throws IOException */ protected static void render(String num, boolean gif, OutputStream out) throws IOException { if (num.getBytes().length > 4) throw new IllegalArgumentException("The length of param num cannot exceed 4."); int width = 40; int height = 15; BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) bi.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); Font mFont = new Font("Tahoma", Font.PLAIN, 14); g.setFont(mFont); g.setColor(Color.BLACK); g.drawString(num, 2, 13); if (gif) { AnimatedGifEncoder e = new AnimatedGifEncoder(); e.setTransparent(Color.WHITE); e.start(out); e.setDelay(0); e.addFrame(bi); e.finish(); } else { ImageIO.write(bi, "png", out); } }
From source file:Paints.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Paint the entire background using a GradientPaint. // The background color varies diagonally from deep red to pale blue g.setPaint(new GradientPaint(0, 0, new Color(150, 0, 0), WIDTH, HEIGHT, new Color(200, 200, 255))); g.fillRect(0, 0, WIDTH, HEIGHT); // fill the background // Use a different GradientPaint to draw a box. // This one alternates between deep opaque green and transparent green. // Note: the 4th arg to Color() constructor specifies color opacity g.setPaint(new GradientPaint(0, 0, new Color(0, 150, 0), 20, 20, new Color(0, 150, 0, 0), true)); g.setStroke(new BasicStroke(15)); // use wide lines g.drawRect(25, 25, WIDTH - 50, HEIGHT - 50); // draw the box // The glyphs of fonts can be used as Shape objects, which enables // us to use Java2D techniques with letters Just as we would with // any other shape. Here we get some letter shapes to draw. Font font = new Font("Serif", Font.BOLD, 10); // a basic font Font bigfont = // a scaled up version font.deriveFont(AffineTransform.getScaleInstance(30.0, 30.0)); GlyphVector gv = bigfont.createGlyphVector(g.getFontRenderContext(), "JAV"); Shape jshape = gv.getGlyphOutline(0); // Shape of letter J Shape ashape = gv.getGlyphOutline(1); // Shape of letter A Shape vshape = gv.getGlyphOutline(2); // Shape of letter V // We're going to outline the letters with a 5-pixel wide line g.setStroke(new BasicStroke(5.0f)); // We're going to fake shadows for the letters using the // following Paint and AffineTransform objects Paint shadowPaint = new Color(0, 0, 0, 100); // Translucent black AffineTransform shadowTransform = AffineTransform.getShearInstance(-1.0, 0.0); // Shear to the right shadowTransform.scale(1.0, 0.5); // Scale height by 1/2 // Move to the baseline of our first letter g.translate(65, 270);//from w w w .ja v a 2 s.c o m // Draw the shadow of the J shape g.setPaint(shadowPaint); g.translate(15, 20); // Compensate for the descender of the J // transform the J into the shape of its shadow, and fill it g.fill(shadowTransform.createTransformedShape(jshape)); g.translate(-15, -20); // Undo the translation above // Now fill the J shape with a solid (and opaque) color g.setPaint(Color.blue); // Fill with solid, opaque blue g.fill(jshape); // Fill the shape g.setPaint(Color.black); // Switch to solid black g.draw(jshape); // And draw the outline of the J // Now draw the A shadow g.translate(75, 0); // Move to the right g.setPaint(shadowPaint); // Set shadow color g.fill(shadowTransform.createTransformedShape(ashape)); // draw shadow // Draw the A shape using a solid transparent color g.setPaint(new Color(0, 255, 0, 125)); // Transparent green as paint g.fill(ashape); // Fill the shape g.setPaint(Color.black); // Switch to solid back g.draw(ashape); // Draw the outline // Move to the right and draw the shadow of the letter V g.translate(175, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(vshape)); // We're going to fill the next letter using a TexturePaint, which // repeatedly tiles an image. The first step is to obtain the image. // We could load it from an image file, but here we create it // ourselves by drawing a into an off-screen image. Note that we use // a GradientPaint to fill the off-screen image, so the fill pattern // combines features of both Paint classes. BufferedImage tile = // Create an image new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB); Graphics2D tg = tile.createGraphics(); // Get its Graphics for drawing tg.setColor(Color.pink); tg.fillRect(0, 0, 50, 50); // Fill tile background with pink tg.setPaint(new GradientPaint(40, 0, Color.green, // diagonal gradient 0, 40, Color.gray)); // green to gray tg.fillOval(5, 5, 40, 40); // Draw a circle with this gradient // Use this new tile to create a TexturePaint and fill the letter V g.setPaint(new TexturePaint(tile, new Rectangle(0, 0, 50, 50))); g.fill(vshape); // Fill letter shape g.setPaint(Color.black); // Switch to solid black g.draw(vshape); // Draw outline of letter // Move to the right and draw the shadow of the final A g.translate(160, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(ashape)); g.fill(ashape); // Fill letter A g.setPaint(Color.black); // Revert to solid black g.draw(ashape); // Draw the outline of the A }
From source file:com.globalsight.util.JfreeCharUtil.java
public static void drawPieChart3D(String title, Map<String, Double> datas, File OutFile) { PieDataset dataset = buildDatas(datas); JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); chart.setBackgroundPaint(Color.white); plot.setForegroundAlpha(0.7f);// www . ja v a2s .co m plot.setCircular(true); TextTitle textTitle = new TextTitle(title); Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20); textTitle.setFont(font); chart.setTitle(textTitle); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(OutFile); ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null); fos_jpg.close(); } catch (Exception e) { s_logger.error(e.getMessage(), e); } }
From source file:playground.anhorni.PLOC.analysis.RunsEnsembleBoxPlot.java
public JFreeChart createChart() { String title = chartTitle;/*www.j a v a2 s . c o m*/ final CategoryAxis xAxis = new CategoryAxis("Hour"); xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10)); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); final NumberAxis yAxis = new NumberAxis("AverageDays_Expenditures"); yAxis.setAutoRangeIncludesZero(true); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setSeriesPaint(0, Color.blue); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false); return this.chart_; }
From source file:net.sf.statcvs.output.xml.chart.AbstractChart.java
/** * create chart with titles and credit information *//*from ww w . j a v a 2 s . co m*/ public void placeTitle() { Font font = new Font("SansSerif", Font.PLAIN, 12); Font creditInformationFont = new Font("SansSerif", Font.PLAIN, 9); TextTitle title = new TextTitle(this.title, font); title.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0)); chart.addSubtitle(title); if (Settings.getShowCreditInformation()) { TextTitle copyright = new TextTitle("generated by statcvs-xml", creditInformationFont); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); } chart.setBackgroundPaint(Color.white); }
From source file:net.sf.mzmine.modules.visualization.scatterplot.scatterplotchart.ScatterPlotRenderer.java
public ScatterPlotRenderer() { super(false, true); ScatterPlotToolTipGenerator toolTipGenerator = new ScatterPlotToolTipGenerator(); setBaseToolTipGenerator(toolTipGenerator); XYItemLabelGenerator ItemlabelGenerator = new ScatterPlotItemLabelGenerator(); setBaseItemLabelGenerator(ItemlabelGenerator); setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, 11)); setBaseItemLabelPaint(Color.black); setBaseItemLabelsVisible(false);//from ww w . j a v a 2s . c om setSeriesItemLabelsVisible(0, false); setSeriesPaint(0, pointColor); setSeriesShape(0, dataPointsShape); setSeriesItemLabelsVisible(1, false); setSeriesPaint(1, searchColor); setSeriesShape(1, dataPointsShape); }
From source file:it.alus.GPSreceiver.instruments.Compass.java
public Compass(boolean trueTrack) { super(null);/*from www . ja va 2 s. c o m*/ isTrueTrack = trueTrack; dataset = new DefaultValueDataset(0.0); DialPlot plot = new DialPlot(); //Image background=Toolkit.getDefaultToolkit().getImage(getClass().getResource("heading.png")); //plot.setBackgroundImage(background); plot.setView(0.0, 0.0, 1.0, 1.0); plot.setDataset(0, dataset); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(Color.lightGray); dialFrame.setForegroundPaint(Color.gray); N = new DialTextAnnotation("N"); N.setFont(new Font("Arial", 1, 32)); N.setPaint(Color.white); N.setAnchor(TextAnchor.CENTER); plot.addLayer(N); S = new DialTextAnnotation("S"); S.setFont(new Font("Arial", 1, 32)); S.setPaint(Color.white); S.setAnchor(TextAnchor.CENTER); plot.addLayer(S); W = new DialTextAnnotation("W"); W.setFont(new Font("Arial", 1, 32)); W.setPaint(Color.white); W.setAnchor(TextAnchor.CENTER); plot.addLayer(W); E = new DialTextAnnotation("E"); E.setFont(new Font("Arial", 1, 32)); E.setPaint(Color.white); E.setAnchor(TextAnchor.CENTER); plot.addLayer(E); repositionDirectionsLabels(90); DialValueIndicator valueindicator = new DialValueIndicator(0); plot.addLayer(valueindicator); plot.setDialFrame(dialFrame); realScale = new StandardDialScale(0, 360, 90, -360, 30, 6); realScale.setVisible(false); realScale.setFirstTickLabelVisible(false); plot.addScale(0, realScale); dispScale = new StandardDialScale(0, 36, 90, -360, 3, 15); dispScale.setFirstTickLabelVisible(false); dispScale.setMajorTickPaint(Color.white); dispScale.setMinorTickPaint(Color.lightGray); dispScale.setFirstTickLabelVisible(true); dispScale.setTickRadius(0.88); dispScale.setTickLabelOffset(0.15); NumberFormat formatter = new DecimalFormat("#"); dispScale.setTickLabelFormatter(formatter); dispScale.setTickLabelFont(new Font("Arial", Font.BOLD, 22)); dispScale.setTickLabelPaint(Color.white); plot.addScale(1, dispScale); plot.setBackground(new DialBackground(Color.black)); Pointer needle = new Pointer(0); needle.setFillPaint(Color.red); needle.setRadius(0.8); plot.addLayer(needle); plot.mapDatasetToScale(1, 1); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.gray); plot.setCap(cap); jChart = new JFreeChart(plot); //jChart.setBackgroundImage(background); super.setChart(jChart); super.setPreferredSize(new Dimension(400, 400)); }
From source file:net.sf.mzmine.chartbasics.chartthemes.EStandardChartTheme.java
public EStandardChartTheme(THEME themeID, String name) { super(name);/* ww w. j a v a2 s .com*/ this.themeID = themeID; setBarPainter(new StandardBarPainter()); setXYBarPainter(new StandardXYBarPainter()); // in theme setAntiAliased(false); setNoBackground(false); // general isAntiAliased = true; masterFont = new Font("Arial", Font.PLAIN, 11); masterFontColor = Color.black; }
From source file:utils.ChartUtils.java
/** * Update IR bar chart/* w w w .j a va 2 s. c o m*/ * * @param labelsByFrequency Labels ordered by frequency * @param IR Imbalance Ratio values * @param cp CategoryPlot */ public static void updateIRBarChart(ImbalancedFeature[] labelsByFrequency, double[] IR, CategoryPlot cp) { DefaultCategoryDataset myData = new DefaultCategoryDataset(); double prob = 0; labelsByFrequency = MetricUtils.sortByFrequency(labelsByFrequency); double sum = 0.0; for (int i = labelsByFrequency.length - 1; i >= 0; i--) { prob = IR[i]; sum += prob; myData.setValue(prob, labelsByFrequency[i].getName(), " "); } cp.setDataset(myData); // add mean mark sum = sum / labelsByFrequency.length; Marker meanMark = new ValueMarker(sum); meanMark.setPaint(Color.red); meanMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); meanMark.setLabel(" Mean: " + MetricUtils.truncateValue(sum, 3)); cp.addRangeMarker(meanMark); //Add Imbalance limit mark Marker limitMark = new ValueMarker(1.5); limitMark.setPaint(Color.black); limitMark.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); if ((sum < 1.3) || (sum > 1.7)) { limitMark.setLabel(" Imbalance limit (IR=1.5)"); } cp.addRangeMarker(limitMark); }