/** * Draws this step. * * @param panel the drawing panel requesting the drawing * @param g the graphics context on which to draw */ public void draw(DrawingPanel panel, Graphics g) { if (track.trackerPanel == panel) { AutoTracker autoTracker = track.trackerPanel.getAutoTracker(); if (autoTracker.isInteracting(track)) return; } TrackerPanel trackerPanel = (TrackerPanel) panel; boolean highlighted = (trackerPanel.getFrameNumber() == n); if (trackerPanel.autoTracker != null && trackerPanel.autoTracker.getWizard().isVisible() && trackerPanel.autoTracker.getTrack() == track) { highlighted = false; } getMark(trackerPanel).draw((Graphics2D) g, highlighted); }
/** * Gets the mark for the specified panel. * * @param trackerPanel the tracker panel * @return the mark */ protected Mark getMark(TrackerPanel trackerPanel) { Mark mark = marks.get(trackerPanel); TPoint selection = null; if (mark == null) { selection = trackerPanel.getSelectedPoint(); Point p = null; valid = true; // assume true for (int n = 0; n < points.length; n++) { if (!valid) continue; // determine if point is valid (ie not NaN) valid = valid && !Double.isNaN(points[n].getX()) && !Double.isNaN(points[n].getY()); screenPoints[n] = points[n].getScreenPosition(trackerPanel); if (valid && selection == points[n]) p = screenPoints[n]; } mark = footprint.getMark(screenPoints); if (p != null) { // point is selected, so draw selection shape transform.setToTranslation(p.x, p.y); int scale = FontSizer.getIntegerFactor(); if (scale > 1) { transform.scale(scale, scale); } final Color color = footprint.getColor(); final Mark stepMark = mark; final Shape selectedShape = transform.createTransformedShape(selectionShape); mark = new Mark() { public void draw(Graphics2D g, boolean highlighted) { stepMark.draw(g, false); Paint gpaint = g.getPaint(); g.setPaint(color); g.fill(selectedShape); g.setPaint(gpaint); } public Rectangle getBounds(boolean highlighted) { Rectangle bounds = selectedShape.getBounds(); bounds.add(stepMark.getBounds(false)); return bounds; } }; } final Mark theMark = mark; mark = new Mark() { public void draw(Graphics2D g, boolean highlighted) { if (!valid) return; theMark.draw(g, false); } public Rectangle getBounds(boolean highlighted) { return theMark.getBounds(highlighted); } }; marks.put(trackerPanel, mark); } return mark; }
/** * Overrides Step getMark method. * * @param trackerPanel the tracker panel * @return the mark */ protected Mark getMark(TrackerPanel trackerPanel) { Mark mark = marks.get(trackerPanel); TPoint selection = null; if (mark == null) { selection = trackerPanel.getSelectedPoint(); Point p = null; // draws this step as "selected" shape if not null valid = true; // true if step is not NaN for (int n = 0; n < points.length; n++) { if (!valid) continue; // determine if point is valid (ie not NaN) valid = valid && !Double.isNaN(points[n].getX()) && !Double.isNaN(points[n].getY()); screenPoints[n] = points[n].getScreenPosition(trackerPanel); // step is "selected" if trackerPanel selectedPoint is position or selectedSteps contains // this step if (valid && (selection == points[n] || trackerPanel.selectedSteps.contains(this))) { p = screenPoints[n]; } } if (p == null) { if (footprint instanceof PositionVectorFootprint) { twoPoints[0] = screenPoints[0]; twoPoints[1] = trackerPanel.getSnapPoint().getScreenPosition(trackerPanel); mark = footprint.getMark(twoPoints); } else mark = footprint.getMark(screenPoints); } else { transform.setToTranslation(p.x, p.y); int scale = FontSizer.getIntegerFactor(); if (scale > 1) { transform.scale(scale, scale); } final Color color = footprint.getColor(); final Shape selectedShape = transform.createTransformedShape(selectionShape); mark = new Mark() { public void draw(Graphics2D g, boolean highlighted) { g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Paint gpaint = g.getPaint(); g.setPaint(color); g.fill(selectedShape); g.setPaint(gpaint); } public Rectangle getBounds(boolean highlighted) { return selectedShape.getBounds(); } }; } final Mark theMark = mark; mark = new Mark() { public void draw(Graphics2D g, boolean highlighted) { if (!valid) { return; } theMark.draw(g, highlighted); } public Rectangle getBounds(boolean highlighted) { return theMark.getBounds(highlighted); } }; marks.put(trackerPanel, mark); // get new text layout String s = ""; // $NON-NLS-1$ VideoClip clip = trackerPanel.getPlayer().getVideoClip(); if (clip.getStepCount() != 1) { s += clip.frameToStep(getFrameNumber()); } if (s.length() == 0) s = " "; // $NON-NLS-1$ TextLayout layout = new TextLayout(s, textLayoutFont, frc); textLayouts.put(trackerPanel, layout); // get layout position (bottom left corner of text) p = getLayoutPosition(trackerPanel); Rectangle bounds = layoutBounds.get(trackerPanel); if (bounds == null) { bounds = new Rectangle(); layoutBounds.put(trackerPanel, bounds); } Rectangle2D rect = layout.getBounds(); // set bounds (top left corner and size) bounds.setRect(p.x, p.y - rect.getHeight(), rect.getWidth(), rect.getHeight()); } return mark; }
/** * Gets the screen bounds of this step on the specified tracker panel. * * @param trackerPanel the tracker panel drawing the step * @return the bounding rectangle */ public Rectangle getBounds(TrackerPanel trackerPanel) { boolean highlighted = (trackerPanel.getFrameNumber() == n); return getMark(trackerPanel).getBounds(highlighted); }
/** * Repaints this on the specified tracker panel. Repainting a step first remarks it and then * requests a repaint of the panel's dirty region. * * @param trackerPanel the tracker panel */ public void repaint(TrackerPanel trackerPanel) { remark(trackerPanel); trackerPanel.repaintDirtyRegion(); }
/** * Erases and remarks this on the specified tracker panel. Remarking creates a new mark for the * step and adds both the old and new bounds to the tracker panel's dirty region. * * @param trackerPanel the tracker panel */ public void remark(TrackerPanel trackerPanel) { erase(trackerPanel); trackerPanel.addDirtyRegion(getBounds(trackerPanel)); // new bounds }
/** * Erases this on the specified tracker panel. Erasing adds the current bounds to the dirty region * and nulls the step's mark to trigger creation of a new one. * * @param trackerPanel the tracker panel */ public void erase(TrackerPanel trackerPanel) { if (marks.get(trackerPanel) == null) return; // already dirty trackerPanel.addDirtyRegion(getBounds(trackerPanel)); // old bounds marks.put(trackerPanel, null); // triggers new mark }