List of usage examples for javax.swing JLabel addMouseListener
public synchronized void addMouseListener(MouseListener l)
From source file:utybo.easypastebin.windows.MainWindow.java
/** * Creates the window/*from ww w . j a v a2 s . com*/ */ @SuppressWarnings({ "rawtypes", "unchecked" }) public MainWindow() { EasyPastebin.LOGGER.log("Initializing the window", SinkJLevel.INFO); setTitle("EasyPastebin"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 664, 431); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); contentPane.add(tabbedPane, BorderLayout.CENTER); JPanel main = new JPanel(); tabbedPane.addTab("EasyPastebin", null, main, null); main.setLayout(null); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(62, 39, 312, 132); main.add(scrollPane); pasteContent = new JTextArea(); pasteContent.setFont(new Font("Monospaced", Font.PLAIN, 11)); pasteContent.setWrapStyleWord(true); pasteContent.setLineWrap(true); pasteContent.setToolTipText("Put your paste here!"); scrollPane.setViewportView(pasteContent); JLabel titleLabel = new JLabel("Title :"); titleLabel.setFont(new Font("Tahoma", Font.PLAIN, 12)); titleLabel.setBounds(10, 11, 42, 21); main.add(titleLabel); pasteTitle = new JTextField(); pasteTitle.setBounds(62, 12, 312, 20); main.add(pasteTitle); pasteTitle.setColumns(10); JLabel lblPaste = new JLabel("Paste :"); lblPaste.setForeground(Color.RED); lblPaste.setFont(new Font("Tahoma", Font.PLAIN, 12)); lblPaste.setBounds(10, 85, 53, 21); main.add(lblPaste); pasteExpireDate = new JComboBox(); pasteExpireDate.setFont(new Font("Tahoma", Font.PLAIN, 12)); pasteExpireDate.setModel(new DefaultComboBoxModel(EnumExpireDate.values())); pasteExpireDate.setBounds(468, 12, 155, 21); main.add(pasteExpireDate); JLabel lblExpireDate = new JLabel("Expire Date :"); lblExpireDate.setFont(new Font("Tahoma", Font.PLAIN, 12)); lblExpireDate.setBounds(384, 14, 81, 14); main.add(lblExpireDate); JLabel lblfieldsInRed = new JLabel("(Fields in red are required)"); lblfieldsInRed.setBounds(72, 182, 302, 14); main.add(lblfieldsInRed); btnSubmit = new JButton("Submit!"); btnSubmit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { EasyPastebin.LOGGER.log("Starting Submit script", SinkJLevel.INFO); btnSubmit.setEnabled(false); btnSubmit.setText("Please wait..."); boolean success = true; String paste = pasteContent.getText(); String title = pasteTitle.getText(); EnumExpireDate expireDate = (EnumExpireDate) pasteExpireDate.getSelectedItem(); if (paste.equals("") || paste.equals(" ") || paste.equals(null)) { pastebinUrl.setText("ERROR"); JOptionPane.showMessageDialog(null, "You cannot send empty pastes!", "Error while processing paste", JOptionPane.ERROR_MESSAGE); } else { try { EasyPastebin.LOGGER.log("Setting options", SinkJLevel.INFO); Map map = new HashMap<String, String>(); map.put("api_dev_key", HttpHelper.API_KEY); map.put("api_option", "paste"); map.put("api_paste_code", paste); if (!(expireDate.equals(null) || expireDate.equals(EnumExpireDate.NEVER))) map.put("api_paste_expire_date", expireDate.getRawName()); if (!(title.equals("") || title.equals(" ") || title.equals(null))) map.put("api_paste_name", title); EasyPastebin.LOGGER.log("Sending paste", SinkJLevel.INFO); String actionResult = HttpHelper.sendPost("http://pastebin.com/api/api_post.php", map) .asString(); EasyPastebin.LOGGER.log("Paste sent, checking output", SinkJLevel.INFO); // Exception handlers if (actionResult.equals("Bad API request, invalid api_option")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Incorrect Pastebin option!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_dev_key")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Incorrect dev key! Try again with a more recent version!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, IP blocked")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Your IP is blocked!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals( "Bad API request, maximum number of 25 unlisted pastes for your free account")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); } if (actionResult.equals( "Bad API request, maximum number of 10 private pastes for your free account")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); } if (actionResult.equals("Bad API request, api_paste_code was empty")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); } if (actionResult.equals("Bad API request, maximum paste file size exceeded")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Your paste is too big!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_expire_date")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Invalid expire date!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_paste_private")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Invalid privacy value!", "Error", JOptionPane.ERROR_MESSAGE); } if (actionResult.equals("Bad API request, invalid api_paste_format")) { success = false; EasyPastebin.LOGGER.log( "The output is an error message : " + actionResult + ". Submit script failed!", SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste. Invalid format!", "Error", JOptionPane.ERROR_MESSAGE); } // END // Starting display stuff if (success == false) { EasyPastebin.LOGGER.log("Submit script failed : success == false", SinkJLevel.ERROR); pastebinUrl.setText("ERROR"); } if (success == true) { EasyPastebin.LOGGER.log("Paste sent! Starting display script!", SinkJLevel.INFO); pastebinUrl.setText(actionResult); JOptionPane.showMessageDialog(null, "Paste successfully sent!", "Done!", JOptionPane.INFORMATION_MESSAGE); EasyPastebin.LOGGER.log("Display script finished! Paste URL is : " + actionResult, SinkJLevel.INFO); } } catch (ClientProtocolException e) { EasyPastebin.LOGGER.log("Unexpected error! " + e, SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste : " + e, "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } catch (IOException e) { EasyPastebin.LOGGER.log("Unexpected error! " + e, SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste : " + e, "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } catch (MissingParamException e) { EasyPastebin.LOGGER.log("Unexpected error! " + e, SinkJLevel.ERROR); JOptionPane.showMessageDialog(null, "Error while processing paste : " + e + "! This is a severe programming error! Try again with a more recent version!", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } EasyPastebin.LOGGER.log("Re-enabling the Submit button ", SinkJLevel.INFO); btnSubmit.setEnabled(true); btnSubmit.setText("Submit another paste!"); EasyPastebin.LOGGER.log("Finished submit script! Success : " + success, SinkJLevel.INFO); } }); btnSubmit.setBounds(386, 45, 237, 44); main.add(btnSubmit); pastebinUrl = new JTextField(); pastebinUrl.setText("The paste's URL will be shown here!"); pastebinUrl.setEditable(false); pastebinUrl.setBounds(384, 198, 239, 32); main.add(pastebinUrl); pastebinUrl.setColumns(10); JPanel about = new JPanel(); tabbedPane.addTab("About", null, about, null); JLabel label = new JLabel("EasyPastebin"); label.setBounds(12, 12, 623, 39); label.setHorizontalAlignment(SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.PLAIN, 25)); JLabel lblTheEasiestWay = new JLabel("The easiest way to use Pastebin.com"); lblTheEasiestWay.setBounds(12, 63, 623, 32); lblTheEasiestWay.setFont(new Font("Dialog", Font.PLAIN, 16)); lblTheEasiestWay.setHorizontalAlignment(SwingConstants.CENTER); about.setLayout(null); about.add(label); about.add(lblTheEasiestWay); JButton btnForkM = new JButton("Fork me on Github!"); btnForkM.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { goToUrl("https://github.com/utybo/EasyPastebin"); } }); btnForkM.setBounds(12, 117, 623, 25); about.add(btnForkM); JButton btnCheckOutUtybos = new JButton("Check out utybo's projects!"); btnCheckOutUtybos.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { goToUrl("http://utybo.github.io/"); } }); btnCheckOutUtybos.setBounds(12, 154, 623, 25); about.add(btnCheckOutUtybos); JButton btnGoToPastebincom = new JButton("Go to Pastebin.com!"); btnGoToPastebincom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { goToUrl("http://www.pastebin.com"); } }); btnGoToPastebincom.setBounds(12, 191, 623, 25); about.add(btnGoToPastebincom); JLabel lblcUtybo = new JLabel( "This soft was made by utybo. It uses Apache's libraries for the interaction with Pastebin's API"); lblcUtybo.setFont(new Font("Dialog", Font.PLAIN, 10)); lblcUtybo.setHorizontalAlignment(SwingConstants.CENTER); lblcUtybo.setBounds(12, 324, 623, 15); about.add(lblcUtybo); JLabel lblClickMeTo = new JLabel("Click me to go to Apache's licence official website"); lblClickMeTo.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { goToUrl("http://www.apache.org/licenses/LICENSE-2.0"); } }); lblClickMeTo.setHorizontalAlignment(SwingConstants.CENTER); lblClickMeTo.setFont(new Font("Dialog", Font.PLAIN, 10)); lblClickMeTo.setBounds(12, 342, 623, 15); about.add(lblClickMeTo); setVisible(true); EasyPastebin.LOGGER.log("Done!", SinkJLevel.INFO); }
From source file:aurelienribon.gdxsetupui.ui.MainPanel.java
private void initUI() { startSetupBtn.addActionListener(new ActionListener() { @Override/*from ww w .j av a2s . c om*/ public void actionPerformed(ActionEvent e) { showSetupView(); } }); startUpdateBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showUpdateView(); } }); changeModeBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showInitView(); } }); JLabel aboutLabel = new JLabel("About this app >"); Style.registerCssClasses(aboutLabel, ".linkLabel"); aboutLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); versionLabel.setLayout(new BorderLayout()); versionLabel.add(aboutLabel, BorderLayout.EAST); aboutLabel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { showAboutPanel(); } }); }
From source file:Installer.java
public static JLabel linkify(final String text, String URL, String toolTip) { URI temp = null;/*from w ww .j ava2s . c o m*/ try { temp = new URI(URL); } catch (Exception e) { e.printStackTrace(); } final URI uri = temp; final JLabel link = new JLabel(); link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); if (!toolTip.equals("")) link.setToolTipText(toolTip); link.setCursor(new Cursor(Cursor.HAND_CURSOR)); link.addMouseListener(new MouseListener() { public void mouseExited(MouseEvent arg0) { link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); } public void mouseEntered(MouseEvent arg0) { link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); } public void mouseClicked(MouseEvent arg0) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(uri); } catch (Exception e) { e.printStackTrace(); } } else { JOptionPane pane = new JOptionPane("Could not open link."); JDialog dialog = pane.createDialog(new JFrame(), ""); dialog.setVisible(true); } } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); return link; }
From source file:com.sshtools.common.ui.SshToolsApplication.java
/** * Show an 'About' dialog/*from w w w . j ava2s . c om*/ * * */ public void showAbout(final Component parent) { JPanel p = new JPanel(new GridBagLayout()); p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); GridBagConstraints gBC = new GridBagConstraints(); gBC.anchor = GridBagConstraints.CENTER; gBC.fill = GridBagConstraints.HORIZONTAL; gBC.insets = new Insets(1, 1, 1, 1); JLabel a = new JLabel(getApplicationName()); a.setFont(a.getFont().deriveFont(24f)); UIUtil.jGridBagAdd(p, a, gBC, GridBagConstraints.REMAINDER); MultilineLabel v = new MultilineLabel(getApplicationName() + " " + getApplicationVersion()); v.setFont(v.getFont().deriveFont(10f)); UIUtil.jGridBagAdd(p, v, gBC, GridBagConstraints.REMAINDER); MultilineLabel x = new MultilineLabel(getAboutAuthors()); x.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0)); x.setFont(x.getFont().deriveFont(12f)); UIUtil.jGridBagAdd(p, x, gBC, GridBagConstraints.REMAINDER); MultilineLabel c = new MultilineLabel(getAboutLicenseDetails()); c.setFont(c.getFont().deriveFont(10f)); UIUtil.jGridBagAdd(p, c, gBC, GridBagConstraints.REMAINDER); final JLabel h = new JLabel(getAboutURL()); h.setForeground(Color.blue); h.setFont(new Font(h.getFont().getName(), Font.BOLD, 10)); h.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); h.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { BrowserLauncher.openURL(getAboutURL()); } catch (IOException ioe) { ioe.printStackTrace(); } } }); UIUtil.jGridBagAdd(p, h, gBC, GridBagConstraints.REMAINDER); JOptionPane.showMessageDialog(parent, p, "About", JOptionPane.PLAIN_MESSAGE, getApplicationLargeIcon()); }
From source file:org.pf.midea.MainUI.java
private void menuItemAboutActionPerformed(ActionEvent e) { JFrame about = new JFrame(" "); about.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel nestedPanel = new JPanel(); nestedPanel.setLayout(new GridLayout(17, 1)); nestedPanel/*from ww w.j a v a 2 s. co m*/ .add(new JLabel("? ? ?")); nestedPanel.add(new JLabel("? ?")); nestedPanel.add(new JLabel(" ?")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel(" . . ?, 20072013")); nestedPanel.add(new JLabel(" ? ? ")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel(" ???")); nestedPanel.add(new JLabel( " ? ? 4.2.")); nestedPanel.add(new JLabel( " ? ??")); nestedPanel.add(new JLabel(" COPYING (??? ).")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel( "? ? ?? ?:")); JLabel labelMail = new JLabel( "<html><a href=\"mailto:oleksandr@natalenko.name\">oleksandr@natalenko.name</a></html>"); labelMail.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop() .mail(new URI("mailto:oleksandr@natalenko.name?subject=" + URLEncoder.encode( "? ? ?", "UTF-8"))); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } } }); nestedPanel.add(labelMail); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel("-? :")); JLabel labelURL = new JLabel("<html><a href=\"http://natalenko.name/\">http://natalenko.name/</a></html>"); labelURL.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI("http://natalenko.name/")); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } } }); nestedPanel.add(labelURL); about.add(nestedPanel); about.pack(); about.setLocationRelativeTo(null); about.setVisible(true); }
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 www . j a v a2s. 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:net.sf.dsig.DSApplet.java
private void initSwing() { try {//from w ww . ja va 2s . c om UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { logger.warn("UIManager.setLookAndFeel() failed", e); } JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); panel.setBackground(Color.decode(backgroundColor)); add(panel); boolean lockPrinted = false; if (formId != null) { Icon lockIcon = new ImageIcon(getClass().getResource("/icons/lock.png")); lockPrinted = true; JButton button = new JButton("Sign", lockIcon); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { available.acquireUninterruptibly(); try { signInternal(formId, null); } catch (Exception ex) { logger.error("Internal sign failed", e); } finally { available.release(); } } }); panel.add(button); } Icon infoIcon = new ImageIcon(getClass().getResource(lockPrinted ? "/icons/info.png" : "/icons/lock.png")); JLabel infoLabel = new JLabel(infoIcon); infoLabel.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { JOptionPane.showMessageDialog(null, printInfoMessage()); } public void mouseEntered(MouseEvent e) { /* NOOP */ } public void mouseExited(MouseEvent e) { /* NOOP */ } public void mousePressed(MouseEvent e) { /* NOOP */ } public void mouseReleased(MouseEvent e) { /* NOOP */ } }); panel.add(infoLabel); }
From source file:edu.harvard.i2b2.query.QueryTopPanel.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() { public void mouseClicked(java.awt.event.MouseEvent evt) { jAndOrLabelMouseClicked(evt); }//from w w w .j a va 2 s.co m }); //jPanel1.add(label); //label.setBounds(rightmostPosition, 90, 30, 18); QueryConceptTreePanel panel = new QueryConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1), this); jPanel1.add(panel); panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100); jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181, 150)); jScrollPane4.setViewportView(jPanel1); dataModel.addPanel(panel, null, rightmostPosition + 5 + 180); jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum()); jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40); }
From source file:edu.harvard.i2b2.query.QueryTopPanel.java
private void jMorePanelsButtonActionPerformed(java.awt.event.ActionEvent evt) { if (dataModel.hasEmptyPanels()) { JOptionPane.showMessageDialog(this, "Please use an existing empty panel before adding a new one."); return;// ww w. java2s. c o m } 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() { public void mouseClicked(java.awt.event.MouseEvent evt) { jAndOrLabelMouseClicked(evt); } }); //jPanel1.add(label); //label.setBounds(rightmostPosition, 90, 30, 18); QueryConceptTreePanel panel = new QueryConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1), this); jPanel1.add(panel); panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100); jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181, getHeight() - 100)); jScrollPane4.setViewportView(jPanel1); dataModel.addPanel(panel, label, rightmostPosition + 5 + 180); /*System.out.println(jScrollPane4.getViewport().getExtentSize().width+":"+ jScrollPane4.getViewport().getExtentSize().height); System.out.println(jScrollPane4.getHorizontalScrollBar().getVisibleRect().width+":" +jScrollPane4.getHorizontalScrollBar().getVisibleRect().height); System.out.println(jScrollPane4.getHorizontalScrollBar().getVisibleAmount()); System.out.println(jScrollPane4.getHorizontalScrollBar().getValue());*/ jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum()); jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40); //this.jScrollPane4.removeAll(); //this.jScrollPane4.setViewportView(jPanel1); //revalidate(); //jScrollPane3.setBounds(420, 0, 170, 300); //jScrollPane4.setBounds(20, 35, 335, 220); resizePanels(getParent().getWidth(), getParent().getHeight()); }
From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java
private RestoreFileWindow(final PReg registry) { super();//from w w w . j a v a2 s .c o m setLayout(null); final JTextField searchField = new JTextField(); searchField.setLayout(null); searchField.setBounds(2, 2, 301, 26); searchField.setBorder(new LineBorder(Color.lightGray)); searchField.setFont(Constants.FONT); add(searchField); final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>" + "<font color=\"gray\">If you think there is a problem with the<br>" + "backup system, please create an issue here:<br>" + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>"); noBackupFilesLabel.setLayout(null); noBackupFilesLabel.setBounds(20, 50, 300, 300); noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f)); noBackupFilesLabel.addMouseListener((OnMouseClick) e -> { String urlPath = "https://github.com/com.edduarte/protbox/issues"; try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI(urlPath)); } else { if (SystemUtils.IS_OS_WINDOWS) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath); } else { java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari", "mozilla", "chrome"); for (String browser : browsers) { if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) { Runtime.getRuntime().exec(new String[] { browser, urlPath }); break; } } } } } catch (Exception ex) { ex.printStackTrace(); } }); DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree(); final JTree tree = new JTree(rootTreeNode); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); if (rootTreeNode.getChildCount() == 0) { searchField.setEnabled(false); add(noBackupFilesLabel); } expandTree(tree); tree.setLayout(null); tree.setRootVisible(false); tree.setEditable(false); tree.setCellRenderer(new SearchableTreeCellRenderer(searchField)); searchField.addKeyListener((OnKeyReleased) e -> { // update and expand tree DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.nodeStructureChanged((TreeNode) model.getRoot()); expandTree(tree); }); final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setBorder(new DropShadowBorder()); scroll.setBorder(new LineBorder(Color.lightGray)); scroll.setBounds(2, 30, 334, 360); add(scroll); JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png"))); close.setLayout(null); close.setBounds(312, 7, 18, 18); close.setFont(Constants.FONT); close.setForeground(Color.gray); close.addMouseListener((OnMouseClick) e -> dispose()); add(close); final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png"))); permanentDeleteButton.setLayout(null); permanentDeleteButton.setBounds(91, 390, 40, 39); permanentDeleteButton.setBackground(Color.black); permanentDeleteButton.setEnabled(false); permanentDeleteButton.addMouseListener((OnMouseClick) e -> { if (permanentDeleteButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (JOptionPane.showConfirmDialog(null, "Are you sure you wish to permanently delete '" + entry.realName() + "'?\nThis file and its " + "backup copies will be deleted immediately. You cannot undo this action.", "Confirm Cancel", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { registry.permanentDelete(entry); dispose(); RestoreFileWindow.getInstance(registry); } else { setVisible(true); } } }); add(permanentDeleteButton); final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png"))); configBackupsButton.setLayout(null); configBackupsButton.setBounds(134, 390, 40, 39); configBackupsButton.setBackground(Color.black); configBackupsButton.setEnabled(false); configBackupsButton.addMouseListener((OnMouseClick) e -> { if (configBackupsButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; JFrame frame = new JFrame("Choose backup policy"); Object option = JOptionPane.showInputDialog(frame, "Choose below the backup policy for this file:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(), pbxFile.getBackupPolicy()); if (option == null) { setVisible(true); return; } PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString()); pbxFile.setBackupPolicy(pickedPolicy); } setVisible(true); } }); add(configBackupsButton); final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png"))); restoreBackupButton.setLayout(null); restoreBackupButton.setBounds(3, 390, 85, 39); restoreBackupButton.setBackground(Color.black); restoreBackupButton.setEnabled(false); restoreBackupButton.addMouseListener((OnMouseClick) e -> { if (restoreBackupButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFolder) { registry.restoreFolderFromEntry((PbxFolder) entry); } else if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; java.util.List<String> snapshots = pbxFile.snapshotsToString(); if (snapshots.isEmpty()) { setVisible(true); return; } JFrame frame = new JFrame("Choose backup"); Object option = JOptionPane.showInputDialog(frame, "Choose below what backup snapshot would you like restore:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0)); if (option == null) { setVisible(true); return; } int pickedIndex = snapshots.indexOf(option.toString()); registry.restoreFileFromEntry((PbxFile) entry, pickedIndex); } dispose(); } }); add(restoreBackupButton); tree.addMouseListener((OnMouseClick) e -> { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { PbxEntry entry = (PbxEntry) node.getUserObject(); if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(false); } else if (entry instanceof PbxFile) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(true); } else { permanentDeleteButton.setEnabled(false); restoreBackupButton.setEnabled(false); configBackupsButton.setEnabled(false); } } }); final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png"))); cancel.setLayout(null); cancel.setBounds(229, 390, 122, 39); cancel.setBackground(Color.black); cancel.addMouseListener((OnMouseClick) e -> dispose()); add(cancel); addWindowFocusListener(new WindowFocusListener() { private boolean gained = false; @Override public void windowGainedFocus(WindowEvent e) { gained = true; } @Override public void windowLostFocus(WindowEvent e) { if (gained) { dispose(); } } }); setSize(340, 432); setUndecorated(true); getContentPane().setBackground(Color.white); setResizable(false); getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100))); Utils.setComponentLocationOnCenter(this); setVisible(true); }