List of usage examples for javax.swing JTree JTree
public JTree()
JTree
with a sample model. From source file:JTreeSimple.java
/** Construct the object including its GUI */ public JTreeSimple() { super("JTreeSimple"); Container cp = getContentPane(); cp.setLayout(new BorderLayout()); myTree = new JTree(); JScrollPane scroller = new JScrollPane(myTree); cp.add(BorderLayout.CENTER, scroller); cp.add(BorderLayout.SOUTH, quitButton = new JButton("Exit")); quitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false);/*w w w. j a va 2 s .co m*/ dispose(); System.exit(0); } }); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); }
From source file:hu.bme.mit.sette.snippetbrowser.SnippetBrowser.java
/** * Initialise the contents of the frame. *///from www. j a va 2s . co m private void initialize() { setTitle("Snippet Browser"); this.setBounds(50, 50, 1000, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSplitPane splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setResizeWeight(0.3); getContentPane().add(splitPane, BorderLayout.CENTER); JScrollPane scrollPaneLeft = new JScrollPane(); splitPane.setLeftComponent(scrollPaneLeft); treeSnippets = new JTree(); scrollPaneLeft.setViewportView(treeSnippets); JScrollPane scrollPaneRight = new JScrollPane(); splitPane.setRightComponent(scrollPaneRight); txtrInfo = new JTextArea(); txtrInfo.setEditable(false); scrollPaneRight.setViewportView(txtrInfo); }
From source file:gtu._work.ui.LoadJspCheckTagUI.java
private void initGUI() { try {/*w w w .ja v a 2 s. c o m*/ BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setTitle("\u8b80\u53d6Jsp\u8cc7\u8a0a"); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(475, 328)); { jTree1 = new JTree(); jScrollPane1.setViewportView(jTree1); jTree1.setModel(null); jTree1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jTree1MouseClicked(evt); } }); jTree1.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { jTree1ValueChanged(evt); } }); } } } { jPanel2 = new JPanel(); jTabbedPane1.addTab("jPanel2", null, jPanel2, null); { subFileNameText = new JTextField(); jPanel2.add(subFileNameText); subFileNameText.setPreferredSize(new java.awt.Dimension(95, 24)); subFileNameText.setText("xhtml"); } { ComboBoxModel jComboBox1Model = new DefaultComboBoxModel( new String[] { "??", "?" }); modifyFileBox = new JComboBox(); jPanel2.add(modifyFileBox); modifyFileBox.setModel(jComboBox1Model); } { exportReportToogleBtn = new JToggleButton(); jPanel2.add(exportReportToogleBtn); exportReportToogleBtn.setText("\u662f\u5426\u532f\u51fa\u5831\u8868"); exportReportToogleBtn.setPreferredSize(new java.awt.Dimension(120, 24)); exportReportToogleBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JCommonUtil.setJToggleButtonText(exportReportToogleBtn, new String[] { "", "?" }); } }); } { projectSrcPathBtn = new JButton(); jPanel2.add(projectSrcPathBtn); projectSrcPathBtn.setText("\u8a2d\u5b9a\u5c08\u6848\u76ee\u8def\u4e26\u6383\u63cf"); projectSrcPathBtn.setPreferredSize(new java.awt.Dimension(233, 95)); projectSrcPathBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1ActionPerformed(evt); } }); } } } this.setSize(496, 395); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.wwidesigner.gui.StudyView.java
@Override protected void initializeComponents() { // create file tree tree = new JTree() { @Override//from ww w .ja va 2s .co m public String getToolTipText(MouseEvent e) { String tip = null; TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path != null) { if (path.getPathCount() == 3) // it is a leaf { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node instanceof TreeNodeWithToolTips) { tip = ((TreeNodeWithToolTips) node).getToolTip(); } } } return tip == null ? getToolTipText() : tip; } }; // Show tooltips for the Study view, and let them persist for 8 seconds. ToolTipManager.sharedInstance().registerComponent(tree); ToolTipManager.sharedInstance().setDismissDelay(8000); // If a Study view node doesn't fit in the pane, expand it when hovering // over it. ExpandedTipUtils.install(tree); tree.setRootVisible(false); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); tree.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path != null) { if (path.getPathCount() == 3) // it is a leaf { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); String category = (String) parentNode.getUserObject(); study.setCategorySelection(category, (String) node.getUserObject()); if (StudyModel.INSTRUMENT_CATEGORY_ID.equals(category) || StudyModel.TUNING_CATEGORY_ID.equals(category)) { try { study.validHoleCount(); } catch (Exception ex) { showException(ex); } } } updateView(); } } }); JScrollPane scrollPane = new JScrollPane(tree); scrollPane.setPreferredSize(new Dimension(225, 100)); add(scrollPane); Preferences myPreferences = getApplication().getPreferences(); String modelName = myPreferences.get(OptimizationPreferences.STUDY_MODEL_OPT, OptimizationPreferences.NAF_STUDY_NAME); setStudyModel(modelName); study.setPreferences(myPreferences); getApplication().getEventManager().subscribe(WIDesigner.FILE_OPENED_EVENT_ID, this); getApplication().getEventManager().subscribe(WIDesigner.FILE_CLOSED_EVENT_ID, this); getApplication().getEventManager().subscribe(WIDesigner.FILE_SAVED_EVENT_ID, this); getApplication().getEventManager().subscribe(WIDesigner.WINDOW_RENAMED_EVENT_ID, this); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTree.java
public DesktopTree() { layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]"); panel = new JPanel(layout); topPanel = new JPanel(new BorderLayout()); topPanel.setVisible(false);//from ww w . java 2s.c o m panel.add(topPanel, "growx"); impl = new JTree(); treeView = new JScrollPane(impl); panel.add(treeView, "grow"); impl.setRootVisible(false); impl.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); impl.setExpandsSelectedPaths(true); impl.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { // select row Point p = e.getPoint(); TreePath treePath = impl.getPathForLocation(p.x, p.y); if (treePath != null) { TreeSelectionModel model = impl.getSelectionModel(); model.setSelectionPath(treePath); } // show popup menu createPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } }); impl.addKeyListener(new KeyAdapter() { protected static final int ENTER_CODE = 10; @Override public void keyPressed(KeyEvent e) { if (ENTER_CODE == e.getKeyCode() && e.getComponent() == DesktopTree.this.getComponent()) { if (enterPressAction != null) { enterPressAction.actionPerform(DesktopTree.this); } else { handleClickAction(); } } } }); }
From source file:com.codeasylum.stress.ui.Jormungandr.java
private synchronized Jormungandr init() throws IOException, SAXException, ParserConfigurationException { TestPlan testPlan;/*from www.ja v a2 s. c o m*/ GhostPanel ghostPanel; GroupLayout groupLayout; ViewPanel viewPanel; JTree testTree; JSplitPane workSplitPane; JScrollPane paletteScrollPane; JScrollPane testScrollPane; setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); exchangeTransport = new ExchangeTransportImpl(exchangeTransportRMIPort); menuHandler = new JormungandrMenuHandler(this, menuDelegateFactory); testExecutor = new TestExecutor(testPlan = new TestPlan(), exchangeTransport); testExecutor.addTestExecutorListener(this); testPlan.getRootTask().setName(palette.getAvatar(RootTask.class).getName()); setGlassPane(ghostPanel = new GhostPanel()); setLayout(groupLayout = new GroupLayout(getContentPane())); testTree = new JTree(); palettePanel = new PalettePanel(this, ghostPanel, palette); testPanel = new TestPanel(this, ghostPanel, palette, viewPanel = new ViewPanel(testTree), testTree); paletteScrollPane = new JScrollPane(palettePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); testScrollPane = new JScrollPane(testPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); workSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, testScrollPane, viewPanel); workSplitPane.setDoubleBuffered(true); workSplitPane.setContinuousLayout(true); workSplitPane.setResizeWeight(0.3); groupLayout.setAutoCreateContainerGaps(true); groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup() .addComponent(paletteScrollPane, (int) palettePanel.getMinimumSize().getWidth() + 3, (int) palettePanel.getPreferredSize().getWidth() + 3, (int) palettePanel.getMaximumSize().getWidth() + 3) .addComponent(workSplitPane)); groupLayout.setVerticalGroup(groupLayout.createParallelGroup() .addComponent(paletteScrollPane, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(workSplitPane, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); setSize(new Dimension(Math.max(800, ((int) getLayout().preferredLayoutSize(this).getWidth()) + 120), Math.min(600, ((int) getLayout().preferredLayoutSize(this).getHeight()) + 38))); setLocationByPlatform(true); addWindowListener(this); return this; }
From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.gui.controls.datasource.WpsDialog.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.//from www. j av a 2s .c o m */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { JPanel jPanel1 = new JPanel(); closeButton = new JButton(); addToMonitorButton = new JButton(); treeScrollPane = new JScrollPane(); wpsTree = new JTree(); JLabel jLabel1 = new JLabel(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setTitle("List of WPS-Servers- and Processes"); setIconImage(new ImageIcon(getClass().getResource("/icons/database.png")).getImage()); setMinimumSize(null); setName("wpsDialog"); // NOI18N setResizable(false); jPanel1.setBorder(BorderFactory.createTitledBorder("")); closeButton.setIcon(new ImageIcon(getClass().getResource("/icons/apply.png"))); // NOI18N closeButton.setText("Close"); closeButton.setName("closeButton"); // NOI18N closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { closeButtonActionPerformed(evt); } }); addToMonitorButton.setIcon(new ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N addToMonitorButton.setText("Add WPS with Processes"); addToMonitorButton.setName("addToMonitorButton"); // NOI18N addToMonitorButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { addToMonitorButtonActionPerformed(evt); } }); DefaultMutableTreeNode treeNode1 = new DefaultMutableTreeNode("root"); wpsTree.setModel(new DefaultTreeModel(treeNode1)); wpsTree.setName("wpsTree"); // NOI18N treeScrollPane.setViewportView(wpsTree); jLabel1.setText( "<html><body>Here is a list of all registered data-sources. You can pick up processes and WPS and add your choice to the monitor through the \"Add WPS with Processes\"-Button. If you select only a WPS, all processes of this WPS will also be added. The processes will be saved, but they have no Jobs or a testrequest.</body></html>"); GroupLayout jPanel1Layout = new GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(addToMonitorButton) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(closeButton)) .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(treeScrollPane, GroupLayout.PREFERRED_SIZE, 630, GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); jPanel1Layout .setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(treeScrollPane, GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(addToMonitorButton).addComponent(closeButton)) .addContainerGap())); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); pack(); }
From source file:ca.sqlpower.wabit.swingui.enterprise.UserPanel.java
public UserPanel(User baseUser) { final MessageDigest digester; try {//w w w . j a v a2s. co m digester = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e1) { throw new RuntimeException(e1); } this.user = baseUser; this.workspace = (WabitWorkspace) this.user.getParent(); this.loginTextField = new JTextField(); this.loginTextField.setText(user.getName()); this.loginLabel = new JLabel("User name"); this.loginTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setName(loginTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.passwordTextField = new JPasswordField(); this.passwordLabel = new JLabel("Password"); this.passwordTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { try { String pass = new String(passwordTextField.getPassword()); String encoded = new String(Hex.encodeHex(digester.digest(pass.getBytes("UTF-8")))); user.setPassword(encoded); } catch (UnsupportedEncodingException e1) { throw new RuntimeException(e1); } } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.fullNameTextField = new JTextField(); this.fullNameTextField.setText(user.getFullName()); this.fullNameLabel = new JLabel("Full name"); this.fullNameTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setFullName(fullNameTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.emailTextField = new JTextField(); this.emailTextField.setText(user.getEmail()); this.emailLabel = new JLabel("Email"); this.emailTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setEmail(emailTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.availableGroupsLabel = new JLabel("Available Groups"); this.availableGroupsListModel = new GroupsListModel(user, workspace, false); this.availableGroupsList = new JList(this.availableGroupsListModel); this.availableGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.availableGroupsList.setCellRenderer(new DefaultListCellRenderer() { final JTree dummyTree = new JTree(); final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer(); @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0, cellHasFocus); } }); this.availableGroupsScrollPane = new JScrollPane(this.availableGroupsList); this.currentGroupsLabel = new JLabel("Current Memberships"); this.currentGroupsListModel = new GroupsListModel(user, workspace, true); this.currentGroupsList = new JList(this.currentGroupsListModel); this.currentGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.currentGroupsList.setCellRenderer(new DefaultListCellRenderer() { final JTree dummyTree = new JTree(); final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer(); @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0, cellHasFocus); } }); this.groupsLabel = new JLabel("Edit user memberships"); this.currentGroupsScrollPane = new JScrollPane(this.currentGroupsList); this.addButton = new JButton(">"); this.addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] selection = availableGroupsList.getSelectedValues(); if (selection.length == 0) { return; } try { workspace.begin("Add user to groups"); for (Object object : selection) { ((Group) object).addMember(new GroupMember(user)); } } finally { workspace.commit(); } } }); this.removeButton = new JButton("<"); this.removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] selection = currentGroupsList.getSelectedValues(); if (selection.length == 0) { return; } try { workspace.begin("Remove user from groups"); Map<Group, GroupMember> toRemove = new ArrayMap<Group, GroupMember>(); for (Object object : selection) { for (GroupMember membership : ((Group) object).getChildren(GroupMember.class)) { if (membership.getUser().getUUID().equals(user.getUUID())) { toRemove.put((Group) object, membership); } } } for (Entry<Group, GroupMember> entry : toRemove.entrySet()) { entry.getKey().removeMember(entry.getValue()); } } finally { workspace.commit(); } } }); Action deleteAction = new DeleteFromTreeAction(this.workspace, this.user, this.panel, this.workspace.getSession().getContext()); this.toolbarBuilder.add(deleteAction, "Delete this user", WabitIcons.DELETE_ICON_32); // Panel building time JPanel namePassPanel = new JPanel(new MigLayout()); namePassPanel.add(this.loginLabel, "align right, gaptop 20"); namePassPanel.add(this.loginTextField, "span, wrap, wmin 600"); namePassPanel.add(this.passwordLabel, "align right"); namePassPanel.add(this.passwordTextField, "span, wrap, wmin 600"); namePassPanel.add(this.fullNameLabel, "align right, gaptop 20"); namePassPanel.add(this.fullNameTextField, "span, wrap, wmin 600"); namePassPanel.add(this.emailLabel, "align right"); namePassPanel.add(this.emailTextField, "span, wrap, wmin 600"); this.panel.add(namePassPanel, "north"); this.panel.add(this.groupsLabel, "span, wrap, gaptop 20, align center"); JPanel buttonsPanel = new JPanel(new MigLayout()); buttonsPanel.add(this.addButton, "wrap"); buttonsPanel.add(this.removeButton); JPanel availablePanel = new JPanel(new MigLayout()); availablePanel.add(this.availableGroupsLabel, "wrap, align center"); availablePanel.add(this.availableGroupsScrollPane, "wmin 300"); JPanel currentPanel = new JPanel(new MigLayout()); currentPanel.add(this.currentGroupsLabel, "wrap, align center"); currentPanel.add(this.currentGroupsScrollPane, "wmin 300"); this.panel.add(availablePanel); this.panel.add(buttonsPanel, "shrink, span 1 2"); this.panel.add(currentPanel); }
From source file:gtu._work.etc._3DSMovieRenamer.java
private void initGUI() { try {/*ww w. j a v a 2 s. c om*/ final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this); BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setTitle("3DS Rename"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("vid list", null, jPanel1, null); { openDir = new JButton(); jPanel1.add(openDir, BorderLayout.NORTH); openDir.setText("open dir"); openDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("openDir.actionPerformed", evt); } }); } { ListModel vidListModel = new DefaultListModel(); vidList = new JList(); jPanel1.add(vidList, BorderLayout.CENTER); vidList.setModel(vidListModel); vidList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("vidList.mouseClicked", evt); } }); vidList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { swingUtil.invokeAction("vidList.keyPressed", evt); } }); } { jPanel3 = new JPanel(); jPanel1.add(jPanel3, BorderLayout.SOUTH); jPanel3.setPreferredSize(new java.awt.Dimension(445, 34)); { renameText = new JTextField(); jPanel3.add(renameText); renameText.setPreferredSize(new java.awt.Dimension(187, 24)); } { renameBtn = new JButton(); jPanel3.add(renameBtn); renameBtn.setText("rename"); renameBtn.setPreferredSize(new java.awt.Dimension(106, 24)); renameBtn.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("renameBtn.mouseClicked", evt); } }); } { forceChange = new JCheckBox(); jPanel3.add(forceChange); forceChange.setText("force"); forceChange.setPreferredSize(new java.awt.Dimension(64, 21)); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("copy", null, jPanel2, null); { jScrollPane1 = new JScrollPane(); jPanel2.add(jScrollPane1, BorderLayout.CENTER); { ListModel copyToListModel = new DefaultListModel(); copyToList = new JList(); jScrollPane1.setViewportView(copyToList); copyToList.setModel(copyToListModel); copyToList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("copyToList.mouseClicked", evt); } }); } } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("BT Movie", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.WEST); jScrollPane2.setPreferredSize(new java.awt.Dimension(254, 355)); { btDirTree = new JTree(); jScrollPane2.setViewportView(btDirTree); btDirTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction(evt); } }); btDirTree.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { swingUtil.invokeAction(evt); } }); JTreeUtil.newInstance(btDirTree).fileSystem(DEFAULT_BT_DIR); } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); jPanel4.add(jPanel5, BorderLayout.CENTER); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); jScrollPane3.setPreferredSize(new java.awt.Dimension(427, 355)); { DefaultListModel btMovListModel = new DefaultListModel(); btMovList = new JList(); jScrollPane3.setViewportView(btMovList); btMovList.setModel(btMovListModel); btMovList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction(evt); } }); btMovList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(btMovList).defaultJListKeyPressed(evt); } }); } } } } { jPanel6 = new JPanel(); FlowLayout jPanel6Layout = new FlowLayout(); jTabbedPane1.addTab("common", null, jPanel6, null); jPanel6.setLayout(jPanel6Layout); { execute3dsVidTransfer = new JButton(); jPanel6.add(execute3dsVidTransfer); execute3dsVidTransfer.setText("execute 3ds video transfer"); execute3dsVidTransfer.setPreferredSize(new java.awt.Dimension(207, 42)); execute3dsVidTransfer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String bat = "C:/apps/_movie/3DSVideov1.00/3DS Video.exe"; try { Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", bat)); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } { openMovieAppDir = new JButton(); jPanel6.add(openMovieAppDir); openMovieAppDir.setText("open movie app dir"); openMovieAppDir.setPreferredSize(new java.awt.Dimension(207, 42)); openMovieAppDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { Desktop.getDesktop().open(new File("C:/apps/_movie")); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } { jPanel7 = new JPanel(); BorderLayout jPanel7Layout = new BorderLayout(); jTabbedPane1.addTab("fake rename", null, jPanel7, null); jPanel7.setLayout(jPanel7Layout); { openFakeRenameDir = new JButton(); jPanel7.add(openFakeRenameDir, BorderLayout.NORTH); openFakeRenameDir.setText("open dir"); openFakeRenameDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JCommonUtil._jFileChooser_selectDirectoryOnly(); if (file != null) { DefaultListModel model = new DefaultListModel(); for (File f : file.listFiles()) { model.addElement(f); } openFakeRenameDirList.setModel(model); } } }); } { DefaultListModel openFakeRenameDirListModel = new DefaultListModel(); openFakeRenameDirList = new JList(); jPanel7.add(openFakeRenameDirList, BorderLayout.CENTER); openFakeRenameDirList.setModel(openFakeRenameDirListModel); openFakeRenameDirList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { File file = (File) JListUtil.getLeadSelectionObject(openFakeRenameDirList); try { Process process = Runtime.getRuntime() .exec(String.format("cmd /c call \"%s\"", file)); InputStream ins = process.getInputStream(); while (ins.read() != -1) { //TODO } ins.close(); System.out.println("done..."); } catch (IOException e) { e.printStackTrace(); } } }); openFakeRenameDirList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(openFakeRenameDirList).defaultJListKeyPressed(evt); } }); } { jPanel8 = new JPanel(); jPanel7.add(jPanel8, BorderLayout.SOUTH); jPanel8.setPreferredSize(new java.awt.Dimension(681, 43)); { openFakeRenameDir_newName = new JTextField(); jPanel8.add(openFakeRenameDir_newName); openFakeRenameDir_newName.setPreferredSize(new java.awt.Dimension(287, 27)); } { fakeRenameExecute = new JButton(); jPanel8.add(fakeRenameExecute); fakeRenameExecute.setText("execute"); fakeRenameExecute.setPreferredSize(new java.awt.Dimension(95, 27)); fakeRenameExecute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { DefaultListModel model = (DefaultListModel) openFakeRenameDirList.getModel(); //TODO } }); } } } swingUtil.addAction("copyToList.mouseClicked", new Action() { public void action(EventObject evt) throws Exception { try { if (((MouseEvent) evt).getButton() == 3) { JMenuItem reloadMenu = new JMenuItem(); reloadMenu.setText("reload SD card directory"); reloadMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultListModel copyToListModel = new DefaultListModel(); for (final File f : load3DSDir.listFiles(new FilenameFilter() { public boolean accept(File paramFile, String paramString) { if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) { return true; } return false; } })) { copyToListModel.addElement(f); } copyToList.setModel(copyToListModel); } }); JMenuItem copyAllToMenu = new JMenuItem(); { copyAllToMenu.setText( String.format("move %d vids to...", vidList.getModel().getSize())); final File toDir = (File) JListUtil.getLeadSelectionObject(copyToList); if (toDir == null || !toDir.exists() || !toDir.isDirectory()) { copyAllToMenu.setEnabled(false); } if (vidList.getModel().getSize() == 0) { copyAllToMenu.setText("copy no file..."); copyAllToMenu.setEnabled(false); } copyAllToMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultListModel model = JListUtil.newInstance(vidList).getModel(); if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil .newInstance().iconWaringMessage().confirmButtonYesNo() .showConfirmDialog("are you sure copy files : " + model.getSize() + "\n to dir : " + toDir, "COPY VIDS")) { return; } for (int ii = 0; ii < model.getSize(); ii++) { File src = (File) model.getElementAt(ii); src.renameTo(new File(toDir, src.getName())); } JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("copy completed!", "SUCCESS"); loadDirVids(); } }); } JPopupMenuUtil.newInstance(copyToList).applyEvent((MouseEvent) evt) .addJMenuItem(reloadMenu, copyAllToMenu).show(); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); swingUtil.addAction("openDir.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir not corrent!, set desktop", getTitle()); loadDir = FileUtil.DESKTOP_DIR; } else { loadDir = file; } loadDirVids(); } }); swingUtil.addAction("vidList.mouseClicked", new Action() { // final String player = "C:/Program Files (x86)/GRETECH/GomPlayer/GOM.EXE"; public void action(EventObject evt) throws Exception { int pos = -1; if ((pos = vidList.getLeadSelectionIndex()) == -1) { return; } MouseEvent mevt = (MouseEvent) evt; final File selectItem = (File) vidList.getModel().getElementAt(pos); List<JMenuItem> menuList = new ArrayList<JMenuItem>(); JMenuItem simpleRenamer = new JMenuItem(); final String simpleRenamePrefix = RandomUtil.upperCase(3); simpleRenamer.setText("Rename : " + simpleRenamePrefix); simpleRenamer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { String value = StringUtils.defaultString(JOptionPaneUtil.newInstance() .showInputDialog("3 char prefix?", "AVI PREFIX"), simpleRenamePrefix); if (value != null && value.matches("[a-zA-Z]{3}")) { selectItem.renameTo(getNewFile(selectItem.getParentFile(), value)); loadDirVids(); } else { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("prefix is not correct!", "ERROR"); } } }); menuList.add(simpleRenamer); if (load3DSDir == null) { reload3DSDir(); if (load3DSDir == null) { JMenuItem disable = new JMenuItem(); disable.setText("MOVE : SD card is not set!"); disable.setEnabled(false); menuList.add(disable); } } else { for (final File f : load3DSDir.listFiles(new FilenameFilter() { public boolean accept(File paramFile, String paramString) { if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) { return true; } return false; } })) { JMenuItem copyTo = new JMenuItem(); copyTo.setText("MOVE : " + f.getName()); copyTo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil .newInstance().iconQuestionMessage().confirmButtonYesNo() .showConfirmDialog(// "are you sure move file\n" + // selectItem + "\n" + // "to\n" + // "dir : " + f + " ??"// , "COPY FILE")) { File copyToNewDirFile = new File(f, selectItem.getName()); if (copyToNewDirFile.exists()) { JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog( "target dir file already exist!, need rename!", "FILE ALREADY EXIST"); return; } selectItem.renameTo(copyToNewDirFile); loadDirVids(); JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("move completed!", "MOVE FILE"); } } }); menuList.add(copyTo); } } JPopupMenuUtil.newInstance(vidList).applyEvent(mevt) .addJMenuItem(menuList.toArray(new JMenuItem[menuList.size()])).show(); if (mevt.getClickCount() != 2) { return; } String clkItemPath = selectItem.getAbsolutePath(); String command = "cmd /c call \"" + clkItemPath + "\""; System.out.println(command); Runtime.getRuntime().exec(command); } }); swingUtil.addAction("vidList.keyPressed", new Action() { public void action(EventObject evt) throws Exception { JListUtil.newInstance(vidList).defaultJListKeyPressed(evt); } }); swingUtil.addAction("renameBtn.mouseClicked", new Action() { Pattern aviNamePattern = Pattern.compile("^([a-zA-Z]{3})_\\d{4}\\.[aA][vV][iI]$"); public void action(EventObject evt) throws Exception { String name = StringUtils.defaultIfEmpty(renameText.getText(), RandomUtil.upperCase(3)); System.out.println("name = " + name + ", force : " + forceChange.isSelected()); if (!name.matches("[a-zA-Z]{3}")) { renameText.setText(""); JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("rename must eng 3 char!", "ERROR"); return; } DefaultListModel model = (DefaultListModel) vidList.getModel(); boolean matchOk = false; if (model.size() != 0) { File oldFile = null; Matcher matcher = null; for (int ii = 0; ii < model.getSize(); ii++) { oldFile = (File) model.getElementAt(ii); if (!oldFile.exists()) { JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog( "file not exeist : \n" + oldFile.getAbsolutePath(), getTitle()); return; } matcher = aviNamePattern.matcher(oldFile.getName()); matchOk = matcher.find(); System.out.println("matchOk = " + matchOk); if (matchOk && !forceChange.isSelected()) { oldFile.renameTo(getNewFile(oldFile.getParentFile(), matcher.group(1))); } else { oldFile.renameTo(getNewFile(oldFile.getParentFile(), name)); } } JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog("success!", getTitle()); } loadDirVids(); } }); ToolTipManager.sharedInstance().setInitialDelay(0); swingUtil.addAction(btMovList, MouseEvent.class, new Action() { public void action(EventObject evt) throws Exception { final File file = (File) JListUtil.getLeadSelectionObject(btMovList); if (JMouseEventUtil.buttonLeftClick(1, evt)) { btMovList.setToolTipText( DateFormatUtils.format(file.lastModified(), "yyyy/MM/dd HH:mm:ss") + " length:" + (file.length() / 1024) + "k"); } final Object[] objects = btMovList.getSelectedValues(); JPopupMenuUtil.newInstance(btMovList).applyEvent(evt)// .addJMenuItem("move out", (objects != null && objects.length > 0), new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { List<File> list = new ArrayList<File>(); for (Object val : objects) { list.add((File) val); } if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure move file from\n" + list.toString().replace(',', '\n') + "\nto\n" + DEFAULT_BT_DIR, "MOVE")) { return; } StringBuilder sb = new StringBuilder(); File moveTo = null; for (File file : list) { sb.append((file.renameTo( moveTo = new File(DEFAULT_BT_DIR, file.getName())) && moveTo.exists()) ? "" : file + "\n"); } JCommonUtil._jOptionPane_showMessageDialog_info( sb.length() == 0 ? "move success!" : "move failed!\n" + sb); } }) .addJMenuItem("delete this", file.exists(), new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure delete file \n" + file, "DELETE")) { return; } boolean result = file.delete(); System.out.println("!!!!!" + result + "..." + file.exists()); JCommonUtil._jOptionPane_showMessageDialog_info( result ? "delete success!" : "delete failed!"); } }).show(); if (JMouseEventUtil.buttonLeftClick(2, evt)) { Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", file)); } } }); swingUtil.addAction(btDirTree, MouseEvent.class, new Action() { File getSingleFile() { return ((JFile) JTreeUtil.newInstance(btDirTree).getSelectItem().getUserObject()).getFile(); } public void action(EventObject evt) throws Exception { int selectCount = btDirTree.getSelectionModel().getSelectionCount(); if (selectCount == 1) { final File file = getSingleFile(); JPopupMenuUtil.newInstance(btDirTree).applyEvent(evt).addJMenuItem("delete this", selectCount == 1 && file.exists(), new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { if (file.isFile()) { if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure delete FILE : \n" + file, "WARNING")) { file.delete(); JCommonUtil._jOptionPane_showMessageDialog_info( (file.exists() ? "delete failed!" : "delete success!")); } } if (file.isDirectory()) { StringBuilder sb = new StringBuilder(); if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure delete DIR : \n" + file, "WARNING")) { List<Boolean> delL = new ArrayList<Boolean>(); for (File f : file.listFiles()) { if (fileExtensionPattern.matcher(f.getName()).find() || f.length() > 1000000L) { if (!JCommonUtil ._JOptionPane_showConfirmDialog_yesNoOption( "delete this : \n" + f, "CHECK AGAIN")) { continue; } delL.add(f.delete()); } delL.add(f.delete()); } for (File f : file.listFiles()) { if (f.exists()) { sb.append(f + "\n"); } } System.out.println("delL.contains(false)==================>" + delL.contains(false)); } if (!file.delete()) { sb.append(file + "\n"); } JCommonUtil._jOptionPane_showMessageDialog_info( sb.length() > 0 ? "delete failed!\nlist:\n" + sb : "delete success!"); if (sb.length() == 0) { DefaultMutableTreeNode node = JTreeUtil.newInstance(btDirTree) .getSelectItem(); System.out.println( JTreeUtil.newInstance(btDirTree).removeNode(node)); } } } }).addJMenuItem("open dir", new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { File openTarget = file; if (file.isFile()) { openTarget = file.getParentFile(); } try { Desktop.getDesktop().open(openTarget); } catch (IOException e) { JCommonUtil.handleException(e); } } }).show(); } } }); swingUtil.addAction(btDirTree, PropertyChangeEvent.class, new Action() { public void action(EventObject evt) throws Exception { List<File> list = new ArrayList<File>(); for (DefaultMutableTreeNode node : JTreeUtil.newInstance(btDirTree).getSelectItems()) { JFile jfile = (JFile) node.getUserObject(); if (jfile.getFile().isDirectory()) { for (File f : jfile.getFile().listFiles(new FilenameFilter() { public boolean accept(File paramFile, String paramString) { return fileExtensionPattern.matcher(paramString).find(); } })) { System.out.println(f.getName() + "...." + f.length()); list.add(f); } } } Collections.sort(list, new Comparator<File>() { public int compare(File paramT1, File paramT2) { return paramT1.lastModified() > paramT2.lastModified() ? -1 : 1; } }); btMovList.setModel(JListUtil.createModel(list.iterator())); } }); } this.setSize(702, 422); loadDirVids(); reload3DSDir(); } catch (Exception e) { e.printStackTrace(); } }
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 ww w . j a va2 s . c om*/ */ 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"); } }