Skip to content

Commit 70d9b06

Browse files
author
brunomnsilva
committed
Added SmartGraphPanel constructor to accept different css file from the default.
1 parent 98c542d commit 70d9b06

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

releases/JavaFXSmartGraph-0.9.jar

216 Bytes
Binary file not shown.

releases/JavaFXSmartGraph-0.9.zip

1.09 KB
Binary file not shown.

src/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import static com.brunomnsilva.smartgraph.graphview.UtilitiesJavaFX.pick;
5959
import static com.brunomnsilva.smartgraph.graphview.UtilitiesPoint2D.attractiveForce;
6060
import static com.brunomnsilva.smartgraph.graphview.UtilitiesPoint2D.repellingForce;
61+
import java.net.URI;
6162
import java.util.concurrent.Callable;
6263
import java.util.concurrent.ExecutionException;
6364
import java.util.concurrent.FutureTask;
@@ -142,7 +143,7 @@ public SmartGraphPanel(Graph<V, E> theGraph, SmartGraphProperties properties) {
142143
* vertices.
143144
*
144145
* @param theGraph underlying graph
145-
* @param placementStrategy placement strategy
146+
* @param placementStrategy placement strategy, null for default
146147
*/
147148
public SmartGraphPanel(Graph<V, E> theGraph, SmartPlacementStrategy placementStrategy) {
148149
this(theGraph, null, placementStrategy);
@@ -154,11 +155,27 @@ public SmartGraphPanel(Graph<V, E> theGraph, SmartPlacementStrategy placementStr
154155
* vertices.
155156
*
156157
* @param theGraph underlying graph
157-
* @param properties custom properties
158-
* @param placementStrategy placement strategy
158+
* @param properties custom properties, null for default
159+
* @param placementStrategy placement strategy, null for default
159160
*/
160161
public SmartGraphPanel(Graph<V, E> theGraph, SmartGraphProperties properties,
161162
SmartPlacementStrategy placementStrategy) {
163+
164+
this(theGraph, properties, placementStrategy, null);
165+
}
166+
167+
/**
168+
* Constructs a visualization of the graph referenced by
169+
* <code>theGraph</code>, using custom properties and custom placement of
170+
* vertices.
171+
*
172+
* @param theGraph underlying graph
173+
* @param properties custom properties, null for default
174+
* @param placementStrategy placement strategy, null for default
175+
* @param cssFile alternative css file, instead of default 'smartgraph.css'
176+
*/
177+
public SmartGraphPanel(Graph<V, E> theGraph, SmartGraphProperties properties,
178+
SmartPlacementStrategy placementStrategy, URI cssFile) {
162179

163180
if (theGraph == null) {
164181
throw new IllegalArgumentException("The graph cannot be null.");
@@ -177,7 +194,7 @@ public SmartGraphPanel(Graph<V, E> theGraph, SmartGraphProperties properties,
177194
edgeNodes = new HashMap<>();
178195

179196
//set stylesheet and class
180-
loadStylesheet();
197+
loadStylesheet(cssFile);
181198

182199
initNodes();
183200

@@ -934,13 +951,18 @@ public SmartStylableNode getStylableEdge(E edgeElement) {
934951
}
935952

936953
/**
937-
* Loads the default stylesheet and applies the .graph class to this panel.
954+
* Loads the stylesheet and applies the .graph class to this panel.
938955
*/
939-
private void loadStylesheet() {
956+
private void loadStylesheet(URI cssFile) {
940957
try {
941-
File f = new File("smartgraph.css");
958+
String css;
959+
if( cssFile != null ) {
960+
css = cssFile.toURL().toExternalForm();
961+
} else {
962+
File f = new File("smartgraph.css");
963+
css = f.toURI().toURL().toExternalForm();
964+
}
942965

943-
String css = f.toURI().toURL().toExternalForm();
944966
getStylesheets().add(css);
945967
this.getStyleClass().add("graph");
946968
} catch (MalformedURLException ex) {

src/com/brunomnsilva/smartgraph/graphview/SmartGraphProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public SmartGraphProperties(InputStream inputStream) {
9999
try {
100100
properties.load(inputStream);
101101
} catch (IOException ex) {
102-
System.err.println("The file provided by the input stream does not exist. Using default values.");
102+
String msg = "The file provided by the input stream does not exist. Using default values.";
103+
Logger.getLogger(SmartGraphProperties.class.getName()).log(Level.WARNING, msg);
103104
}
104105
}
105106

0 commit comments

Comments
 (0)