Skip to content

Commit 24114db

Browse files
committed
Added Moving Title Setting
1 parent 9cdd314 commit 24114db

File tree

6 files changed

+66
-31
lines changed

6 files changed

+66
-31
lines changed

resources/fxml/FXMarquee.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<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">
77
<children>
8-
<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" />
8+
<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" />
99
</children>
1010

1111
<!--

resources/fxml/WebBrowserTabController.fxml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
<JFXCheckBox fx:id="requestMobileSite" text="Request Mobile Site" textFill="WHITE" />
111111
</graphic>
112112
</MenuItem>
113+
<MenuItem mnemonicParsing="false">
114+
<graphic>
115+
<JFXCheckBox fx:id="movingTitleAnimation" selected="true" text="Moving Title Animation" textFill="WHITE" />
116+
</graphic>
117+
</MenuItem>
113118
<MenuItem fx:id="about" mnemonicParsing="false" text="About ?" />
114119
</items>
115120
</MenuButton>

src/main/java/com/goxr3plus/javafxwebbrowser/application/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static double getVisualScreenHeight() {
7575
* @param args
7676
*/
7777
public static void main(String[] args) {
78+
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
7879
launch(args);
7980
}
8081
}

src/main/java/com/goxr3plus/javafxwebbrowser/browser/WebBrowserController.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class WebBrowserController extends StackPane {
3030
/** The logger. */
3131
private final Logger logger = Logger.getLogger(getClass().getName());
3232

33-
public final static String VERSION = "Version 3.5.0";
33+
public static final String VERSION = "Version 3.5.0";
34+
35+
public static boolean MOVING_TITLES_ENABLED = true;
3436

3537
//------------------------------------------------------------
3638
@FXML
@@ -180,6 +182,16 @@ public TabPane getTabPane() {
180182
return tabPane;
181183
}
182184

185+
/**
186+
* Sets the moving titles enabled or disabled on all the tabs
187+
*
188+
* @param value
189+
*/
190+
public void setMovingTitlesEnabled(boolean value) {
191+
MOVING_TITLES_ENABLED = value;
192+
tabPane.getTabs().forEach(tab -> ( (WebBrowserTabController) tab.getContent() ).setMovingTitleEnabled(value));
193+
}
194+
183195
/**
184196
* This is a list holding all the proposed websites for the user
185197
*/
@@ -264,20 +276,7 @@ public TabPane getTabPane() {
264276
"https://www.gismeteo.ru", "https://www.github.com", "https://www.github.io", "https://www.givemesport.com", "https://www.gizmodo.com", "https://www.glassdoor.com",
265277
"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",
266278
"https://www.godaddy.com", "https://www.gofundme.com", "https://www.gogoanime.io", "https://www.gomovies.to", "https://www.gongchang.com", "https://www.goo.gl",
267-
"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",
268-
"https://www.google.bg", "https://www.google.by", "https://www.google.ca", "https://www.google.ch", "https://www.google.cl", "https://www.google.cn",
269-
"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",
270-
"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",
271-
"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",
272-
"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",
273-
"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",
274-
"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",
275-
"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",
276-
"https://www.google.dz", "https://www.google.es", "https://www.google.fi", "https://www.google.fr", "https://www.google.gr", "https://www.google.hr",
277-
"https://www.google.hu", "https://www.google.ie", "https://www.google.iq", "https://www.google.it", "https://www.google.kz", "https://www.google.lk",
278-
"https://www.google.lt", "https://www.google.nl", "https://www.google.no", "https://www.google.pl", "https://www.google.pt", "https://www.google.ro",
279-
"https://www.google.rs", "https://www.google.ru", "https://www.google.se", "https://www.google.si", "https://www.google.sk", "https://www.google.tm",
280-
"https://www.google.tn", "https://www.googleusercontent.com", "https://www.googlevideo.com", "https://www.gotporn.com", "https://www.gov.uk", "https://www.gpo.gov",
279+
"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",
281280
"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",
282281
"https://www.gutefrage.net", "https://www.gyazo.com", "https://www.haber7.com", "https://www.hamariweb.com", "https://www.hao123.com", "https://www.harvard.edu",
283282
"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",

src/main/java/com/goxr3plus/javafxwebbrowser/browser/WebBrowserTabController.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public class WebBrowserTabController extends StackPane {
108108
@FXML
109109
private ProgressIndicator tryAgainIndicator;
110110

111+
@FXML
112+
private JFXCheckBox movingTitleAnimation;
113+
111114
// -------------------------------------------------------------
112115

113116
/** The engine. */
@@ -174,7 +177,9 @@ private void initialize() {
174177
//System.out.println("WebEngine exception occured" + error.toString())
175178
checkForInternetConnection();
176179
});
177-
180+
// com.sun.javafx.webkit.WebConsoleListener
181+
// .setDefaultListener((webView , message , lineNumber , sourceId) -> System.out.println("Console: [" + sourceId + ":" + lineNumber + "] " + message));
182+
//
178183
//Add listener to the WebEngine
179184
webEngine.getLoadWorker().stateProperty().addListener(new FavIconProvider());
180185
webEngine.getLoadWorker().stateProperty().addListener(new DownloadDetector());
@@ -199,7 +204,7 @@ private void initialize() {
199204
//handle pop up windows
200205
webEngine.setCreatePopupHandler(l -> webBrowserController.createAndAddNewTab().getWebView().getEngine());
201206
//System.out.println(webEngine.getUserAgent())
202-
webEngine.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0");
207+
//webEngine.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0");
203208
//System.out.println(webEngine.getUserAgent());
204209

205210
//History
@@ -256,6 +261,10 @@ private void initialize() {
256261

257262
// HBOX
258263
HBox hBox = new HBox();
264+
hBox.setOnMouseClicked(m -> {
265+
if (m.getButton() == MouseButton.MIDDLE)
266+
this.webBrowserController.removeTab(tab);
267+
});
259268
hBox.getChildren().addAll(facIconImageView, stack, marquee);
260269
tab.setGraphic(hBox);
261270

@@ -325,6 +334,12 @@ private void initialize() {
325334
reloadWebSite();
326335
});
327336

337+
//movingTitleAnimation
338+
movingTitleAnimation.selectedProperty().addListener((observable , oldValue , newValue) -> {
339+
marquee.checkAnimationValidity(newValue);
340+
});
341+
movingTitleAnimation.setSelected(WebBrowserController.MOVING_TITLES_ENABLED);
342+
328343
//Load the website
329344
loadWebSite(firstWebSite);
330345

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

339354
alert.showAndWait();
340355
});
@@ -515,6 +530,15 @@ public void setHistory(WebHistory history) {
515530
this.history = history;
516531
}
517532

533+
/**
534+
* Determines if the tab title will have a moving animation or not
535+
*
536+
* @param value
537+
*/
538+
public void setMovingTitleEnabled(boolean value) {
539+
movingTitleAnimation.setSelected(value);
540+
}
541+
518542
///////////////////////////// INNER CLASSES ////////////////////////////////
519543
public class FavIconProvider implements ChangeListener<State> {
520544

src/main/java/com/goxr3plus/javafxwebbrowser/marquee/FXMarquee.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import javafx.util.Duration;
1818
import main.java.com.goxr3plus.javafxwebbrowser.tools.InfoTool;
1919

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

2928
@FXML
30-
private Label text;
29+
private Label label;
3130

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

8281
// text
83-
text.setText(value);
82+
label.setText(value);
8483

8584
return this;
8685
}
@@ -91,7 +90,7 @@ public FXMarquee setText(String value) {
9190
* @return The TextProperty
9291
*/
9392
public StringProperty textProperty() {
94-
return text.textProperty();
93+
return label.textProperty();
9594
}
9695

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

107106
@Override
108107
public void handle(ActionEvent event) {
109-
double textWidth = text.getLayoutBounds().getWidth();
108+
double textWidth = label.getLayoutBounds().getWidth();
110109
double paneWidth = getWidth();
111-
double layoutX = text.getLayoutX();
110+
double layoutX = label.getLayoutX();
112111

113112
if (2 * OFFSET + textWidth <= paneWidth && layoutX >= OFFSET) {
114113
// stop, if the pane is large enough and the position is
115114
// correct
116-
text.setLayoutX(OFFSET);
115+
label.setLayoutX(OFFSET);
117116
timeline.stop();
118117
} else {
119118
if ( ( rightMovement && layoutX >= OFFSET ) || ( !rightMovement && layoutX + textWidth + OFFSET <= paneWidth )) {
@@ -127,7 +126,7 @@ public void handle(ActionEvent event) {
127126
} else {
128127
layoutX -= 1;
129128
}
130-
text.setLayoutX(layoutX);
129+
label.setLayoutX(layoutX);
131130
}
132131
}
133132
});
@@ -138,7 +137,7 @@ public void handle(ActionEvent event) {
138137
// animation
139138
InvalidationListener listener = o -> checkAnimationValidity(animationAllowed);
140139

141-
text.layoutBoundsProperty().addListener(listener);
140+
label.layoutBoundsProperty().addListener(listener);
142141
widthProperty().addListener(listener);
143142

144143
}
@@ -149,15 +148,22 @@ public void handle(ActionEvent event) {
149148
public void checkAnimationValidity(boolean continueAnimation) {
150149
animationAllowed = continueAnimation;
151150
if (animationAllowed) {
152-
double textWidth = text.getLayoutBounds().getWidth();
151+
double textWidth = label.getLayoutBounds().getWidth();
153152
double paneWidth = getWidth();
154-
text.setLayoutX(5);
153+
label.setLayoutX(5);
155154
if (textWidth + 2 * OFFSET > paneWidth && timeline.getStatus() != Animation.Status.RUNNING)
156155
timeline.play();
157156
} else {
158-
text.setLayoutX(OFFSET);
157+
label.setLayoutX(OFFSET);
159158
timeline.stop();
160159
}
161160
}
162161

162+
/**
163+
* @return the label
164+
*/
165+
public Label getLabel() {
166+
return label;
167+
}
168+
163169
}

0 commit comments

Comments
 (0)