001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: AutoScrollSelectionRectangle.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.gui.old;
009:
010: import java.awt.*;
011: import java.awt.geom.GeneralPath;
012:
013: class AutoScrollSelectionRectangle extends AutoScroll {
014: private Point mStructurePanelSelectionStartPoint = null;
015:
016: private GeneralPath mAutoScrollSelectionRectangle = null;
017: private Point mAutoScrollSelectionStartPoint = null;
018: private Point mAutoScrollSelectionEndPoint = null;
019:
020: AutoScrollSelectionRectangle(StructurePanel structurePanel,
021: Point firstDestination, Point dragStartPoint) {
022: super (structurePanel);
023:
024: getStructurePanel().eraseSelectionRectangle();
025:
026: mStructurePanelSelectionStartPoint = dragStartPoint;
027:
028: mAutoScrollSelectionRectangle = new GeneralPath();
029: mAutoScrollSelectionStartPoint = new Point();
030: mAutoScrollSelectionEndPoint = new Point();
031:
032: initializeAutoScroll(firstDestination, structurePanel);
033: }
034:
035: void prepareVisualAssistanceCustom() {
036: mAutoScrollSelectionStartPoint.x = getScrollpaneLocationOnGlasspaneX()
037: + mStructurePanelSelectionStartPoint.x
038: - getScrollPane().getViewport().getViewPosition().x;
039: mAutoScrollSelectionStartPoint.y = getScrollpaneLocationOnGlasspaneY()
040: + mStructurePanelSelectionStartPoint.y
041: - getScrollPane().getViewport().getViewPosition().y;
042: }
043:
044: void calculateVisualAssistanceCustom(Point destination,
045: int horizontalId, int verticalId) {
046: switch (horizontalId) {
047: case VISUAL_ASSISTANCE_HORIZONTAL_LEFT:
048: mAutoScrollSelectionEndPoint.x = getScrollpaneLocationOnGlasspaneX();
049: break;
050: case VISUAL_ASSISTANCE_HORIZONTAL_MIDDLE:
051: mAutoScrollSelectionEndPoint.x = getScrollpaneLocationOnGlasspaneX()
052: + destination.x
053: - getScrollPane().getViewport().getViewPosition().x;
054: break;
055: case VISUAL_ASSISTANCE_HORIZONTAL_RIGHT:
056: mAutoScrollSelectionEndPoint.x = getScrollpaneLocationOnGlasspaneX()
057: + getViewRectWidth() - 1;
058: break;
059: }
060: switch (verticalId) {
061: case VISUAL_ASSISTANCE_VERTICAL_TOP:
062: mAutoScrollSelectionEndPoint.y = getScrollpaneLocationOnGlasspaneY();
063: break;
064: case VISUAL_ASSISTANCE_VERTICAL_MIDDLE:
065: mAutoScrollSelectionEndPoint.y = getScrollpaneLocationOnGlasspaneY()
066: + destination.y
067: - getScrollPane().getViewport().getViewPosition().y;
068: break;
069: case VISUAL_ASSISTANCE_VERTICAL_BOTTOM:
070: mAutoScrollSelectionEndPoint.y = getScrollpaneLocationOnGlasspaneY()
071: + getViewRectHeight() - 1;
072: break;
073: }
074: }
075:
076: void eraseVisualAssistanceCustom(Graphics2D g2d) {
077: g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
078: RenderingHints.VALUE_STROKE_PURE);
079: g2d
080: .setStroke(getStructurePanel()
081: .getSelectionRectangleStroke());
082: g2d.setXORMode(Color.white);
083: g2d.draw(mAutoScrollSelectionRectangle);
084: }
085:
086: void updateVisualAssistanceAfterScroll(int horizontalOffset,
087: int verticalOffset) {
088: mAutoScrollSelectionStartPoint.x -= horizontalOffset;
089: mAutoScrollSelectionStartPoint.y -= verticalOffset;
090: }
091:
092: void drawVisualAssistanceCustom(Graphics2D g2d) {
093: g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
094: RenderingHints.VALUE_STROKE_PURE);
095: g2d
096: .setStroke(getStructurePanel()
097: .getSelectionRectangleStroke());
098: g2d.setXORMode(Color.white);
099: mAutoScrollSelectionRectangle.reset();
100: mAutoScrollSelectionRectangle.moveTo(
101: mAutoScrollSelectionStartPoint.x,
102: mAutoScrollSelectionStartPoint.y);
103: mAutoScrollSelectionRectangle.lineTo(
104: mAutoScrollSelectionEndPoint.x,
105: mAutoScrollSelectionStartPoint.y);
106: mAutoScrollSelectionRectangle.lineTo(
107: mAutoScrollSelectionEndPoint.x,
108: mAutoScrollSelectionEndPoint.y);
109: mAutoScrollSelectionRectangle.lineTo(
110: mAutoScrollSelectionStartPoint.x,
111: mAutoScrollSelectionEndPoint.y);
112: mAutoScrollSelectionRectangle.lineTo(
113: mAutoScrollSelectionStartPoint.x,
114: mAutoScrollSelectionStartPoint.y);
115: g2d.draw(mAutoScrollSelectionRectangle);
116: }
117:
118: void cleanupVisualAssistanceCustom() {
119: }
120: }
|