/** * Allows the OMGraphicHandler to receive graphics or take some action on one. * * @param graphic the OMGraphic to do the action on. * @param action the OMAction describing what to do to the graphic. * @return true if the action was able to be carried out. */ public boolean doAction(OMGraphic graphic, OMAction action) { OMGraphicList list = getList(); if (list != null) { list.doAction(graphic, action); } return true; // we can handle it. }
/** * Prepare the poly for rendering. * * @param proj Projection * @return true if generate was successful */ public boolean generate(Projection proj) { boolean ret = super.generate(proj); createLabels(); labels.generate(proj); points.generate(proj); return ret; }
public void createLabels() { labels.clear(); points.clear(); if (rawllpts == null) { return; } if (rawllpts.length < 4) { return; } Geo lastGeo = new Geo(rawllpts[0], rawllpts[1], units == DECIMAL_DEGREES); double latpnt = rawllpts[0]; double lonpnt = rawllpts[1]; if (units == RADIANS) { latpnt = ProjMath.radToDeg(latpnt); lonpnt = ProjMath.radToDeg(lonpnt); } points.add(new OMPoint(latpnt, lonpnt, 1)); Geo curGeo = null; double cumulativeDist = 0.0; for (int p = 2; p < rawllpts.length; p += 2) { if (curGeo == null) { curGeo = new Geo(rawllpts[p], rawllpts[p + 1], units == DECIMAL_DEGREES); } else { if (units == DECIMAL_DEGREES) { curGeo.initialize(rawllpts[p], rawllpts[p + 1]); } else { curGeo.initializeRadians(rawllpts[p], rawllpts[p + 1]); } } double dist = getDist(lastGeo, curGeo); cumulativeDist += dist; labels.add(createLabel(lastGeo, curGeo, dist, cumulativeDist, distUnits)); latpnt = rawllpts[p]; lonpnt = rawllpts[p + 1]; if (units == RADIANS) { latpnt = ProjMath.radToDeg(latpnt); lonpnt = ProjMath.radToDeg(lonpnt); } points.add(new OMPoint(latpnt, lonpnt, 1)); lastGeo.initialize(curGeo); } }
/** Set the OMGraphicList within this OMGraphicHandler. Works if canSetGraphicList == true. */ public synchronized void setList(OMGraphicList omgl) { if (DEBUG) { Debug.output( "FilterSupport.setList() with " + (omgl != null ? omgl.size() + " graphics." : "null list.")); } list = omgl; }
/** * Return the graphic list currently being used by the OMGraphicHandler. If filters have been * applied, then the OMGraphics that have made it through the filter are visible. List may be * null, if it hasn't been set. * * @see OMGraphic#isVisible(). */ public synchronized OMGraphicList getList() { if (DEBUG) { Debug.output( "FilterSupport.getList() with " + (list != null ? list.size() + " graphics." : "null list.")); } return list; }
/** render points */ protected void renderPoints(Graphics g) { Paint pointPaint = getLabelPaint(); for (Iterator<OMGraphic> it = points.iterator(); it.hasNext(); ) { OMGraphic point = (OMPoint) it.next(); point.setLinePaint(pointPaint); point.setFillPaint(pointPaint); point.render(g); } }
/** render labels */ protected void renderLabels(Graphics g) { Font f = getFont(); Paint labelPaint = getLabelPaint(); Paint mattingPaint = getMattingPaint(); boolean isMatted = isMatted(); for (Iterator<OMGraphic> it = labels.iterator(); it.hasNext(); ) { OMText text = (OMText) it.next(); text.setFont(f); text.setLinePaint(labelPaint); if (isMatted) { text.setFillPaint(mattingPaint); } text.render(g); } }
/** * Method that provides a recursive mechanism to go through OMGraphicsLists to filter out areas, * inside or outside another. */ protected OMGraphicList filterList(OMGraphicList omgl, Area area, boolean getInsideArea) { OMGraphicList ret = new OMGraphicList(); boolean DEBUG_DETAIL = Debug.debugging("filtersupportdetail"); boolean DEBUG = Debug.debugging("filtersupport") || DEBUG_DETAIL; if (DEBUG) { Debug.output("FilterSupport.filterList"); } int count = 0; // for debugging if (area != null && omgl != null) { // just checking for (OMGraphic omg : omgl) { if (DEBUG) { Debug.output("FilterSupport.filterList evaluating " + (count++) + " OMGraphic, " + omg); } boolean outsideFilter = true; // If not visible, automatically fails... if (!omg.isVisible()) { if (DEBUG) { Debug.output(" OMGraphic not visible, ignoring"); } continue; } if (omg instanceof OMGraphicList) { if (omg == omgl) { Debug.output(" OMGraphic is parent list (points to itself), ignoring..."); continue; } if (DEBUG) { Debug.output(" (filterList recursiving handing OMGraphicList)"); } OMGraphicList subList = filterList((OMGraphicList) omg, area, getInsideArea); if (!subList.isEmpty()) { if (DEBUG) { Debug.output( " +++ OMGraphicList's contents (" + subList.size() + ") pass filter, adding..."); } if (((OMGraphicList) omg).isVague()) { passedFilter(omg); omg.setVisible(true); ret.add(omg); } else { passedFilter(subList); ret.add(subList); } } else { if (DEBUG) { Debug.output(" --- OMGraphicList's contents fail filter, ignoring..."); } failedFilter(omg); } continue; } else { Shape omgShape = omg.getShape(); if (omgShape != null) { if (omgShape.getBounds2D().getWidth() == 0 && omgShape.getBounds2D().getHeight() == 0) { if (area.contains(omgShape.getBounds2D().getX(), omgShape.getBounds2D().getY())) { if (DEBUG_DETAIL) { Debug.output(" +++ omg contains position"); } outsideFilter = false; } } else if (area.intersects(omgShape.getBounds2D())) { if (DEBUG_DETAIL) { Debug.output(" +++ omg intersects bounds"); } // The area.interects() method above is a // general case. If you care about // preciseness, set the precise flag. // Depending on the performance cost, we might // want to make it permanent. if (precise) { Area omgArea = new Area(omgShape); if (!omgArea.isSingular()) { Area clone = (Area) area.clone(); clone.intersect(omgArea); if (!clone.isEmpty()) { outsideFilter = false; } } else { outsideFilter = false; } } else { outsideFilter = false; } } } // decide what to do depending on filteredOut and // getInsideArea if ((outsideFilter && !getInsideArea) || (!outsideFilter && getInsideArea)) { if (DEBUG) { Debug.output(" +++ OMGraphic passes filter, adding..."); } passedFilter(omg); ret.add(omg); } else { if (DEBUG) { Debug.output(" --- OMGraphic fails filter, hiding..."); } failedFilter(omg); } } } } return ret; }
/** Remove all filters, and reset all graphics to be visible. */ public void resetFiltering() { OMGraphicList list = getList(); if (list != null) list.setVisible(true); }