| Author | DaveJarvis <email> |
|---|---|
| Date | 2020-07-05 21:48:01 GMT-0700 |
| Commit | 891e945f19b855be05a4b66cff5bba72441265fd |
| Parent | 62c99af |
| local -r path_jdk="/tmp/${file_jdk}" | ||
| - if [ ! -f ${path_jdk} ]; then | ||
| - $log "Download ${url_jdk}" | ||
| + # File must have contents. | ||
| + if [ ! -s ${path_jdk} ]; then | ||
| + $log "Download ${url_jdk} to ${path_jdk}" | ||
| wget -q "${url_jdk}" -O "${path_jdk}" | ||
| fi |
| stage.show(); | ||
| + | ||
| + // After the stage is visible, the panel dimensions are known, which | ||
| + // allows scaling images to fit the preview panel. | ||
| + getMainWindow().init(); | ||
| } | ||
| public MainWindow() { | ||
| + sNotifier.addObserver( this ); | ||
| + | ||
| mStatusBar = createStatusBar(); | ||
| mLineNumberText = createLineNumberText(); | ||
| mFindTextField = createFindTextField(); | ||
| mScene = createScene(); | ||
| mSpellChecker = createSpellChecker(); | ||
| + // Add the close request listener before the window is shown. | ||
| initLayout(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Called after the stage is shown. | ||
| + */ | ||
| + public void init() { | ||
| initFindInput(); | ||
| initSnitch(); | ||
| initDefinitionListener(); | ||
| initTabAddedListener(); | ||
| initTabChangedListener(); | ||
| initPreferences(); | ||
| initVariableNameInjector(); | ||
| - | ||
| - sNotifier.addObserver( this ); | ||
| } | ||
| editorPane.addTabSelectionListener( | ||
| ( tabPane, oldTab, newTab ) -> { | ||
| - // Clear the preview pane when closing an editor. When the last | ||
| - // tab is closed, this ensures that the preview pane is empty. | ||
| if( newTab == null ) { | ||
| + // Clear the preview pane when closing an editor. When the last | ||
| + // tab is closed, this ensures that the preview pane is empty. | ||
| getPreviewPane().clear(); | ||
| } | ||
| - | ||
| - // If there was no old tab, then this is a first time load, which | ||
| - // can be ignored. | ||
| - if( oldTab != null ) { | ||
| - if( newTab != null ) { | ||
| - final FileEditorTab tab = (FileEditorTab) newTab; | ||
| - updateVariableNameInjector( tab ); | ||
| - process( tab ); | ||
| - } | ||
| + else { | ||
| + final var tab = (FileEditorTab) newTab; | ||
| + updateVariableNameInjector( tab ); | ||
| + process( tab ); | ||
| } | ||
| } | ||
| private void initPreferences() { | ||
| initDefinitionPane(); | ||
| - final var editor = getFileEditorPane(); | ||
| - editor.initPreferences(); | ||
| - final var tab = editor.newEditor(); | ||
| - | ||
| - // This is a bonafide hack to ensure the preview panel scales any images | ||
| - // to fit the panel width. The preview panel width isn't known until after | ||
| - // the main window is displayed. However, these preferences are initialized | ||
| - // prior to showing the main window. The preferences include loading the | ||
| - // text for an editor, which then parses it. Upon parsing, the width of | ||
| - // the preview pane is a negative (invalid) value. By waiting to load the | ||
| - // editors until after the main window is shown, a valid preview panel | ||
| - // width can be determined and thus the images scaled to fit. | ||
| - // | ||
| - // To avoid this hack, the preferences need to be loaded separately from | ||
| - // opening the editors. Those preferences can be used to get the window | ||
| - // sizes for showing the main window. Once the main window is shown, all | ||
| - // the subsequent initializations can take place. | ||
| - addShowListener( editor, ( __ ) -> { | ||
| - editor.closeEditor( tab, false ); | ||
| - editor.initPreferences(); | ||
| - } ); | ||
| + getFileEditorPane().initPreferences(); | ||
| } | ||
| public static final char SUFFIX = '`'; | ||
| - private final String mDelimiterBegan; | ||
| - private final String mDelimiterEnded; | ||
| - | ||
| - public RVariableDecorator() { | ||
| - final var prefs = getUserPreferences(); | ||
| - mDelimiterBegan = prefs.getRDelimiterBegan(); | ||
| - mDelimiterEnded = prefs.getRDelimiterEnded(); | ||
| - } | ||
| + private final String mDelimiterBegan = | ||
| + getUserPreferences().getRDelimiterBegan(); | ||
| + private final String mDelimiterEnded = | ||
| + getUserPreferences().getRDelimiterEnded(); | ||
| /** |
| package com.scrivenvar.preview; | ||
| +import com.scrivenvar.util.ProtocolResolver; | ||
| import javafx.beans.property.IntegerProperty; | ||
| import javafx.beans.property.SimpleIntegerProperty; | ||
| * | ||
| * @param uri Path to the image resource to load. | ||
| - * @param width Maximum image width (scaled to fit), in pixels. | ||
| - * @param height Image height, in pixels. | ||
| + * @param width Ignored. | ||
| + * @param height Ignored. | ||
| * @return The scaled image, or a placeholder image if the URI's content | ||
| * could not be retrieved. | ||
| assert height >= 0; | ||
| - boolean exists; | ||
| + boolean exists = true; | ||
| try { | ||
| - exists = Files.exists( Paths.get( new URI( uri ) ) ); | ||
| + final String protocol = ProtocolResolver.getProtocol( uri ); | ||
| + | ||
| + if( "file".equals( protocol ) ) { | ||
| + exists = Files.exists( Paths.get( new URI( uri ) ) ); | ||
| + } | ||
| } catch( final Exception e ) { | ||
| exists = false; | ||
| * | ||
| * @param uri Path to the image file to load. | ||
| - * @param w Unused (usually -1, which is useless). | ||
| - * @param h Unused (ditto). | ||
| + * @param w Ignored. | ||
| + * @param h Ignored. | ||
| * @return Resource representing the rendered image and path. | ||
| */ | ||
| */ | ||
| private void setWidth( final ComponentEvent e ) { | ||
| - final int width = (int) (e.getComponent().getWidth() * .9); | ||
| + final int width = (int) (e.getComponent().getWidth() * .95); | ||
| HTMLPreviewPane.this.mImageLoader.widthProperty().set( width ); | ||
| } |
| private ResolvedLink resolve( final ResolvedLink link ) { | ||
| String url = link.getUrl(); | ||
| + final String protocol = ProtocolResolver.getProtocol( url ); | ||
| try { | ||
| // If the direct file name exists, then use it directly. | ||
| - if( Path.of( url ).toFile().exists() ) { | ||
| + if( ("file".equals( protocol ) && Path.of( url ).toFile().exists()) || | ||
| + protocol.startsWith( "http" ) ) { | ||
| return valid( link, url ); | ||
| } | ||
| } | ||
| - final String protocol = ProtocolResolver.getProtocol( url ); | ||
| if( "file".equals( protocol ) ) { | ||
| url = "file://" + url; | ||
| Delta | 42 lines added, 53 lines removed, 11-line decrease |
|---|