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

📄 gwindow.java

📁 use Java code to draw on pad canvas
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * Stop the current interaction. The current interaction will get   * an ABORT event so it has the possibility to do cleanup. If no   * interaction is installed, this method has no effect.    */  public void stopInteraction()  {    // Nothing to do if no current interaction    if (interaction_ == null) return;        interaction_.event (null, ABORT, 0, 0);    interaction_      = null;    interactionScene_ = null;      }      /**   * Ensure correct regions for all objects. Only objects with its   * isRegionValid_ flag set to false (and their parents) will be   * recomputed.   */  void computeRegion()  {    // This is default setting from window point of view    int visibilityMask = GObject.DATA_VISIBLE       |                          GObject.ANNOTATION_VISIBLE |                         GObject.SYMBOLS_VISIBLE;    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      scene.computeRegion (visibilityMask);    }  }    /**   * Force a complete redraw of all visible elements.   * <p>   * Normally this method is called automatically when 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 calling GObject.redraw() on the   * affected objects instead.   */  public void redraw()  {    // This is default setting from window point of view    int visibilityMask = GObject.DATA_VISIBLE       |                          GObject.ANNOTATION_VISIBLE |                         GObject.SYMBOLS_VISIBLE    |                         GObject.WIDGETS_VISIBLE;    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      scene.redraw (visibilityMask);    }  }    /**   * Refresh the graphics scene. Only elements that has been changed    * since the last refresh are affected.   */  public void refresh()  {    // This is default setting from window point of view    int visibilityMask = GObject.DATA_VISIBLE       |                          GObject.ANNOTATION_VISIBLE |                         GObject.SYMBOLS_VISIBLE    |                         GObject.WIDGETS_VISIBLE;    // Check if annotation has changed    boolean isAnnotationUpdated = false;    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      if (!scene.isAnnotationValid()) {        isAnnotationUpdated = true;        break;      }    }    // Return here if nothing has changed    if (!isAnnotationUpdated && damageRegion_.isEmpty())      return;    // Compute positions of all annotations    computeTextPositions();    // Compute positions of all integrated AWT components    computeComponentPositions();    // Compute region for all elements    computeRegion();    // Clip damage to viewport    Region viewportRegion = new Region();    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      viewportRegion.union (scene.getRegion());    }    damageRegion_.intersect (viewportRegion);        // Clear the damaged area in the canvas    canvas_.setClipArea (damageRegion_);    canvas_.clear (damageRegion_.getExtent());    Region allDamage = new Region (damageRegion_);        // Rendering pass 1: DATA    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      damageRegion_ = Region.intersect (allDamage, scene.getRegion());      canvas_.setClipArea (damageRegion_);      scene.refreshData (visibilityMask);    }    // Rendering pass 2: ANNOTATION    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      damageRegion_ = Region.intersect (allDamage, scene.getRegion());      canvas_.setClipArea (damageRegion_);      scene.refreshAnnotation (visibilityMask);    }    // Rendering pass 3: COMPONENTS    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      damageRegion_ = Region.intersect (allDamage, scene.getRegion());      canvas_.setClipArea (damageRegion_);      scene.refreshComponents (visibilityMask);    }        canvas_.refresh();    damageRegion_.clear();  }  /**   * Compute all text positions in entire window.   */  void computeTextPositions()  {    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      if (!scene.isAnnotationValid())        scene.computeTextPositions();    }  }  /**   * Compute all component (Swing widgets) positions in entire window.   */  void computeComponentPositions()  {    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      // TODO: if (!scene.isAnnotationValid())      scene.computeComponentPositions();    }  }  /**   * Method called when the pointer enters this window. If an interaction   * is installed, pass a FOCUS_IN event to it.   *    * @param x  X position of mouse.   * @param y  Y position of mouse.      */  void mouseEntered (int x, int y)  {    if (interaction_ == null) return;    interaction_.event (getScene (x, y), FOCUS_IN, x, y);  }    /**   * Method called when the pointer exits this window. If an interaction   * is installed, pass a FOCUS_OUT event to it.   *    * @param x  X position of mouse.   * @param y  Y position of mouse.      */  void mouseExited (int x, int y)  {    if (interaction_ == null) return;    interaction_.event (getScene (x, y), FOCUS_OUT, x, y);  }    /**   * Method called when a mouse pressed event occurs in this window.   * If an interaction is installed, pass a BUTTON*_DOWN event to it.   *    * @param buttonEvent  Button event trigging this method.   * @param x            X position of mouse.   * @param y            Y position of mouse.      */  void mousePressed (int buttonEvent, int x, int y)  {    if (interaction_ == null) return;    interactionScene_ = getScene (x, y);    interaction_.event (interactionScene_, buttonEvent, x, y);  }    /**   * Method called when a mouse release event occurs in this window.   * If an interaction is installed, pass a BUTTON*_UP event to it.   *    * @param buttonEvent  Button event trigging this method.   * @param x            X position of mouse.   * @param y            Y position of mouse.      */  void mouseReleased (int buttonEvent, int x, int y)  {    if (interaction_ == null) return;    interaction_.event (interactionScene_, buttonEvent, x, y);  }    /**   * Method called when the mouse is dragged (moved with button pressed) in   * this window. If an interaction is installed, pass a BUTTON*_DRAG   * event to it.   *    * @param buttonEvent  Button event trigging this method.   * @param x            X position of mouse.   * @param y            Y position of mouse.      */  void mouseDragged (int buttonEvent, int x, int y)  {    if (interaction_ == null) return;    interaction_.event (interactionScene_, buttonEvent, x, y);  }    /**   * Method called when the mouse is moved inside this window.   * If an interaction is installed, pass a MOTION event to it.   *    * @param x  X position of mouse.   * @param y  Y position of mouse.      */  void mouseMoved (int x, int y)  {    if (interaction_ == null) return;    interaction_.event (getScene (x, y), MOTION, x, y);  }    /**   * Called when the window is resized. Reset the dimension variables   * and resize scenes accordingly.   */  void resize()  {    // Get the new window size    int width  = canvas_.getWidth();    int height = canvas_.getHeight();    // Refuse to resize to zero as we cannot possible resize back    if (width == 0 || height == 0) return;        // Compute resize factors    double dx = (double) width  / (double) width_;    double dy = (double) height / (double) height_;    // Set new window size    width_  = width;    height_ = height;    // Mark entire window as damaged    damageRegion_.clear();    Rect allWindow = new Rect (0, 0, width_, height_);    damageRegion_.union (allWindow);    // Resize every scene accordingly    for (Iterator i = scenes_.iterator(); i.hasNext(); ) {      GScene scene = (GScene) i.next();      scene.resize (dx, dy);    }    // Recompute geometry    redraw();    // Render graphics    refresh();  }        /**   * Print the current image.   *    * @return  True if no exception was caught, false otherwise.   */  public boolean print()  {    boolean isOk = canvas_.print();    return isOk;  }    /**   * Store the current graphic image as a GIF file.   *    * @param file  File to store in.   */  public void saveAsGif (File file)    throws IOException  {    canvas_.saveAsGif (file);  }}

⌨️ 快捷键说明

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