Skip to content

Commit f95507b

Browse files
committed
upgrade to scala 2.8, switched to jung library, enhanced gui, enabled jsp parsing. Olaf Sonderegger
1 parent 93a482a commit f95507b

14 files changed

+471
-268
lines changed

pom.xml

100644100755
+27-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<version>1.0-SNAPSHOT</version>
66
<inceptionYear>2010</inceptionYear>
77
<properties>
8-
<scala.version>2.7.7</scala.version>
8+
<scala.version>2.8.0</scala.version>
9+
<jung.version>2.0.1</jung.version>
910
</properties>
1011

1112
<repositories>
@@ -54,16 +55,31 @@
5455
<artifactId>scala-swing</artifactId>
5556
<version>${scala.version}</version>
5657
</dependency>
57-
<dependency>
58-
<groupId>org.jgrapht</groupId>
59-
<artifactId>jgrapht-jdk1.5</artifactId>
60-
<version>0.7.3</version>
61-
</dependency>
62-
<dependency>
63-
<groupId>jgraph</groupId>
64-
<artifactId>jgraph</artifactId>
65-
<version>5.13.0.0</version>
66-
</dependency>
58+
<dependency>
59+
<groupId>net.sf.jung</groupId>
60+
<artifactId>jung-api</artifactId>
61+
<version>${jung.version}</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>net.sf.jung</groupId>
65+
<artifactId>jung-graph-impl</artifactId>
66+
<version>${jung.version}</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>net.sf.jung</groupId>
70+
<artifactId>jung-algorithms</artifactId>
71+
<version>${jung.version}</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>net.sf.jung</groupId>
75+
<artifactId>jung-io</artifactId>
76+
<version>${jung.version}</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>net.sf.jung</groupId>
80+
<artifactId>jung-visualization</artifactId>
81+
<version>${jung.version}</version>
82+
</dependency>
6783
</dependencies>
6884

6985
<build>

src/main/scala/net/rawyler/struts/App.scala

100644100755
+108-62
Original file line numberDiff line numberDiff line change
@@ -4,99 +4,145 @@ import scala.swing._
44

55
import scala.swing.event.ButtonClicked
66

7-
import javax.swing.{JFrame, JScrollPane, UIManager}
7+
import java.awt.{Color,Toolkit}
88

9-
import java.awt.Dimension
9+
import javax.swing.{JFrame, JScrollPane, UIManager}
1010

1111
import javax.swing.filechooser.FileNameExtensionFilter
1212

1313
import java.io.{ File, IOException }
1414

15-
import org.jgrapht.ext.JGraphModelAdapter
16-
17-
import org.jgrapht.graph.DefaultEdge
18-
19-
import org.jgraph.JGraph
20-
2115

