List of usage examples for javax.swing JLabel setText
@BeanProperty(preferred = true, visualUpdate = true, description = "Defines the single line of text this component will display.") public void setText(String text)
From source file:de.ailis.xadrian.frames.MainFrame.java
/** * Creates the status bar./*from ww w .j a va2s.c o m*/ */ private void createStatusBar() { final JLabel statusBar = this.statusBar = new JLabel(" "); statusBar.setBorder(new EmptyBorder(2, 5, 2, 5)); add(statusBar, BorderLayout.SOUTH); addWindowFocusListener(new WindowAdapter() { @Override public void windowLostFocus(final WindowEvent e) { statusBar.setText(" "); } }); }
From source file:net.daboross.outputtablesclient.gui.OutputInterface.java
@Override public void onUpdate(final RobotTable table, final String key, final String value, final UpdateAction action) { if (!application.getOutput().getNameTable().contains(table.getName())) { return;//from ww w.j a va 2s . c o m } if (action == UpdateAction.NEW) { // if (key.equalsIgnoreCase(":RangeGUI")) { // Output.oLog("Range: %s", value); // try { // application.getCustomInterface().setTo(Double.parseDouble(value)); // } catch (NumberFormatException ex) { // Output.oLog("Invalid range '%s'", value); // } // } ensureTableExists(table.getName()); JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(new LineBorder(Color.BLACK)); tableKeyAndKeyToValuePanel.get(table.getName()).put(key, panel); JLabel keyLabel = new JLabel(key); keyLabel.setBorder(new EmptyBorder(5, 5, 5, 5)); panel.add(keyLabel, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0)); JSeparator separator = new JSeparator(JSeparator.VERTICAL); separator.setPreferredSize(new Dimension(2, 20)); panel.add(separator, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0)); JLabel valueLabel = new JLabel(value); valueLabel.setBorder(new EmptyBorder(5, 5, 5, 5)); panel.add(valueLabel, new GBC().fill(GridBagConstraints.VERTICAL).gridy(0)); tableKeyAndKeyToValueLabel.get(table.getName()).put(key, valueLabel); JPanel parentPanel = tableKeyToTablePanel.get(table.getName()); parentPanel.add(panel); parentPanel.revalidate(); } else if (action == UpdateAction.UPDATE) { // if (key.equalsIgnoreCase(":RangeGUI")) { // Output.oLog("Range: %s", value); // try { // application.getCustomInterface().setTo(Double.parseDouble(value)); // } catch (NumberFormatException ex) { // Output.oLog("Invalid range '%s'", value); // } // } ensureTableExists(table.getName()); JLabel valueLabel = tableKeyAndKeyToValueLabel.get(table.getName()).get(key); valueLabel.setText(value); } else if (action == UpdateAction.DELETE) { if (tableKeyToTablePanel.get(table.getName()) == null) { return; } JPanel parentPanel = tableKeyToTablePanel.get(table.getName()); JPanel valuePanel = tableKeyAndKeyToValuePanel.get(table.getName()).remove(key); parentPanel.remove(valuePanel); parentPanel.revalidate(); } }
From source file:de.ailis.xadrian.frames.MainFrame.java
/** * Installs status handler for the specified component an all its child * components./* www. j a v a2 s. c o m*/ * * @param component * The component to install the status handler for. */ private void installStatusHandler(final JComponent component) { final JLabel statusBar = this.statusBar; final String text = component.getToolTipText(); if (text != null && !text.isEmpty()) { component.addMouseListener(new MouseAdapter() { @Override public void mouseExited(final MouseEvent e) { statusBar.setText(" "); } @Override public void mouseEntered(final MouseEvent e) { statusBar.setText(component.getToolTipText()); } }); } for (final Component child : component.getComponents()) { if (!(child instanceof JComponent)) continue; installStatusHandler((JComponent) child); } if (component instanceof JMenu) { for (final MenuElement menuElement : ((JMenu) component).getSubElements()) { if (!(menuElement instanceof JComponent)) continue; installStatusHandler((JComponent) menuElement); } } }
From source file:org.duracloud.syncui.SyncUIDriver.java
/** * Note: The embedded Jetty server setup below is based on the example configuration in the Eclipse documentation: * https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html#embedded-webapp-jsp *///from w ww. j a va 2 s .c om private static void launchServer(final String url, final CloseableHttpClient client) { try { final JDialog dialog = new JDialog(); dialog.setSize(new java.awt.Dimension(400, 75)); dialog.setModalityType(ModalityType.MODELESS); dialog.setTitle("DuraCloud Sync"); dialog.setLocationRelativeTo(null); JPanel panel = new JPanel(); final JLabel label = new JLabel("Loading..."); final JProgressBar progress = new JProgressBar(); progress.setStringPainted(true); panel.add(label); panel.add(progress); dialog.add(panel); dialog.setVisible(true); port = SyncUIConfig.getPort(); contextPath = SyncUIConfig.getContextPath(); Server srv = new Server(port); // Setup JMX MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); srv.addBean(mbContainer); ProtectionDomain protectionDomain = org.duracloud.syncui.SyncUIDriver.class.getProtectionDomain(); String warFile = protectionDomain.getCodeSource().getLocation().toExternalForm(); log.debug("warfile: {}", warFile); WebAppContext context = new WebAppContext(); context.setContextPath(contextPath); context.setWar(warFile); context.setExtractWAR(Boolean.TRUE); Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(srv); classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration"); context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$"); srv.setHandler(context); new Thread(new Runnable() { @Override public void run() { createSysTray(url, srv); while (true) { if (progress.getValue() < 100) { progress.setValue(progress.getValue() + 3); } sleep(2000); if (isAppRunning(url, client)) { break; } } progress.setValue(100); label.setText("Launching browser..."); launchBrowser(url); dialog.setVisible(false); } }).start(); srv.start(); srv.join(); } catch (Exception e) { log.error("Error launching server: " + e.getMessage(), e); } }
From source file:net.java.sip.communicator.gui.AuthenticationSplash.java
/** * * We use dynamic layout managers, so that layout is dynamic and will * adapt properly to user-customized fonts and localized text. The * GridBagLayout makes it easy to line up components of varying * sizes along invisible vertical and horizontal grid lines. It * is important to sketch the layout of the interface and decide * on the grid before writing the layout code. * * Here we actually use//from w ww.ja va 2 s .co m * our own subclass of GridBagLayout called StringGridBagLayout, * which allows us to use strings to specify constraints, rather * than having to create GridBagConstraints objects manually. * * * We use the JLabel.setLabelFor() method to connect * labels to what they are labeling. This allows mnemonics to work * and assistive to technologies used by persons with disabilities * to provide much more useful information to the user. */ private void initComponents(final Frame parent) { Container contents = getContentPane(); contents.setLayout(new BorderLayout()); String title = Utils.getProperty("net.java.sip.communicator.gui.AUTH_WIN_TITLE"); if (title == null) title = "Login Manager"; setTitle(title); setResizable(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { dialogDone(CMD_CANCEL, parent); } }); // Accessibility -- all frames, dialogs, and applets should // have a description getAccessibleContext().setAccessibleDescription("Authentication Splash"); String authPromptLabelValue = Utils.getProperty("net.java.sip.communicator.gui.AUTHENTICATION_PROMPT"); if (authPromptLabelValue == null) authPromptLabelValue = "Please register to the service or enter your credentials to log in:"; JLabel splashLabel = new JLabel(authPromptLabelValue); splashLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); splashLabel.setHorizontalAlignment(SwingConstants.CENTER); splashLabel.setHorizontalTextPosition(SwingConstants.CENTER); contents.add(splashLabel, BorderLayout.NORTH); JPanel centerPane = new JPanel(); centerPane.setLayout(new GridBagLayout()); userNameTextField = new JTextField(); // needed below // user name label JLabel userNameLabel = new JLabel(); userNameLabel.setDisplayedMnemonic('U'); // setLabelFor() allows the mnemonic to work userNameLabel.setLabelFor(userNameTextField); String userNameLabelValue = Utils.getProperty("net.java.sip.communicator.gui.USER_NAME_LABEL"); if (userNameLabelValue == null) userNameLabelValue = "Username"; int gridy = 0; userNameLabel.setText(userNameLabelValue); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = gridy; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(12, 12, 0, 0); centerPane.add(userNameLabel, c); // user name text c = new GridBagConstraints(); c.gridx = 1; c.gridy = gridy++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; c.insets = new Insets(12, 7, 0, 11); centerPane.add(userNameTextField, c); passwordTextField = new JPasswordField(); //needed below // password label JLabel passwordLabel = new JLabel(); passwordLabel.setDisplayedMnemonic('P'); passwordLabel.setLabelFor(passwordTextField); String pLabelStr = PropertiesDepot.getProperty("net.java.sip.communicator.gui.PASSWORD_LABEL"); if (pLabelStr == null) pLabelStr = "Password"; passwordLabel.setText(pLabelStr); c = new GridBagConstraints(); c.gridx = 0; c.gridy = gridy; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(11, 12, 0, 0); centerPane.add(passwordLabel, c); // password text passwordTextField.setEchoChar('\u2022'); c = new GridBagConstraints(); c.gridx = 1; c.gridy = gridy++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; c.insets = new Insets(11, 7, 0, 11); centerPane.add(passwordTextField, c); //Set a relevant realm value //Bug report by Steven Lass (sltemp at comcast.net) //JLabel realmValueLabel = new JLabel("SipPhone.com"); // needed below // realm label JLabel realmLabel = new JLabel(); realmLabel.setDisplayedMnemonic('R'); realmLabel.setLabelFor(realmValueLabel); realmLabel.setText("Realm"); realmValueLabel = new JLabel(); // Buttons along bottom of window JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, 0)); loginButton = new JButton(); loginButton.setText("Login"); loginButton.setActionCommand(CMD_LOGIN); loginButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dialogDone(event, parent); } }); buttonPanel.add(loginButton); // space buttonPanel.add(Box.createRigidArea(new Dimension(5, 0))); registerButton = new JButton(); registerButton.setMnemonic('G'); registerButton.setText("Register"); registerButton.setActionCommand(CMD_REGISTER); registerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dialogDone(event, parent); } }); buttonPanel.add(registerButton); buttonPanel.add(Box.createRigidArea(new Dimension(5, 0))); cancelButton = new JButton(); cancelButton.setText("Cancel"); cancelButton.setActionCommand(CMD_CANCEL); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dialogDone(event, parent); } }); buttonPanel.add(cancelButton); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.insets = new Insets(11, 12, 11, 11); centerPane.add(buttonPanel, c); contents.add(centerPane, BorderLayout.CENTER); getRootPane().setDefaultButton(loginButton); equalizeButtonSizes(); setFocusTraversalPolicy(new FocusTraversalPol()); }
From source file:dpcs.UninstallUserApps.java
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) public UninstallUserApps() { setResizable(false);/*from w ww . j av a2s . c o m*/ setTitle("Uninstall User Apps"); setIconImage( Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png"))); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 482, 430); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel AppStatus = new JLabel(""); AppStatus.setBounds(12, 366, 456, 17); contentPane.add(AppStatus); UserAppUninstallDone = new JLabel(""); UserAppUninstallDone.setText(""); UserAppUninstallDone.setBounds(151, 312, 186, 56); contentPane.add(UserAppUninstallDone); JLabel lblSelect = new JLabel("Select an app to remove"); lblSelect.setBounds(26, 12, 405, 17); contentPane.add(lblSelect); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(22, 41, 428, 259); contentPane.add(scrollPane); final JButton btnUninstall = new JButton("Uninstall"); btnUninstall.setToolTipText("Uninstall the selected app"); btnUninstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { UserAppUninstallDone.setText(""); if (list.getSelectedValue() == null) { JOptionPane.showMessageDialog(null, "Please select an app first"); } else { try { AppStatus.setText("Uninstalling..."); String[] commands = new String[3]; commands[0] = "adb"; commands[1] = "uninstall"; commands[2] = "" + list.getSelectedValue(); Process p1 = Runtime.getRuntime().exec(commands, null); p1.waitFor(); Process p2 = Runtime.getRuntime() .exec("adb shell pm list packages -3 > /sdcard/.userapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt"); p3.waitFor(); Process p4 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt"); p4.waitFor(); lines = IOUtils.readLines(new FileInputStream(".userapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(list); File file = new File(".userapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } AppStatus.setText("App has been uninstalled successfully"); UserAppUninstallDone .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png"))); btnUninstall.setSelected(false); } catch (Exception e1) { System.err.println(e1); } } } }); btnUninstall.setBounds(26, 327, 107, 27); contentPane.add(btnUninstall); JButton btnRefresh = new JButton("Refresh"); btnRefresh.setToolTipText("Refresh the apps list"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Process p1 = Runtime.getRuntime().exec("adb shell pm list packages -3 > /sdcard/.userapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".userapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(list); File file = new File(".userapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } } }); btnRefresh.setBounds(344, 327, 107, 27); contentPane.add(btnRefresh); try { Process p1 = Runtime.getRuntime().exec("adb shell pm list packages -3 > /sdcard/.userapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".userapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(list); File file = new File(".userapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } }
From source file:dpcs.UninstallPrivApps.java
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) public UninstallPrivApps() { setResizable(false);/*from w ww .j a v a2 s . c o m*/ setTitle("Uninstall Priv-apps"); setIconImage( Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png"))); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 482, 500); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel AppStatus = new JLabel(""); AppStatus.setBounds(8, 404, 456, 17); contentPane.add(AppStatus); PrivAppUninstallDone = new JLabel(""); PrivAppUninstallDone.setText(""); PrivAppUninstallDone.setBounds(151, 312, 186, 56); contentPane.add(PrivAppUninstallDone); JLabel lblSelect = new JLabel("Select an app to remove"); lblSelect.setBounds(25, 12, 405, 17); contentPane.add(lblSelect); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(22, 41, 428, 259); contentPane.add(scrollPane); final JButton btnUninstall = new JButton("Uninstall"); btnUninstall.setToolTipText("Uninstall the selected app"); btnUninstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PrivAppUninstallDone.setText(""); if (list.getSelectedValue() == null) { JOptionPane.showMessageDialog(null, "Please select an app first"); } else { try { AppStatus.setText("Uninstalling..."); Process p1 = Runtime.getRuntime().exec("adb remount"); p1.waitFor(); String[] commands = new String[3]; commands[0] = "adb shell su -c rm -r"; commands[1] = "/system/priv-app/"; commands[2] = " " + list.getSelectedValue(); Process p2 = Runtime.getRuntime().exec(commands, null); p2.waitFor(); Process p3 = Runtime.getRuntime() .exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt"); p3.waitFor(); Process p4 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt"); p4.waitFor(); Process p5 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt"); p5.waitFor(); lines = IOUtils.readLines(new FileInputStream(".privapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); File file = new File(".privapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } AppStatus.setText("App has been uninstalled successfully"); PrivAppUninstallDone .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png"))); btnUninstall.setSelected(false); } catch (Exception e1) { System.err.println(e1); } } } }); btnUninstall.setBounds(26, 327, 107, 27); contentPane.add(btnUninstall); JButton btnRefresh = new JButton("Refresh"); btnRefresh.setToolTipText("Refresh the apps list"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Process p1 = Runtime.getRuntime() .exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".privapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); File file = new File(".privapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } } }); btnRefresh.setBounds(344, 327, 107, 27); contentPane.add(btnRefresh); try { Process p1 = Runtime.getRuntime().exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".privapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); JLabel lblNewLabel = new JLabel("Note: You should also remove app's odex file if it exits "); lblNewLabel.setBounds(25, 374, 438, 17); contentPane.add(lblNewLabel); JLabel lblNeedsRootAnd = new JLabel("Needs root and does not work on production android builds!"); lblNeedsRootAnd.setBounds(25, 426, 454, 17); contentPane.add(lblNeedsRootAnd); JLabel lblOnlyForAndroid = new JLabel("Uninstallation only for android 4.4.x and higher!"); lblOnlyForAndroid.setBounds(8, 452, 450, 15); contentPane.add(lblOnlyForAndroid); File file = new File(".privapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e) { System.err.println(e); } }
From source file:be.agiv.security.demo.Main.java
private void invokeClaimsAwareService() { GridBagLayout gridBagLayout = new GridBagLayout(); GridBagConstraints gridBagConstraints = new GridBagConstraints(); JPanel contentPanel = new JPanel(gridBagLayout); final JLabel ipStsLabel = new JLabel("IP-STS:"); gridBagConstraints.gridx = 0;//from ww w . j a v a 2s . c o m gridBagConstraints.gridy = 0; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.ipadx = 5; gridBagLayout.setConstraints(ipStsLabel, gridBagConstraints); contentPanel.add(ipStsLabel); final JTextField ipStsTextField = new JTextField( "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13", 60); gridBagConstraints.gridx++; gridBagLayout.setConstraints(ipStsTextField, gridBagConstraints); contentPanel.add(ipStsTextField); JLabel realmLabel = new JLabel("Realm:"); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagLayout.setConstraints(realmLabel, gridBagConstraints); contentPanel.add(realmLabel); JTextField realmTextField = new JTextField(AGIVSecurity.BETA_REALM, 30); gridBagConstraints.gridx++; gridBagLayout.setConstraints(realmTextField, gridBagConstraints); contentPanel.add(realmTextField); final CredentialPanel credentialPanel = new CredentialPanel(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(credentialPanel, gridBagConstraints); contentPanel.add(credentialPanel); final JLabel rStsLabel = new JLabel("R-STS:"); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = 1; gridBagLayout.setConstraints(rStsLabel, gridBagConstraints); contentPanel.add(rStsLabel); final JTextField rStsTextField = new JTextField( "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13", 60); gridBagConstraints.gridx++; gridBagLayout.setConstraints(rStsTextField, gridBagConstraints); contentPanel.add(rStsTextField); JLabel serviceRealmLabel = new JLabel("Service realm:"); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagLayout.setConstraints(serviceRealmLabel, gridBagConstraints); contentPanel.add(serviceRealmLabel); JTextField serviceRealmTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_REALM, 60); gridBagConstraints.gridx++; gridBagLayout.setConstraints(serviceRealmTextField, gridBagConstraints); contentPanel.add(serviceRealmTextField); JLabel urlLabel = new JLabel("Service URL:"); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagLayout.setConstraints(urlLabel, gridBagConstraints); contentPanel.add(urlLabel); JTextField urlTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_LOCATION, 60); gridBagConstraints.gridx++; gridBagLayout.setConstraints(urlTextField, gridBagConstraints); contentPanel.add(urlTextField); final JCheckBox noWsPolicyCheckBox = new JCheckBox("WSDL without WS-Policy"); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(noWsPolicyCheckBox, gridBagConstraints); contentPanel.add(noWsPolicyCheckBox); final JCheckBox useWsSecureConversationCheckBox = new JCheckBox("Use WS-SecureConversation"); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(useWsSecureConversationCheckBox, gridBagConstraints); contentPanel.add(useWsSecureConversationCheckBox); final JCheckBox usePreviousSecurityCheckBox = new JCheckBox("Use previous AGIV Security"); final JCheckBox cancelPreviousSecureConversationToken = new JCheckBox("Cancel previous conversation token"); usePreviousSecurityCheckBox.setEnabled(null != this.agivSecurity); cancelPreviousSecureConversationToken.setEnabled(false); usePreviousSecurityCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { LOG.debug("use previous security: " + usePreviousSecurityCheckBox.isSelected()); boolean newSecurity = !usePreviousSecurityCheckBox.isSelected(); ipStsLabel.setEnabled(newSecurity); ipStsTextField.setEditable(newSecurity); credentialPanel.setEnabled(newSecurity); rStsLabel.setEnabled(newSecurity); rStsTextField.setEnabled(newSecurity); cancelPreviousSecureConversationToken.setEnabled(!newSecurity); } }); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(usePreviousSecurityCheckBox, gridBagConstraints); contentPanel.add(usePreviousSecurityCheckBox); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(cancelPreviousSecureConversationToken, gridBagConstraints); contentPanel.add(cancelPreviousSecureConversationToken); JPanel expiresPanel = new JPanel(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = 2; gridBagLayout.setConstraints(expiresPanel, gridBagConstraints); contentPanel.add(expiresPanel); JLabel expiresLabelLabel = new JLabel("Secure conversation token expires:"); expiresLabelLabel.setEnabled(null != this.agivSecurity); expiresPanel.add(expiresLabelLabel); JLabel expiresLabel = new JLabel(); expiresLabel.setEnabled(null != this.agivSecurity); expiresPanel.add(expiresLabel); if (null != this.agivSecurity) { if (false == this.agivSecurity.getSecureConversationTokens().isEmpty()) { SecurityToken secureConversationToken = this.agivSecurity.getSecureConversationTokens().values() .iterator().next(); expiresLabel.setText(secureConversationToken.getExpires().toString()); } } int dialogResult = JOptionPane.showConfirmDialog(this, contentPanel, "Claims Aware Service", JOptionPane.OK_CANCEL_OPTION); if (dialogResult == JOptionPane.CANCEL_OPTION) { return; } final String location = urlTextField.getText(); final String serviceRealm = serviceRealmTextField.getText(); final String ipStsLocation = ipStsTextField.getText(); final String rStsLocation = rStsTextField.getText(); final String username = credentialPanel.getUsername(); final String password = credentialPanel.getPassword(); final File pkcs12File = credentialPanel.getPKCS12File(); final String realm = realmTextField.getText(); ExecutorService executor = Executors.newFixedThreadPool(1); FutureTask<ArrayOfClaimInfo> futureTask = new FutureTask<ArrayOfClaimInfo>( new Callable<ArrayOfClaimInfo>() { public ArrayOfClaimInfo call() throws Exception { Service service; if (noWsPolicyCheckBox.isSelected()) { service = ClaimsAwareServiceFactory.getInstanceNoWSPolicy(); } else { service = ClaimsAwareServiceFactory.getInstance(); } IService iservice = service.getWS2007FederationHttpBindingIService(new AddressingFeature()); BindingProvider bindingProvider = (BindingProvider) iservice; if (false == usePreviousSecurityCheckBox.isSelected()) { if (null != username) { Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm, username, password); } else { Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm, pkcs12File, password); } Main.this.agivSecurity.addSTSListener(Main.this); if (Main.this.proxyEnable) { agivSecurity.setProxy(Main.this.proxyHost, Main.this.proxyPort, Main.this.proxyType); } } if (cancelPreviousSecureConversationToken.isSelected()) { Main.this.agivSecurity.cancelSecureConversationTokens(); } Main.this.agivSecurity.enable(bindingProvider, location, useWsSecureConversationCheckBox.isSelected(), serviceRealm); ArrayOfClaimInfo result = iservice.getData(0); return result; } }) { @Override protected void done() { try { ArrayOfClaimInfo result = get(); List<ClaimInfo> claims = result.getClaimInfo(); StringBuffer message = new StringBuffer(); for (ClaimInfo claim : claims) { message.append(claim.getName()); message.append(" = "); message.append(claim.getValue()); message.append("\n"); } JOptionPane.showMessageDialog(Main.this, message.toString(), "Claims Aware Service Result", JOptionPane.INFORMATION_MESSAGE); } catch (final Exception e) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { Main.this.statusBar.setErrorStatus(e.getMessage()); } }); } catch (Exception e1) { } showException(e); } } }; executor.execute(futureTask); }
From source file:com.tascape.qa.th.android.driver.App.java
/** * The method starts a GUI to let an user inspect element tree and take screenshot when the user is interacting * with the app-under-test manually. Please make sure to set timeout long enough for manual interaction. * * @param timeoutMinutes timeout in minutes to fail the manual steps * * @throws Exception if case of error/*from w w w. jav a 2 s . c o m*/ */ public void interactManually(int timeoutMinutes) throws Exception { LOG.info("Start manual UI interaction"); long end = System.currentTimeMillis() + timeoutMinutes * 60000L; AtomicBoolean visible = new AtomicBoolean(true); AtomicBoolean pass = new AtomicBoolean(false); String tName = Thread.currentThread().getName() + "m"; SwingUtilities.invokeLater(() -> { JDialog jd = new JDialog((JFrame) null, "Manual Device UI Interaction - " + device.getProductDetail()); jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); JPanel jpContent = new JPanel(new BorderLayout()); jd.setContentPane(jpContent); jpContent.setPreferredSize(new Dimension(1088, 828)); jpContent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel jpInfo = new JPanel(); jpContent.add(jpInfo, BorderLayout.PAGE_START); jpInfo.setLayout(new BorderLayout()); { JButton jb = new JButton("PASS"); jb.setForeground(Color.green.darker()); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_START); jb.addActionListener(event -> { pass.set(true); jd.dispose(); visible.set(false); }); } { JButton jb = new JButton("FAIL"); jb.setForeground(Color.red); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_END); jb.addActionListener(event -> { pass.set(false); jd.dispose(); visible.set(false); }); } JLabel jlTimeout = new JLabel("xxx seconds left", SwingConstants.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); new SwingWorker<Long, Long>() { @Override protected Long doInBackground() throws Exception { while (System.currentTimeMillis() < end) { Thread.sleep(1000); long left = (end - System.currentTimeMillis()) / 1000; this.publish(left); } return 0L; } @Override protected void process(List<Long> chunks) { Long l = chunks.get(chunks.size() - 1); jlTimeout.setText(l + " seconds left"); if (l < 850) { jlTimeout.setForeground(Color.red); } } }.execute(); JPanel jpResponse = new JPanel(new BorderLayout()); JPanel jpProgress = new JPanel(new BorderLayout()); jpResponse.add(jpProgress, BorderLayout.PAGE_START); JTextArea jtaJson = new JTextArea(); jtaJson.setEditable(false); jtaJson.setTabSize(4); Font font = jtaJson.getFont(); jtaJson.setFont(new Font("Courier New", font.getStyle(), font.getSize())); JTree jtView = new JTree(); JTabbedPane jtp = new JTabbedPane(); jtp.add("tree", new JScrollPane(jtView)); jtp.add("json", new JScrollPane(jtaJson)); jpResponse.add(jtp, BorderLayout.CENTER); JPanel jpScreen = new JPanel(); jpScreen.setMinimumSize(new Dimension(200, 200)); jpScreen.setLayout(new BoxLayout(jpScreen, BoxLayout.PAGE_AXIS)); JScrollPane jsp1 = new JScrollPane(jpScreen); jpResponse.add(jsp1, BorderLayout.LINE_START); JPanel jpJs = new JPanel(new BorderLayout()); JTextArea jtaJs = new JTextArea(); jpJs.add(new JScrollPane(jtaJs), BorderLayout.CENTER); JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jpResponse, jpJs); jSplitPane.setResizeWeight(0.88); jpContent.add(jSplitPane, BorderLayout.CENTER); JPanel jpLog = new JPanel(); jpLog.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); jpLog.setLayout(new BoxLayout(jpLog, BoxLayout.LINE_AXIS)); JCheckBox jcbTap = new JCheckBox("Enable Click", null, false); jpLog.add(jcbTap); jpLog.add(Box.createHorizontalStrut(8)); JButton jbLogUi = new JButton("Log Screen"); jpResponse.add(jpLog, BorderLayout.PAGE_END); { jpLog.add(jbLogUi); jbLogUi.addActionListener((ActionEvent event) -> { jtaJson.setText("waiting for screenshot..."); Thread t = new Thread(tName) { @Override public void run() { LOG.debug("\n\n"); try { WindowHierarchy wh = device.loadWindowHierarchy(); jtView.setModel(getModel(wh)); jtaJson.setText(""); jtaJson.append(wh.root.toJson().toString(2)); jtaJson.append("\n"); File png = device.takeDeviceScreenshot(); BufferedImage image = ImageIO.read(png); int w = device.getDisplayWidth(); int h = device.getDisplayHeight(); BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = resizedImg.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(image, 0, 0, w, h, null); g2.dispose(); JLabel jLabel = new JLabel(new ImageIcon(resizedImg)); jpScreen.removeAll(); jsp1.setPreferredSize(new Dimension(w + 30, h)); jpScreen.add(jLabel); jLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { LOG.debug("clicked at {},{}", e.getPoint().getX(), e.getPoint().getY()); if (jcbTap.isSelected()) { device.click(e.getPoint().x, e.getPoint().y); device.waitForIdle(); jbLogUi.doClick(); } } }); } catch (Exception ex) { LOG.error("Cannot log screen", ex); jtaJson.append("Cannot log screen"); } jtaJson.append("\n\n\n"); LOG.debug("\n\n"); jd.setSize(jd.getBounds().width + 1, jd.getBounds().height + 1); jd.setSize(jd.getBounds().width - 1, jd.getBounds().height - 1); } }; t.start(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbLogMsg = new JButton("Log Message"); jpLog.add(jbLogMsg); JTextField jtMsg = new JTextField(10); jpLog.add(jtMsg); jtMsg.addFocusListener(new FocusListener() { @Override public void focusLost(final FocusEvent pE) { } @Override public void focusGained(final FocusEvent pE) { jtMsg.selectAll(); } }); jtMsg.addKeyListener(new KeyAdapter() { @Override public void keyPressed(java.awt.event.KeyEvent e) { if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) { jbLogMsg.doClick(); } } }); jbLogMsg.addActionListener(event -> { Thread t = new Thread(tName) { @Override public void run() { String msg = jtMsg.getText(); if (StringUtils.isNotBlank(msg)) { LOG.info("{}", msg); jtMsg.selectAll(); } } }; t.start(); try { t.join(); } catch (InterruptedException ex) { LOG.error("Cannot take screenshot", ex); } jtMsg.requestFocus(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbClear = new JButton("Clear"); jpLog.add(jbClear); jbClear.addActionListener(event -> { jtaJson.setText(""); }); } JPanel jpAction = new JPanel(); jpContent.add(jpAction, BorderLayout.PAGE_END); jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS)); jpJs.add(jpAction, BorderLayout.PAGE_END); jd.pack(); jd.setVisible(true); jd.setLocationRelativeTo(null); jbLogUi.doClick(); }); while (visible.get()) { if (System.currentTimeMillis() > end) { LOG.error("Manual UI interaction timeout"); break; } Thread.sleep(500); } if (pass.get()) { LOG.info("Manual UI Interaction returns PASS"); } else { Assert.fail("Manual UI Interaction returns FAIL"); } }
From source file:edu.harvard.i2b2.query.ui.TopPanel.java
public void addPanel() { int rightmostPosition = dataModel.lastLabelPosition(); JLabel label = new JLabel(); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setText("and"); label.setToolTipText("Click to change the relationship"); label.setBorder(javax.swing.BorderFactory.createEtchedBorder()); label.addMouseListener(new java.awt.event.MouseAdapter() { @Override//w w w . ja v a 2 s . co m public void mouseClicked(java.awt.event.MouseEvent evt) { jAndOrLabelMouseClicked(evt); } }); // jPanel1.add(label); // label.setBounds(rightmostPosition, 90, 30, 18); ConceptTreePanel panel = new ConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1), this); jPanel1.add(panel); panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100); jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181 + 60, getHeight() - 100)); jScrollPane4.setViewportView(jPanel1); dataModel.addPanel(panel, label, rightmostPosition + 5 + 180); jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum()); jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40); resizePanels(getParent().getWidth(), getParent().getHeight()); }