Utility Services
createHtmlPanel
public HtmlPanel createHtmlPanel();
Description:
Creates an HtmlPanel Swing component.
Returns:
instance of HtmlPanel component
Example:
private void createHtmlPanelExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
String htmlPanelName = "apiDemoHtmlPanelTest";
//
// components of html panel is created in Webswing-Home-Folder\apps\WebswingDemo\webroot\index.html
//
// ...
// windowOpened: function(win) {
// ...
// if (win.htmlWindow && win.name == "apiDemoHtmlPanelTest") {
// if (win.element.getAttribute("ws-initialized") == "true") {
// return;
// }
// win.element.setAttribute("ws-initialized", "true");
//
// let apiDemoButton = document.createElement("button");
// apiDemoButton.appendChild(document.createTextNode("This is HTML button. Click me!"));
// apiDemoButton.style.margin = "25px";
// apiDemoButton.addEventListener("click", function() {
// win.performAction({actionName: "openApiDemoConfirmDialog"});
// });
//
// let apiDemoResult = document.createElement("div");
// apiDemoResult.style.margin = "25px";
// win.element.appendChild(apiDemoButton);
// win.element.appendChild(apiDemoResult);
//
// win.handleActionEvent = function(name, data, binaryData) {
// if (name == "confirmApiDemoDialogResult") {
// apiDemoResult.innerHTML = 'You have selected: "' + data + '"';
// }
// }
// }
// ...
JFrame window = new JFrame() {{
setIconImage(getToolkit().getImage(ApiDemoExamples.class.getResource("/logo.png")));
setTitle("createHtmlPanel");
setSize(new Dimension(750, 750));
setPreferredSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
HtmlPanel htmlPanel = webswingApi.createHtmlPanel();
htmlPanel.setName(htmlPanelName);
htmlPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
htmlPanel.setVisible(true);
htmlPanel.addWebWindowActionListener(new WebWindowActionListener() {
@Override
public void actionPerformed(WebActionEvent actionEvent) {
if (actionEvent.getActionName().equals("openApiDemoConfirmDialog")) {
SwingUtilities.invokeLater(() -> {
int result = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(window), "Are you sure?");
if (result == JOptionPane.YES_OPTION) {
htmlPanel.performWebAction("confirmApiDemoDialogResult", "yes", null);
console.append("You have selected: yes\n");
} else if (result == JOptionPane.NO_OPTION) {
htmlPanel.performWebAction("confirmApiDemoDialogResult", "no", null);
console.append("You have selected: no\n");
}
});
}
}
@Override
public void windowInitialized() {
console.append("HtmlPanel " + htmlPanelName + " has been initialized!\n");
}
});
window.getContentPane().add(htmlPanel);
}
}
createHtmlPanelBuilder
public HtmlPanelBuilder createHtmlPanelBuilder();
Description:
Creates a new HtmlPanelBuilder that helps creating HtmlPanel component.
Returns:
instance of HtmlPanelBuilder
Example:
private void createHtmlPanelBuilderExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setIconImage(getToolkit().getImage(ApiDemoExamples.class.getResource("/logo.png")));
setTitle("createHtmlPanelBuilder");
setSize(new Dimension(750, 750));
setPreferredSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
HtmlPanel browser = WebswingUtil.getWebswingApi().createHtmlPanelBuilder().webComponent("ws-html-panel-browser").build();
browser.setAlignmentX(Component.LEFT_ALIGNMENT);
browser.setVisible(true);
browser.addWebWindowActionListener(new WebWindowActionListener() {
@Override
public void actionPerformed(WebActionEvent actionEvent) {
}
@Override
public void windowInitialized() {
browser.performWebAction("changeSrc", "https://www.openstreetmap.org/export/embed.html?bbox=16.65458679199219%2C47.95452454972844%2C17.56095886230469%2C48.33525610652687&layer=mapnik", null);
}
});
window.getContentPane().add(browser);
}
}
getLatency
public Integer getLatency();
Description:
Returns the current average end-to-end paint latency or null if latency value is not available.
Returns:
current latency
Example:
private void getLatencyExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
console.append("Latency is :\n");
Integer latency = webswingApi.getLatency();
if (latency == null) {
console.append("N/A\n");
} else {
console.append(latency + "\n");
}
}
}
getWebswingVersion
public String getWebswingVersion();
Description:
Get Webswing Version
Returns:
the Webswing version in 'git describe' format
Example:
private void getWebswingVersionExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
console.append("Webswing version : \n");
console.append(webswingApi.getWebswingVersion() + "\n");
WebswingDemoAboutDialog.open();
}
}
isMirroring
public boolean isMirroring();
Description:
Returns true if current session is being mirrored. Mirroring App is located in - Admin console - Session - Current App - Mirror view.
Returns:
true if current session is being mirrored
Example:
private void isMirroringExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
console.append("Is mirroring?\n");
console.append(webswingApi.isMirroring() + "\n");
}
}
isRecording
public boolean isRecording();
Description:
Returns true if current session is being recorded. Recording App is located in - Admin console - Session - Current App - Menu - Record.
Returns:
true if current session is being recorded
Example:
private void isRecordingExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
console.append("Is recording?\n");
console.append(webswingApi.isRecording() + "\n");
}
}
isCompositingWindowManager
public boolean isCompositingWindowManager();
Description:
Is compositing window manager used? @deprecated
Returns:
true, since version 21.1 this is the default and only window manager
Example:
private void isCompositingWindowManagerExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
console.append("Is compositing window manager?\n");
console.append(webswingApi.isCompositingWindowManager() + "\n");
}
}
isMultiScreenSupportEnabled
public boolean isMultiScreenSupportEnabled();
Description:
Check if multi screen support is enabled in Webswing configuration.
Returns:
true if multi screen support is enabled in Webswing config
Example:
private void isMultiScreenSupportEnabledExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
console.append("Is multi screen support enabled?\n");
console.append(webswingApi.isMultiScreenSupportEnabled() + "\n");
}
}
isTouchMode
public boolean isTouchMode();
Description:
Is touch mode active?
Returns:
true if session is running in touch mode, i.e. on a touch enabled device
Example:
private void isTouchModeExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
console.append("Is touch mode?\n");
console.append(webswingApi.isTouchMode() + "\n");
}
}
registerCustomFileChooser
public void registerCustomFileChooser(JFileChooser fileChooser, Window parent);
Description:
Register JFileChooser that should show Webswing integration toolbar if embedded in a window. Transparent mode is not available in this case. To hide Webswing integration toolbar use WebswingFileChooserUtil.setFileUIHidden(fileChooser, true).
Parameters:
parent window that contains this fileChooser
Example:
private void registerCustomFileChooserExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setTitle("registerCustomFileChooser");
setSize(new Dimension(750, 750));
setPreferredSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
JFileChooser fileChooser = new JFileChooser();
WebswingFileChooserUtil.overridePermissions(fileChooser, true, true, true);
JPanel panel = new JPanel();
panel.add(fileChooser, BorderLayout.CENTER);
webswingApi.registerCustomFileChooser(fileChooser, window);
window.getContentPane().add(panel);
}
}
registerCustomFileChooserProvider
public void registerCustomFileChooserProvider(WebswingFileChooserProvider fileChooserProvider, Window parent);
Description:
Register a provider for custom file chooser that implements WebswingFileChooserProvider. Transparent mode is not available in this case. To hide Webswing integration toolbar use WebswingFileChooserUtil.setFileUIHidden(fileChooserProvider, true);.
Parameters:
parent window that contains the fileChooserProvider relatedComponent
Example:
private void registerCustomFileChooserProviderExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setTitle("registerCustomFileChooserProvider");
setSize(new Dimension(750, 750));
setPreferredSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
CustomFileExplorer customFileExplorer = new CustomFileExplorer(FileSystemView.getFileSystemView().getRoots());
customFileExplorer.setName("custom file explorer");
JPanel btnPanel = new JPanel();
JButton showBtn = new JButton("show");
showBtn.addActionListener(e -> customFileExplorer.setVisible(true));
JButton hideBtn = new JButton("hide");
hideBtn.addActionListener(e -> customFileExplorer.setVisible(false));
btnPanel.add(showBtn);
btnPanel.add(hideBtn);
JPanel panel = new JPanel();
panel.add(btnPanel, BorderLayout.NORTH);
panel.add(customFileExplorer, BorderLayout.SOUTH);
webswingApi.registerCustomFileChooserProvider(customFileExplorer, window);
window.getContentPane().add(panel);
}
}
registerGlobalFileChooserProvider
public void registerGlobalFileChooserProvider(WebswingFileChooserProvider fileChooserProvider);
Description:
Register a global provider for file chooser that is always active until it is unregistered. No other file chooser can be activated while this file chooser provider is registered. Transparent mode is not available in this case. To hide Webswing integration toolbar use WebswingFileChooserUtil.setFileUIHidden(fileChooserProvider, true);.
Parameters:
fileChooserProvider instance of file chooser provider implementation
Example:
private void registerGlobalFileChooserProviderExample() {
console.append("No example.\n");
}
unregisterGlobalFileChooserProvider
public void unregisterGlobalFileChooserProvider();
Description:
Unregister a global provider for file chooser making it effectively inactive.
Example:
private void unregisterGlobalFileChooserProviderExample() {
console.append("No example.\n");
}
getRegisteredGlobalFileChooserProvider
public WebswingFileChooserProvider getRegisteredGlobalFileChooserProvider();
Description:
Get the currently registered global file chooser provider or null if no active global file chooser provider is registered.
Returns:
currently registered global file chooser provider or null
Example:
private void getRegisteredGlobalFileChooserProviderExample() {
console.append("No example.\n");
}
}
registerDropComponent
public void registerDropComponent(JComponent component);
Description:
Register a component as a receiver of DnD drop event from user's host system.
Parameters:
component the component to be registered as drop receiver
Example:
private void registerDropComponentExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JTextArea info = new JTextArea() {{
setBorder(BorderFactory.createTitledBorder("Info"));
setEditable(false);
}};
JLabel imgLabel = new JLabel();
JPanel panel = new JPanel() {{
setBorder(BorderFactory.createTitledBorder("Drag and drop png file from disk here."));
setLayout(new BorderLayout(10, 10));
JPanel controlPanel = new JPanel();
JLabel registerLabel = new JLabel("Drop targets: ");
JButton registerButton = new JButton("register");
registerButton.addActionListener(e -> {
webswingApi.registerDropComponent(this);
});
JButton unregisterButton = new JButton("unregister");
unregisterButton.addActionListener(e -> {
webswingApi.unregisterDropComponent(this);
});
controlPanel.add(registerLabel);
controlPanel.add(registerButton);
controlPanel.add(unregisterButton);
add(controlPanel, BorderLayout.NORTH);
add(imgLabel, BorderLayout.CENTER);
add(info, BorderLayout.SOUTH);
setTransferHandler(new TransferHandler("Api Demo Drop Test") {
@Override
public boolean canImport(TransferSupport support) {
Transferable t = support.getTransferable();
return t.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
}
@Override
public boolean importData(TransferSupport support) {
Transferable t = support.getTransferable();
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
List<File> fileList = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
if (fileList != null && !fileList.isEmpty()) {
ImageIcon imageIcon = null;
File path = fileList.get(0);
long bytes = path.length();
long kilobytes = (bytes / 1024);
info.setText("Name: " + path.getName() + "\nSize: " + kilobytes + " KB");
console.append("Name: " + path.getName() + "\nSize: " + kilobytes + " KB\n");
java.net.URL imageURL = path.toURI().toURL();
if (imageURL == null) {
System.err.println("Resource not found: " + path);
} else {
imageIcon = new ImageIcon(imageURL, "dropped");
}
if (imageIcon == null) {
System.out.println("registerDropComponent:importData: failed to load image from file");
return false;
}
imgLabel.setIcon(new ImageIcon(imageIcon.getImage()));
return true;
}
} catch (UnsupportedFlavorException ufe) {
System.out.println("registerDropComponent:importData: unsupported data flavor");
} catch (IOException ioe) {
System.out.println("registerDropComponent:importData: I/O exception");
}
}
return false;
}
});
}};
webswingApi.registerDropComponent(panel);
new JDialog() {{
setTitle("Register drop component");
setPreferredSize(new Dimension(400, 400));
setSize(new Dimension(400, 400));
setLocationRelativeTo(null);
setResizable(false);
getContentPane().add(panel);
setVisible(true);
}};
}
}
unregisterDropComponent
public void unregisterDropComponent(JComponent component);
Description:
Unregister a component as a receiver of DnD drop event from user's host system.
Parameters:
component the component to be unregistered as drop receiver
Example:
private void unregisterDropComponentExample() {
console.append("Use registerDropComponentExample example.\n");
}
registerWebComponentForDirectRendering
public void registerWebComponentForDirectRendering(JComponent webComponent);
Description:
Registers given web component to be directly rendered in its own canvas. Web components that are not directly rendered are rendered by copying parts of canvas into destination canvas. Note that for this to work you must first register a web container and webComponent must be its direct child.
Parameters:
webComponent web component to register
Example:
private void registerWebComponentForDirectRenderingExample() {
console.append("No example.\n");
}
registerWebContainer
public void registerWebContainer(Container container);
Description:
Registers given container to be a parent web container and all of its child components will be rendered into separate canvases.
Parameters:
container container to register
Example:
private void registerWebContainerExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Web container"));
panel.add(new JButton("This is a button") {{
setPreferredSize(new Dimension(250, 35));
}});
panel.add(new JLabel("This is a label") {{
setPreferredSize(new Dimension(250, 35));
}});
panel.add(new JTextField("This is a text field") {{
setPreferredSize(new Dimension(250, 35));
}});
webswingApi.registerWebContainer(panel);
new JDialog() {{
setTitle("Dialog with web container");
setSize(400, 400);
setLocationRelativeTo(null);
setResizable(false);
getContentPane().add(panel);
setVisible(true);
}};
}
}
isDockingEnabled
public boolean isDockingEnabled(Window window);
Description:
Is docking enabled for window? Docking mode in config must be enabled.
Parameters:
window window to check
Returns:
true if docking in enabled for given window
Example:
private void isDockingEnabledExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setIconImage(getToolkit().getImage(ApiDemoExamples.class.getResource("/logo.png")));
setTitle("isDockingEnabled");
setSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
JTextArea info = new JTextArea();
info.setEditable(false);
info.append("Window undocking is enabled by default\nYou can change the Docking Mode settings in the application configuration\n");
if (webswingApi.isDockingEnabled(window)) {
info.append("Docking is enabled\n");
} else {
info.append("Docking is disabled\n");
}
window.getContentPane().add(new WJPanel() {{
setBorder(new EmptyBorder(10, 10, 10, 10));
setLayout(new BorderLayout(10, 10));
add(info, BorderLayout.CENTER);
}}, BorderLayout.CENTER);
}
}
isUndocked
public boolean isUndocked(Window window);
Description:
Check whether window is in undocked state.
Parameters:
window window to check
Returns:
true if window is undocked
Example:
private void isUndockedExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setIconImage(getToolkit().getImage(ApiDemoExamples.class.getResource("/logo.png")));
setTitle("isUndocked");
setSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
if (webswingApi.isDockingEnabled(window)) {
window.setVisible(true);
JTextArea info = new JTextArea();
info.setEditable(false);
window.getContentPane().add(new WJPanel() {{
setBorder(new EmptyBorder(10, 10, 10, 10));
setLayout(new BorderLayout(10, 10));
add(info, BorderLayout.CENTER);
add(new JButton("Check isUndocked") {{
addActionListener(event -> {
info.setText("Dock/undock this window\nSee button in the right corner\nAfter performing this action, you must click the button [Check isUndocked] again\n\n");
info.append("isUndocked : " + webswingApi.isUndocked(window) + "\n");
});
setPreferredSize(new Dimension(250, 35));
}}, BorderLayout.PAGE_START);
}});
} else {
window.setVisible(false);
console.append("Window undocking is disabled\nYou can change the Docking Mode settings in the application configuration\n");
}
}
}
toggleWindowDock (1)
public void toggleWindowDock(Window window);
Description:
Toggle the dock state of a window. Window must be allowed to change the dock state according to config.
Parameters:
window window to toggle dock state
Throws:
IllegalArgumentException if isDockingEnabled(window) returns false
Example:
private void toggleWindowDockExample1() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setIconImage(getToolkit().getImage(ApiDemoExamples.class.getResource("/logo.png")));
setTitle("toggleWindowDock");
setSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
if (webswingApi.isDockingEnabled(window)) {
window.setVisible(true);
JTextArea info = new JTextArea();
info.setEditable(false);
window.getContentPane().add(new WJPanel() {{
setBorder(new EmptyBorder(10, 10, 10, 10));
setLayout(new BorderLayout(10, 10));
add(info, BorderLayout.CENTER);
info.append("Window undocking is enabled by default\nYou can change the Docking Mode settings in the application configuration\nisDockingEnabled = true\n\nAutomatically change undock/dock.");
add(new JButton("Toggle this window") {{
addActionListener(event -> webswingApi.toggleWindowDock(window));
setPreferredSize(new Dimension(250, 35));
}}, BorderLayout.PAGE_START);
}});
} else {
window.setVisible(false);
console.append("Window undocking is disabled\nYou can change the Docking Mode settings in the application configuration\n");
}
}
}
toggleWindowDock (2)
public void toggleWindowDock(Window window, boolean undocked);
Description:
Toggle the dock state of a window. Window must be allowed to change the dock state according to config.
Parameters:
undocked should the window be docked or undocked
Throws:
IllegalArgumentException if isDockingEnabled(window) returns false
Example:
private void toggleWindowDockExample2() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JCheckBox undockedCheckbox = new JCheckBox("Set Undocked:", true);
undockedCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
Object[] params = { undockedCheckbox };
int result = JOptionPane.showConfirmDialog(null, params, "Set parameter [boolean undocked]", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.OK_OPTION) {
boolean undocked = undockedCheckbox.isSelected();
JFrame window = new JFrame() {{
setIconImage(getToolkit().getImage(ApiDemoExamples.class.getResource("/logo.png")));
setTitle("toggleWindowDock");
setSize(new Dimension(750, 750));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
if (webswingApi.isDockingEnabled(window)) {
window.setVisible(true);
JTextArea info = new JTextArea();
info.setEditable(false);
window.getContentPane().add(new WJPanel() {{
setBorder(new EmptyBorder(10, 10, 10, 10));
setLayout(new BorderLayout(10, 10));
add(info, BorderLayout.CENTER);
info.append("Window undocking is enabled by default\nYou can change the Docking Mode settings in the application configuration\nisDockingEnabled = true\n\n");
if (undocked) {
info.append("Parameter undocked is true, means always undock\n");
} else {
info.append("Parameter undocked is false, means nothing to do\n");
}
add(new JButton("Toggle this window") {{
addActionListener(event -> webswingApi.toggleWindowDock(window, undocked));
setPreferredSize(new Dimension(250, 35));
}}, BorderLayout.PAGE_START);
}});
} else {
window.setVisible(false);
console.append("Window undocking is disabled\nYou can change the Docking Mode settings in the application configuration\n");
}
}
}
}
renderWindowInTab
public void renderWindowInTab(Window window, String tabId, Point position);
Description:
Render Window in provided tab. This method is useful when you opened a new Linked View and you want to move a Window to that view.
Parameters:
position optional position where to place the Window, keeps the current position if null
Example:
private void renderWindowInTabExample() {
if (renderWindowInTabExample_listener != null) {
WebswingUtil.getWebswingApi().removeLinkedViewListener(renderWindowInTabExample_listener);
}
renderWindowInTabExample_listener = new LinkedViewListener() {
@Override
public void onLinkedViewInitialized(LinkedViewEvent evt) {
if ("frame-test".equals(evt.getLinkedViewName())) {
SwingUtilities.invokeLater(() -> {
JFrame fr = new JFrame("Frame");
fr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
fr.setSize(600, 200);
fr.setLocation(100, 100);
JLabel lab = new JLabel("<html><p>This JFrame has been moved to Linked View with name '"
+ evt.getLinkedViewName() + "' and tabId '" + evt.getTabId() + "'.</p></html>");
lab.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
fr.add(lab, BorderLayout.CENTER);
fr.setVisible(true);
WebswingUtil.getWebswingApi().renderWindowInTab(fr, evt.getTabId(), null);
});
}
}
};
WebswingUtil.getWebswingApi().addLinkedViewListener(renderWindowInTabExample_listener);
JFrame window = new JFrame() {{
setTitle("renderWindowInTabExample");
setSize(new Dimension(400, 200));
setPreferredSize(new Dimension(400, 200));
setLocationRelativeTo(null);
setResizable(true);
JButton but = new JButton("Click to open a new Linked View and move a Window to it.");
but.addActionListener(e -> {
try {
String linkedViewUrl = WebswingUtil.getWebswingApi().getLinkedViewUrl() + "&linkedViewName=frame-test";
Desktop.getDesktop().browse(URI.create(linkedViewUrl));
} catch (Exception e1) {
e1.printStackTrace();
}
});
add(but, BorderLayout.CENTER);
setVisible(true);
}};
}
getLinkedViewUrl
public String getLinkedViewUrl();
Description:
Returns a full connection URL to create a new Linked View. Open this URL in browser to create a new connection to this instance. You can then render Windows in the new tab using WebswingApi.renderWindowInTab. In linkedViewListener you can listen to initialization event of the Linked View. The URL can be used multiple times.
Returns:
linked view URL
Example:
private void getLinkedViewUrlExample() {
JFrame fr = new JFrame("Frame");
fr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
fr.setSize(600, 200);
JTextArea lab = new JTextArea("1. Open the Linked View URL in a new tab.\n"
+ "2. In the new tab open javascript console and type: webswingInstance0.getWindows()[1].renderHere()\n"
+ "3. This Window should render in the new tab.");
lab.setEditable(false);
lab.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
lab.setOpaque(false);
lab.setBorder(null);
lab.setLineWrap(true);
lab.setWrapStyleWord(true);
lab.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JTextArea field = new JTextArea();
field.setText(WebswingUtil.getWebswingApi().getLinkedViewUrl());
field.setLineWrap(true);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(field);
panel.add(lab);
fr.add(panel, BorderLayout.CENTER);
fr.setLocationRelativeTo(null);
fr.setVisible(true);
field.selectAll();
field.requestFocus();
}
resetInactivityTimeout
public void resetInactivityTimeout();
Description:
Reset session timeout to prevent automatic termination. Useful if a long-running operation has to finish even if user disconnects or is inactive for longer timeframe. Note: Reset needs to be called in periods shorter than configured session timeout. ("webswing.sessionTimeoutSec" system property) Note2: This method has no effect if session timeout is set to 0
Example:
private void resetInactivityTimeoutExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
Timer timer = new Timer("ApiDemoResetInactivityTimeoutTimer", true);
JButton runButton = new JButton("Run") {{
setSize(new Dimension(150, 35));
setPreferredSize(new Dimension(150, 35));
setMinimumSize(new Dimension(150, 35));
setMaximumSize(new Dimension(150, 35));
setVisible(true);
}};
JTextArea info = new JTextArea(34, 50) {{
setEditable(false);
}};
runButton.addActionListener(e -> {
runButton.setVisible(false);
info.append("resetInactivityTimeout: started\n");
timer.scheduleAtFixedRate(new TimerTask() {
final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
int count = 0;
@Override
public void run() {
webswingApi.resetInactivityTimeout();
count++;
info.append("resetInactivityTimeout: " + sdf.format(new Date()) + " - count: " + count + "\n");
System.out.println("resetInactivityTimeout: " + sdf.format(new Date()) + " - count: " + count);
if (count == 120) {
// end after 2 minutes
timer.cancel();
info.append("resetInactivityTimeout: finished\n");
runButton.setVisible(true);
}
info.setCaretPosition(info.getDocument().getLength());
}
}, 1000, 1000); // every second
});
JDialog dialog = new JDialog() {{
setSize(new Dimension(800, 800));
setPreferredSize(new Dimension(800, 800));
setMinimumSize(new Dimension(800, 800));
setMaximumSize(new Dimension(800, 800));
setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
setResizable(false);
setLocationRelativeTo(null);
setTitle("Reset inactivity timeout dialog");
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (runButton.isVisible()) {
dispose();
} else {
int confirm = JOptionPane.showOptionDialog(null, "Are you sure to close this dialog? Timer has been aborted!", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == JOptionPane.YES_OPTION) {
timer.cancel();
dispose();
console.append("resetInactivityTimeout: timer has been aborted\n");
}
}
}
});
}};
JPanel panel = new JPanel() {{
setLayout(new BorderLayout(10, 10));
add(new WJPanel(new WBoxLayout(BoxLayout.X_AXIS)) {{
setBorder(new EmptyBorder(10, 10, 10, 10));
add(Box.createHorizontalGlue());
add(runButton);
add(Box.createHorizontalGlue());
}}, BorderLayout.PAGE_START);
add(new WJPanel(new WBoxLayout(BoxLayout.Y_AXIS)) {{
setBorder(new EmptyBorder(10, 10, 10, 10));
add(new JTextArea(10, 10) {{
setBorder(BorderFactory.createTitledBorder("Info"));
setEditable(false);
append("For this example please check:\n");
append("Admin - Applications - Webswing demo - App Config - Session Timeout - must be greater than 0\n");
append("It automatically writes time and count for every second\n");
append("When you close the browser and when you come back after one hour, the timer will be still running\n");
append("But do not open new session\n");
append("Open this link\n");
append("http://localhost:8080/webswing-demo/#Webswing+API\n");
}});
add(new JScrollPane(info) {{
setBorder(BorderFactory.createTitledBorder("Console"));
}});
add(Box.createHorizontalGlue());
}}, BorderLayout.CENTER);
}};
dialog.getContentPane().add(panel);
dialog.setVisible(true);
}
}
setInactivityTimeout
public void setInactivityTimeout(long seconds);
Description:
Overrides the default inactivity timeout value from configuration for current session only. Only takes effect if 'timeoutIfInactive' configuration option is enabled.
Parameters:
seconds new inactivity timeout in seconds
Example:
private void setInactivityTimeoutExample() {
console.append("No example.\n");
}
resolveRecordingConsent
public void resolveRecordingConsent(boolean accept);
Description:
Control the recording consent flow - accept/deny, if there is an active consent request for recording.
Parameters:
accept should the recording consent be accepted
Example:
private void resolveRecordingConsentExample() {
console.append("No example.\n");
}
resolveMirroringConsent
public void resolveMirroringConsent(boolean accept);
Description:
Control the mirroring consent flow - accept/deny, if there is an active consent request for mirroring.
Parameters:
accept should the mirroring consent be accepted
Example:
private void resolveMirroringConsentExample() {
console.append("No example.\n");
}
lockSession
public void lockSession();
Description:
Immediately locks this session. When locked user can not use this session and a lock overlay is displayed. To unlock user has to re-login.
Example:
private void lockSessionExample() {
console.append("No example.\n");
}
isSessionLocked
public boolean isSessionLocked();
Description:
Check if session is locked.
Returns:
true if this session is locked.
Example:
private void isSessionLockedExample() {
console.append("No example.\n");
}
setSetting
public void setSetting(String key, String value) throws AppSettingException;
Description:
Set a Webswing setting. The list of Webswing settings is available in Admin Console app configuration.
Parameters:
value Webswing setting value
Throws:
AppSettingException when it is not allowed to set this setting at runtime
Example:
private void setSettingExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setTitle("setSettingExample");
setSize(new Dimension(500, 200));
setPreferredSize(new Dimension(500, 200));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
JLabel label = new JLabel("");
JPanel panel = new JPanel();
JButton getButton = new JButton("get setting");
getButton.addActionListener(e -> {
String res = WebswingUtil.getWebswingApi().getSetting("webswing.test.key");
label.setText("Value of 'webswing.test.key' is: " + (res == null ? "null" : res));
});
JButton setButton = new JButton("set setting");
setButton.addActionListener(e -> {
try {
WebswingUtil.getWebswingApi().setSetting("webswing.test.key", UUID.randomUUID().toString());
} catch (AppSettingException e1) {
e1.printStackTrace();
}
label.setText("Value of 'webswing.test.key' has been set.");
});
panel.add(getButton);
panel.add(setButton);
panel.add(label);
window.getContentPane().add(panel, BorderLayout.CENTER);
}
}
getSetting
public String getSetting(String key);
Description:
Get a Webswing setting value.
Parameters:
key Webswing setting key
Returns:
value of the Webswing setting
Example:
private void getSettingExample() {
WebswingApi webswingApi = WebswingUtil.getWebswingApi();
if (webswingApi != null) {
JFrame window = new JFrame() {{
setTitle("getSettingExample");
setSize(new Dimension(500, 200));
setPreferredSize(new Dimension(500, 200));
setLocationRelativeTo(null);
setVisible(true);
setResizable(true);
}};
JLabel label = new JLabel("");
JPanel panel = new JPanel();
JButton getButton = new JButton("get setting");
getButton.addActionListener(e -> {
String res = WebswingUtil.getWebswingApi().getSetting("webswing.test.key");
label.setText("Value of 'webswing.test.key' is: " + (res == null ? "null" : res));
});
JButton setButton = new JButton("set setting");
setButton.addActionListener(e -> {
try {
WebswingUtil.getWebswingApi().setSetting("webswing.test.key", UUID.randomUUID().toString());
} catch (AppSettingException e1) {
e1.printStackTrace();
}
label.setText("Value of 'webswing.test.key' has been set.");
});
panel.add(getButton);
panel.add(setButton);
panel.add(label);
window.getContentPane().add(panel, BorderLayout.CENTER);
}
}