2216
/**
2317
* Read XML files and generate the graph
2418
*/
25-
object App extends SimpleGUIApplication {
26-
27-
final val WIDTH = 1600
28-
29-
final val HEIGHT = 1024
19+
object App extends SimpleSwingApplication {
20+
21+
// val reader = new StrutsXmlReader
22+
val reader = new StrutsReader
3023

31-
val reader = new StrutsXmlReader
32-
33-
val graphCreator = new GraphCreator
24+
// val graphCreator = new GraphCreator
25+
val jung = new JUNGFacade
26+
27+
val screenSize = Toolkit.getDefaultToolkit().getScreenSize()
3428

3529
var currentFiles: Seq[File] = null
36-
37-
val mainPanel = new BoxPanel(Orientation.Vertical) {
30+
31+
val buttonPanel = new BoxPanel(Orientation.Horizontal) {
32+
33+
border = Swing.EmptyBorder(10,10,10,10)
34+
3835
val openFilesButton = new Button {
3936
text = "Open file(s)"
4037
}
38+
val saveGraphAsButton = new Button {
39+
text = "Save graph as ..."
40+
visible = false
41+
}
42+
4143
contents += openFilesButton
44+
contents += saveGraphAsButton
4245

4346
listenTo(openFilesButton)
47+
listenTo(saveGraphAsButton)
48+
49+
reactions += {
50+
case ButtonClicked(b) =>
51+
if(b == openFilesButton) openFile
52+
if(b == saveGraphAsButton) saveGraphAsFile
53+
}
54+
}
55+
56+
val infoPanel = new BoxPanel(Orientation.Vertical) {
57+
58+
contents += new Label("Interactive modes:")
59+
contents += new TextArea {
60+
background = Color.lightGray
61+
text = "[p] - picking mode\n" +
62+
"* drag and drop vertices\n" +
63+
"* press [Shift] to select multiple vertices\n" +
64+
"* press [CTRL] to center a specific vertex\n\n" +
65+
"[t] - transforming mode\n" +
66+
"* move graph around\n" +
67+
"* scroll to zoom in and out\n" +
68+
"* press [Shift] or [CTRL] to transform graph"
69+
}
70+
}
71+
72+
val drawPanel = new BoxPanel(Orientation.Vertical) {
73+
74+
background = Color.white
75+
76+
def draw(vertices: Map[String, VertexRepresentator], edges: Map[Int, EdgeRepresentator]) = {
77+
contents += Component.wrap(jung.buildGraph(vertices, edges).prepareLayout.formDesign.activateControllers.plot)
78+
}
79+
80+
}
81+
82+
def top = new MainFrame {
83+
title = "Struts Actions and Forwards"
4484

45-
def getFileChooser = {
85+
UIManager setLookAndFeel UIManager.getSystemLookAndFeelClassName
86+
87+
JFrame setDefaultLookAndFeelDecorated true
88+
89+
minimumSize = screenSize
90+
91+
contents = new BorderPanel {
92+
layout += buttonPanel -> BorderPanel.Position.North
93+
layout += drawPanel -> BorderPanel.Position.Center
94+
layout += infoPanel -> BorderPanel.Position.East
95+
}
96+
}
97+
98+
def getFileChooser = {
4699
val dir = if (currentFiles == null) new File(System.getProperty("user.home")) else currentFiles.first
47100
new FileChooser(dir) {
48-
fileFilter = new FileNameExtensionFilter("Struts XML", "xml")
49-
// strange behaviour of multiSelectionEnable = true, had to use _
50-
multiSelectionEnable_= (true)
101+
fileFilter = new FileNameExtensionFilter("Struts Files", "xml", "jsp", "jspf")
102+
103+
multiSelectionEnabled = true
51104
}
52-
}
53-
54-
def openFile: Unit = {
55-
val fileChoser = getFileChooser
56-
fileChoser.title = "Choose Struts XML file(s) to analyse"
57-
fileChoser.showOpenDialog(this) match {
58-
case FileChooser.Result.Approve =>
59-
try {
60-
if (fileChoser.selectedFile.exists) {
61-
currentFiles = fileChoser.selectedFiles
62-
val fileNames = for (currentFile <- currentFiles) yield currentFile.getAbsolutePath
63-
64-
val fromXML = reader.fromXML(fileNames:_*)
65-
val graph = graphCreator.toGraph(fromXML)
66-
val adapter = new JGraphModelAdapter(graph);
67-
val jScrollPane = new JScrollPane(new JGraph(adapter))
68-
jScrollPane.setMinimumSize(new Dimension(WIDTH, HEIGHT))
69-
70-
val vertexPositioner = new VertexPositioner[String, DefaultEdge]
71-
vertexPositioner.positionVertices(adapter, fromXML, (WIDTH, HEIGHT))
105+
}
106+
107+
def openFile: Unit = {
108+
val fileChooser = getFileChooser
109+
fileChooser.title = "Choose Struts file(s) to analyse"
110+
fileChooser.showOpenDialog(drawPanel) match {
111+
case FileChooser.Result.Approve =>
112+
try {
113+
if (fileChooser.selectedFile.exists) {
114+
115+
currentFiles = fileChooser.selectedFiles
72116

73-
contents += Component.wrap(jScrollPane)
117+
val fileNames = for (currentFile <- currentFiles) yield currentFile.getAbsolutePath
118+
119+
// XML & JSP
120+
val (vertices, edges) = reader.readFiles(fileNames:_*)
121+
122+
drawPanel.draw(vertices, edges)
74123

75-
jScrollPane.updateUI
124+
buttonPanel.saveGraphAsButton.visible = true
76125
}
77126
} catch {
78127
case e: IOException =>
79-
Dialog.showMessage(this, "Error loading File: " + e.getMessage)
128+
Dialog.showMessage(drawPanel, "Error loading File: " + e.getMessage)
129+
80130
}
81131
case FileChooser.Result.Cancel => ;
82132
case FileChooser.Result.Error => ;
83133
}
84-
}
85-
86-
reactions += {
87-
case ButtonClicked(openFilesButton) => openFile
88-
}
89134
}
90-
91-
def top = new MainFrame {
92-
title = "Struts Actions and Forwards"
93-
94-
UIManager setLookAndFeel UIManager.getSystemLookAndFeelClassName
95-
96-
JFrame setDefaultLookAndFeelDecorated true
97-
98-
minimumSize = new Dimension(WIDTH, HEIGHT)
99-
100-
contents = mainPanel
101-
}
135+
136+
def saveGraphAsFile: Unit = {
137+
val dir = new File(System.getProperty("user.home"))
138+
val fileChooser = new FileChooser(dir) {
139+
fileFilter = new FileNameExtensionFilter("Image (*.jpg, *.png, *.gif)", "jpg", "png", "gif", "jpeg")
140+
title = "Save graph as file"
141+
}
142+
fileChooser.showSaveDialog(drawPanel) match {
143+
case FileChooser.Result.Approve => jung.saveGraphAs(fileChooser.selectedFile)
144+
case FileChooser.Result.Cancel => ;
145+
case FileChooser.Result.Error => ;
146+
}
147+
}
102148
}

src/main/scala/net/rawyler/struts/GraphCreator.scala

-30
This file was deleted.

0 commit comments

Comments
 (0)