--- a/lib/browser/GraphBrowser/Graph.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/Graph.java Thu Apr 29 22:42:38 1999 +0200
@@ -74,7 +74,7 @@
/********************************************************************/
public Graph(InputStream s,TreeNode tn) throws IOException, ParseError {
- StreamTokenizer tok=new StreamTokenizer(s);
+ StreamTokenizer tok=new StreamTokenizer(new InputStreamReader(s));
String name,dir,vertexID;
Vertex ve1,ve2;
boolean children,unfoldDir;
@@ -1006,7 +1006,7 @@
public void PS(String fname,boolean printable) throws IOException {
FileOutputStream f = new FileOutputStream(fname);
- PrintStream p = new PrintStream(f);
+ PrintWriter p = new PrintWriter(f, true);
if (printable)
p.println("%!PS-Adobe-2.0\n\n%%BeginProlog");
--- a/lib/browser/GraphBrowser/GraphBrowser.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/GraphBrowser.java Thu Apr 29 22:42:38 1999 +0200
@@ -8,7 +8,7 @@
method, which is used for the stand-alone version, as well as
"init(...)", "start(...)" and "stop(...)" methods which are used for
the applet version.
- Note: GraphBrowser is designed for the 1.0.2 version of the JDK.
+ Note: GraphBrowser is designed for the 1.1.x version of the JDK.
***************************************************************************/
package GraphBrowser;
@@ -38,7 +38,7 @@
if (isApplet)
getAppletContext().showStatus("calculating layout, please wait ...");
else {
- f.setCursor(Frame.WAIT_CURSOR);
+ f.setCursor(new Cursor(Cursor.WAIT_CURSOR));
}
}
@@ -46,24 +46,22 @@
if (isApplet)
getAppletContext().showStatus("ready !");
else {
- f.setCursor(Frame.DEFAULT_CURSOR);
+ f.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
public void viewFile(String fname) {
try {
if (isApplet)
- getAppletContext().showDocument(new URL(getDocumentBase(), fname),"_blank");
+ getAppletContext().showDocument(new URL(getDocumentBase(), fname), "_blank");
else {
- String path=gfname.substring(0,gfname.lastIndexOf('/')+1);
- InputStream is;
- String line, text="";
- DataInputStream di;
+ String path = gfname.substring(0, gfname.lastIndexOf('/') + 1);
+ BufferedReader br;
+ String line, text = "";
- is=new FileInputStream(path+fname);
- di=new DataInputStream(is);
- while ((line=di.readLine())!=null)
- text+=line+"\n";
+ br = new BufferedReader(new FileReader(path + fname));
+ while ((line = br.readLine()) != null)
+ text += line + "\n";
if (fname.endsWith(".html")) {
/**** convert HTML to text (just a quick hack) ****/
@@ -106,7 +104,7 @@
}
Frame f=new TextFrame(fname.substring(fname.lastIndexOf('/')+1),text);
- f.resize(500,600);
+ f.setSize(500,600);
f.show();
}
} catch (Exception exn) {
@@ -128,11 +126,20 @@
gv=new GraphView(new Graph(is,tn),this);
tb=new TreeBrowser(tn,gv);
gv.setTreeBrowser(tb);
- Vector v=new Vector(10,10);
+ Vector v = new Vector(10,10);
tn.collapsedDirectories(v);
gv.collapseDir(v);
- Component gv2=new Border(gv,5);
- Component tb2=new Border(tb,5);
+
+ ScrollPane scrollp1 = new ScrollPane();
+ ScrollPane scrollp2 = new ScrollPane();
+ scrollp1.add(gv);
+ scrollp2.add(tb);
+ scrollp1.getHAdjustable().setUnitIncrement(20);
+ scrollp1.getVAdjustable().setUnitIncrement(20);
+ scrollp2.getHAdjustable().setUnitIncrement(20);
+ scrollp2.getVAdjustable().setUnitIncrement(20);
+ Component gv2 = new Border(scrollp1, 5);
+ Component tb2 = new Border(scrollp2, 5);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints cnstr = new GridBagConstraints();
setLayout(gridbag);
@@ -180,7 +187,7 @@
is.close();
}
f=new GraphBrowserFrame(gb);
- f.resize(700,500);
+ f.setSize(700,500);
f.show();
} catch (IOException exn) {
System.out.println("Can't open graph file "+args[0]);
--- a/lib/browser/GraphBrowser/GraphBrowserFrame.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/GraphBrowserFrame.java Thu Apr 29 22:42:38 1999 +0200
@@ -11,71 +11,69 @@
package GraphBrowser;
import java.awt.*;
+import java.awt.event.*;
import java.io.*;
import awtUtilities.*;
-public class GraphBrowserFrame extends Frame {
+public class GraphBrowserFrame extends Frame implements ActionListener {
GraphBrowser gb;
- MenuItem i1,i2;
- String graphDir,psDir;
+ MenuItem i1, i2;
+ String graphDir, psDir;
public void checkMenuItems() {
if (gb.isEmpty()) {
- i1.disable();
- i2.disable();
+ i1.setEnabled(false);
+ i2.setEnabled(false);
} else {
- i1.enable();
- i2.enable();
+ i1.setEnabled(true);
+ i2.setEnabled(true);
}
}
- public boolean action(Event evt, Object arg) {
- if (evt.target instanceof MenuItem) {
- String label=(String)arg;
- if (label.equals("Quit"))
- System.exit(0);
- else if (label.equals("Export to PostScript")) {
- PS(true,label);
- return true;
- } else if (label.equals("Export to EPS")) {
- PS(false,label);
- return true;
- } else if (label.equals("Open ...")) {
- FileDialog fd=new FileDialog(this,"Open graph file",FileDialog.LOAD);
- if (graphDir!=null)
- fd.setDirectory(graphDir);
- fd.show();
- if (fd.getFile()==null) return true;
- graphDir=fd.getDirectory();
- String fname=graphDir+fd.getFile();
- GraphBrowser gb2=new GraphBrowser(fname);
- try {
- InputStream is=new FileInputStream(fname);
- gb2.initBrowser(is);
- is.close();
- } catch (IOException exn) {
- String button[]={"OK"};
- MessageDialog md=new MessageDialog(this,"Error","Can't open file "+fname+".",button);
- md.resize(350,200);
- md.show();
- return true;
- }
- remove(gb);
- add("Center",gb2);
- gb=gb2;
- checkMenuItems();
- validate();
- return true;
+ public void actionPerformed(ActionEvent evt) {
+ String label = evt.getActionCommand();
+ if (label.equals("Quit"))
+ System.exit(0);
+ else if (label.equals("Export to PostScript")) {
+ PS(true, label);
+ return;
+ } else if (label.equals("Export to EPS")) {
+ PS(false, label);
+ return;
+ } else if (label.equals("Open ...")) {
+ FileDialog fd = new FileDialog(this, "Open graph file", FileDialog.LOAD);
+ if (graphDir != null)
+ fd.setDirectory(graphDir);
+ fd.setVisible(true);
+ if (fd.getFile() == null) return;
+ graphDir = fd.getDirectory();
+ String fname = graphDir + fd.getFile();
+ GraphBrowser gb2 = new GraphBrowser(fname);
+ try {
+ InputStream is = new FileInputStream(fname);
+ gb2.initBrowser(is);
+ is.close();
+ } catch (IOException exn) {
+ String button[] = {"OK"};
+ MessageDialog md = new MessageDialog(this, "Error",
+ "Can't open file " + fname + ".", button);
+ md.setSize(350, 200);
+ md.setVisible(true);
+ return;
}
+ remove(gb);
+ add("Center", gb2);
+ gb = gb2;
+ checkMenuItems();
+ validate();
}
- return false;
}
public void PS(boolean printable,String label) {
FileDialog fd=new FileDialog(this,label,FileDialog.SAVE);
if (psDir!=null)
fd.setDirectory(psDir);
- fd.show();
+ fd.setVisible(true);
if (fd.getFile()==null) return;
psDir=fd.getDirectory();
String fname=psDir+fd.getFile();
@@ -85,8 +83,8 @@
MessageDialog md=new MessageDialog(this,"Warning",
"Warning: File "+fname+" already exists. Overwrite?",
buttons);
- md.resize(350,200);
- md.show();
+ md.setSize(350,200);
+ md.setVisible(true);
if (md.getText().equals("Cancel")) return;
}
@@ -96,23 +94,28 @@
String button[]={"OK"};
MessageDialog md=new MessageDialog(this,"Error",
"Unable to write file "+fname+".",button);
- md.resize(350,200);
- md.show();
+ md.setSize(350,200);
+ md.setVisible(true);
}
}
public GraphBrowserFrame(GraphBrowser br) {
super("GraphBrowser");
- gb=br;
- MenuBar mb=new MenuBar();
- Menu m1=new Menu("File");
- m1.add(new MenuItem("Open ..."));
- m1.add(i1=new MenuItem("Export to PostScript"));
- m1.add(i2=new MenuItem("Export to EPS"));
- m1.add(new MenuItem("Quit"));
+ MenuItem i3, i4;
+ gb = br;
+ MenuBar mb = new MenuBar();
+ Menu m1 = new Menu("File");
+ m1.add(i3 = new MenuItem("Open ..."));
+ m1.add(i1 = new MenuItem("Export to PostScript"));
+ m1.add(i2 = new MenuItem("Export to EPS"));
+ m1.add(i4 = new MenuItem("Quit"));
+ i1.addActionListener(this);
+ i2.addActionListener(this);
+ i3.addActionListener(this);
+ i4.addActionListener(this);
checkMenuItems();
mb.add(m1);
setMenuBar(mb);
- add("Center",br);
+ add("Center", br);
}
}
--- a/lib/browser/GraphBrowser/GraphView.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/GraphView.java Thu Apr 29 22:42:38 1999 +0200
@@ -12,25 +12,28 @@
package GraphBrowser;
import java.awt.*;
+import java.awt.event.*;
import java.io.*;
import java.util.*;
import awtUtilities.*;
-public class GraphView extends ScrollCanvas {
- Graph gra,gra2;
- GraphBrowser parent;
- Vertex v=null;
- Vector collapsed=new Vector(10,10);
- Vector collapsedDirs=new Vector(10,10);
+public class GraphView extends Canvas implements MouseListener, MouseMotionListener {
+ Graph gra, gra2;
+ GraphBrowser browser;
+ Vertex v = null;
+ Vector collapsed = new Vector(10,10);
+ Vector collapsedDirs = new Vector(10,10);
TreeBrowser tb;
long timestamp;
- Vertex highlighted=null;
+ Vertex highlighted = null;
+ Dimension size;
+ boolean parent_needs_layout;
public void setTreeBrowser(TreeBrowser br) {
tb=br;
}
- public GraphBrowser getBrowser() { return parent; }
+ public GraphBrowser getBrowser() { return browser; }
public Graph getGraph() { return gra; }
@@ -38,23 +41,35 @@
public GraphView(Graph gr,GraphBrowser br) {
gra2=gr;
- parent=br;
+ browser=br;
gra=(Graph)(gra2.clone());
+ parent_needs_layout = true;
+ size = new Dimension(0, 0);
+ addMouseListener(this);
+ addMouseMotionListener(this);
}
public void PS(String fname,boolean printable) throws IOException {
gra.PS(fname,printable);
}
- public void paintCanvas(Graphics g)
- {
- set_size(gra.max_x-gra.min_x,gra.max_y-gra.min_y);
+ public void paint(Graphics g) {
gra.draw(g);
+ if (highlighted!=null) highlighted.drawBox(g,Color.white);
+ size = new Dimension(gra.max_x-gra.min_x, gra.max_y-gra.min_y);
+ if (parent_needs_layout) {
+ parent_needs_layout = false;
+ getParent().doLayout();
+ }
}
- public boolean mouseMove(Event evt,int x,int y) {
- x+=gra.min_x;
- y+=gra.min_y;
+ public Dimension getPreferredSize() {
+ return size;
+ }
+
+ public void mouseMoved(MouseEvent evt) {
+ int x = evt.getX() + gra.min_x;
+ int y = evt.getY() + gra.min_y;
Vertex v2=gra.vertexAt(x,y);
Graphics g=getGraphics();
@@ -68,9 +83,10 @@
if (v2!=null) v2.drawButtons(g);
v=v2;
}
- return true;
}
+ public void mouseDragged(MouseEvent evt) {}
+
/*****************************************************************/
/* This method is called if successor / predecessor nodes (whose */
/* numbers are stored in Vector c) of a certain node should be */
@@ -122,22 +138,34 @@
}
public void relayout() {
- parent.showWaitMessage();
+ browser.showWaitMessage();
highlighted=null;
gra.layout(getGraphics());
v=null;
+ parent_needs_layout = true;
update(getGraphics());
- parent.showReadyMessage();
+ browser.showReadyMessage();
}
public void focusToVertex(int n) {
Vertex vx=gra.getVertexByNum(n);
if (vx!=null) {
- focus_to(vx.getX()-gra.min_x,vx.getY()-gra.min_y);
- highlighted=vx;
+ ScrollPane scrollp = (ScrollPane)(getParent());
+ Dimension vpsize = scrollp.getViewportSize();
+
+ int x = vx.getX()-gra.min_x;
+ int y = vx.getY()-gra.min_y;
+ int offset_x = Math.min(scrollp.getHAdjustable().getMaximum(),
+ Math.max(0,x-vpsize.width/2));
+ int offset_y = Math.min(scrollp.getVAdjustable().getMaximum(),
+ Math.max(0,y-vpsize.height/2));
+
Graphics g=getGraphics();
g.translate(-gra.min_x,-gra.min_y);
+ if (highlighted!=null) highlighted.drawBox(g,Color.lightGray);
vx.drawBox(g,Color.white);
+ highlighted=vx;
+ scrollp.setScrollPosition(offset_x, offset_y);
}
}
@@ -165,11 +193,11 @@
}
}
- public boolean mouseDown(Event evt,int x,int y) {
- Vector code=null;
+ public void mouseClicked(MouseEvent evt) {
+ Vector code = null;
Vertex v2;
- x+=gra.min_x;
- y+=gra.min_y;
+ int x = evt.getX() + gra.min_x;
+ int y = evt.getY() + gra.min_y;
if (v!=null) {
int num=v.getNumber();
@@ -214,15 +242,14 @@
inflateNode(v.getInflate());
v=null;
} else {
- if (evt.when-timestamp < 400 && !(v.getPath().equals("")))
- parent.viewFile(v.getPath());
- timestamp=evt.when;
+ if (evt.getWhen()-timestamp < 400 && !(v.getPath().equals("")))
+ browser.viewFile(v.getPath());
+ timestamp=evt.getWhen();
}
}
- return true;
}
- public boolean mouseExit(Event evt,int x,int y) {
+ public void mouseExited(MouseEvent evt) {
Graphics g=getGraphics();
g.translate(-gra.min_x,-gra.min_y);
if (highlighted!=null) {
@@ -231,6 +258,11 @@
}
if (v!=null) v.removeButtons(g);
v=null;
- return true;
}
+
+ public void mouseEntered(MouseEvent evt) {}
+
+ public void mousePressed(MouseEvent evt) {}
+
+ public void mouseReleased(MouseEvent evt) {}
}
--- a/lib/browser/GraphBrowser/NormalVertex.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/NormalVertex.java Thu Apr 29 22:42:38 1999 +0200
@@ -138,7 +138,7 @@
g.setColor(Color.black);
}
- public void PS(PrintStream p) {
+ public void PS(PrintWriter p) {
p.print(leftX()+" "+getY()+" "+gra.box_width+" "+
gra.box_height+" (");
for (int i=0;i<label.length();i++)
--- a/lib/browser/GraphBrowser/Spline.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/Spline.java Thu Apr 29 22:42:38 1999 +0200
@@ -104,7 +104,7 @@
g.drawLine(p.x,p.y,end.x,end.y);
}
- public void PS(PrintStream p) {
+ public void PS(PrintWriter p) {
Point p0,p1,p2;
int i;
--- a/lib/browser/GraphBrowser/TreeBrowser.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/TreeBrowser.java Thu Apr 29 22:42:38 1999 +0200
@@ -11,24 +11,41 @@
package GraphBrowser;
import java.awt.*;
-import awtUtilities.ScrollCanvas;
+import java.awt.event.*;
import java.util.*;
-public class TreeBrowser extends ScrollCanvas
+public class TreeBrowser extends Canvas implements MouseListener
{
TreeNode t;
TreeNode selected;
GraphView gv;
long timestamp;
+ Dimension size;
+ boolean parent_needs_layout;
- public TreeBrowser(TreeNode tn,GraphView gr) {
+ public TreeBrowser(TreeNode tn, GraphView gr) {
t=tn;gv=gr;
+ size = new Dimension(0, 0);
+ parent_needs_layout = true;
+ addMouseListener(this);
}
- public boolean mouseDown(Event e,int x,int y)
+ public Dimension getPreferredSize() {
+ return size;
+ }
+
+ public void mouseEntered(MouseEvent evt) {}
+
+ public void mouseExited(MouseEvent evt) {}
+
+ public void mouseReleased(MouseEvent evt) {}
+
+ public void mousePressed(MouseEvent evt) {}
+
+ public void mouseClicked(MouseEvent e)
{
- TreeNode l=t.lookup(y);
+ TreeNode l=t.lookup(e.getY());
if (l!=null)
{
@@ -41,15 +58,15 @@
Vertex vx=gv.getGraph().getVertexByNum(l.getNumber());
gv.focusToVertex(l.getNumber());
vx=gv.getOriginalGraph().getVertexByNum(l.getNumber());
- if (e.when-timestamp < 400 && !(vx.getPath().equals("")))
+ if (e.getWhen()-timestamp < 400 && !(vx.getPath().equals("")))
gv.getBrowser().viewFile(vx.getPath());
- timestamp=e.when;
+ timestamp=e.getWhen();
}
- selected=l;repaint();
-
+ selected=l;
+ parent_needs_layout = true;
+ repaint();
}
- return true;
}
public void selectNode(TreeNode nd) {
@@ -58,13 +75,19 @@
t.collapsedDirectories(v);
gv.collapseDir(v);
gv.relayout();
- selected=nd;repaint();
+ selected=nd;
+ parent_needs_layout = true;
+ repaint();
}
- public void paintCanvas(Graphics g)
+ public void paint(Graphics g)
{
- Dimension d=t.draw(g,5,5,selected);
- set_size(5+d.width,5+d.height);
+ Dimension d = t.draw(g,5,5,selected);
+ if (parent_needs_layout) {
+ size = new Dimension(5+d.width, 5+d.height);
+ parent_needs_layout = false;
+ getParent().doLayout();
+ }
}
}
--- a/lib/browser/GraphBrowser/TreeNode.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/TreeNode.java Thu Apr 29 22:42:38 1999 +0200
@@ -33,7 +33,7 @@
public class TreeNode
{
- static Font f=new Font("Helvetica",Font.PLAIN,15);
+ static Font f=new Font("Helvetica", Font.PLAIN, 14);
int starty,endy,number;
String name,path;
--- a/lib/browser/GraphBrowser/Vertex.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/GraphBrowser/Vertex.java Thu Apr 29 22:42:38 1999 +0200
@@ -202,5 +202,5 @@
public boolean rightButton(int x,int y) { return false; }
- public void PS(PrintStream p) {}
+ public void PS(PrintWriter p) {}
}
--- a/lib/browser/awtUtilities/Border.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/awtUtilities/Border.java Thu Apr 29 22:42:38 1999 +0200
@@ -14,7 +14,7 @@
public class Border extends Panel {
int bs;
- public Insets insets() {
+ public Insets getInsets() {
return new Insets(bs*3/2,bs*3/2,bs*3/2,bs*3/2);
}
@@ -25,8 +25,8 @@
}
public void paint(Graphics g) {
- int w=size().width;
- int h=size().height;
+ int w = getSize().width;
+ int h = getSize().height;
int x1[]={0,bs,w-bs,w}, y1[]={0,bs,bs,0};
int x2[]={w,w-bs,w-bs,w}, y2[]={0,bs,h-bs,h};
int y3[]={h,h-bs,h-bs,h};
--- a/lib/browser/awtUtilities/MessageDialog.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/awtUtilities/MessageDialog.java Thu Apr 29 22:42:38 1999 +0200
@@ -10,18 +10,16 @@
package awtUtilities;
import java.awt.*;
+import java.awt.event.*;
-public class MessageDialog extends Dialog {
+public class MessageDialog extends Dialog implements ActionListener {
String txt;
public String getText() { return txt; }
- public boolean action(Event evt, Object arg) {
- if (evt.target instanceof Button) {
- txt=(String)arg;
- hide();
- return true;
- } else return false;
+ public void actionPerformed(ActionEvent evt) {
+ txt = evt.getActionCommand();
+ setVisible(false);
}
public MessageDialog(Frame parent,String title,String text,String []buttons) {
@@ -48,7 +46,10 @@
}
add(p1);add(p2);
- for (i=0;i<buttons.length;i++)
- p2.add(new Button(buttons[i]));
+ for (i=0;i<buttons.length;i++) {
+ Button bt = new Button(buttons[i]);
+ p2.add(bt);
+ bt.addActionListener(this);
+ }
}
}
--- a/lib/browser/awtUtilities/TextFrame.java Thu Apr 29 18:34:30 1999 +0200
+++ b/lib/browser/awtUtilities/TextFrame.java Thu Apr 29 22:42:38 1999 +0200
@@ -10,19 +10,20 @@
package awtUtilities;
import java.awt.*;
+import java.awt.event.*;
-public class TextFrame extends Frame {
- public boolean action(Event evt,Object obj) {
- if (evt.target instanceof Button)
- hide();
- return true;
+public class TextFrame extends Frame implements ActionListener {
+ public void actionPerformed(ActionEvent evt) {
+ setVisible(false);
}
public TextFrame(String title,String text) {
super(title);
- TextArea ta=new TextArea(text,200,80);
+ TextArea ta = new TextArea(text,200,80);
+ Button bt = new Button("Dismiss");
+ bt.addActionListener(this);
ta.setEditable(false);
- add("Center",ta);
- add("South",new Button("Dismiss"));
+ add("Center", ta);
+ add("South", bt);
}
}