File: Grapher.java

package info (click to toggle)
jftp 1.60%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,268 kB
  • ctags: 7,519
  • sloc: java: 21,584; xml: 187; sh: 15; makefile: 13
file content (217 lines) | stat: -rw-r--r-- 5,273 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import java.io.*;
import java.net.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;

public class Grapher extends Canvas
{

public String files[] = new String[] {"JFtp.java", "LoadSet.java","EventCollector.java", "EventProcessor.java", "FtpEvent.java","DirCellRenderer.java","DirPanel.java",
"Displayer.java","HostChooser.java","HostList.java","Properties.java","Updater.java","GUIDefaults.java","HPasswordField.java",
"DataConnection.java","FtpClient.java","FtpConnection.java","FtpConstants.java","FtpServerSocket.java","FtpURLConnection.java",
"FtpURLStreamHandler.java","JConnection.java","LocalIO.java","Log.java","Log4JLogger.java","Logger.java","SystemLogger.java",
"CommandLine.java","SaveSet.java","Settings.java","Acceptor.java","Event.java","EventHandler.java","FtpEventConstants.java",
"FtpEventHandler.java","AutoRemover.java","Creator.java","DirCanvas.java","DirEntry.java","DirLister.java","DownloadList.java",
"LoadPanel.java","PathChanger.java","RemoteCommand.java","Remover.java","RemoverQuery.java","ResumeDialog.java",
"StatusCanvas.java","StatusPanel.java","Template.java","HFrame.java","HImage.java","HImageButton.java","HPanel.java",
"HTextField.java","ConnectionHandler.java","ConnectionListener.java","FtpServer.java","Transfer.java","StringUtils.java" };

public String prefix =  "/home/cdemon/JFtp/j-ftp/src/java/net/sf/jftp/";
public String[] paths = new String[] { prefix, prefix+"gui/", prefix+"net/", prefix+"util/", prefix+"config/", prefix+"gui/framework",
								   prefix+"event/" };

public Hashtable table = new Hashtable();
public Hashtable pool = new Hashtable();

public static int width = 800;
public static int height = 600;

public Grapher()
{
 setSize(width,height);

 try
 {
	for(int i=0; i<files.length; i++)
	{
		File f = getFile(files[i]);

		if(f != null && f.exists())
		{
			for(int j=0; j<files.length; j++)
			{
				int x = countRelations(f, files[j]);
				if(x > 0) table.put(files[i] + ":" +files[j].substring(0, files[j].indexOf(".java")),  new String(""+x));
			}
		}
	}

 show();
 repaint();
 }
 catch(Exception ex)
 {
 	ex.printStackTrace();
 }
}

public void paint(Graphics g)
{
	// init
	g.setColor(Color.white);
	g.fillRect(0,0,getSize().width, getSize().height);
	g.setColor(Color.blue);
	g.setFont(new Font("serif", Font.BOLD, 14));

	// points
 	Random r = new Random();

	for(int i=0; i<files.length; i++)
	{
		while(true)
		{
			int x = r.nextInt(width-200);
			int y = r.nextInt(height-20);
			if(y<30) y=30;

			if(check(x, y))
			{
				//System.out.println("adding: " + files[i]);
				String tmp = files[i].substring(0,files[i].indexOf(".java"));
				Point p = new Point(x, y);
				pool.put(tmp, p);

				linkPoints(g, p);

				//g.drawString(tmp, x, y);

				break;
			}
		}
	}

	g.setColor(Color.blue);

	for(int i=0; i<files.length; i++)
	{
		String tmp = files[i].substring(0,files[i].indexOf(".java"));
		Point p2 = (Point) pool.get(tmp);
		if(p2 == null) continue;
		//g.setColor(new Color(255,180,180));
		//g.fillRect((int)  p2.getX(), (int)  p2.getY()-12, 80,  15);
		//g.setColor(Color.blue);
		g.drawString(tmp, (int)  p2.getX(), (int)  p2.getY());
	}

}

public void linkPoints(Graphics g, Point p)
{
	// fill

	Enumeration k = table.keys();
	Enumeration e = table.elements();
	String xk = null;
	String file = null;
	String link = null;

	while(k.hasMoreElements())
	{
		xk = (String) k.nextElement();
		int x = Integer.parseInt((String)e.nextElement());

		file = xk.substring(0, xk.indexOf(":"));
		file = file.substring(0,file.indexOf(".java"));
		link = xk.substring( xk.indexOf(":")+1);

		//System.out.println("<" + file + "> " + "(" + link + ")" + " - " + x);
		Point x2 = (Point) pool.get(file);
		if(x2 == null) continue;

		if(x > 0)
		{
			//for(int y=0; y<x; y++)
			//{
				int color = 255 - x*10 +40;
				if(color < 0) color=0;
				if(color > 255) color = 255;

				g.setColor(new Color(color,color,color));
				if(color < 255) g.drawLine(((int)p.getX()+20),((int)p.getY()+15),((int)x2.getX()+20),((int)x2.getY()+15));
			//}
		}

	}
}


public boolean check(int x, int y)
{
	Enumeration e = pool.elements();
	Point d = null;
	int a;
	int b;

	while(e.hasMoreElements())
	{
		d = (Point) e.nextElement();
		a = (int) d.getX();
		b = (int) d.getY();

		if(a > x-100 && a < x+100) {
			if(b > y-20 && b < y +20)
			{
				return false;
			}
		}
	}

	return true;
}

public int countRelations(File f, String what) throws IOException
{
	int x = 0;
	String tmp;
	what = what.substring(0, what.indexOf(".java"));

  	URL url = f.toURL();
	DataInputStream in = new DataInputStream(new BufferedInputStream(url.openStream()));

	while(true)
	{
		tmp = in.readLine();
		//System.out.println(f.getAbsolutePath() + ": " + tmp + ": " +what);
		if(tmp == null) break;
		if(tmp.indexOf(what) >= 0) x++;
	}

	in.close();

	return x;
}

public File getFile(String name)
{
	for(int i=0; i<paths.length; i++)
	{
		File f = new File(paths[i]+name);
		if(f.exists()) return f;
	}

	return null;
}

public static void main(String argv[])
{
	Grapher g = new Grapher();
	JFrame j = new JFrame();
	j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	j.getContentPane().setLayout(new BorderLayout(5,5));
	j.setSize(width+10,height+25);
	j.getContentPane().add("Center",g);
	j.show();
}

}