-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebMenu.java
More file actions
147 lines (124 loc) · 4.25 KB
/
WebMenu.java
File metadata and controls
147 lines (124 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import javafx.beans.property.SimpleStringProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.text.FontSmoothingType;
import javafx.scene.web.WebView;
public class WebMenu extends MenuButton
{
public WebMenu(WebView webView)
{
// Set the Text of the WebMenu
this.setText("Options");
// Set the Style-properties of the Navigation Bar
this.setStyle("-fx-padding: 10;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 5;" +
"-fx-border-radius: 5;" +
"-fx-border-color: blue;");
// Create the Menu Items
CheckMenuItem ctxMenu = new CheckMenuItem("Enable Context Menu");
ctxMenu.setSelected(true);
MenuItem normalFontMenu = new MenuItem("Normal");
MenuItem biggerFontMenu = new MenuItem("10% Bigger");
MenuItem smallerFontMenu = new MenuItem("10% Smaller");
MenuItem normalZoomMenu = new MenuItem("Normal");
MenuItem biggerZoomMenu = new MenuItem("10% Bigger");
MenuItem smallerZoomMenu = new MenuItem("10% Smaller");
// Create the RadioMenuItems
RadioMenuItem grayMenu = new RadioMenuItem("GRAY");
grayMenu.setSelected(true);
RadioMenuItem lcdMenu = new RadioMenuItem("LCD");
// Create the Menus
Menu scalingMenu = new Menu("Font Scale");
scalingMenu.textProperty().bind(new SimpleStringProperty("Font Scale ").concat(webView.fontScaleProperty().multiply(100.0)).concat("%"));
Menu smoothingMenu = new Menu("Font Smoothing");
Menu zoomMenu = new Menu("Zoom");
zoomMenu.textProperty().bind(new SimpleStringProperty("Zoom ").concat(webView.zoomProperty().multiply(100.0)).concat("%"));
// Add the Items to the corresponding Menu
scalingMenu.getItems().addAll(normalFontMenu, biggerFontMenu, smallerFontMenu);
smoothingMenu.getItems().addAll(grayMenu, lcdMenu);
zoomMenu.getItems().addAll(normalZoomMenu, biggerZoomMenu, smallerZoomMenu);
// Create the ToggleGroup
new ToggleGroup().getToggles().addAll(lcdMenu, grayMenu);
// Define the Event Handler
normalFontMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setFontScale(1.0);
}
});
biggerFontMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setFontScale(webView.getFontScale() + 0.10);
}
});
smallerFontMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setFontScale(webView.getFontScale() - 0.10);
}
});
grayMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setFontSmoothingType(FontSmoothingType.GRAY);
}
});
lcdMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setFontSmoothingType(FontSmoothingType.LCD);
}
});
normalZoomMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setZoom(1.0);
}
});
biggerZoomMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setZoom(webView.getZoom() + 0.10);
}
});
smallerZoomMenu.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
webView.setZoom(webView.getZoom() - 0.10);
}
});
webView.contextMenuEnabledProperty().bind(ctxMenu.selectedProperty());
// Enabled JavaScript option
CheckMenuItem scriptMenu = new CheckMenuItem("Enable JavaScript");
scriptMenu.setSelected(true);
webView.getEngine().javaScriptEnabledProperty().bind(scriptMenu.selectedProperty());
// Add Menus to the WebMenu
this.getItems().addAll(ctxMenu, scalingMenu, smoothingMenu, zoomMenu, new SeparatorMenuItem(), scriptMenu);
}
}