List of usage examples for java.awt Point Point
public Point()
From source file:CoordinatesDemo.java
public void updateCursorLocation(int x, int y) { if (x < 0 || y < 0) { cursorPoint = null;/*from ww w. j a v a 2 s . c om*/ updateLabel(); return; } if (cursorPoint == null) { cursorPoint = new Point(); } cursorPoint.x = x; cursorPoint.y = y; updateLabel(); }
From source file:it.marcoberri.mbmeteo.action.chart.GetLastTDial.java
/** * Processes requests for both HTTP//from w w w .ja va2 s . c o m * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("start : " + this.getClass().getName()); final HashMap<String, String> params = getParams(request.getParameterMap()); final Integer dimy = Default.toInteger(params.get("dimy"), 600); final Integer dimx = Default.toInteger(params.get("dimx"), 800); Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get(); DefaultValueDataset dataset = new DefaultValueDataset(meteolog.getOutdoorTemperature()); // get data for diagrams DialPlot plot = new DialPlot(); plot.setView(0.0, 0.0, 1.0, 1.0); plot.setDataset(0, dataset); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setBackground(db); StandardDialScale scale = new StandardDialScale(); scale.setLowerBound(-20); scale.setUpperBound(40); scale.setTickLabelOffset(0.14); scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10)); plot.addScale(0, scale); DialPointer needle = new DialPointer.Pointer(0); plot.addLayer(needle); JFreeChart chart1 = new JFreeChart(plot); chart1.setTitle("Temperature C"); final File f = File.createTempFile("mbmeteo", ".jpg"); ChartUtilities.saveChartAsJPEG(f, chart1, dimx, dimy); response.setContentType("image/jpeg"); response.setHeader("Content-Length", "" + f.length()); response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\""); final OutputStream out = response.getOutputStream(); final FileInputStream in = new FileInputStream(f.toString()); final int size = in.available(); final byte[] content = new byte[size]; in.read(content); out.write(content); in.close(); out.close(); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java
private void init() { this.srcPoint = new Point(); this.selectionColor = createSelectionColor(); this.rubberBandMouseListener = new MouseAdapter() { @Override//from w w w.j a v a 2 s . c o m public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); Rectangle rect = getCellBounds(index, index); if (!rect.contains(e.getPoint())) { clearSelection(); getSelectionModel().setAnchorSelectionIndex(-1); getSelectionModel().setLeadSelectionIndex(-1); setFocusable(false); } else { setFocusable(true); } } @Override public void mouseReleased(MouseEvent e) { setFocusable(true); rubberBand = null; repaint(); } }; this.rubberBandMouseMotionListener = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { setFocusable(true); if (rubberBand == null) { srcPoint.setLocation(e.getPoint()); } Point destPoint = e.getPoint(); rubberBand = new Path2D.Double(); rubberBand.moveTo(srcPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, destPoint.y); rubberBand.lineTo(srcPoint.x, destPoint.y); rubberBand.closePath(); setSelectedIndices(getIntersectsIdices(rubberBand)); repaint(); } }; addMouseListener(rubberBandMouseListener); addMouseMotionListener(rubberBandMouseMotionListener); }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.SimpleDial.java
/** * Creates the chart ./*from w w w . jav a 2 s . com*/ * * @return A Simple Dial chart . */ public JFreeChart createChart() { logger.debug("IN"); if (dataset == null) { logger.debug("The dataset to be represented is null"); return null; } DialPlot plot = new DialPlot(); plot.setDataset((ValueDataset) dataset); logger.debug("Created the new Dial Plot"); ArcDialFrame dialFrame = null; plot.setView(0.21, 0.0, 0.58, 0.30); dialFrame = new ArcDialFrame(60.0, 60.0); dialFrame.setInnerRadius(0.65); dialFrame.setOuterRadius(0.90); dialFrame.setForegroundPaint(Color.darkGray); dialFrame.setStroke(new BasicStroke(3.0f)); plot.setDialFrame(dialFrame); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(240, 240, 240)); DialBackground sdb = new DialBackground(gp); GradientPaintTransformType gradientPaintTransformType = GradientPaintTransformType.HORIZONTAL; sdb.setGradientPaintTransformer(new StandardGradientPaintTransformer(gradientPaintTransformType)); plot.addLayer(sdb); increment = (upper - lower) / 4; StandardDialScale scale = null; scale = new StandardDialScale(lower, upper, 115.0, -50.0, increment, minorTickCount); // sets intervals for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(), interval.getColor()); range.setInnerRadius(0.70); range.setOuterRadius(0.75); plot.addLayer(range); } scale.setTickRadius(0.88); scale.setTickLabelOffset(0.07); Font f = new Font("Arial", Font.PLAIN, 11); scale.setTickLabelFont(f); //scale.setMajorTickIncrement(25.0); plot.addScale(0, scale); DialPointer needle = new DialPointer.Pin(); needle.setRadius(0.82); plot.addLayer(needle); JFreeChart chart1 = new JFreeChart(plot); logger.debug("Created the chart"); chart1.setBackgroundPaint(color); logger.debug("Setted background color of the chart"); TextTitle title = setStyleTitle(name, styleTitle); chart1.setTitle(title); logger.debug("Setted the title of the chart"); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart1.addSubtitle(subTitle); logger.debug("Setted the subtitle of the chart"); } logger.debug("OUT"); return chart1; }
From source file:it.marcoberri.mbmeteo.action.chart.GetLastUDial.java
/** * Processes requests for both HTTP/*w w w.j ava2 s . c om*/ * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("start : " + this.getClass().getName()); final HashMap<String, String> params = getParams(request.getParameterMap()); final Integer dimy = Default.toInteger(params.get("dimy"), 600); final Integer dimx = Default.toInteger(params.get("dimx"), 800); Meteolog meteolog = ds.find(Meteolog.class).order("-time").limit(1).get(); DefaultValueDataset dataset = new DefaultValueDataset(meteolog.getOutdoorHumidity()); // get data for diagrams DialPlot plot = new DialPlot(); plot.setInsets(RectangleInsets.ZERO_INSETS); //plot.setView(0.1, 0.1, 0.9, 0.9); // plot.set plot.setDataset(0, dataset); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setBackground(db); StandardDialScale scale = new StandardDialScale(); scale.setLowerBound(0); scale.setUpperBound(100); scale.setTickLabelOffset(0.14); scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10)); plot.addScale(0, scale); plot.setInsets(RectangleInsets.ZERO_INSETS); DialPointer needle = new DialPointer.Pointer(0); plot.addLayer(needle); JFreeChart chart1 = new JFreeChart(plot); chart1.setTitle("Humidity %"); final File f = File.createTempFile("mbmeteo", ".jpg"); ChartUtilities.saveChartAsJPEG(f, chart1, dimx, dimy); response.setContentType("image/jpeg"); response.setHeader("Content-Length", "" + f.length()); response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\""); final OutputStream out = response.getOutputStream(); final FileInputStream in = new FileInputStream(f.toString()); final int size = in.available(); final byte[] content = new byte[size]; in.read(content); out.write(content); in.close(); out.close(); }
From source file:br.unicamp.rctapp.codelets.behaviors.GetClosestJewel.java
@Override public void act() { String jewelName = ""; closestJewel = (Thing) closestJewelMO.getI(); cis = (CreatureInnerSense) innerSenseMO.getI(); //Find distance between closest apple and self //If closer than reachDistance, eat the apple if (closestJewel != null) { double jewelX = 0; double jewelY = 0; try {/* w ww. ja v a2s. c om*/ jewelX = closestJewel.getX1(); jewelY = closestJewel.getY1(); jewelName = closestJewel.getName(); } catch (Exception e) { e.printStackTrace(); } double selfX = cis.getPosition().getX(); double selfY = cis.getPosition().getY(); Point2D pApple = new Point(); pApple.setLocation(jewelX, jewelY); Point2D pSelf = new Point(); pSelf.setLocation(selfX, selfY); double distance = pSelf.distance(pApple); JSONObject message = new JSONObject(); try { if (distance < reachDistance) { //eat it message.put("OBJECT", jewelName); message.put("ACTION", "PICKUP"); handsMO.updateI(message.toString()); } else { handsMO.updateI(""); //nothing } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { handsMO.updateI(""); //nothing } }
From source file:org.cyberoam.iview.charts.MeterChart.java
/** * This method generates JFreeChart instance for Meter chart with dial port and iView customization. * @param reportID//from ww w . j av a2 s .c om * @param rsw * @param request * @return */ public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; ReportColumnBean reportColumnBean = null; GraphBean graphBean = null; try { DefaultValueDataset data = null; graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId()); reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnDBname = reportColumnBean.getDbColumnName(); rsw.first(); double used = Double.parseDouble(rsw.getString(yColumnDBname)); data = new DefaultValueDataset(100 - used); DialPlot plot = new DialPlot(data); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.white); int imgWidth = graphBean.getWidth(); int imgHeight = graphBean.getHeight(); if (request != null && request.getParameter("imgwidth") != null && !"".equalsIgnoreCase(request.getParameter("imgwidth")) && !"null".equalsIgnoreCase(request.getParameter("imgwidth"))) { imgWidth = Integer.parseInt(request.getParameter("imgwidth")); } if (request != null && request.getParameter("imgheight") != null && !"".equalsIgnoreCase(request.getParameter("imgheight")) && !"null".equalsIgnoreCase(request.getParameter("imgheight"))) { imgHeight = Integer.parseInt(request.getParameter("imgheight")); } plot.setView((1 - ((double) imgWidth / (double) imgHeight)) / 2, plot.getViewY(), ((double) imgWidth / (double) imgHeight), plot.getViewHeight()); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(new Color(54, 73, 109)); dialFrame.setRadius(0.8); dialFrame.setStroke(new BasicStroke(0)); plot.setDialFrame(dialFrame); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(196, 210, 219)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(db); DialValueIndicator dvi = new DialValueIndicator(0); dvi.setRadius(0.55); dvi.setBackgroundPaint(gp); dvi.setNumberFormat(new DecimalFormat("###")); dvi.setFont(new Font("Vandara", Font.CENTER_BASELINE, 10)); dvi.setOutlinePaint(Color.lightGray); plot.addLayer(dvi); StandardDialScale scale = new StandardDialScale(0, 100, -120, -300, 10, 4); scale.setTickRadius(0.75); scale.setTickLabelOffset(0.15); scale.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 9)); plot.addScale(0, scale); StandardDialRange range = new StandardDialRange(0.0, 50.0, Color.green); range.setInnerRadius(0.35); range.setOuterRadius(0.38); plot.addLayer(range); StandardDialRange range2 = new StandardDialRange(50.0, 75.0, Color.yellow); range2.setInnerRadius(0.35); range2.setOuterRadius(0.38); plot.addLayer(range2); StandardDialRange range3 = new StandardDialRange(75.0, 100.0, Color.red); range3.setInnerRadius(0.35); range3.setOuterRadius(0.38); plot.addLayer(range3); DialPointer needle = new DialPointer.Pointer(); needle.setRadius(0.55); plot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); plot.setCap(cap); } catch (Exception e) { CyberoamLogger.appLog.debug("MeterChart=>Exception : " + e, e); } return chart; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPopupButton.java
protected void showPopup() { popup.removeAll();/*ww w . j a v a 2s . c om*/ for (final Action action : actionList) { if (action.isVisible()) { final JMenuItem menuItem = new JMenuItem(action.getCaption()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { action.actionPerform((Component) action.getOwner()); } }); menuItem.setEnabled(action.isEnabled()); menuItem.setName(action.getId()); initAction(action, menuItem); popup.add(menuItem); } } int popupHeight = popup.getComponentCount() * 25; Point pt = new Point(); SwingUtilities.convertPointToScreen(pt, impl); int y; if (pt.getY() + impl.getHeight() + popupHeight < Toolkit.getDefaultToolkit().getScreenSize().getHeight()) { y = impl.getHeight(); } else { y = -popupHeight; } // do not show ugly empty popup if (popup.getComponentCount() > 0) { popup.show(impl, 0, y); } }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.Speedometer.java
/** * Creates a chart of type Speedometer.//from w w w .j av a 2 s. c om * * @return A Speedometer Chart */ public JFreeChart createChart() { logger.debug("IN"); if (dataset == null) { logger.debug("The dataset to be represented is null"); return null; } DialPlot plot = new DialPlot(); logger.debug("Created new DialPlot"); plot.setDataset((ValueDataset) dataset); plot.setDialFrame(new StandardDialFrame()); plot.setBackground(new DialBackground()); if (dialtextuse) { //Usually it shoudn'tbe used. It is a type of title written into the graph DialTextAnnotation annotation1 = new DialTextAnnotation(dialtext); annotation1.setFont(styleTitle.getFont()); annotation1.setRadius(0.7); plot.addLayer(annotation1); } DialValueIndicator dvi = new DialValueIndicator(0); plot.addLayer(dvi); increment = (upper - lower) / 10; StandardDialScale scale = new StandardDialScale(lower, upper, -120, -300, 10.0, 4); // if (!( increment > 0)){ // increment = 0.01; // } scale.setMajorTickIncrement(increment); logger.debug("Setted the unit after which a new MajorTickline will be drawed"); scale.setMinorTickCount(minorTickCount); logger.debug("Setted the number of MinorTickLines between every MajorTickline"); scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); Font f = new Font("Arial", Font.PLAIN, 11); scale.setTickLabelFont(f); plot.addScale(0, scale); plot.addPointer(new DialPointer.Pin()); DialCap cap = new DialCap(); plot.setCap(cap); // sets intervals for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(), interval.getColor()); range.setInnerRadius(0.52); range.setOuterRadius(0.55); plot.addLayer(range); logger.debug("new range added to the plot"); } GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(db); plot.removePointer(0); DialPointer.Pointer p = new DialPointer.Pointer(); //Pointer color p.setFillPaint(Color.black); plot.addPointer(p); logger.debug("Setted all properties of the plot"); JFreeChart chart = new JFreeChart(name, plot); logger.debug("Created the chart"); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); logger.debug("Setted the title of the chart"); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); logger.debug("Setted the subtitle of the chart"); } chart.setBackgroundPaint(color); logger.debug("Setted background color of the chart"); logger.debug("OUT"); return chart; }
From source file:com.romraider.logger.ecu.ui.handler.dash.DialGaugeStyle.java
protected JFreeChart buildChart() { DialPlot plot = new DialPlot(); plot.setView(0.0, 0.0, 1.0, 1.0);//from ww w .j a va 2 s.c om plot.setDataset(0, current); plot.setDataset(1, max); plot.setDataset(2, min); DialFrame dialFrame = new StandardDialFrame(); plot.setDialFrame(dialFrame); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer(new StandardGradientPaintTransformer(VERTICAL)); plot.setBackground(db); unitsLabel.setFont(new Font(Font.DIALOG, BOLD, 15)); unitsLabel.setRadius(0.7); unitsLabel.setLabel(loggerData.getSelectedConvertor().getUnits()); plot.addLayer(unitsLabel); DecimalFormat format = new DecimalFormat(loggerData.getSelectedConvertor().getFormat()); DialValueIndicator dvi = new DialValueIndicator(0); dvi.setNumberFormat(format); plot.addLayer(dvi); EcuDataConvertor convertor = loggerData.getSelectedConvertor(); GaugeMinMax minMax = convertor.getGaugeMinMax(); StandardDialScale scale = new StandardDialScale(minMax.min, minMax.max, 225.0, -270.0, minMax.step, 5); scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); scale.setTickLabelFont(new Font(Font.DIALOG, PLAIN, 12)); scale.setTickLabelFormatter(format); plot.addScale(0, scale); plot.addScale(1, scale); plot.addScale(2, scale); StandardDialRange range = new StandardDialRange(rangeLimit(minMax, 0.75), minMax.max, RED); range.setInnerRadius(0.52); range.setOuterRadius(0.55); plot.addLayer(range); StandardDialRange range2 = new StandardDialRange(rangeLimit(minMax, 0.5), rangeLimit(minMax, 0.75), ORANGE); range2.setInnerRadius(0.52); range2.setOuterRadius(0.55); plot.addLayer(range2); StandardDialRange range3 = new StandardDialRange(minMax.min, rangeLimit(minMax, 0.5), GREEN); range3.setInnerRadius(0.52); range3.setOuterRadius(0.55); plot.addLayer(range3); DialPointer needleCurrent = new DialPointer.Pointer(0); plot.addLayer(needleCurrent); DialPointer needleMax = new DialPointer.Pin(1); needleMax.setRadius(0.84); ((DialPointer.Pin) needleMax).setPaint(RED); ((DialPointer.Pin) needleMax).setStroke(new BasicStroke(1.5F)); plot.addLayer(needleMax); DialPointer needleMin = new DialPointer.Pin(2); needleMin.setRadius(0.84); ((DialPointer.Pin) needleMin).setPaint(BLUE); ((DialPointer.Pin) needleMin).setStroke(new BasicStroke(1.5F)); plot.addLayer(needleMin); DialCap cap = new DialCap(); cap.setRadius(0.10); plot.setCap(cap); JFreeChart chart = new JFreeChart(plot); chart.setTitle(loggerData.getName()); return chart; }