Example usage for javax.swing JTree setModel

List of usage examples for javax.swing JTree setModel

Introduction

In this page you can find the example usage for javax.swing JTree setModel.

Prototype

@BeanProperty(description = "The TreeModel that will provide the data.")
public void setModel(TreeModel newModel) 

Source Link

Document

Sets the TreeModel that will provide the data.

Usage

From source file:FileTreeDemo.java

public static void main(String[] args) {
    // Figure out where in the filesystem to start displaying
    File root;/*from   w  w  w .  j  a v a  2s .  com*/
    if (args.length > 0)
        root = new File(args[0]);
    else
        root = new File(System.getProperty("user.home"));

    // Create a TreeModel object to represent our tree of files
    FileTreeModel model = new FileTreeModel(root);

    // Create a JTree and tell it to display our model
    JTree tree = new JTree();
    tree.setModel(model);

    // The JTree can get big, so allow it to scroll.
    JScrollPane scrollpane = new JScrollPane(tree);

    // Display it all in a window and make the window appear
    JFrame frame = new JFrame("FileTreeDemo");
    frame.getContentPane().add(scrollpane, "Center");
    frame.setSize(400, 600);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    MyTreeNode root = new MyTreeNode(1, 0);
    DefaultTreeModel model = new DefaultTreeModel(root);
    JProgressBar bar = new JProgressBar();
    PropertyChangeListener progressListener = new PropertyChangeListener() {
        @Override/* w ww  .j  av a 2s  . co m*/
        public void propertyChange(PropertyChangeEvent evt) {
            bar.setValue((Integer) evt.getNewValue());
        }
    };
    JTree tree = new JTree();
    tree.setShowsRootHandles(true);
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {
        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath();
            if (path.getLastPathComponent() instanceof MyTreeNode) {
                MyTreeNode node = (MyTreeNode) path.getLastPathComponent();
                node.loadChildren(model, progressListener);
            }
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {

        }
    });
    tree.setModel(model);
    root.loadChildren(model, progressListener);
    frame.add(new JScrollPane(tree));
    frame.add(bar, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}

From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final FilteringTreeModel model = new FilteringTreeModel(createTreeModel());

    // setup text field
    final JTextField filterTextField = new JTextField(30);
    filterTextField.addActionListener(new ActionListener() {

        @Override/*from   www.  j  a v a  2s.com*/
        public void actionPerformed(ActionEvent e) {
            model.viewFilterChanged();
        }
    });

    // setup tree
    final JTree tree = new JTree();
    final IViewFilter<ITreeNode> filter = new AbstractViewFilter<ITreeNode>() {

        @Override
        public boolean isHiddenUnfiltered(ITreeNode node) {
            final String nodeValue = node.toString();
            final String expected = filterTextField.getText();

            final boolean isHidden = !StringUtils.isBlank(nodeValue) && !StringUtils.isBlank(expected)
                    && nodeValue.startsWith("child")
                    && !nodeValue.toLowerCase().contains(expected.toLowerCase());

            System.out.println(nodeValue + " does not match " + expected + " => " + isHidden);
            return isHidden;
        }
    };
    model.setViewFilter(filter);
    tree.setModel(model);

    // set 
    final JPanel panel = new JPanel();

    new GridLayoutBuilder()
            .add(new GridLayoutBuilder.HorizontalGroup(new GridLayoutBuilder.Cell(new JScrollPane(tree)),
                    new GridLayoutBuilder.FixedCell(filterTextField)))
            .addTo(panel);

    frame.getContentPane().add(panel);

    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:eu.europa.ec.markt.dss.applet.util.ComponentFactory.java

/**
 * //from  ww  w  .j a v a  2s  .c  o  m
 * @param name
 * @param model
 * @param cellRenderer
 * @return
 */
public static JTree tree(final String name, final TreeModel model, final TreeCellRenderer cellRenderer) {
    final JTree tree = new JTree();
    tree.setName(name);
    tree.setModel(model);
    if (cellRenderer != null) {
        tree.setCellRenderer(cellRenderer);
    }
    return tree;
}

