Skip to content

Commit

Permalink
Added Moving Title Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
goxr3plus committed Mar 5, 2018
1 parent 9cdd314 commit 24114db
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 31 deletions.
2 changes: 1 addition & 1 deletion resources/fxml/FXMarquee.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<fx:root fx:id="root" maxHeight="25.0" minHeight="25.0" prefHeight="25.0" prefWidth="100.0" style="-fx-background-color: white;" type="Pane" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="text" layoutX="5.0" layoutY="3.0" style="-fx-text-fill: black; -fx-font-size: 13; -fx-font-weight: 400;" text="Stopped" />
<Label fx:id="label" layoutX="5.0" layoutY="3.0" style="-fx-text-fill: black; -fx-font-size: 13; -fx-font-weight: 400;" text="Stopped" />
</children>

<!--
Expand Down
5 changes: 5 additions & 0 deletions resources/fxml/WebBrowserTabController.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
<JFXCheckBox fx:id="requestMobileSite" text="Request Mobile Site" textFill="WHITE" />
</graphic>
</MenuItem>
<MenuItem mnemonicParsing="false">
<graphic>
<JFXCheckBox fx:id="movingTitleAnimation" selected="true" text="Moving Title Animation" textFill="WHITE" />
</graphic>
</MenuItem>
<MenuItem fx:id="about" mnemonicParsing="false" text="About ?" />
</items>
</MenuButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static double getVisualScreenHeight() {
* @param args
*/
public static void main(String[] args) {
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
launch(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class WebBrowserController extends StackPane {
/** The logger. */
private final Logger logger = Logger.getLogger(getClass().getName());

public final static String VERSION = "Version 3.5.0";
public static final String VERSION = "Version 3.5.0";

public static boolean MOVING_TITLES_ENABLED = true;

//------------------------------------------------------------
@FXML
Expand Down Expand Up @@ -180,6 +182,16 @@ public TabPane getTabPane() {
return tabPane;
}

/**
* Sets the moving titles enabled or disabled on all the tabs
*
* @param value
*/
public void setMovingTitlesEnabled(boolean value) {
MOVING_TITLES_ENABLED = value;
tabPane.getTabs().forEach(tab -> ( (WebBrowserTabController) tab.getContent() ).setMovingTitleEnabled(value));
}

/**
* This is a list holding all the proposed websites for the user
*/
Expand Down Expand Up @@ -264,20 +276,7 @@ public TabPane getTabPane() {
"https://www.gismeteo.ru", "https://www.github.com", "https://www.github.io", "https://www.givemesport.com", "https://www.gizmodo.com", "https://www.glassdoor.com",
"https://www.globo.com", "https://www.gmarket.co.kr", "https://www.gmw.cn", "https://www.gmx.net", "https://www.gnu.org", "https://www.go.com", "https://www.goal.com",
"https://www.godaddy.com", "https://www.gofundme.com", "https://www.gogoanime.io", "https://www.gomovies.to", "https://www.gongchang.com", "https://www.goo.gl",
"https://www.goo.ne.jp", "https://www.goodreads.com", "https://www.google.ae", "https://www.google.at", "https://www.google.az", "https://www.google.be",
"https://www.google.bg", "https://www.google.by", "https://www.google.ca", "https://www.google.ch", "https://www.google.cl", "https://www.google.cn",
"https://www.google.co.ao", "https://www.google.co.id", "https://www.google.co.il", "https://www.google.co.in", "https://www.google.co.jp", "https://www.google.co.kr",
"https://www.google.co.nz", "https://www.google.co.th", "https://www.google.co.uk", "https://www.google.co.ve", "https://www.google.co.za", "https://www.google.com",
"https://www.google.com.ar", "https://www.google.com.au", "https://www.google.com.br", "https://www.google.com.co", "https://www.google.com.do",
"https://www.google.com.ec", "https://www.google.com.eg", "https://www.google.com.gt", "https://www.google.com.hk", "https://www.google.com.kw",
"https://www.google.com.ly", "https://www.google.com.mm", "https://www.google.com.mx", "https://www.google.com.ng", "https://www.google.com.pe",
"https://www.google.com.ph", "https://www.google.com.pk", "https://www.google.com.sa", "https://www.google.com.sg", "https://www.google.com.tr",
"https://www.google.com.tw", "https://www.google.com.ua", "https://www.google.com.vn", "https://www.google.cz", "https://www.google.de", "https://www.google.dk",
"https://www.google.dz", "https://www.google.es", "https://www.google.fi", "https://www.google.fr", "https://www.google.gr", "https://www.google.hr",
"https://www.google.hu", "https://www.google.ie", "https://www.google.iq", "https://www.google.it", "https://www.google.kz", "https://www.google.lk",
"https://www.google.lt", "https://www.google.nl", "https://www.google.no", "https://www.google.pl", "https://www.google.pt", "https://www.google.ro",
"https://www.google.rs", "https://www.google.ru", "https://www.google.se", "https://www.google.si", "https://www.google.sk", "https://www.google.tm",
"https://www.google.tn", "https://www.googleusercontent.com", "https://www.googlevideo.com", "https://www.gotporn.com", "https://www.gov.uk", "https://www.gpo.gov",
"https://www.goo.ne.jp", "https://www.goodreads.com", "https://www.googleusercontent.com", "https://www.googlevideo.com", "https://www.gotporn.com", "https://www.gov.uk", "https://www.gpo.gov",
"https://www.grammarly.com", "https://www.gravatar.com", "https://www.grid.id", "https://www.groupon.com", "https://www.gsmarena.com", "https://www.guardian.co.uk",
"https://www.gutefrage.net", "https://www.gyazo.com", "https://www.haber7.com", "https://www.hamariweb.com", "https://www.hao123.com", "https://www.harvard.edu",
"https://www.hatena.ne.jp", "https://www.hatenablog.com", "https://www.hbr.org", "https://www.hclips.com", "https://www.hdfcbank.com", "https://www.hdzog.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public class WebBrowserTabController extends StackPane {
@FXML
private ProgressIndicator tryAgainIndicator;

@FXML
private JFXCheckBox movingTitleAnimation;

// -------------------------------------------------------------

/** The engine. */
Expand Down Expand Up @@ -174,7 +177,9 @@ private void initialize() {
//System.out.println("WebEngine exception occured" + error.toString())
checkForInternetConnection();
});

// com.sun.javafx.webkit.WebConsoleListener
// .setDefaultListener((webView , message , lineNumber , sourceId) -> System.out.println("Console: [" + sourceId + ":" + lineNumber + "] " + message));
//
//Add listener to the WebEngine
webEngine.getLoadWorker().stateProperty().addListener(new FavIconProvider());
webEngine.getLoadWorker().stateProperty().addListener(new DownloadDetector());
Expand All @@ -199,7 +204,7 @@ private void initialize() {
//handle pop up windows
webEngine.setCreatePopupHandler(l -> webBrowserController.createAndAddNewTab().getWebView().getEngine());
//System.out.println(webEngine.getUserAgent())
webEngine.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0");
//webEngine.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0");
//System.out.println(webEngine.getUserAgent());

//History
Expand Down Expand Up @@ -256,6 +261,10 @@ private void initialize() {

// HBOX
HBox hBox = new HBox();
hBox.setOnMouseClicked(m -> {
if (m.getButton() == MouseButton.MIDDLE)
this.webBrowserController.removeTab(tab);
});
hBox.getChildren().addAll(facIconImageView, stack, marquee);
tab.setGraphic(hBox);

Expand Down Expand Up @@ -325,6 +334,12 @@ private void initialize() {
reloadWebSite();
});

//movingTitleAnimation
movingTitleAnimation.selectedProperty().addListener((observable , oldValue , newValue) -> {
marquee.checkAnimationValidity(newValue);
});
movingTitleAnimation.setSelected(WebBrowserController.MOVING_TITLES_ENABLED);

//Load the website
loadWebSite(firstWebSite);

Expand All @@ -334,7 +349,7 @@ private void initialize() {
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("JavaFX Browser");
alert.setHeaderText(null);
alert.setContentText("Browser Version :" + WebBrowserController.VERSION+"\n"+"Created by: GOXR3PLUS STUDIO");
alert.setContentText("Browser Version :" + WebBrowserController.VERSION + "\n" + "Created by: GOXR3PLUS STUDIO");

alert.showAndWait();
});
Expand Down Expand Up @@ -515,6 +530,15 @@ public void setHistory(WebHistory history) {
this.history = history;
}

/**
* Determines if the tab title will have a moving animation or not
*
* @param value
*/
public void setMovingTitleEnabled(boolean value) {
movingTitleAnimation.setSelected(value);
}

///////////////////////////// INNER CLASSES ////////////////////////////////
public class FavIconProvider implements ChangeListener<State> {

Expand Down
30 changes: 18 additions & 12 deletions src/main/java/com/goxr3plus/javafxwebbrowser/marquee/FXMarquee.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javafx.util.Duration;
import main.java.com.goxr3plus.javafxwebbrowser.tools.InfoTool;


/**
* When the screen element is not big enough to show the text then an animation will start automatically
*
Expand All @@ -27,7 +26,7 @@
public class FXMarquee extends Pane {

@FXML
private Label text;
private Label label;

// minimum distance to Pane bounds
private static final double OFFSET = 5;
Expand Down Expand Up @@ -80,7 +79,7 @@ private void initialize() {
public FXMarquee setText(String value) {

// text
text.setText(value);
label.setText(value);

return this;
}
Expand All @@ -91,7 +90,7 @@ public FXMarquee setText(String value) {
* @return The TextProperty
*/
public StringProperty textProperty() {
return text.textProperty();
return label.textProperty();
}

/**
Expand All @@ -106,14 +105,14 @@ private final void startAnimation() {

@Override
public void handle(ActionEvent event) {
double textWidth = text.getLayoutBounds().getWidth();
double textWidth = label.getLayoutBounds().getWidth();
double paneWidth = getWidth();
double layoutX = text.getLayoutX();
double layoutX = label.getLayoutX();

if (2 * OFFSET + textWidth <= paneWidth && layoutX >= OFFSET) {
// stop, if the pane is large enough and the position is
// correct
text.setLayoutX(OFFSET);
label.setLayoutX(OFFSET);
timeline.stop();
} else {
if ( ( rightMovement && layoutX >= OFFSET ) || ( !rightMovement && layoutX + textWidth + OFFSET <= paneWidth )) {
Expand All @@ -127,7 +126,7 @@ public void handle(ActionEvent event) {
} else {
layoutX -= 1;
}
text.setLayoutX(layoutX);
label.setLayoutX(layoutX);
}
}
});
Expand All @@ -138,7 +137,7 @@ public void handle(ActionEvent event) {
// animation
InvalidationListener listener = o -> checkAnimationValidity(animationAllowed);

text.layoutBoundsProperty().addListener(listener);
label.layoutBoundsProperty().addListener(listener);
widthProperty().addListener(listener);

}
Expand All @@ -149,15 +148,22 @@ public void handle(ActionEvent event) {
public void checkAnimationValidity(boolean continueAnimation) {
animationAllowed = continueAnimation;
if (animationAllowed) {
double textWidth = text.getLayoutBounds().getWidth();
double textWidth = label.getLayoutBounds().getWidth();
double paneWidth = getWidth();
text.setLayoutX(5);
label.setLayoutX(5);
if (textWidth + 2 * OFFSET > paneWidth && timeline.getStatus() != Animation.Status.RUNNING)
timeline.play();
} else {
text.setLayoutX(OFFSET);
label.setLayoutX(OFFSET);
timeline.stop();
}
}

/**
* @return the label
*/
public Label getLabel() {
return label;
}

}

0 comments on commit 24114db

Please sign in to comment.