📄 gobject.java
字号:
/** * Find all objects inside a specified rectangle. Objects are * returned with front most object on screen last in list. Seacrh is * done in the subtree of this object (including this). If no objects * is inside, an empty list is returned. * * @param x0, y0, x1, y1 Rectangle to check. * @return All objects intersecting the rectangle. */ public List findAllInside (int x0, int y0, int x1, int y1) { List objects = new ArrayList(); findAllInside (x0, y0, x1, y1, objects); return objects; } /** * Find all objects intersecting a specified point. Objects are * returned with front most object on screen last in list. Seacrh is * done in the subtree of this object (including this). If no objects * intersects, an empty list is returned. * * @param x X coordinate of point to check. * @param y Y coordinate of point to check. * @return All objects intersecting the specfied point. */ public List findAll (int x, int y) { return findAll (x - 1, y - 1, x + 1, y + 1); } /** * Find all sub objects that intersects the given rectangle. * * @param x0 X coordinate of upper left corner of rectangle. * @param y0 Y coordinate of upper left corner of rectangle. * @param x1 X coordinate of lower right corner of rectangle. * @param y1 Y coordinate of lower right corner of rectangle. * @param objects Object collection to add to. */ private void findAll (int x0, int y0, int x1, int y1, List objects) { // Don't scan any furher if the region doesn't intersect if (!region_.isIntersecting (new Rect (x0, y0, x1 - x0 + 1, y1 - y0 + 1))) return; // Check subobjects first for (Iterator i = children_.iterator(); i.hasNext(); ) { GObject child = (GObject) i.next(); child.findAll (x0, y0, x1, y1, objects); } // The region intersects, but we need to consider each segment if (segments_ != null) { for (Iterator i = segments_.iterator(); i.hasNext(); ) { GSegment segment = (GSegment) i.next(); if (segment.isIntersectingRectangle (x0, y0, x1, y1)) { objects.add (this); break; } } } } /** * Find all sub objects that are inside the given rectangle. * * @param x0 X coordinate of upper left corner of rectangle. * @param y0 Y coordinate of upper left corner of rectangle. * @param x1 X coordinate of lower right corner of rectangle. * @param y1 Y coordinate of lower right corner of rectangle. * @param objects Object collection to add to. */ private void findAllInside (int x0, int y0, int x1, int y1, List objects) { Box box = new Box (x0, y0, x1, y1); // Don't scan any furher if the region doesn't intersect if (!region_.isIntersecting (new Rect (box))) return; // Check subobjects first for (Iterator i = children_.iterator(); i.hasNext(); ) { GObject child = (GObject) i.next(); child.findAllInside (x0, y0, x1, y1, objects); } if (region_.isInsideOf (new Rect (box))) objects.add (this); } /** * Unlink self from parent child list. */ public void remove() { if (parent_ != null) parent_.remove (this); } /** * Remove child from child list. * * @param child Child object to remove. */ public void remove (GObject child) { // Update damage with removed region child.updateDamage(); children_.remove (child); child.parent_ = null; // Annotation might need to be recomputed // TODO: Check if subtree actually has texts before assuming this GScene scene = getScene(); if (scene != null) scene.setAnnotationValid (false); // Force a region recompmutation isRegionValid_ = false; } /** * Remove all children objects. */ public void removeAll() { // Loop over a copy of the children list as they are removed Collection children = new ArrayList (children_); for (Iterator i = children.iterator(); i.hasNext(); ) { GObject child = (GObject) i.next(); remove (child); } } /** * Return the position of this object among its siblings. * * @return Position of this object among its siblings. */ private int getPosition() { if (parent_ == null) return -1; return parent_.children_.indexOf (this); } /** * Return the child object at specified position. * * @param position Position to return child of. * @return Requested child (or null if non existing). */ public GObject getChild (int position) { if (position < 0 || position > children_.size() - 1) return null; return (GObject) children_.get (position); } /** * Return true if this object is in front of all its siblings. * * @return True if this object is in fron of all siblings, false otherwise. */ public boolean isInFront() { return parent_ == null ? false : getPosition() == parent_.getNChildren()-1; } /** * Return true if this object is behind all its siblings. * * @return True if this object is behind all siblings, false otherwise. */ public boolean isInBack() { return parent_ == null ? false : getPosition() == 0; } /** * Return the sibling object in the immediate front of this object. * * @return The sibling object in the immediate front of this object * (or null if this object is in front, or it is not attach to a * parent). */ public GObject getObjectInFront() { if (parent_ == null) return null; if (isInFront()) return null; int position = getPosition(); return parent_.getChild (position + 1); } /** * Return the sibling object immediately behind this object. * * @return The sibling object immediately behind this object * (or null if this object is in back, or it is not attach to a * parent). */ public GObject getObjectBehind() { if (parent_ == null) return null; if (isInBack()) return null; int position = getPosition(); return parent_.getChild (position - 1); } /** * Add a new segment to this object. * * @param segment Segment to add. */ public void addSegment (GSegment segment) { // Lazy create as not all GObjects will have segments if (segments_ == null) segments_ = new ArrayList(); // Do nothing if it is there already if (segments_.contains (segment)) return; segments_.add (segment); segment.setOwner (this); // Since segment style may inherit from this segment.updateStyle(); } /** * Return the n'th segment of this object. * * @param segmentNo Segment number to return. * @return N'th segment (or null if non existent). */ public GSegment getSegment (int segmentNo) { int nSegments = getNSegments(); return segmentNo < 0 || segmentNo >= nSegments ? null : (GSegment) segments_.get (segmentNo); } /** * Return number of segments in this GObject. * * @return Number of segments in this GObject. */ public int getNSegments() { return segments_ != null ? segments_.size() : 0; } /** * Remove the specified segment from this GObject. * * @param segment Segment to remove. If the specified segment is not * a child of this GObject, this call has no effect. */ public void removeSegment (GSegment segment) { // Cannot remove if it doesn't belong here if (segment.getOwner() != this) return; // Update damage Region region = segment.getRegion(); GWindow window = getWindow(); if (window != null) window.updateDamageArea (region); // If there was texts on this segment, flag annotation to be redone if (segment.getTexts() != null) { GScene scene = getScene(); if (scene != null) scene.setAnnotationValid (false); } segments_.remove (segment); segment.setOwner (null); if (segments_.size() == 0) segments_ = null; isRegionValid_ = false; } /** * Remove specified segment from this GObject. * * @param segmentNo Segment to remove. If the specified segment does not * exist, this casll has no effect. */ public void removeSegment (int segmentNo) { GSegment segment = getSegment (segmentNo); if (segment != null) removeSegment (segment); } /** * Remove all segments from this GObject. */ public void removeSegments() { while (segments_ != null) removeSegment (0); } /** * Remove sequence of segments from this object. * * @param from Starting segment * @param to Ending segment (-1 indicates all). */ public void removeSegments (int from, int to) { if (segments_ == null || from >= segments_.size()) return; if (from < 0) from = 0; if (to >= segments_.size() || to == -1) to = segments_.size() - 1; if (to < 0) to = 0; int nSegments = from - to + 1; for (int i = 0; i < nSegments; i++) removeSegment (from); isRegionValid_ = false; } /** * Remove sequence of segments from this object. Remove all from * specified start segment. * * @param from Starting segment */ public void removeSegments (int from) { removeSegments (from, -1); } /** * Refresh all segments of this GObject. * * @param visibilityMask Visibility of parent object. */ void refreshData (int visibilityMask) { // Compute actual visibility of this object visibilityMask &= visibilityMask_; // If data is not visible on this level, return if ((visibilityMask & DATA_VISIBLE) == 0) return; // If we don't intersect with the damage, return if (!region_.isIntersecting (getWindow().getDamageRegion())) return; // Refreshing self if (segments_ != null) { GCanvas canvas = (GCanvas) getWindow().getCanvas(); for (Iterator i = segments_.iterator(); i.hasNext(); ) { GSegment segment = (GSegment) i.next(); if (!segment.isVisible()) continue; // Render the segment canvas.render (segment.getX(), segment.getY(), segment.getActualStyle()); // Render vertex images GImage vertexImage = segment.getVertexImage(); if (vertexImage != null) canvas.render (segment.getX(), segment.getY(), vertexImage); // Render the images Collection images = segment.getImages(); if (images != null) { for (Iterator j = images.iterator(); j.hasNext(); ) { GImage image = (GImage) j.next(); if (image != null && image.isVisible()) canvas.render (image); } } } } // Refreshing children for (Iterator i = children_.iterator(); i.hasNext(); ) { GObject child = (GObject) i.next(); child.refreshData (visibilityMask); } } /** * Refresh all annotations of this GObject. * * @param visibilityMask Visibility of parent object. */ void refreshAnnotation (int visibilityMask) { // Compute actual visibility of this object visibilityMask &= visibilityMask_; // If annotation is not visible on this level, return if ((visibilityMask & GObject.ANNOTATION_VISIBLE) == 0) return; // If we don't intersect with damage, return if (!region_.isIntersecting (getWindow().getDamageRegion())) return; // Refreshing self if (segments_ != null) { GCanvas canvas = (GCanvas) getWindow().getCanvas(); for (Iterator i = segments_.iterator(); i.hasNext(); ) { GSegment segment = (GSegment) i.next(); if (!segment.isVisible()) continue; Collection texts = segment.getTexts(); if (texts != null) { for (Iterator j = texts.iterator(); j.hasNext(); ) { GText text = (GText) j.next(); if (text != null && text.isVisible()) canvas.render (text, text.getActualStyle()); } } } } // Refreshing children for (Iterator i = children_.iterator(); i.hasNext(); ) { GObject child = (GObject) i.next(); child.refreshAnnotation (visibilityMask); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -