| 110 | 110 | local -r path_jdk="/tmp/${file_jdk}" |
| 111 | 111 | |
| 112 | if [ ! -f ${path_jdk} ]; then | |
| 113 | $log "Download ${url_jdk}" | |
| 112 | # File must have contents. | |
| 113 | if [ ! -s ${path_jdk} ]; then | |
| 114 | $log "Download ${url_jdk} to ${path_jdk}" | |
| 114 | 115 | wget -q "${url_jdk}" -O "${path_jdk}" |
| 115 | 116 | fi |
| 104 | 104 | |
| 105 | 105 | stage.show(); |
| 106 | ||
| 107 | // After the stage is visible, the panel dimensions are known, which | |
| 108 | // allows scaling images to fit the preview panel. | |
| 109 | getMainWindow().init(); | |
| 106 | 110 | } |
| 107 | 111 |
| 203 | 203 | |
| 204 | 204 | public MainWindow() { |
| 205 | sNotifier.addObserver( this ); | |
| 206 | ||
| 205 | 207 | mStatusBar = createStatusBar(); |
| 206 | 208 | mLineNumberText = createLineNumberText(); |
| 207 | 209 | mFindTextField = createFindTextField(); |
| 208 | 210 | mScene = createScene(); |
| 209 | 211 | mSpellChecker = createSpellChecker(); |
| 210 | 212 | |
| 213 | // Add the close request listener before the window is shown. | |
| 211 | 214 | initLayout(); |
| 215 | } | |
| 216 | ||
| 217 | /** | |
| 218 | * Called after the stage is shown. | |
| 219 | */ | |
| 220 | public void init() { | |
| 212 | 221 | initFindInput(); |
| 213 | 222 | initSnitch(); |
| 214 | 223 | initDefinitionListener(); |
| 215 | 224 | initTabAddedListener(); |
| 216 | 225 | initTabChangedListener(); |
| 217 | 226 | initPreferences(); |
| 218 | 227 | initVariableNameInjector(); |
| 219 | ||
| 220 | sNotifier.addObserver( this ); | |
| 221 | 228 | } |
| 222 | 229 | |
| ... | ||
| 411 | 418 | editorPane.addTabSelectionListener( |
| 412 | 419 | ( tabPane, oldTab, newTab ) -> { |
| 413 | // Clear the preview pane when closing an editor. When the last | |
| 414 | // tab is closed, this ensures that the preview pane is empty. | |
| 415 | 420 | if( newTab == null ) { |
| 421 | // Clear the preview pane when closing an editor. When the last | |
| 422 | // tab is closed, this ensures that the preview pane is empty. | |
| 416 | 423 | getPreviewPane().clear(); |
| 417 | 424 | } |
| 418 | ||
| 419 | // If there was no old tab, then this is a first time load, which | |
| 420 | // can be ignored. | |
| 421 | if( oldTab != null ) { | |
| 422 | if( newTab != null ) { | |
| 423 | final FileEditorTab tab = (FileEditorTab) newTab; | |
| 424 | updateVariableNameInjector( tab ); | |
| 425 | process( tab ); | |
| 426 | } | |
| 425 | else { | |
| 426 | final var tab = (FileEditorTab) newTab; | |
| 427 | updateVariableNameInjector( tab ); | |
| 428 | process( tab ); | |
| 427 | 429 | } |
| 428 | 430 | } |
| ... | ||
| 435 | 437 | private void initPreferences() { |
| 436 | 438 | initDefinitionPane(); |
| 437 | final var editor = getFileEditorPane(); | |
| 438 | editor.initPreferences(); | |
| 439 | final var tab = editor.newEditor(); | |
| 440 | ||
| 441 | // This is a bonafide hack to ensure the preview panel scales any images | |
| 442 | // to fit the panel width. The preview panel width isn't known until after | |
| 443 | // the main window is displayed. However, these preferences are initialized | |
| 444 | // prior to showing the main window. The preferences include loading the | |
| 445 | // text for an editor, which then parses it. Upon parsing, the width of | |
| 446 | // the preview pane is a negative (invalid) value. By waiting to load the | |
| 447 | // editors until after the main window is shown, a valid preview panel | |
| 448 | // width can be determined and thus the images scaled to fit. | |
| 449 | // | |
| 450 | // To avoid this hack, the preferences need to be loaded separately from | |
| 451 | // opening the editors. Those preferences can be used to get the window | |
| 452 | // sizes for showing the main window. Once the main window is shown, all | |
| 453 | // the subsequent initializations can take place. | |
| 454 | addShowListener( editor, ( __ ) -> { | |
| 455 | editor.closeEditor( tab, false ); | |
| 456 | editor.initPreferences(); | |
| 457 | } ); | |
| 439 | getFileEditorPane().initPreferences(); | |
| 458 | 440 | } |
| 459 | 441 | |
| 41 | 41 | public static final char SUFFIX = '`'; |
| 42 | 42 | |
| 43 | private final String mDelimiterBegan; | |
| 44 | private final String mDelimiterEnded; | |
| 45 | ||
| 46 | public RVariableDecorator() { | |
| 47 | final var prefs = getUserPreferences(); | |
| 48 | mDelimiterBegan = prefs.getRDelimiterBegan(); | |
| 49 | mDelimiterEnded = prefs.getRDelimiterEnded(); | |
| 50 | } | |
| 43 | private final String mDelimiterBegan = | |
| 44 | getUserPreferences().getRDelimiterBegan(); | |
| 45 | private final String mDelimiterEnded = | |
| 46 | getUserPreferences().getRDelimiterEnded(); | |
| 51 | 47 | |
| 52 | 48 | /** |
| 28 | 28 | package com.scrivenvar.preview; |
| 29 | 29 | |
| 30 | import com.scrivenvar.util.ProtocolResolver; | |
| 30 | 31 | import javafx.beans.property.IntegerProperty; |
| 31 | 32 | import javafx.beans.property.SimpleIntegerProperty; |
| ... | ||
| 73 | 74 | * |
| 74 | 75 | * @param uri Path to the image resource to load. |
| 75 | * @param width Maximum image width (scaled to fit), in pixels. | |
| 76 | * @param height Image height, in pixels. | |
| 76 | * @param width Ignored. | |
| 77 | * @param height Ignored. | |
| 77 | 78 | * @return The scaled image, or a placeholder image if the URI's content |
| 78 | 79 | * could not be retrieved. |
| ... | ||
| 85 | 86 | assert height >= 0; |
| 86 | 87 | |
| 87 | boolean exists; | |
| 88 | boolean exists = true; | |
| 88 | 89 | |
| 89 | 90 | try { |
| 90 | exists = Files.exists( Paths.get( new URI( uri ) ) ); | |
| 91 | final String protocol = ProtocolResolver.getProtocol( uri ); | |
| 92 | ||
| 93 | if( "file".equals( protocol ) ) { | |
| 94 | exists = Files.exists( Paths.get( new URI( uri ) ) ); | |
| 95 | } | |
| 91 | 96 | } catch( final Exception e ) { |
| 92 | 97 | exists = false; |
| ... | ||
| 102 | 107 | * |
| 103 | 108 | * @param uri Path to the image file to load. |
| 104 | * @param w Unused (usually -1, which is useless). | |
| 105 | * @param h Unused (ditto). | |
| 109 | * @param w Ignored. | |
| 110 | * @param h Ignored. | |
| 106 | 111 | * @return Resource representing the rendered image and path. |
| 107 | 112 | */ |
| 134 | 134 | */ |
| 135 | 135 | private void setWidth( final ComponentEvent e ) { |
| 136 | final int width = (int) (e.getComponent().getWidth() * .9); | |
| 136 | final int width = (int) (e.getComponent().getWidth() * .95); | |
| 137 | 137 | HTMLPreviewPane.this.mImageLoader.widthProperty().set( width ); |
| 138 | 138 | } |
| 105 | 105 | private ResolvedLink resolve( final ResolvedLink link ) { |
| 106 | 106 | String url = link.getUrl(); |
| 107 | final String protocol = ProtocolResolver.getProtocol( url ); | |
| 107 | 108 | |
| 108 | 109 | try { |
| 109 | 110 | // If the direct file name exists, then use it directly. |
| 110 | if( Path.of( url ).toFile().exists() ) { | |
| 111 | if( ("file".equals( protocol ) && Path.of( url ).toFile().exists()) || | |
| 112 | protocol.startsWith( "http" ) ) { | |
| 111 | 113 | return valid( link, url ); |
| 112 | 114 | } |
| ... | ||
| 151 | 153 | } |
| 152 | 154 | |
| 153 | final String protocol = ProtocolResolver.getProtocol( url ); | |
| 154 | 155 | if( "file".equals( protocol ) ) { |
| 155 | 156 | url = "file://" + url; |