📄 glpanel.java~
字号:
/*
* TouchGraph LLC. Apache-Style Software License
*
*
* Copyright (c) 2001-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;
import com.touchgraph.graphlayout.interaction.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Hashtable;
/** GLPanel contains code for adding scrollbars and interfaces to the TGPanel
* The "GL" prefix indicates that this class is GraphLayout specific, and
* will probably need to be rewritten for other applications.
*
* @author Alexander Shapiro
* @version 1.21 $Id: GLPanel.java,v 1.31 2002/04/04 06:19:49 x_ander Exp $
*/
public class GLPanel extends JPanel {
public String zoomLabel = "Zoom"; // label for zoom menu item
public String rotateLabel = "Rotate"; // label for rotate menu item
public String localityLabel = "Locality"; // label for locality menu item
public HVScroll hvScroll;
public ZoomScroll zoomScroll;
//public HyperScroll hyperScroll; // unused
public RotateScroll rotateScroll;
public LocalityScroll localityScroll;
public JPopupMenu glPopup;
public Hashtable scrollBarHash; //= new Hashtable();
protected TGPanel tgPanel;
protected TGLensSet tgLensSet;
protected TGUIManager tgUIManager;
private Color defaultColor = Color.lightGray;
private String [] labels;
private int [] ass;
private double [] strength;
private double [][] dist;
private int K;
private int N;
// ............
/** Default constructor.
*/
public GLPanel() {
scrollBarHash = new Hashtable();
tgLensSet = new TGLensSet();
tgPanel = new TGPanel();
hvScroll = new HVScroll(tgPanel, tgLensSet);
zoomScroll = new ZoomScroll(tgPanel);
//hyperScroll = new HyperScroll(tgPanel);
rotateScroll = new RotateScroll(tgPanel);
localityScroll = new LocalityScroll(tgPanel);
initialize();
}
public GLPanel(Color color, String [] l, int [] a, double [] s, int NN, double [][] d, int KK) {
defaultColor = color;
this.setBackground(color);
scrollBarHash = new Hashtable();
tgLensSet = new TGLensSet();
tgPanel = new TGPanel();
hvScroll = new HVScroll(tgPanel, tgLensSet);
zoomScroll = new ZoomScroll(tgPanel);
//hyperScroll = new HyperScroll(tgPanel);
rotateScroll = new RotateScroll(tgPanel);
localityScroll = new LocalityScroll(tgPanel);
labels = l;
ass = a;
strength = s;
N = NN;
dist = d;
K = KK;
initialize();
}
/** Constructor with a Color to be used for UI background.
*/
public GLPanel( Color color ) {
defaultColor = color;
this.setBackground(color);
scrollBarHash = new Hashtable();
tgLensSet = new TGLensSet();
tgPanel = new TGPanel();
tgPanel.setBackground(color);
hvScroll = new HVScroll(tgPanel, tgLensSet);
//hvScroll.getHorizontalSB().setBackground(Color.orange);
//hvScroll.getVerticalSB().setBackground(Color.cyan);
zoomScroll = new ZoomScroll(tgPanel);
//zoomScroll.getZoomSB().setBackground(Color.green);
//hyperScroll = new HyperScroll(tgPanel);
rotateScroll = new RotateScroll(tgPanel);
//rotateScroll.getRotateSB().setBackground(Color.blue);
localityScroll = new LocalityScroll(tgPanel);
//localityScroll.getLocalitySB().setBackground(Color.red);
initialize();
}
/** Initialize panel, lens, and establish a random graph as a demonstration.
*/
public void initialize() {
buildPanel();
buildLens();
tgPanel.setLensSet(tgLensSet);
addUIs();
//tgPanel.addNode(); //Add a starting node.
try {
//randomGraph();
myGraph();
} catch ( TGException tge ) {
System.err.println(tge.getMessage());
tge.printStackTrace(System.err);
}
tgPanel.setSelect(tgPanel.getGES().getFirstNode()); //Select first node, so hiding works
setVisible(true);
}
/** Return the TGPanel used with this GLPanel. */
public TGPanel getTGPanel() {
return tgPanel;
}
// navigation .................
/** Return the HVScroll used with this GLPanel. */
public HVScroll getHVScroll()
{
return hvScroll;
}
///** Return the HyperScroll used with this GLPanel. */
//public HyperScroll getHyperScroll()
//{
// return hyperScroll;
//}
/** Sets the horizontal offset to p.x, and the vertical offset to p.y
* given a Point <tt>p<tt>.
*/
public void setOffset( Point p ) {
hvScroll.setOffset(p);
};
/** Return the horizontal and vertical offset position as a Point. */
public Point getOffset() {
return hvScroll.getOffset();
};
// rotation ...................
/** Return the RotateScroll used with this GLPanel. */
public RotateScroll getRotateScroll()
{
return rotateScroll;
}
/** Set the rotation angle of this GLPanel (allowable values between 0 to 359). */
public void setRotationAngle( int angle ) {
rotateScroll.setRotationAngle(angle);
}
/** Return the rotation angle of this GLPanel. */
public int getRotationAngle() {
return rotateScroll.getRotationAngle();
}
// locality ...................
/** Return the LocalityScroll used with this GLPanel. */
public LocalityScroll getLocalityScroll()
{
return localityScroll;
}
/** Set the locality radius of this TGScrollPane
* (allowable values between 0 to 4, or LocalityUtils.INFINITE_LOCALITY_RADIUS).
*/
public void setLocalityRadius( int radius ) {
localityScroll.setLocalityRadius(radius);
}
/** Return the locality radius of this GLPanel. */
public int getLocalityRadius() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -