Changeset 892
- Timestamp:
- 02/14/14 12:12:52 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/assets/style/jfx.css
r888 r892 79 79 } 80 80 81 .browser-status-label { 82 -fx-background-color: derive(-fx-base, -16%), linear-gradient(to bottom, derive(-fx-base, 2%), derive(-fx-base, -8%)); 83 -fx-background-insets: 0, 1 1 0 0; 84 -fx-padding: 4 8 4 8; 85 -fx-background-radius: 0 2 0 0; 86 } 87 81 88 .fa { 82 89 -fx-font-family: FontAwesome; -
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r888 r892 15 15 import java.lang.reflect.Field; 16 16 17 import javafx.animation.FadeTransition; 17 18 import javafx.application.Platform; 18 19 import javafx.beans.value.ChangeListener; … … 50 51 import javafx.scene.text.Font; 51 52 import javafx.scene.web.WebEngine; 53 import javafx.scene.web.WebEvent; 52 54 import javafx.scene.web.WebView; 55 import javafx.util.Duration; 53 56 import netscape.javascript.JSObject; 54 57 … … 94 97 private Button _convertButton; 95 98 private ToggleButton _readableModeButton; 99 private Label _statusLabel; 100 private FadeTransition _statusFadeIn; 101 private FadeTransition _statusFadeOut; 96 102 97 103 private TextField _urlField; … … 117 123 } 118 124 } 119 120 private Point getCoordFromCaret(TextField text) {121 TextFieldSkin skin = (TextFieldSkin) text.getSkin();122 123 Point2D onScene = text.localToScene(0, 0);124 125 double x = onScene.getX() + JfxBrowser.this.getX();// - org.expeditee.gui.Browser._theBrowser.getOrigin().x;126 double y = onScene.getY() + JfxBrowser.this.getY();// - org.expeditee.gui.Browser._theBrowser.getOrigin().y;127 128 Rectangle2D cp = skin.getCharacterBounds(text.getCaretPosition());129 130 return new Point((int) (cp.getMinX() + x), (int) (cp.getMinY() + y));131 }132 133 private int getCaretFromCoord(TextField text, MouseEvent e) {134 TextFieldSkin skin = (TextFieldSkin) text.getSkin();135 HitInfo hit = skin.getIndex(e);136 return hit.getInsertionIndex();137 }138 139 /**140 * @param src The MouseEvent to clone141 * @param node The node the position will be relative to142 * @param x The position in Expeditee space143 * @param y The position in Expeditee space144 * @return A fake MouseEvent for a specific position relative to a Node145 */146 private MouseEvent getMouseEventForPosition(MouseEvent src, Node node, int x, int y) {147 MouseEvent dst = (MouseEvent) ((Event) src).copyFor(null, null);148 try {149 MouseEvent_x.set(dst, x - node.localToScene(0, 0).getX());150 MouseEvent_y.set(dst, y - node.localToScene(0, 0).getY());151 } catch (Exception e) {152 e.printStackTrace();153 }154 return dst;155 }156 125 157 126 public JfxBrowser(Text source, final String[] args) { … … 236 205 this._urlProgressBar.getStyleClass().add("url-progress-bar"); 237 206 this._urlProgressBar.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); 207 208 // Status label that displays the URL when a link is hovered over 209 this._statusLabel = new Label(); 210 this._statusLabel.getStyleClass().addAll("browser-status-label"); 211 this._statusLabel.setVisible(false); 212 213 this._statusFadeIn = new FadeTransition(); 214 this._statusFadeIn.setDuration(Duration.millis(200)); 215 this._statusFadeIn.setNode(this._statusLabel); 216 this._statusFadeIn.setFromValue(0); 217 this._statusFadeIn.setToValue(1); 218 this._statusFadeIn.setCycleCount(1); 219 this._statusFadeIn.setAutoReverse(false); 220 221 this._statusFadeOut = new FadeTransition(); 222 this._statusFadeOut.setDuration(Duration.millis(400)); 223 this._statusFadeOut.setNode(this._statusLabel); 224 this._statusFadeOut.setFromValue(1); 225 this._statusFadeOut.setToValue(0); 226 this._statusFadeOut.setCycleCount(1); 227 this._statusFadeOut.setAutoReverse(false); 228 229 this._statusFadeOut.setOnFinished(new EventHandler<ActionEvent>() { 230 231 @Override 232 public void handle(ActionEvent arg0) { 233 JfxBrowser.this._statusLabel.setVisible(false); 234 } 235 }); 236 238 237 239 238 StackPane urlbar = new StackPane(); … … 262 261 // size. This also means that the webview's prefSize must be manually set when the Pane resizes, using the event handlers below 263 262 Pane browserPane = new Pane(); 264 browserPane.getChildren().add (_webView);263 browserPane.getChildren().addAll(_webView, this._statusLabel); 265 264 266 265 HBox.setHgrow(browserPane, Priority.ALWAYS); … … 280 279 public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) { 281 280 JfxBrowser.this._webView.setPrefHeight((Double) newValue); 281 JfxBrowser.this._statusLabel.setTranslateY((Double) newValue - JfxBrowser.this._statusLabel.heightProperty().doubleValue()); 282 282 } 283 283 }); … … 317 317 // Disable right click menu 318 318 this._webView.setContextMenuEnabled(false); 319 320 // Showing the status label when a link is hovered over 321 this._webEngine.setOnStatusChanged(new EventHandler<WebEvent<String>>() { 322 323 @Override 324 public void handle(WebEvent<String> arg0) { 325 if (arg0.getData() != null && hasValidProtocol(arg0.getData())) { 326 JfxBrowser.this._statusLabel.setText(arg0.getData()); 327 328 JfxBrowser.this._statusFadeOut.stop(); 329 330 if(JfxBrowser.this._statusLabel.isVisible()) { 331 // Don't play the fade in if the label is already partially visible 332 JfxBrowser.this._statusLabel.setOpacity(1); 333 } else { 334 JfxBrowser.this._statusLabel.setVisible(true); 335 JfxBrowser.this._statusFadeIn.play(); 336 } 337 } else { 338 JfxBrowser.this._statusFadeIn.stop(); 339 340 JfxBrowser.this._statusFadeOut.play(); 341 } 342 } 343 }); 344 345 319 346 final EventDispatcher initial = this._urlField.getEventDispatcher(); 347 320 348 this._urlField.setEventDispatcher(new EventDispatcher() { 321 349 @Override … … 958 986 } 959 987 988 private Point getCoordFromCaret(TextField text) { 989 TextFieldSkin skin = (TextFieldSkin) text.getSkin(); 990 991 Point2D onScene = text.localToScene(0, 0); 992 993 double x = onScene.getX() + JfxBrowser.this.getX();// - org.expeditee.gui.Browser._theBrowser.getOrigin().x; 994 double y = onScene.getY() + JfxBrowser.this.getY();// - org.expeditee.gui.Browser._theBrowser.getOrigin().y; 995 996 Rectangle2D cp = skin.getCharacterBounds(text.getCaretPosition()); 997 998 return new Point((int) (cp.getMinX() + x), (int) (cp.getMinY() + y)); 999 } 1000 1001 private int getCaretFromCoord(TextField text, MouseEvent e) { 1002 TextFieldSkin skin = (TextFieldSkin) text.getSkin(); 1003 HitInfo hit = skin.getIndex(e); 1004 return hit.getInsertionIndex(); 1005 } 1006 1007 /** 1008 * @param src The MouseEvent to clone 1009 * @param node The node the position will be relative to 1010 * @param x The position in Expeditee space 1011 * @param y The position in Expeditee space 1012 * @return A fake MouseEvent for a specific position relative to a Node 1013 */ 1014 private MouseEvent getMouseEventForPosition(MouseEvent src, Node node, int x, int y) { 1015 MouseEvent dst = (MouseEvent) ((Event) src).copyFor(null, null); 1016 try { 1017 MouseEvent_x.set(dst, x - node.localToScene(0, 0).getX()); 1018 MouseEvent_y.set(dst, y - node.localToScene(0, 0).getY()); 1019 } catch (Exception e) { 1020 e.printStackTrace(); 1021 } 1022 return dst; 1023 } 1024 960 1025 private void enableReadableMode() { 961 1026 String readabilityJs;
Note:
See TracChangeset
for help on using the changeset viewer.