/** * use default orientation or orientation of axis * * @param event * @return */ public Orientation getOrientation(ChartGestureEvent event) { ChartEntity ce = event.getEntity(); if (ce instanceof AxisEntity) { JFreeChart chart = event.getChartPanel().getChart(); PlotOrientation orient = PlotOrientation.HORIZONTAL; if (chart.getXYPlot() != null) orient = chart.getXYPlot().getOrientation(); else if (chart.getCategoryPlot() != null) orient = chart.getCategoryPlot().getOrientation(); Entity entity = event.getGesture().getEntity(); if ((entity.equals(Entity.DOMAIN_AXIS) && orient.equals(PlotOrientation.VERTICAL)) || (entity.equals(Entity.RANGE_AXIS) && orient.equals(PlotOrientation.HORIZONTAL))) return Orientation.HORIZONTAL; else return Orientation.VERTICAL; } return orient; }
/** * Created an entity for the axis. * * @param cursor the initial cursor value. * @param state the axis state after completion of the drawing with a * possibly updated cursor position. * @param dataArea the data area. * @param edge the edge. * @param plotState the PlotRenderingInfo from which a reference to the * entity collection can be obtained. * * @since 1.0.13 */ protected void createAndAddEntity(double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) { if (plotState == null || plotState.getOwner() == null) { return; // no need to create entity if we can't save it anyways... } Rectangle2D hotspot = null; if (edge.equals(RectangleEdge.TOP)) { hotspot = new Rectangle2D.Double(dataArea.getX(), state.getCursor(), dataArea.getWidth(), cursor - state.getCursor()); } else if (edge.equals(RectangleEdge.BOTTOM)) { hotspot = new Rectangle2D.Double(dataArea.getX(), cursor, dataArea.getWidth(), state.getCursor() - cursor); } else if (edge.equals(RectangleEdge.LEFT)) { hotspot = new Rectangle2D.Double(state.getCursor(), dataArea.getY(), cursor - state.getCursor(), dataArea.getHeight()); } else if (edge.equals(RectangleEdge.RIGHT)) { hotspot = new Rectangle2D.Double(cursor, dataArea.getY(), state.getCursor() - cursor, dataArea.getHeight()); } EntityCollection e = plotState.getOwner().getEntityCollection(); if (e != null) { e.add(new AxisEntity(hotspot, this)); } }
/** * The ValueAxis of this event's entity or null if the entity is different to an AxisEntity or if * the axis is not a ValueAxis * * @return */ public ValueAxis getAxis() { if (entity != null && entity instanceof AxisEntity && ((AxisEntity) entity).getAxis() instanceof ValueAxis) return (ValueAxis) ((AxisEntity) entity).getAxis(); else return null; }
/** * The gesture entity type * * @param entity * @return */ public static Entity getGestureEntity(ChartEntity entity) { if (entity == null) return NONE; if (entity instanceof PlotEntity) return PLOT; if (entity instanceof AxisEntity) { AxisEntity e = (AxisEntity) entity; if (e.getAxis().getPlot() instanceof XYPlot) { XYPlot plot = ((XYPlot) e.getAxis().getPlot()); for (int i = 0; i < plot.getDomainAxisCount(); i++) if (plot.getDomainAxis(i).equals(e.getAxis())) return DOMAIN_AXIS; for (int i = 0; i < plot.getRangeAxisCount(); i++) if (plot.getRangeAxis(i).equals(e.getAxis())) return RANGE_AXIS; } // else return basic axis return AXIS; } if (entity instanceof LegendItemEntity) return LEGEND_ITEM; if (entity instanceof XYItemEntity) return XY_ITEM; if (entity instanceof XYAnnotationEntity) return XY_ANNOTATION; if (entity instanceof TitleEntity) { if (((TitleEntity) entity).getTitle() instanceof TextTitle) return TEXT_TITLE; else return NON_TEXT_TITLE; } if (entity instanceof JFreeChartEntity) return JFREECHART; if (entity instanceof CategoryItemEntity) return CATEGORY_ITEM; return GENERAL; }
/** * Created an entity for the axis. * * @param cursor the initial cursor value. * @param state the axis state after completion of the drawing with a * possibly updated cursor position. * @param dataArea the data area. * @param edge the edge. * @param plotState the PlotRenderingInfo from which a reference to the * entity collection can be obtained. * * @since 1.0.13 */ protected void createAndAddEntity(double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState){ if (plotState == null || plotState.getOwner() == null) { return; // no need to create entity if we can´t save it anyways... } Rectangle2D hotspot = null; if (edge.equals(RectangleEdge.TOP)){ hotspot = new Rectangle2D.Double(dataArea.getX(), state.getCursor(), dataArea.getWidth(), cursor - state.getCursor()); } else if(edge.equals(RectangleEdge.BOTTOM)) { hotspot = new Rectangle2D.Double(dataArea.getX(), cursor, dataArea.getWidth(), state.getCursor() - cursor); } else if(edge.equals(RectangleEdge.LEFT)) { hotspot = new Rectangle2D.Double(state.getCursor(), dataArea.getY(), cursor - state.getCursor(), dataArea.getHeight()); } else if(edge.equals(RectangleEdge.RIGHT)){ hotspot = new Rectangle2D.Double(cursor, dataArea.getY(), state.getCursor() - cursor, dataArea.getHeight()); } EntityCollection e = plotState.getOwner().getEntityCollection(); if (e != null) { e.add(new AxisEntity(hotspot, this)); } }
/** * Created an entity for the axis. * * @param cursor the initial cursor value. * @param state the axis state after completion of the drawing with a * possibly updated cursor position. * @param dataArea the data area. * @param edge the edge. * @param plotState the PlotRenderingInfo from which a reference to the * entity collection can be obtained. * * @since 1.0.13 */ protected void createAndAddEntity(double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) { if (plotState == null || plotState.getOwner() == null) { return; // no need to create entity if we can´t save it anyways... } Rectangle2D hotspot = null; if (edge.equals(RectangleEdge.TOP)) { hotspot = new Rectangle2D.Double(dataArea.getX(), state.getCursor(), dataArea.getWidth(), cursor - state.getCursor()); } else if (edge.equals(RectangleEdge.BOTTOM)) { hotspot = new Rectangle2D.Double(dataArea.getX(), cursor, dataArea.getWidth(), state.getCursor() - cursor); } else if (edge.equals(RectangleEdge.LEFT)) { hotspot = new Rectangle2D.Double(state.getCursor(), dataArea.getY(), cursor - state.getCursor(), dataArea.getHeight()); } else if (edge.equals(RectangleEdge.RIGHT)) { hotspot = new Rectangle2D.Double(cursor, dataArea.getY(), state.getCursor() - cursor, dataArea.getHeight()); } EntityCollection e = plotState.getOwner().getEntityCollection(); if (e != null) { e.add(new AxisEntity(hotspot, this)); } }