/* * TouchGraph LLC. Apache-Style Software License * * * Copyright (c) 2002 Alexander Shapiro. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by * TouchGraph LLC (http://www.touchgraph.com/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "TouchGraph" or "TouchGraph LLC" must not be used to endorse * or promote products derived from this software without prior written * permission. For written permission, please contact * alex@touchgraph.com * * 5. Products derived from this software may not be called "TouchGraph", * nor may "TouchGraph" appear in their name, without prior written * permission of alex@touchgraph.com. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL TOUCHGRAPH OR ITS CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * */ package com.touchgraph.graphlayout.interaction; import com.touchgraph.graphlayout.*; import java.awt.event.*; import javax.swing.*; /** HVScroll: Allows for scrolling horizontaly+vertically. This can be * done in all sorts of ways, for instance by using the scrollbars, or by * dragging. * *
* This code is more complex then it would seem it should be, because scrolling
* has to be independent of the screen being warped by lenses. HVScroll needs
* to use the tgLensSet object because the offset is recorded in real coordinates, while
* the user interacts with the drawn coordinates.
*
* @author Alexander Shapiro
* @version 1.20
*/
public class HVScroll implements GraphListener {
private DScrollbar horizontalSB;
private DScrollbar verticalSB;
HVLens hvLens;
HVDragUI hvDragUI;
HVScrollToCenterUI hvScrollToCenterUI;
public boolean scrolling;
private boolean adjustmentIsInternal;
private TGPanel tgPanel;
private TGLensSet tgLensSet;
TGPoint2D offset;
// ............
/** Constructor with a TGPanel tgp and TGLensSet tgls.
*/
public HVScroll(TGPanel tgp, TGLensSet tgls) {
tgPanel=tgp;
tgLensSet=tgls;
offset=new TGPoint2D(0,0);
scrolling = false;
adjustmentIsInternal = false;
horizontalSB = new DScrollbar(JScrollBar.HORIZONTAL, 0, 100, -1000, 1100);
horizontalSB.setBlockIncrement(100);
horizontalSB.setUnitIncrement(20);
horizontalSB.addAdjustmentListener(new horizAdjustmentListener());
verticalSB = new DScrollbar(JScrollBar.VERTICAL, 0, 100, -1000, 1100);
verticalSB.setBlockIncrement(100);
verticalSB.setUnitIncrement(20);
verticalSB.addAdjustmentListener(new vertAdjustmentListener());
hvLens=new HVLens();
hvDragUI = new HVDragUI(); //Hopefully this approach won't eat too much memory
hvScrollToCenterUI = new HVScrollToCenterUI();
tgPanel.addGraphListener(this);
}
public JScrollBar getHorizontalSB() { return horizontalSB; }
public JScrollBar getVerticalSB() { return verticalSB; }
public HVDragUI getHVDragUI() { return hvDragUI; }
public HVLens getLens() { return hvLens; }
public TGAbstractClickUI getHVScrollToCenterUI() { return hvScrollToCenterUI; }
public TGPoint2D getTopLeftDraw() {
TGPoint2D tld = tgPanel.getTopLeftDraw();
tld.setLocation(tld.x-tgPanel.getSize().width/4,tld.y-tgPanel.getSize().height/4);
return tld;
}
public TGPoint2D getBottomRightDraw() {
TGPoint2D brd = tgPanel.getBottomRightDraw();
brd.setLocation(brd.x+tgPanel.getSize().width/4,brd.y+tgPanel.getSize().height/4);
return brd;
}
public TGPoint2D getDrawCenter() { //Should probably be called from tgPanel
return new TGPoint2D(tgPanel.getSize().width/2,tgPanel.getSize().height/2);
}
public void graphMoved() { //From GraphListener interface
if (tgPanel.getDragNode()==null && tgPanel.getSize().height>0) {
TGPoint2D drawCenter = getDrawCenter();
TGPoint2D tld = getTopLeftDraw();
TGPoint2D brd = getBottomRightDraw();
double newH = (-(tld.x-drawCenter.x)/(brd.x-tld.x)*2000-1000);
double newV = (-(tld.y-drawCenter.y)/(brd.y-tld.y)*2000-1000);
boolean beyondBorder;
beyondBorder = true;
if(newH