📄 gscene.java
字号:
} /** * Adjust the current world extent according to current viewport. * This method is called whenever the viewport has changed. */ private void adjustCurrentWorldExtent() { // Do nothing if the world extent is supposed to fit viewport if (shouldWorldExtentFitViewport_) return; // Viewport dimensions double viewportWidth = (double) viewport_.getWidth(); double viewportHeight = (double) viewport_.getHeight(); // World dimensions double worldWidth = currentWorldExtent_.getWidth(); double worldHeight = currentWorldExtent_.getHeight(); // Compute adjusted width or height double newWorldWidth; double newWorldHeight; if (worldWidth / worldHeight > viewportWidth / viewportHeight) { newWorldWidth = worldWidth; newWorldHeight = viewportHeight / viewportWidth * worldWidth; } else { newWorldWidth = viewportWidth / viewportHeight * worldHeight; newWorldHeight = worldHeight; } currentWorldExtent_.extendWidth (newWorldWidth); currentWorldExtent_.extendHeight (newWorldHeight); } /** * Update region for this GObject. The region of a GScene is always the * viewport extent. */ private void updateRegion() { if (viewport_.isSkewed()) { // TODO. Missing the create Region of a general polygon, // this case is special though and can be hacked by adding // a rectangle for each scan line in the viewport. } else { Rect rectangle = new Rect (viewport_.getX0(), viewport_.getY0(), (int) viewport_.getWidth(), (int) viewport_.getHeight()); getRegion().set (rectangle); } flagRegionValid (true); } /** * Resize this scene the specified fraction in x and y direction. * <p> * If a client uses scenes wich covers a specific part of a window, * it may want to extend GScene and override this method in order to * adjust the viewport according to the new window size. This can * be done as follows: * * <pre> * protected void resize (double dx, double dy) * { * super (dx, dy); * setViewport (...); * } * </pre> * * @param dx Resize fraction in x direction. * @param dy Resize fraction in y direction. */ protected void resize (double dx, double dy) { if (isViewportFixed_) return; // Resize viewport viewport_.resize (dx, dy); // Resize world extent if (!shouldWorldExtentFitViewport_) { // If we resize the world extents accordingly we will see more // than before, in same scale, thus "see more". // If we keep the world extent unchanged we will see the same // extent as before but rescaled, thus "see bigger" if (!shouldZoomOnResize_) { initialWorldExtent_.resize (dx, dy); currentWorldExtent_.resize (dx, dy); } adjustCurrentWorldExtent(); } transformer_.update (viewport_, currentWorldExtent_); // Compute new region updateRegion(); if (scrollHandler_ != null) scrollHandler_.updateScrollBars(); } /** * Zoom a specified amount around center of viewport. * * @param zoomFactor Zoom factor. Zoom in with factor < 1.0 and * out with factor > 1.0. */ public void zoom (double zoomFactor) { double x = viewport_.getCenterX(); double y = viewport_.getCenterY(); zoom ((int) Math.round (x), (int) Math.round (y), zoomFactor); } /** * Zoom a specific amount using specified point as fixed. * * <ul> * <li> Zoom in: zoom (x, y, 0.9); * <li> Zoom out: zoom (x, y, 1.1); * <li> etc. * </ul> * * @param x X coordinate of fixed point during zoom. * @param y Y coordinate of fixed point during zoom. * @param zoomFactor Zoom factor. */ public void zoom (int x, int y, double zoomFactor) { int x0 = viewport_.getX0(); int y0 = viewport_.getY0(); int x1 = viewport_.getX3(); int y1 = viewport_.getY3(); double width = viewport_.getWidth(); double height = viewport_.getHeight(); x0 += (1.0 - zoomFactor) * (x - x0); x1 -= (1.0 - zoomFactor) * (x1 - x); y0 += (1.0 - zoomFactor) * (y - y0); y1 -= (1.0 - zoomFactor) * (y1 - y); zoom (x0, y0, x1, y1); } /** * Zoom into a specific device area. * * @param x0 X value of first corner of zoom rectangle. * @param y0 Y value of first corner of zoom rectangle. * @param x1 X value of second corner of zoom rectangle. * @param y1 Y value of second corner of zoom rectangle. */ public void zoom (int x0, int y0, int x1, int y1) { // Make sure x0,y0 is upper left and x1,y1 is lower right if (x1 < x0) { int temp = x1; x1 = x0; x0 = temp; } if (y1 < y0) { int temp = y1; y1 = y0; y0 = temp; } // Tranform to world double w0[] = transformer_.deviceToWorld (x0, y1); double w1[] = transformer_.deviceToWorld (x1, y1); double w2[] = transformer_.deviceToWorld (x0, y0); zoom (w0, w1, w2); } /** * Zoom into a specified world area. * * @param w0 First world coordinate of zoom area [x,y,z]. * @param w1 Second world coordinate of zoom area [x,y,z]. * @param w2 Third world coordinate of zoom area [x,y,z]. */ public void zoom (double w0[], double w1[], double w2[]) { // Set new world extent currentWorldExtent_.set (w0, w1, w2); // Flag entire scene as damaged window_.updateDamageArea (getRegion()); // Make sure we keep aspect ratio (if required) adjustCurrentWorldExtent(); // Update the transformer transformer_.update (viewport_, currentWorldExtent_); // Redraw all affected elements window_.redraw(); // Rerender the graphics window_.refresh(); // Update scrollbars if present if (scrollHandler_ != null) scrollHandler_.updateScrollBars(); } /** * Unzoom. Unzooming sets the current world extent back to the initial * world extent as specified by the client application by setWorldExtent(). */ public void unzoom() { zoom (initialWorldExtent_.get(0), initialWorldExtent_.get(1), initialWorldExtent_.get(2)); } /** * Pan a specific device distance. * * @param dx Distance to pan in x direction. * @param dy Distance to pan in y direction. */ public void pan (int dx, int dy) { int x0 = viewport_.getX0() - dx; int y0 = viewport_.getY0() - dy; int x1 = viewport_.getX3() - dx; int y1 = viewport_.getY3() - dy; zoom (x0, y0, x1, y1); } /** * Flag the annotation of this scene as valid or invalid. Annotation * is set to invalid if annotation is changed somewhere down the tree. * This is an instruction to the GWindow to redo the annotation on this * scene. When the annotation is redone, this flag is set to valid. * * @param isAnnotationValid True if the annotation of this scene is valid * false otherwise. */ void setAnnotationValid (boolean isAnnotationValid) { isAnnotationValid_ = isAnnotationValid; } /** * Check if annotation in this scene is valid. * * @return True if the annotation is valid, false otherwise. */ boolean isAnnotationValid() { return isAnnotationValid_; } /** * Compute positions of all text (GText) elements in this scene. */ void computeTextPositions() { annotator_.reset(); super.computeTextPositions(); isAnnotationValid_ = true; } /** * Compute positions of all AWT components (GComponent) elements * in this scene. */ void computeComponentPositions() { super.computeComponentPositions(); } /** * Compute positions of the specified positionals. * * @param positionals Positionals to compute positions of. */ void computePositions (Collection positionals) { annotator_.computePositions (positionals); } /** * Compute positions for positional object that are attached * to every vertex of its owner. * * @param positional Positional to compute position for. */ void computeVertexPositions (GPositional positional) { annotator_.computeVertexPositions (positional); } /** * Instruct this scene to update and respond to the specified * scrollbars during zoom. * <p> * <b>NOTE I:</b> The client application is responsible for laying out * the scrollbars in the AWT/Swing GUI. The scrollbars should have no * access listeneres nor logic added, as this is controlled by the * GScene through the internal GScrollHandler object. * <p> * <b>NOTE II:</b> Do not put the graphics panel in a JScrollPane and use * the JScrollPane scrollbars as input to this method, as a JScrollPane * contains scroll logic that interfer with the internal GScene logic. * The correct approach is to create horizontal and vertical JScrollBar * explicitly. * <p> * Specifying both horizontal and vertical scrollbar as <em>null</em> * turns off scroll handling in this scene. * * @param hScrollBar Horizontal scrollbar (or null if a horizontal * scrollbar is not used). * @param hScrollBar Vertical scrollbar (or null if a vertical scrollbar * is not used). */ public void installScrollHandler (Adjustable hScrollBar, Adjustable vScrollBar) { if (hScrollBar == null && vScrollBar == null) scrollHandler_ = null; else scrollHandler_ = new GScrollHandler (this, hScrollBar, vScrollBar); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -