Example usage for javax.swing.event TreeSelectionEvent getSource

List of usage examples for javax.swing.event TreeSelectionEvent getSource

Introduction

In this page you can find the example usage for javax.swing.event TreeSelectionEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:Main.java

public static void main(String args[]) {
    JTree tree = new JTree();
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {

        @Override//from  w  w  w.j a v  a  2s. c  o  m
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            System.out.println("Min: " + treeSource.getMinSelectionRow());
            System.out.println("Max: " + treeSource.getMaxSelectionRow());
            System.out.println("Lead: " + treeSource.getLeadSelectionRow());
            System.out.println("Row: " + treeSource.getSelectionRows()[0]);
        }
    };
    tree.addTreeSelectionListener(treeSelectionListener);
    JFrame frame = new JFrame();
    frame.add(new JScrollPane(tree));
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:TreeSelectionRow.java

public static void main(String args[]) {
    String title = "JTree Sample";
    JFrame frame = new JFrame(title);
    JTree tree = new JTree();
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            System.out.println("Min: " + treeSource.getMinSelectionRow());
            System.out.println("Max: " + treeSource.getMaxSelectionRow());
            System.out.println("Lead: " + treeSource.getLeadSelectionRow());
            System.out.println("Row: " + treeSource.getSelectionRows()[0]);
        }/* ww  w . ja  va2  s. c  o  m*/
    };
    tree.addTreeSelectionListener(treeSelectionListener);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JTree tree = new JTree();
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    int treeSelectedRows[] = { 3, 1 };
    tree.setSelectionRows(treeSelectedRows);
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {

        @Override//from  ww  w . j a  v  a2  s.  c om
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            System.out.println("Min: " + treeSource.getMinSelectionRow());
            System.out.println("Max: " + treeSource.getMaxSelectionRow());
            System.out.println("Lead: " + treeSource.getLeadSelectionRow());
            System.out.println("Row: " + treeSource.getSelectionRows()[0]);
        }
    };
    tree.addTreeSelectionListener(treeSelectionListener);
    JFrame frame = new JFrame("JTree With Multi-Discontiguous selection");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setPreferredSize(new Dimension(380, 320));
    frame.setLocation(150, 150);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JTree tree = new JTree();
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    int treeSelectedRows[] = { 3, 1 };
    tree.setSelectionRows(treeSelectedRows);
    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {

        @Override//from   w  w w .j ava 2  s  .c om
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            System.out.println("Min: " + treeSource.getMinSelectionRow());
            System.out.println("Max: " + treeSource.getMaxSelectionRow());
            System.out.println("Lead: " + treeSource.getLeadSelectionRow());
            System.out.println("Row: " + treeSource.getSelectionRows()[0]);
        }
    };
    tree.addTreeSelectionListener(treeSelectionListener);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JScrollPane(tree));
    frame.setPreferredSize(new Dimension(380, 320));
    frame.setLocation(150, 150);
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

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

    JTree tree = new JTree();
    tree.setRootVisible(true);//  w  w  w. j a  v  a 2  s.c  om
    TreeModel model = tree.getModel();
    Object rootObject = model.getRoot();
    if ((rootObject != null) && (rootObject instanceof DefaultMutableTreeNode)) {
        DefaultMutableTreeNode r = (DefaultMutableTreeNode) rootObject;
        printDescendents(r);
        Enumeration breadth = r.breadthFirstEnumeration();
        Enumeration depth = r.depthFirstEnumeration();
        Enumeration preOrder = r.preorderEnumeration();
        printEnumeration(breadth, "Breadth");
        printEnumeration(depth, "Depth");
        printEnumeration(preOrder, "Pre");
    }

    TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
            JTree treeSource = (JTree) treeSelectionEvent.getSource();
            TreePath path = treeSource.getSelectionPath();
            System.out.println(path);
            System.out.println(path.getPath());
            System.out.println(path.getParentPath());
            System.out.println(((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject());
            System.out.println(path.getPathCount());
        }
    };
    tree.addTreeSelectionListener(treeSelectionListener);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 400);
    frame.setVisible(true);
}

From source file:UsingTreeSelectionListener.java

