List of usage examples for java.awt Rectangle Rectangle
public Rectangle(Point p, Dimension d)
From source file:bicat.gui.GraphicPane.java
/** * Default constructor, initializes some values. *///from w w w. j a va 2s . c o m public GraphicPane() { geneList = null; graphDataList = null; filledRect = new Rectangle(0, 0); xStep = 10; yStep = 160; // sta ovo tacno znaci??? (size of the cells of the // visualized matrix?) colorWheel = new Color[8]; // samo 8? colorWheel[0] = Color.BLUE; colorWheel[1] = Color.CYAN; colorWheel[2] = Color.GREEN; colorWheel[3] = Color.MAGENTA; colorWheel[4] = Color.ORANGE; colorWheel[5] = Color.PINK; colorWheel[6] = Color.RED; colorWheel[7] = Color.YELLOW; // /* * DefaultPieDataset dpd = new DefaultPieDataset(); * dpd.setValue("Category 1",50); dpd.setValue("Category 2",50); */ // create a dataset... /* * DefaultPieDataset data = new DefaultPieDataset(); * data.setValue("Java", new Double(43.2)); data.setValue("Visual * Basic", new Double(0.0)); data.setValue("C/C++", new Double(17.5)); * * JFreeChart chart = ChartFactory.createPieChart("Sample",data, * true,true,false); ChartFrame frame = new ChartFrame("See", chart); * frame.pack(); // this.add(frame); //frame.pack(); * frame.setVisible(true); */ /* * chart = ChartFactory.createXYLineChart("Expression Profiles of a * Bicluster","genes","conditions", new * org.jfree.data.xy.DefaultTableXYDataset(), * org.jfree.chart.plot.PlotOrientation.HORIZONTAL, false,false,false); * * //ChartPanel cp = new ChartPanel(chart_1); chartPanel = new * ChartPanel(chart); this.add(chartPanel); //cp); * //,BorderLayout.WEST); this.setVisible(true); * //this.add("Proba",chart_1); //ChartFrame frame_1 = new * ChartFrame("XY",chart_1); //frame_1.pack(); * //frame_1.setVisible(true); */ }
From source file:asl.util.PlotMaker.java
public void plotPSD(double per[], double[] model, double[] nhnmPer, double[] nhnm, double[] psd, String modelName, String plotString) { // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png" final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format(// w w w . jav a2 s. c o m "== plotPSD: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return; } Boolean plotNHNM = false; //if (nhnm.length > 0) { if (nhnm != null) { plotNHNM = true; } final XYSeries series1 = new XYSeries(modelName); final XYSeries series2 = new XYSeries(channel.toString()); final XYSeries series3 = new XYSeries("NHNM"); for (int k = 0; k < per.length; k++) { series1.add(per[k], model[k]); series2.add(per[k], psd[k]); } if (plotNHNM) { for (int k = 0; k < nhnmPer.length; k++) { series3.add(nhnmPer[k], nhnm[k]); } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShape(2, rectangle); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesLinesVisible(2, true); Paint[] paints = new Paint[] { Color.blue, Color.red, Color.black }; renderer.setSeriesPaint(0, paints[0]); renderer.setSeriesPaint(1, paints[1]); renderer.setSeriesPaint(2, paints[2]); final NumberAxis rangeAxis1 = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB"); //rangeAxis1.setRange( new Range(-190, -120)); rangeAxis1.setRange(new Range(-190, -95)); rangeAxis1.setTickUnit(new NumberTickUnit(5.0)); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(0.05, 10000)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); seriesCollection.addSeries(series2); if (plotNHNM) { seriesCollection.addSeries(series3); } final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final JFreeChart chart = new JFreeChart(xyplot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:it.cnr.icar.eric.client.ui.swing.graph.JBGraph.java
public void insert(Point point) { RegistryBrowser.setWaitCursor();/*from ww w . ja v a 2s .c o m*/ try { if (RegistryBrowser.getInstance().getClient().getConnection() == null) { RegistryBrowser.displayError("Connect to a registry by specifying Registry Location first."); return; } RegistryObject ro = createRegistryObject(); // Construct Vertex with no Label JBGraphCell vertex = new JBGraphCell(ro, true); registryObjectToCellMap.put(ro, vertex); // Add one Floating Port vertex.add(new DefaultPort()); // Snap the Point to the Grid point = snap(new Point(point)); // Default Size for the new Vertex Dimension size = new Dimension(25, 25); // Create a Map that holds the attributes for the Vertex Map<?, ?> map = GraphConstants.createMap(); // Add a Bounds Attribute to the Map GraphConstants.setBounds(map, new Rectangle(point, size)); // Add a Border Color Attribute to the Map GraphConstants.setBorderColor(map, Color.black); // Add a White Background GraphConstants.setBackground(map, Color.white); // Make Vertex Opaque GraphConstants.setOpaque(map, true); // Construct a Map from cells to Maps (for insert) Hashtable<DefaultGraphCell, Map<?, ?>> attributes = new Hashtable<DefaultGraphCell, Map<?, ?>>(); // Associate the Vertex with its Attributes attributes.put(vertex, map); // Insert the Vertex and its Attributes getModel().insert(new Object[] { vertex }, null, null, attributes); } catch (JAXRException e) { e.printStackTrace(); RegistryBrowser.displayError(e); } RegistryBrowser.setDefaultCursor(); }
From source file:PhysicDrawing.PhysicGraph.java
private JFreeChart createAccelerationChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart("Acceleration", // chart title "X - Time (s)", // x axis label "Y - A (px/s^2)", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );//from www . j a va 2 s.c om // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); // vertical line plot.setRangeGridlinePaint(Color.white); // horizontal line XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); // (index , value) renderer.setSeriesLinesVisible(1, true); renderer.setSeriesPaint(0, Color.RED, true); renderer.setSeriesPaint(1, Color.black, true); renderer.setSeriesPaint(2, Color.white, true); renderer.setSeriesShape(0, new Rectangle(1, 1)); renderer.setSeriesShape(1, new Rectangle(1, 1)); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartCanvas.java
/** * Draws the content of the canvas and updates the * {@code renderingInfo} attribute with the latest rendering * information./*from ww w .j a v a 2 s.c o m*/ */ public final void draw() { GraphicsContext ctx = getGraphicsContext2D(); ctx.save(); double width = getWidth(); double height = getHeight(); if (width > 0 && height > 0) { ctx.clearRect(0, 0, width, height); this.info = new ChartRenderingInfo(); this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info); } ctx.restore(); this.anchor = null; }
From source file:com.limegroup.gnutella.gui.notify.AnimatedWindow.java
private void prepareAnimation(Point location) { if (animationImage != null) { // already have an image, this could be the case if a hide animation // is started while a show animation is still in progress or the // other// w ww . ja v a 2 s . c om // way around return; } // reset window to original size to capture all content pack(); Dimension size = getSize(); if (mode.needsBackgroundImage() && backgroundImage == null) { try { Robot robot = new Robot(); backgroundImage = robot.createScreenCapture(new Rectangle(location, size)); } catch (AWTException e) { LOG.warn("Could not capture background image", e); backgroundImage = null; } } animationImage = getGraphicsConfiguration().createCompatibleImage(size.width, size.height); Graphics grahpics = animationImage.getGraphics(); getContentPane().paint(grahpics); grahpics.dispose(); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYDataset dataset = (XYDataset) datasets.getDatasets().get("1"); final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend, false, false);//w ww . j av a2 s . co m sparkLineGraph.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); sparkLineGraph.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); sparkLineGraph.addSubtitle(subTitle); } sparkLineGraph.setBorderVisible(false); sparkLineGraph.setBorderPaint(Color.BLACK); XYPlot plot = sparkLineGraph.getXYPlot(); plot.setOutlineVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(color); // calculate the last marker color Paint colorLast = getLastPointColor(); // Calculate average, minimum and maximum to draw plot borders. boolean isFirst = true; double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; int count = 0; for (int i = 0; i < timeSeries.getItemCount(); i++) { if (timeSeries.getValue(i) != null) { count++; if (isFirst) { min = timeSeries.getValue(i).doubleValue(); max = timeSeries.getValue(i).doubleValue(); isFirst = false; } double n = timeSeries.getValue(i).doubleValue(); //calculate avg, min, max avg += n; if (n < min) min = n; if (n > max) max = n; } } // average avg = avg / (double) count; // calculate min and max between thresholds! boolean isFirst2 = true; double lb = 0, ub = 0; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); if (isFirst2 == true) { ub = thres.doubleValue(); lb = thres.doubleValue(); isFirst2 = false; } if (thres.doubleValue() > ub) ub = thres.doubleValue(); if (thres.doubleValue() < lb) lb = thres.doubleValue(); } plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2)); addMarker(1, avg, Color.GRAY, 0.8f, plot); //addAvaregeSeries(series, plot); addPointSeries(timeSeries, plot); int num = 3; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); TargetThreshold targThres = thresholds.get(thres); Color color = Color.WHITE; if (targThres != null && targThres.getColor() != null) { color = targThres.getColor(); } if (targThres.isVisible()) { addMarker(num++, thres.doubleValue(), color, 0.5f, plot); } } ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin(0.2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); plot.getRenderer().setSeriesPaint(0, Color.BLACK); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public boolean getItemShapeVisible(int _series, int item) { TimeSeriesDataItem tsdi = timeSeries.getDataItem(item); if (tsdi == null) return false; Month period = (Month) tsdi.getPeriod(); int currMonth = period.getMonth(); int currYear = period.getYearValue(); int lastMonthFilled = lastMonth.getMonth(); int lastYearFilled = lastMonth.getYearValue(); boolean isLast = false; if (currYear == lastYearFilled && currMonth == lastMonthFilled) { isLast = true; } return isLast; } }; renderer.setSeriesPaint(0, Color.decode("0x000000")); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(colorLast); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0)); if (wlt_mode.doubleValue() == 0) { renderer.setBaseItemLabelsVisible(Boolean.FALSE, true); } else { renderer.setBaseItemLabelsVisible(Boolean.TRUE, true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"), new DecimalFormat("0.###")) { public String generateLabel(CategoryDataset dataset, int row, int column) { if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0) return ""; String columnKey = (String) dataset.getColumnKey(column); int separator = columnKey.indexOf('-'); String month = columnKey.substring(0, separator); String year = columnKey.substring(separator + 1); int monthNum = Integer.parseInt(month); if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) { if (wlt_mode.doubleValue() == 2 && column % 2 == 0) return ""; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, monthNum - 1); SimpleDateFormat dataFormat = new SimpleDateFormat("MMM"); return dataFormat.format(calendar.getTime()); } else return "" + monthNum; } }); } if (wlt_mode.doubleValue() == 3) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2)); } else if (wlt_mode.doubleValue() == 4) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4)); } if (legend == true) { LegendItemCollection collection = createThresholdLegend(plot); LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage); collection.add(item); plot.setFixedLegendItems(collection); } plot.setRenderer(0, renderer); logger.debug("OUT"); return sparkLineGraph; }
From source file:net.openbyte.gui.CreateProjectFrame.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - Gary Lee button1 = new JButton(); textField1 = new JTextField(); label1 = new JLabel(); comboBox1 = new JComboBox<>(); label2 = new JLabel(); comboBox2 = new JComboBox<>(); label3 = new JLabel(); button2 = new JButton(); //======== this ======== setTitle("Project Creation"); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); setResizable(false);/* w w w .j a v a 2 s . c om*/ Container contentPane = getContentPane(); contentPane.setLayout(null); //---- button1 ---- button1.setText("Create project"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button1ActionPerformed(e); } }); contentPane.add(button1); button1.setBounds(new Rectangle(new Point(340, 170), button1.getPreferredSize())); contentPane.add(textField1); textField1.setBounds(10, 25, 245, textField1.getPreferredSize().height); //---- label1 ---- label1.setText("Project Name"); contentPane.add(label1); label1.setBounds(new Rectangle(new Point(10, 5), label1.getPreferredSize())); //---- comboBox1 ---- comboBox1.setModel(new DefaultComboBoxModel<>(new String[] { "Minecraft Forge", "MCP", "Bukkit" })); comboBox1.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { comboBox1ItemStateChanged(e); } }); contentPane.add(comboBox1); comboBox1.setBounds(10, 70, 245, comboBox1.getPreferredSize().height); //---- label2 ---- label2.setText("Modification API"); contentPane.add(label2); label2.setBounds(new Rectangle(new Point(10, 50), label2.getPreferredSize())); //---- comboBox2 ---- comboBox2.setModel(new DefaultComboBoxModel<>(new String[] { "1.8.9", "1.7.10" })); contentPane.add(comboBox2); comboBox2.setBounds(10, 120, 245, comboBox2.getPreferredSize().height); //---- label3 ---- label3.setText("Minecraft Version"); contentPane.add(label3); label3.setBounds(new Rectangle(new Point(10, 100), label3.getPreferredSize())); //---- button2 ---- button2.setText("Cancel"); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button2ActionPerformed(e); } }); contentPane.add(button2); button2.setBounds(new Rectangle(new Point(10, 170), button2.getPreferredSize())); { // compute preferred size Dimension preferredSize = new Dimension(); for (int i = 0; i < contentPane.getComponentCount(); i++) { Rectangle bounds = contentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = contentPane.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } setSize(480, 240); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents }
From source file:PNGDecoder.java
/** Static method performing one component screen capture into PNG image format file with given fileName. * @param comp Component to be captured//w ww. j a v a 2 s . c o m * @param fileName String image target filename * @param mode image color mode */ public static void captureScreen(Component comp, String fileName, byte mode) { captureScreen(new Rectangle(comp.getLocationOnScreen(), comp.getSize()), fileName, mode); }
From source file:edu.jhuapl.graphs.controller.GraphController.java
public GraphObject createPieGraph(GraphDataInterface graphData, Encoding encoding) { GraphObject graph = null;/*from ww w . j a v a2s .c o m*/ Map<String, Object> graphMetaData = new HashMap<String, Object>(); List<PointInterface> points = new ArrayList<PointInterface>(); setPieGraphMetaData(graphData, graphMetaData, points); // I'm ashamed of this code in so many ways String graphTitle = (String) graphMetaData.get(GraphSource.GRAPH_TITLE); try { // add the created chart properties JFreeChartGraphSource graphSource = new JFreeChartGraphSource(); graphSource.setData(Arrays.asList(new DataSeries(points, new HashMap<String, Object>()))); graphSource.setParams(graphMetaData); graphSource.initialize(); if (graphData.showLegend()) { PiePlot plot = (PiePlot) graphSource.getChart().getPlot(); // use rectangles as the legend shapes plot.setLegendItemShape(new Rectangle(7, 8)); // generate tooltip for the legend items in the following format: "lineSetLabels - count" if (graphData.percentBased()) { plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} - {1} ({2})", new DecimalFormat("#.##"), new DecimalFormat("#.##%"))); } else { plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} - {1} ({2})", new DecimalFormat("#"), new DecimalFormat("#.##%"))); } } // render the graph to get the image map RenderedGraph renderedGraph = graphSource.renderGraph(graphData.getGraphWidth(), graphData.getGraphHeight(), encoding); String extension = ".dat"; switch (encoding) { case JPEG: extension = ".jpg"; break; case PNG: case PNG_WITH_TRANSPARENCY: extension = ".png"; break; } String imageFileName = getCleanValue(graphTitle) + "_piegraph" + extension; // get the image map String imageMapName = "imageMap" + graphDataId; String imageMap = appendImageMapTarget(renderedGraph.getImageMap(imageMapName), graphData.getLineSetURLTarget()); try { // store away the graph data file graphDataHandler.putGraphData(graphData, graphDataId); graph = new GraphObject(graphSource, renderedGraph, imageFileName, imageMapName, imageMap, graphDataId); } catch (GraphException e) { System.out.println(e.getMessage()); e.printStackTrace(); } } catch (GraphException e) { System.out.println("Could not create pie graph " + graphTitle); e.printStackTrace(); } return graph; }