Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Replace if/else with switch for link listener

AuthorDaveJarvis <email>
Date2020-09-12 18:49:10 GMT-0700
Commitd0b35724787ecebf349c755494b14996028fabef
Parent324e7c5
Delta11 lines added, 10 lines removed, 1-line increase
src/main/java/com/scrivenvar/preview/HTMLPreviewPane.java
import com.scrivenvar.adapters.DocumentAdapter;
import com.scrivenvar.graphics.SvgReplacedElementFactory;
-import com.scrivenvar.util.ProtocolResolver;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import static com.scrivenvar.Constants.*;
import static com.scrivenvar.StatusBarNotifier.alert;
-import static com.scrivenvar.util.ProtocolResolver.*;
+import static com.scrivenvar.util.ProtocolResolver.getProtocol;
import static java.awt.Desktop.Action.BROWSE;
import static java.awt.Desktop.getDesktop;
final var protocol = getProtocol( link );
- if( protocol.isHttp() ) {
- final var desktop = getDesktop();
+ switch( protocol ) {
+ case HTTP:
+ final var desktop = getDesktop();
- if( desktop.isSupported( BROWSE ) ) {
- desktop.browse( new URI( link ) );
- }
- }
- else if( protocol.isFile() ) {
- // TODO: #88 -- publish a message to the event bus.
+ if( desktop.isSupported( BROWSE ) ) {
+ desktop.browse( new URI( link ) );
+ }
+ break;
+ case FILE:
+ // TODO: #88 -- publish a message to the event bus.
+ break;
}
} catch( final Exception e ) {