⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gobject.java

📁 use Java code to draw on pad canvas
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
  /**   * Refresh all AWT components of this GObject.   *    * @param visibilityMask  Visibility of parent object.   */  void refreshComponents (int visibilityMask)  {    // Compute actual visibility of this object        visibilityMask &= visibilityMask_;    // If components are not visible on this level, return    if ((visibilityMask & GObject.WIDGETS_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 components = segment.getComponents();        if (components != null) {          for (Iterator j = components.iterator(); j.hasNext(); ) {            GComponent component = (GComponent) j.next();            canvas.render (component);          }        }      }    }    // Refreshing children    for (Iterator i = children_.iterator(); i.hasNext(); ) {      GObject child = (GObject) i.next();      child.refreshComponents (visibilityMask);    }  }    /**   * The redraw method ensures that the geometry in the entire   * scene becomes up to date. Called initially and then in the   * following cases:   *   * <ul>   * <li>resize   * <li>setViewport   * <li>setWorldExtent   * <li>setVisibility to on, because invisible views are not   *     redrawn in the case above.   * </ul>   *    * @param visibilityMask   */  protected void redraw (int visibilityMask)  {    // If not visible at this level, skip here but mark as not drawn    isDrawn_ = false;    visibilityMask &= visibilityMask_;    if (visibilityMask == 0) return;    // Mark annotation as dirty    if (this instanceof GScene) {      GScene scene = (GScene) this;      scene.setAnnotationValid (false);    }    // Redraw children    for (Iterator i = children_.iterator(); i.hasNext(); ) {      GObject child = (GObject) i.next();      child.redraw (visibilityMask);    }    // Let application object draw itself    draw();    // Compute posistions for all images    computeImagePositions();    // Marks as redrawn    isDrawn_ = true;  }    /**   * Force a redraw of this object.   * <p>   * Normally this method is called automatically whenever needed   * (typically on retransformations).   * A client application <em>may</em> call this method explicitly   * if some external factor that influence the graphics has been   * changed. However, beware of the performance overhead of such   * an approach, and consider reorganizing the code so that model   * changes explictly affects the graphics elements.   */  public void redraw()  {    redraw (getVisibility());  }    /**   * Set new style for this object. Style elements not explicitly   * set within this GStyle object are inherited from parent   * objects. Child objects with not explicit set style will   * inherit from this style object. A GObject does not need a style   * instance; in this case all style elements are inherited.   *    * @param style  Style of this object (or null if the intent is   *               to unset the current style).   */  public void setStyle (GStyle style)  {    if (style_ != null)      style_.removeListener (this);        style_ = style;    if (style_ != null)      style_.addListener (this);    updateStyle();  }      /**   * Return style of this object. This is the style set by setStyle()   * and not necesserily the style as it appears on screen as unset   * style elements are inherited from parents.   *    * @return  Style of this object as specified with setStyle(), (or   *          null if no style has been provided).   */  public GStyle getStyle()  {    return style_;  }    /**   * This is the actual style used for this object when   * inheritance for unset values are resolved.   *    * @return  Actual style for this segment.   */  GStyle getActualStyle()  {    return actualStyle_;  }      /**   * Resolve unset values in the style element of this object.   * This involved creating a default "actual style" element,   * override with style elements of the parents actual style   * and override with style elements explicitly set in the style   * of this object (if any).   */  private void updateStyle()  {    // Initialize the actual style used for this object    actualStyle_ = new GStyle();    // Update with parent style    if (parent_ != null)      actualStyle_.update (parent_.getActualStyle());    // Update (and possible override) with present style    if (style_ != null)      actualStyle_.update (style_);    // Update style of segments    if (segments_ != null) {      for (Iterator i = segments_.iterator(); i.hasNext(); ) {        GSegment segment = (GSegment) i.next();        segment.updateStyle();      }    }    // Update style of children objects    for (Iterator i = children_.iterator(); i.hasNext(); ) {      GObject child = (GObject) i.next();      child.updateStyle();    }  }    /**   * Change the visibility for this object.   * <p>   * NOTE: The present visibility is maintained, and the new   * flag is taken as an <em>instruction</em> for change.   *   * The instruction is an or'ed combination of:   *   * <ul>   *   <li> DATA_VISIBLE           *   <li> ANNOTATION_VISIBLE   *   <li> SYMBOLS_VISIBLE   *   <li> WIDGETS_VISIBLE   *   <li> DATA_INVISIBLE   *   <li> ANNOTATION_INVISIBLE   *   <li> SYMBOLS_INVISIBLE   *   <li> WIDGETS_INVISIBLE   * </ul>   *   * The settings VISIBLE and INVISIBLE are conveniences compound   * for all visible and invisible settings respectively.   *   * @param visibilityMask  Visibility instruction.   */  public void setVisibility (int visibilityMask)  {    int  oldVisibilityMask = visibilityMask_;    // Determine the new visibility code    if ((visibilityMask & DATA_VISIBLE)         != 0)       visibilityMask_ |=  DATA_VISIBLE;    if ((visibilityMask & ANNOTATION_VISIBLE)   != 0)       visibilityMask_ |=  ANNOTATION_VISIBLE;    if ((visibilityMask & SYMBOLS_VISIBLE)      != 0)         visibilityMask_ |=  SYMBOLS_VISIBLE;    if ((visibilityMask & WIDGETS_VISIBLE)      != 0)         visibilityMask_ |=  WIDGETS_VISIBLE;    if ((visibilityMask & DATA_INVISIBLE)       != 0)      visibilityMask_ &= ~DATA_VISIBLE;    if ((visibilityMask & ANNOTATION_INVISIBLE) != 0)        visibilityMask_ &= ~ANNOTATION_VISIBLE;    if ((visibilityMask & SYMBOLS_INVISIBLE)    != 0)       visibilityMask_ &= ~SYMBOLS_VISIBLE;    if ((visibilityMask & WIDGETS_INVISIBLE)    != 0)         visibilityMask_ &= ~WIDGETS_VISIBLE;    // Return if nothing has changed    if (oldVisibilityMask == visibilityMask_)      return;    // Redraw if something was turned on and draw has not been done    if (visibilityMask_ != 0 && !isDrawn_)      redraw (visibilityMask_);        // Symbol visibility has changed    if ((oldVisibilityMask & SYMBOLS_VISIBLE) !=        (visibilityMask_ & SYMBOLS_VISIBLE))      changeSymbolVisibility();    // Widget visibility has changed    if ((oldVisibilityMask & WIDGETS_VISIBLE) !=        (visibilityMask_ & WIDGETS_VISIBLE))      changeWidgetVisibility ();      // Annotation visibility has changed    if ((oldVisibilityMask & ANNOTATION_VISIBLE) !=        (visibilityMask_ & ANNOTATION_VISIBLE)) {      GScene scene = getScene();      if (scene != null)        scene.setAnnotationValid (false);            // Redo annotation unless this was an empty object      if (children_.size() > 0 || getNSegments() > 0) {        updateDamage();        // Don't think we need this. Check for errors later.        // getWindow().computeTextPositions();      }    }        // Data visibility has changed    if ((oldVisibilityMask & DATA_VISIBLE) !=        (visibilityMask_ & DATA_VISIBLE)) {          // If the visibility is turned on, we must find the region first      if ((visibilityMask & DATA_VISIBLE) != 0)        getWindow().computeRegion();            updateDamage();    }  }    private void changeSymbolVisibility()  {    // TODO        // Handle children first  }    private void changeWidgetVisibility()  {    // TODO        // Handle children first  }    /**   * Compute position of all GTexts in the subtree rooted   * at this GObject.   */  void computeTextPositions()  {    GScene scene = getScene();    if (scene == null) return;        // Stop here if annotation is not visible    if ((visibilityMask_ & ANNOTATION_VISIBLE) == 0)      return;    //    // Do annotation on children    //    for (Iterator i = children_.iterator(); i.hasNext(); ) {      GObject child = (GObject) i.next();      child.computeTextPositions();    }    //    // Do annotation on self    //    // Do annotation on all segments    if (segments_ != null) {      for (Iterator i = segments_.iterator(); i.hasNext(); ) {        GSegment segment = (GSegment) i.next();        Collection texts = segment.getTexts();        scene.computePositions (texts);      }    }  }    /**   * Compute position of all GComponents in the subtree   * rooted at this GObject.   */  void computeComponentPositions()  {    GScene scene = getScene();    if (scene == null) return;        // Stop here if annotation is not visible    if ((visibilityMask_ & WIDGETS_VISIBLE) == 0)      return;    //    // Do annotation on children    //    for (Iterator i = children_.iterator(); i.hasNext(); ) {      GObject child = (GObject) i.next();      child.computeComponentPositions();    }    //    // Do annotation on self    //    // Do annotation on all segments    if (segments_ != null) {      for (Iterator i = segments_.iterator(); i.hasNext(); ) {        GSegment segment = (GSegment) i.next();        Collection components = segment.getComponents();        scene.computePositions (components);      }    }  }    /**   * Compute position of all GImages in the subtree rooted   * at this GObject.   */  void computeImagePositions()  {    GScene scene = getScene();    if (scene == null) return;    // Loop over all segments and position their images    if (segments_ != null) {      for (Iterator i = segments_.iterator(); i.hasNext(); ) {        GSegment segment = (GSegment) i.next();        Collection images = segment.getImages();        scene.computePositions (images);        GImage vertexImage = segment.getVertexImage();        if (vertexImage != null)          scene.computeVertexPositions (vertexImage);      }    }    // Compute image positions for children    for (Iterator i = children_.iterator(); i.hasNext(); ) {      GObject child = (GObject) i.next();      child.computeImagePositions();    }  }    /**   * Update window damage area with the region extent of this object.   */  private void updateDamage()  {    GWindow window = getWindow();    if (window != null)      window.updateDamageArea (region_);      }      /**   * Return parent GObject of this object.   *    * @return  Parent of this object (or null if it doesn't have a parent).   */  public GObject getParent()  {    return parent_;  }      /**   * Convenience method for refreshing the window canvas.   * Equivalent to <code>getWindow().refresh();</code>.   */  public void refresh()  {    GWindow window = getWindow();    if (window != null)      window.refresh();  }        /**   * This method should be overloaded for graphics objects with drawable   * elements (GSegments). Intermediate nodes should leave the method empty.   */  public void draw()  {  }    /**   * Called when the style of this object is changed.   *    * @param style  Style that has changed.   */  public void styleChanged (GStyle style)  {    updateStyle();    updateDamage();  }      /**   * Return a string representation of this object.   *    * @return  String representation of this object.   */  public String toString()  {    return "GObject: " + name_;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -