Skip to content

Commit

Permalink
Fix AIBenchJTreeManager
Browse files Browse the repository at this point in the history
An error was detected in the AIBenchJTreeManager, caused by the
datatypes that do not have an associated icon. The current code tried to
recover their icon as a global resource and, as the icon URL was null,
it caused an error.

This commit fixes this error by checking first whether the icon URL is
null or not.

In addition, this commit also simplifies some additional code in the
same class.
  • Loading branch information
mrjato committed Jan 13, 2017
1 parent a5a7573 commit a143802
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ Creating an AIBench application using the archetype
----
Simply run the following command to create a new AIBench application using the Maven archetype:
```bash
mvn archetype:generate -DarchetypeGroupId=es.uvigo.ei.sing -DarchetypeArtifactId=aibench-archetype -DarchetypeVersion=2.7.2 -DgroupId=es.uvigo.ei.sing -DartifactId=my-aibench-application -DinteractiveMode=false -DarchetypeCatalog=http://sing.ei.uvigo.es/maven2/archetype-catalog.xml
mvn archetype:generate -DarchetypeGroupId=es.uvigo.ei.sing -DarchetypeArtifactId=aibench-archetype -DarchetypeVersion=2.7.3 -DgroupId=es.uvigo.ei.sing -DartifactId=my-aibench-application -DinteractiveMode=false -DarchetypeCatalog=http://sing.ei.uvigo.es/maven2/archetype-catalog.xml
```
This command creates the new application under the folder `my-aibench-application`. You can select the version of the archetype (corresponding to the AIBench version) in `-DarchetypeVersion`.
2 changes: 1 addition & 1 deletion aibench-aibench/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.uvigo.ei.sing</groupId>
<artifactId>aibench-project</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<!--
WARNING: change version using (in the parent project):
mvn versions:set -DnewVersion=[new_version]
Expand Down
2 changes: 1 addition & 1 deletion aibench-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.uvigo.ei.sing</groupId>
<artifactId>aibench-project</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<!--
WARNING: change version using (in the parent project):
mvn versions:set -DnewVersion=[new_version]
Expand Down
2 changes: 1 addition & 1 deletion aibench-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.uvigo.ei.sing</groupId>
<artifactId>aibench-project</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<!--
WARNING: change version using (in the parent project):
mvn versions:set -DnewVersion=[new_version]
Expand Down
3 changes: 2 additions & 1 deletion aibench-pluginmanager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<parent>
<groupId>es.uvigo.ei.sing</groupId>
<artifactId>aibench-project</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<!--
WARNING: change version using (in the parent project):
mvn versions:set -DnewVersion=[new_version]
mvn versions:commit
This will change the version in all modules at-once
-->

<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion aibench-shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.uvigo.ei.sing</groupId>
<artifactId>aibench-project</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<!--
WARNING: change version using (in the parent project):
mvn versions:set -DnewVersion=[new_version]
Expand Down
2 changes: 1 addition & 1 deletion aibench-workbench/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.uvigo.ei.sing</groupId>
<artifactId>aibench-project</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<!--
WARNING: change version using:
mvn versions:set -DnewVersion=[new_version]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,36 +289,39 @@ public Component getTreeCellRendererComponent(JTree tree,
tree, value, sel, expanded, leaf, row, hasFocus);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

if (leaf == false
&& !(node.getUserObject() instanceof ClipboardItem)) {
if (!leaf && !(node.getUserObject() instanceof ClipboardItem)) {
final String iconDatatype = Workbench.CONFIG.getProperty("icon.datatype");
URL imageURL = Util.getGlobalResourceURL(iconDatatype);
c.setIcon(new ImageIcon(iconDatatype == null ?
getClass().getResource("/images/datatype.png") : imageURL));

c.setIcon(new ImageIcon(iconDatatype == null
? getClass().getResource("/images/datatype.png")
: Util.getGlobalResourceURL(iconDatatype)
));
}

if (node.equals(tree.getModel().getRoot())) {
final String iconClipboard = Workbench.CONFIG
.getProperty("icon.clipboard");
URL imageURL = Launcher.class.getProtectionDomain()
.getCodeSource().getLocation();
try {
if (imageURL.getFile().endsWith(".jar")) {
imageURL = new URL(imageURL.toString()
.substring(
0,
imageURL.toString()
.lastIndexOf('/'))
+ "/../" + iconClipboard);
} else {
imageURL = new URL(imageURL + "../"
+ iconClipboard);
final String iconClipboard = Workbench.CONFIG.getProperty("icon.clipboard");

c.setText("");
if (iconClipboard == null) {
c.setIcon(new ImageIcon(getClass().getResource("/images/clipboard.gif")));
} else {
URL imageUrl = Launcher.class.getProtectionDomain()
.getCodeSource().getLocation();
try {
final String imageUrlString = imageUrl.toString();
String baseUrl;

if (imageUrl.getFile().endsWith(".jar")) {
baseUrl = imageUrlString.substring(0, imageUrlString.lastIndexOf('/')) + "/";
} else {
baseUrl = imageUrlString;
}

c.setIcon(new ImageIcon(new URL(baseUrl + "../" + iconClipboard)));
} catch (MalformedURLException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
}
c.setIcon(new ImageIcon(
iconClipboard == null ? getClass().getResource(
"/images/clipboard.gif") : imageURL));
c.setText("");
}

return c;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>es.uvigo.ei.sing</groupId>
<artifactId>aibench-project</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
<!--
WARNING: change version using:
mvn versions:set -DnewVersion=[new_version]
Expand Down

0 comments on commit a143802

Please sign in to comment.