Search in sources :

Example 1 with TreePane

use of org.openlcb.swing.networktree.TreePane in project JMRI by JMRI.

the class NetworkTreePane method initComponents.

@Override
public void initComponents(CanSystemConnectionMemo memo) {
    this.memo = memo;
    memo.getTrafficController().addCanListener(this);
    // add GUI components
    setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
    treePane = new TreePane();
    treePane.setPreferredSize(new Dimension(300, 300));
    treePane.initComponents((MimicNodeStore) memo.get(MimicNodeStore.class), (Connection) memo.get(Connection.class), (NodeID) memo.get(NodeID.class), new ActionLoader(memo.get(OlcbInterface.class)));
    add(treePane);
    treePane.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            JTree tree = (JTree) e.getSource();
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            if (node.getUserObject() instanceof NodeTreeRep.SelectionKey) {
                ((NodeTreeRep.SelectionKey) node.getUserObject()).select(node);
            }
        }
    });
}
Also used : TreePane(org.openlcb.swing.networktree.TreePane) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NodeTreeRep(org.openlcb.swing.networktree.NodeTreeRep) TreeSelectionListener(javax.swing.event.TreeSelectionListener) Dimension(java.awt.Dimension) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 2 with TreePane

use of org.openlcb.swing.networktree.TreePane in project JMRI by JMRI.

the class TreePaneDemo method setUp.

@Before
public void setUp() throws Exception {
    store = new MimicNodeStore(connection, nid1);
    Message msg = new ProducerIdentifiedMessage(nid1, eventA, EventState.Unknown);
    store.put(msg, null);
    // build the TreePane, but don't put it in a frame (yet).
    pane = new TreePane();
    pane.initComponents(store, null, null, new NodeTreeRep.SelectionKeyLoader() {

        @Override
        public NodeTreeRep.SelectionKey cdiKey(String name, NodeID node) {
            return new NodeTreeRep.SelectionKey(name, node) {

                @Override
                public void select(DefaultMutableTreeNode rep) {
                    System.out.println("Making special fuss over: " + rep + " for " + name + " on " + node);
                }
            };
        }
    });
    if (GraphicsEnvironment.isHeadless()) {
        // don't bother setting up a frame in headless.
        return;
    }
    // Test is really popping a window before doing all else
    frame = new JFrame();
    frame.setTitle("TreePane Test");
    frame.add(pane);
    frame.pack();
    frame.setMinimumSize(new java.awt.Dimension(200, 200));
    frame.setVisible(true);
}
Also used : MimicNodeStore(org.openlcb.MimicNodeStore) SimpleNodeIdentInfoReplyMessage(org.openlcb.SimpleNodeIdentInfoReplyMessage) Message(org.openlcb.Message) ProducerIdentifiedMessage(org.openlcb.ProducerIdentifiedMessage) ProtocolIdentificationReplyMessage(org.openlcb.ProtocolIdentificationReplyMessage) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProducerIdentifiedMessage(org.openlcb.ProducerIdentifiedMessage) TreePane(org.openlcb.swing.networktree.TreePane) JFrame(javax.swing.JFrame) NodeTreeRep(org.openlcb.swing.networktree.NodeTreeRep) NodeID(org.openlcb.NodeID) Before(org.junit.Before)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 NodeTreeRep (org.openlcb.swing.networktree.NodeTreeRep)2 TreePane (org.openlcb.swing.networktree.TreePane)2 Dimension (java.awt.Dimension)1 JFrame (javax.swing.JFrame)1 JTree (javax.swing.JTree)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 Before (org.junit.Before)1 Message (org.openlcb.Message)1 MimicNodeStore (org.openlcb.MimicNodeStore)1 NodeID (org.openlcb.NodeID)1 ProducerIdentifiedMessage (org.openlcb.ProducerIdentifiedMessage)1 ProtocolIdentificationReplyMessage (org.openlcb.ProtocolIdentificationReplyMessage)1 SimpleNodeIdentInfoReplyMessage (org.openlcb.SimpleNodeIdentInfoReplyMessage)1