-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddressPanel.m
164 lines (132 loc) · 6.57 KB
/
AddressPanel.m
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
classdef AddressPanel < handle
properties(Access = protected)
BackButton
ForwardButton
RefreshButton
HomeButton
BookmanButton
AddressField
Pane
Browser(1,1) Browser
end
properties(Access = protected)
BrowserListeners
end
methods(Access = protected)
function this = AddressPanel( browser )
if nargin
this.Browser = browser;
this.create(browser);
this.BrowserListeners = [...
addlistener(browser,'AddressChanged',@this.onAddressChange),...
addlistener(browser,'CanGoBackUpdated',@this.onCanGoBack),...
addlistener(browser,'CanGoForwardUpdated',@this.onCanGoForward)];
end
end
end
methods
function delete( this )
try delete(this.BrowserListeners); catch; end
try delete(this.Pane); catch; end
end
end
methods(Access = protected)
function onBrowserPanelAction( this, ~, evnt )
if (evnt.getID == javax.swing.event.AncestorEvent.ANCESTOR_REMOVED)
if isa(evnt.getAncestorParent,...
'com.jidesoft.swing.JideTabbedPane'); return;end
delete(this);
end
end
function onMouseClicked( this, src, evnt ) %#ok<INUSD>
java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager.clearGlobalFocusOwner;
this.AddressField.requestFocus();
end
function onAddressChange( this, ~, ~ )
try this.AddressField.setText(this.Browser.URL);catch;end
end
function onCanGoBack( this, ~, ~ )
this.BackButton.setEnabled(this.Browser.CanGoBack);
end
function onCanGoForward( this, ~, ~ )
this.ForwardButton.setEnabled(this.Browser.CanGoForward);
end
function URL = getAddress( this )
URL = this.AddressField.getText().toString.char;
URL = this.Browser.validateURL(URL);
end
function create( this, browser )
import com.jidesoft.swing.JideBoxLayout
import javax.swing.BorderFactory
cefBrowser = browser.getFocusedBrowser();
panel = handle(cefBrowser.getUIComponent,'CallbackProperties');
panel.AncestorRemovedCallback = @this.onBrowserPanelAction;
iconpath = [fullfile(fileparts(mfilename('fullpath')),'icons'),filesep];
border = BorderFactory.createLineBorder(java.awt.Color.WHITE,4,true);
cls = 'javax.swing.JPanel';
browserPanel = javaObjectEDT(cls,java.awt.BorderLayout);
addressPane = javaObjectEDT(cls);
addressPane.setBackground(java.awt.Color.WHITE);
cls = 'com.jidesoft.swing.JideBoxLayout';
layout = javaObjectEDT(cls,addressPane,JideBoxLayout.X_AXIS,6);
addressPane.setLayout(layout);
addressPane.setBorder(BorderFactory.createCompoundBorder(...
com.jidesoft.swing.PartialLineBorder(java.awt.Color(0.9,0.9,0.9,0.6),2,com.jidesoft.swing.PartialSide.SOUTH),...
BorderFactory.createEmptyBorder(4,4,4,4)));
cls = 'com.jidesoft.swing.NullJideButton';
icon = javax.swing.ImageIcon([iconpath,'back.png']);
backButton = handle(javaObjectEDT(cls,icon),'CallbackProperties');
backButton.setEnabled(false);
backButton.setFocusable(false);
backButton.ActionPerformedCallback = @(~,~) browser.goBack;
icon = javax.swing.ImageIcon([iconpath,'forward.png']);
forwardButton = handle(javaObjectEDT(cls,icon),'CallbackProperties');
forwardButton.setEnabled(false);
forwardButton.setFocusable(false);
forwardButton.ActionPerformedCallback = @(~,~) browser.goForward;
icon = javax.swing.ImageIcon([iconpath,'refresh.png']);
reloadButton = handle(javaObjectEDT(cls,icon),'CallbackProperties');
reloadButton.setFocusable(false);
reloadButton.ActionPerformedCallback = @(~,~) cefBrowser.reloadIgnoreCache;
icon = javax.swing.ImageIcon([iconpath,'home.png']);
homeButton = handle(javaObjectEDT(cls,icon),'CallbackProperties');
homeButton.setFocusable(false);
homeButton.ActionPerformedCallback = @(~,~) browser.loadURL(browser.DEFAULT_URL);
icon = javax.swing.ImageIcon([iconpath,'bookmark.png']);
bookmarkButton = handle(javaObjectEDT(cls,icon),'CallbackProperties');
bookmarkButton.setEnabled(false);
bookmarkButton.setFocusable(false);
cls = 'com.jidesoft.swing.LabeledTextField';
addressField = javaObjectEDT(cls,[],' ');
addressField.setText(cefBrowser.getURL);
addressField.setBorder(BorderFactory.createCompoundBorder(border,BorderFactory.createEmptyBorder(0,4,0,0)));
addressField.setBackground(java.awt.Color(0.9,0.9,0.9,0.6))
addressField.setPreferredSize(java.awt.Dimension(100,36));
txtFld = handle(addressField.getTextField(),'CallbackProperties');
txtFld.ActionPerformedCallback = @(~,~) browser.loadURL(this.getAddress());
txtFld.MouseClickedCallback = @this.onMouseClicked;
addressPane.add(backButton,JideBoxLayout.FIX);
addressPane.add(forwardButton,JideBoxLayout.FIX);
addressPane.add(reloadButton,JideBoxLayout.FIX);
addressPane.add(homeButton,JideBoxLayout.FIX);
addressPane.add(addressField,JideBoxLayout.VARY);
addressPane.add(bookmarkButton,JideBoxLayout.FIX);
browserPanel.add(addressPane,'North');
browserPanel.add(panel,'Center');
drawnow();
this.BackButton = backButton;
this.ForwardButton = forwardButton;
this.RefreshButton = reloadButton;
this.HomeButton = homeButton;
this.BookmanButton = bookmarkButton;
this.AddressField = addressField;
this.Pane = browserPanel;
end
end
methods(Access = public, Static = true)
function browserPanel = getBrowserPanel( browser )
addressPane = AddressPanel(browser);
browserPanel = addressPane.Pane;
end
end
end