public void valueChanged(TreeSelectionEvent se) {
    JTree tree = (JTree) se.getSource();
    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    String selectedNodeName = selectedNode.toString();
    if (selectedNode.isLeaf()) {

        System.out.println(selectedNodeName);

    }/*from   w  ww.j  a v  a  2s  .  c  o  m*/
}

From source file:it.unibas.spicygui.vista.listener.ConstraintColoringTreeSelectionListener.java

public void valueChanged(TreeSelectionEvent e) {
    JTree albero = (JTree) e.getSource();
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) albero.getLastSelectedPathComponent();
    if (treeNode == null) {
        return;//w  w w  .ja  v a2  s.com
    }
    TreeNodeAdapter adapter = (TreeNodeAdapter) treeNode.getUserObject();
    INode node = adapter.getINode();
    analyzeConnectionConstraints(node);
    analyzeJoinConditions(node);
    analyzeConnections(node);
}

From source file:wsattacker.plugin.intelligentdos.ui.dialog.Result_NB.java

private void resultTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {// GEN-FIRST:event_jTree1ValueChanged
    JTree tree = (JTree) evt.getSource();
    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (selectedNode != null && selectedNode.isLeaf()) {
        SuccessfulAttack sa = (SuccessfulAttack) selectedNode.getUserObject();
        jLabel1.setText(FormatHelper.toHTML(sa));

        StringBuilder builder = new StringBuilder();
        builder.append("<html>");
        String format = "-";
        if (!Double.isNaN(sa.getRatio())) {
            format = df.format(sa.getRatio());
        }//from  w w  w.j  a v a  2s .  c o m
        builder.append("Attack roundtrip time ratio: ").append(format);
        builder.append("<br />");
        builder.append("the payload is ").append(sa.getEfficiency().name());
        builder.append("<br />");
        builder.append("<br />");
        double reuqestsPerSecond = ((int) (sa.getParamItem().getReuqestsPerSecond() * 100.0)) / 100.0;
        builder.append(reuqestsPerSecond).append(" requests per second were sent");
        builder.append("<br />");
        if (sa.getTamperedContent() != null) {
            long l = (long) (sa.getTamperedContent().getBytes(Charset.forName("UTF-8")).length
                    * sa.getParamItem().getReuqestsPerSecond());
            builder.append("the traffic was (approx) ").append(FileUtils.byteCountToDisplaySize(l))
                    .append(" per second");
        }

        builder.append("</html>");

        successMetric.setText(builder.toString());

        jTextArea1.setText(sa.getXmlWithPlaceholder());

        JFreeChart createOverlaidChart = ChartHelper.createOverlaidChart(sa);
        JFreeChart createWhiskerChart = ChartHelper.createWhiskerChart(sa);
        ((ChartPanel) chartPanel1).setChart(createOverlaidChart);
        ((ChartPanel) chartPanel2).setChart(createWhiskerChart);
    } else {
        jLabel1.setText("");
        successMetric.setText("");
    }
}

From source file:com.projity.pm.graphic.chart.ChartLegend.java

private void initTree() {
    //      tree = new JTree(chartInfo.getNodeModel());
    tree = new JTree(chartInfo.getCache());
    tree.setExpandsSelectedPaths(true);//from ww  w  . ja  v a 2s.  c  o m
    final JTree finalTree = tree;
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            if (selecting)
                return;
            TreePath[] paths = ((JTree) evt.getSource()).getSelectionPaths(); //evt.getPaths();
            chartInfo.updateChart(selectedObjects, pathsToList(paths));
        }

    });
    tree.setCellRenderer(new TreeRenderer());
    if (treeScrollPane == null)
        treeScrollPane = new JScrollPane(tree);
    else
        treeScrollPane.getViewport().add(tree);
}

From source file:com.enderville.enderinstaller.ui.Installer.java

@Override
public void valueChanged(TreeSelectionEvent e) {
    if (!e.isAddedPath()) {
        return;//from  www.  j  av  a 2 s  .c  om
    }
    TreePath path = e.getPath();
    CheckBoxTree tree = getModTree();
    if (e.getSource() == tree.getSelectionModel()) {
        DefaultMutableTreeNode last = (DefaultMutableTreeNode) path.getLastPathComponent();
        loadModDescription(last.getUserObject().toString());
    } else if (e.getSource() == tree.getCheckBoxTreeSelectionModel()) {
        getPresetDropdown().setSelectedItem(PRESET_CUSTOM);
    }
}