From source file:be.ugent.maf.cellmissy.gui.controller.TracksWriterController.java

/**
 * Initialise the data tree (JTree).//from  w  ww. ja va2  s  .com
 */
private void initDataTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("cellmissy");
    JTree dataTree = tracksWriterDialog.getDataTree();
    MapDataTreeModel mapDataTreeModel = new MapDataTreeModel(root, projectMap);
    dataTree.setModel(mapDataTreeModel);
    dataTree.setEditable(true);
}

From source file:com.t3.client.ui.T3Frame.java

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);
    tree.setCellRenderer(new TokenPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {
        // TODO: Make this a handler class, not an aic
        @Override//from w w w.ja va  2 s  .c o  m
        public void mousePressed(MouseEvent e) {
            // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY()));
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);

                if (row instanceof Token) {
                    if (e.getClickCount() == 2) {
                        Token token = (Token) row;
                        getCurrentZoneRenderer().clearSelectedTokens();
                        getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY()));

                        // Pick an appropriate tool
                        getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class);
                        getCurrentZoneRenderer().setActiveLayer(token.getLayer());
                        getCurrentZoneRenderer().selectToken(token.getId());
                        getCurrentZoneRenderer().requestFocusInWindow();
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        Token firstToken = null;
                        Set<GUID> selectedTokenSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof Token) {
                                Token token = (Token) path.getLastPathComponent();
                                if (firstToken == null) {
                                    firstToken = token;
                                }
                                if (AppUtil.playerOwns(token)) {
                                    selectedTokenSet.add(token.getId());
                                }
                            }
                        }
                        if (!selectedTokenSet.isEmpty()) {
                            try {
                                if (firstToken.isStamp()) {
                                    new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                } else {
                                    new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                }
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }
    });
    TabletopTool.getEventDispatcher().addListener(new AppEventListener() {
        @Override
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, TabletopTool.ZoneEvent.Activated);
    return tree;
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);
    tree.setCellRenderer(new TokenPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {
        // TODO: Make this a handler class, not an aic
        @Override//from   ww w  . j  a  va  2  s . c  o m
        public void mousePressed(MouseEvent e) {
            // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY()));
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);

                if (row instanceof Token) {
                    if (e.getClickCount() == 2) {
                        Token token = (Token) row;
                        getCurrentZoneRenderer().clearSelectedTokens();
                        getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY()));

                        // Pick an appropriate tool
                        getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class);
                        getCurrentZoneRenderer().setActiveLayer(token.getLayer());
                        getCurrentZoneRenderer().selectToken(token.getId());
                        getCurrentZoneRenderer().requestFocusInWindow();
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        Token firstToken = null;
                        Set<GUID> selectedTokenSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof Token) {
                                Token token = (Token) path.getLastPathComponent();
                                if (firstToken == null) {
                                    firstToken = token;
                                }
                                if (AppUtil.playerOwns(token)) {
                                    selectedTokenSet.add(token.getId());
                                }
                            }
                        }
                        if (!selectedTokenSet.isEmpty()) {
                            try {
                                if (firstToken.isStamp()) {
                                    new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                } else {
                                    new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                }
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }
    });
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return tree;
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private JComponent createDrawTreePanel() {
    final JTree tree = new JTree();
    drawablesPanel = new DrawablesPanel();
    drawPanelTreeModel = new DrawPanelTreeModel(tree);
    tree.setModel(drawPanelTreeModel);
    tree.setCellRenderer(new DrawPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setContinuousLayout(true);

    splitPane.setTopComponent(new JScrollPane(tree));
    splitPane.setBottomComponent(drawablesPanel);
    splitPane.setDividerLocation(100);/*from  w ww.j a v a  2 s. co  m*/
    // Add mouse Event for right click menu
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);
                if (row instanceof DrawnElement) {
                    if (e.getClickCount() == 2) {
                        DrawnElement de = (DrawnElement) row;
                        getCurrentZoneRenderer()
                                .centerOn(new ZonePoint((int) de.getDrawable().getBounds().getCenterX(),
                                        (int) de.getDrawable().getBounds().getCenterY()));
                    }
                }

                int[] treeRows = tree.getSelectionRows();
                java.util.Arrays.sort(treeRows);
                drawablesPanel.clearSelectedIds();
                for (int i = 0; i < treeRows.length; i++) {
                    TreePath p = tree.getPathForRow(treeRows[i]);
                    if (p.getLastPathComponent() instanceof DrawnElement) {
                        DrawnElement de = (DrawnElement) p.getLastPathComponent();
                        drawablesPanel.addSelectedId(de.getDrawable().getId());
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                    drawablesPanel.clearSelectedIds();
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DrawnElement firstElement = null;
                        Set<GUID> selectedDrawSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof DrawnElement) {
                                DrawnElement de = (DrawnElement) path.getLastPathComponent();
                                if (firstElement == null) {
                                    firstElement = de;
                                }
                                selectedDrawSet.add(de.getDrawable().getId());
                            }
                        }
                        if (!selectedDrawSet.isEmpty()) {
                            try {
                                new DrawPanelPopupMenu(selectedDrawSet, x, y, getCurrentZoneRenderer(),
                                        firstElement).showPopup(tree);
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }

    });
    // Add Zone Change event
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            drawPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return splitPane;
}

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/*  w w w  . j  av  a2s . co 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:de.codesourcery.jasm16.ide.ui.views.WorkspaceExplorer.java

private JPanel createPanel() {
    treeModel = createTreeModel();/*  w w  w.  j  a v a 2 s  .  c om*/
    tree.setModel(treeModel);
    setColors(tree);
    tree.setRootVisible(false);

    //      for (int i = 0; i < tree.getRowCount(); i++) {
    //         tree.expandRow(i);
    //      }

    tree.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                final WorkspaceTreeNode selection = getSelectedNode();
                if (selection != null) {
                    deleteResource(selection);
                }
            } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                refreshWorkspace(null);
            }
        }
    });

    tree.addMouseListener(new MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
                if (path != null) {
                    final WorkspaceTreeNode selected = (WorkspaceTreeNode) path.getLastPathComponent();
                    final IAssemblyProject project = getProject(selected);
                    try {
                        if (project != null) {
                            onTreeNodeLeftClick(project, selected);
                        } else {
                            System.err.println("Unable to locate project for " + selected);
                        }
                    } catch (IOException e1) {
                        LOG.error("mouseClicked(): Internal error", e1);
                    }
                }
            }
        }
    });

    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {

        }
    };

    tree.getSelectionModel().addTreeSelectionListener(selectionListener);

    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        public Color getTextSelectionColor() {
            return Color.GREEN;
        };

        public java.awt.Color getTextNonSelectionColor() {
            return Color.GREEN;
        };

        public Color getBackgroundSelectionColor() {
            return Color.BLACK;
        };

        public Color getBackgroundNonSelectionColor() {
            return Color.BLACK;
        };

        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {

            java.awt.Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
                    row, hasFocus);

            String label = value.toString();
            Color color = getTextColor();
            if (value instanceof WorkspaceTreeNode) {
                if (value instanceof ProjectNode) {
                    final ProjectNode projectNode = (ProjectNode) value;
                    final IAssemblyProject project = projectNode.getValue();
                    label = project.getName();

                    if (project.isClosed()) {
                        color = Color.LIGHT_GRAY;
                    } else {
                        if (projectNode.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                    }
                } else if (value instanceof FileNode) {
                    FileNode fn = (FileNode) value;
                    label = fn.getValue().getName();
                    switch (fn.type) {
                    case DIRECTORY:
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    case OBJECT_FILE:
                        label = "[O] " + label;
                        break;
                    case EXECUTABLE:
                        label = "[E] " + label;
                        break;
                    case SOURCE_CODE:
                        label = "[S] " + label;
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    default:
                        // ok
                    }
                }
            }
            setForeground(color);
            setText(label);
            return result;
        };

    });

    setupPopupMenu();

    final JScrollPane pane = new JScrollPane(tree);
    setColors(pane);

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());
    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    setColors(result);
    result.add(pane, cnstrs);
    return result;
}