Skip to content

Commit

Permalink
Handing better missing JavaFX.
Browse files Browse the repository at this point in the history
  • Loading branch information
akivela committed Aug 5, 2015
1 parent 90c55ed commit 2aea409
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
17 changes: 15 additions & 2 deletions src/org/wandora/application/gui/previews/PreviewFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static PreviewPanel create(final Locator locator) {
PreviewPanel previewPanel = null;

try {
if(FXMediaPlayer.canView(urlString)) {
if(hasJavaFX() && FXMediaPlayer.canView(urlString)) {
previewPanel = new FXMediaPlayer(urlString);
}
else if(AudioMidi.canView(urlString)) {
Expand All @@ -72,7 +72,7 @@ else if(FMJ.canView(urlString)) {
else if(GST.canView(urlString)) {
previewPanel = new GST(urlString);
}
else {
else if(HTML.canView(urlString)) {
previewPanel = new HTML(urlString);
}
}
Expand All @@ -88,4 +88,17 @@ else if(GST.canView(urlString)) {
return previewPanel;
}
}




private static boolean hasJavaFX() {
try {
Class jfxPanel = Class.forName("javafx.embed.swing.JFXPanel");
return true;
}
catch (ClassNotFoundException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,6 @@ public static boolean canView(String url) {
}
}

return answer && hasJavaFX();
}


public static boolean hasJavaFX() {
try {
Class jfxPanel = Class.forName("javafx.embed.swing.JFXPanel");
return true;
}
catch (ClassNotFoundException e) {
return false;
}
return answer;
}
}
37 changes: 37 additions & 0 deletions src/org/wandora/application/gui/previews/formats/HTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@

import org.wandora.application.gui.*;
import org.wandora.application.*;
import static org.wandora.application.gui.previews.Util.endsWithAny;
import org.wandora.application.tools.*;
import org.wandora.topicmap.*;
import org.wandora.utils.DataURL;


/**
Expand Down Expand Up @@ -500,4 +502,39 @@ public void save(File file) {
}
}
}




// -------------------------------------------------------------------------


public static boolean canView(String url) {
if(url != null) {
if(DataURL.isDataURL(url)) {
try {
DataURL dataURL = new DataURL(url);
String mimeType = dataURL.getMimetype();
if(mimeType != null) {
String lowercaseMimeType = mimeType.toLowerCase();
if(lowercaseMimeType.startsWith("text/plain") ||
lowercaseMimeType.startsWith("text/html")) {
return true;
}
}
}
catch(Exception e) {
// Ignore --> Can't view
}
}
else {
if(endsWithAny(url.toLowerCase(), ".html", ".htm", ".txt")) {
return true;
}
}
}

return false;
}

}

0 comments on commit 2aea409

Please sign in to comment.