-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix paths to resource files when using the jar (#44)
* Fix paths to resource files when using the jar * Introduced factory for SmartGraphPanel creation * Fixed SmartGraph styling bug for package diagrams * Fix in resource loading approach --------- Co-authored-by: Vassilis Zafeiris <[email protected]>
- Loading branch information
1 parent
d9c2ee3
commit 62e23cf
Showing
4 changed files
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package model.diagram.javafx; | ||
|
||
import com.brunomnsilva.smartgraph.graph.Graph; | ||
import com.brunomnsilva.smartgraph.graphview.SmartCircularSortedPlacementStrategy; | ||
import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel; | ||
import com.brunomnsilva.smartgraph.graphview.SmartGraphProperties; | ||
import util.Resources; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Objects; | ||
|
||
public class SmartGraphFactory { | ||
|
||
public static final String DEFAULT_PROPERTIES_PATH = "styles/smartgraph.properties"; | ||
public static final String DEFAULT_STYLE_PATH = "styles/smartgraph.css"; | ||
|
||
/** | ||
* Factory for SmartGraphPanel object creation | ||
* @param graph | ||
* @return | ||
*/ | ||
public static SmartGraphPanel<String, String> createGraphView(Graph<String, String> graph) | ||
{ | ||
try | ||
{ | ||
SmartGraphProperties properties = getSmartgraphProperties(); | ||
URI url = getSmartGraphStyleURI(); | ||
URI cssFile = Objects.requireNonNull(url); | ||
return new SmartGraphPanel<>(graph, properties, new SmartCircularSortedPlacementStrategy(), cssFile); | ||
} | ||
catch (URISyntaxException ignored) | ||
{ | ||
// Fallback to default paths. | ||
return new SmartGraphPanel<>(graph, new SmartCircularSortedPlacementStrategy()); | ||
} | ||
} | ||
|
||
public static SmartGraphProperties getSmartgraphProperties() { | ||
return new SmartGraphProperties(Resources.loadResourceFile(DEFAULT_PROPERTIES_PATH)); | ||
} | ||
|
||
public static URI getSmartGraphStyleURI() throws URISyntaxException { | ||
return Resources.getResourceURI(DEFAULT_STYLE_PATH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package util; | ||
|
||
import com.brunomnsilva.smartgraph.graphview.SmartGraphProperties; | ||
import model.diagram.javafx.JavaFXClassVisualization; | ||
|
||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class Resources { | ||
|
||
public static InputStream loadResourceFile(String relativePath) { | ||
return Resources.class.getClassLoader().getResourceAsStream(relativePath); | ||
} | ||
|
||
public static URI getResourceURI(String relativePath) throws URISyntaxException { | ||
return Resources.class.getClassLoader().getResource(relativePath).toURI(); | ||
} | ||
|
||
} |