Changeset 892


Ignore:
Timestamp:
02/14/14 12:12:52 (10 years ago)
Author:
ngw8
Message:

Added a status bar to the jfx browser that shows up when a link is hovered over

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/assets/style/jfx.css

    r888 r892  
    7979}
    8080
     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
    8188.fa {
    8289    -fx-font-family: FontAwesome;   
  • trunk/src/org/expeditee/items/widgets/JfxBrowser.java

    r888 r892  
    1515import java.lang.reflect.Field;
    1616
     17import javafx.animation.FadeTransition;
    1718import javafx.application.Platform;
    1819import javafx.beans.value.ChangeListener;
     
    5051import javafx.scene.text.Font;
    5152import javafx.scene.web.WebEngine;
     53import javafx.scene.web.WebEvent;
    5254import javafx.scene.web.WebView;
     55import javafx.util.Duration;
    5356import netscape.javascript.JSObject;
    5457
     
    9497        private Button _convertButton;
    9598        private ToggleButton _readableModeButton;
     99        private Label _statusLabel;
     100        private FadeTransition _statusFadeIn;
     101        private FadeTransition _statusFadeOut;
    96102
    97103        private TextField _urlField;
     
    117123        }
    118124        }
    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 clone
    141          * @param node The node the position will be relative to
    142          * @param x The position in Expeditee space
    143          * @param y The position in Expeditee space
    144          * @return A fake MouseEvent for a specific position relative to a Node
    145          */
    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         }
    156125
    157126        public JfxBrowser(Text source, final String[] args) {
     
    236205                        this._urlProgressBar.getStyleClass().add("url-progress-bar");
    237206                        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                       
    238237
    239238                        StackPane urlbar = new StackPane();
     
    262261                        // size. This also means that the webview's prefSize must be manually set when the Pane resizes, using the event handlers below
    263262                        Pane browserPane = new Pane();
    264                         browserPane.getChildren().add(_webView);
     263                        browserPane.getChildren().addAll(_webView, this._statusLabel);
    265264                       
    266265                        HBox.setHgrow(browserPane, Priority.ALWAYS);
     
    280279                                public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) {
    281280                                        JfxBrowser.this._webView.setPrefHeight((Double) newValue);
     281                                        JfxBrowser.this._statusLabel.setTranslateY((Double) newValue - JfxBrowser.this._statusLabel.heightProperty().doubleValue());
    282282                                }
    283283                        });
     
    317317                        // Disable right click menu
    318318                        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                       
    319346                        final EventDispatcher initial = this._urlField.getEventDispatcher();
     347                       
    320348                        this._urlField.setEventDispatcher(new EventDispatcher() {
    321349                                @Override
     
    958986        }
    959987       
     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       
    9601025        private void enableReadableMode() {
    9611026                String readabilityJs;
Note: See TracChangeset for help on using the changeset viewer.