~ubuntu-branches/ubuntu/utopic/figtree/utopic

« back to all changes in this revision

Viewing changes to src/figtree/application/FigTreePanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-02-21 08:17:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110221081738-80pe2ulo8rg7up10
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package figtree.application;
 
2
 
 
3
import figtree.treeviewer.decorators.AttributableDecorator;
 
4
import jam.controlpalettes.ControlPalette;
 
5
import jam.disclosure.SlideOpenPanel;
 
6
import figtree.treeviewer.*;
 
7
import figtree.treeviewer.painters.*;
 
8
 
 
9
import javax.swing.*;
 
10
import java.awt.*;
 
11
 
 
12
/**
 
13
 * This is a panel that has a TreeViewer and a BasicControlPalette with
 
14
 * the default Controllers and Painters.
 
15
 *
 
16
 * @author Andrew Rambaut
 
17
 * @version $Id: FigTreePanel.java,v 1.13 2007/09/05 10:51:49 rambaut Exp $
 
18
 */
 
19
public class FigTreePanel extends JPanel {
 
20
 
 
21
    public FigTreePanel(JFrame frame, final ExtendedTreeViewer treeViewer, ControlPalette controlPalette) {
 
22
 
 
23
        this.treeViewer = treeViewer;
 
24
        this.controlPalette = controlPalette;
 
25
 
 
26
        controlPalette.getPanel().setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.GRAY));
 
27
        controlPalette.getPanel().setBackground(new Color(231, 237, 246));
 
28
        controlPalette.getPanel().setOpaque(true);
 
29
 
 
30
        treeViewerController = new TreeViewerController(treeViewer);
 
31
        controlPalette.addController(treeViewerController);
 
32
 
 
33
        controlPalette.addController(new MultipleTreesController(treeViewer));
 
34
 
 
35
        controlPalette.addController(new TreeAppearanceController(treeViewer, frame));
 
36
 
 
37
        treesController = new TreesController(treeViewer);
 
38
        controlPalette.addController(treesController);
 
39
 
 
40
        controlPalette.addController(new TimeScaleController(treeViewer));
 
41
 
 
42
        // Create a tip label painter and its controller
 
43
        final BasicLabelPainter tipLabelPainter = new BasicLabelPainter(BasicLabelPainter.PainterIntent.TIP);
 
44
        controlPalette.addController(new LabelPainterController("Tip Labels", "tipLabels", tipLabelPainter, frame));
 
45
        treeViewer.setTipLabelPainter(tipLabelPainter);
 
46
 
 
47
        // Create a node label painter and its controller
 
48
        final BasicLabelPainter nodeLabelPainter = new BasicLabelPainter(BasicLabelPainter.PainterIntent.NODE);
 
49
        nodeLabelPainter.setVisible(false);
 
50
        controlPalette.addController(new LabelPainterController("Node Labels", "nodeLabels", nodeLabelPainter, frame));
 
51
        treeViewer.setNodeLabelPainter(nodeLabelPainter);
 
52
 
 
53
        // Create a node shape painter and its controller
 
54
        final NodeBarPainter nodeBarPainter = new NodeBarPainter();
 
55
        nodeBarPainter.setForeground(new Color(24, 32, 228, 128));
 
56
        nodeBarPainter.setVisible(false);
 
57
        controlPalette.addController(new NodeBarController("Node Bars", nodeBarPainter));
 
58
        treeViewer.setNodeBarPainter(nodeBarPainter);
 
59
 
 
60
        // Create a branch label painter and its controller
 
61
        final BasicLabelPainter branchLabelPainter = new BasicLabelPainter(BasicLabelPainter.PainterIntent.BRANCH);
 
62
        branchLabelPainter.setVisible(false);
 
63
        controlPalette.addController(new LabelPainterController("Branch Labels", "branchLabels", branchLabelPainter, frame));
 
64
        treeViewer.setBranchLabelPainter(branchLabelPainter);
 
65
 
 
66
        // Create a scale controller
 
67
        final ScaleBarPainter scaleBarPainter = new ScaleBarPainter();
 
68
        scaleBarPainter.setVisible(true);
 
69
        controlPalette.addController(new ScaleBarPainterController(scaleBarPainter));
 
70
        treeViewer.addScalePainter(scaleBarPainter);
 
71
 
 
72
        // Create a scale axis controller
 
73
        final ScaleAxisPainter scaleAxisPainter = new ScaleAxisPainter();
 
74
        final ScaleGridPainter scaleGridPainter = new ScaleGridPainter();
 
75
        scaleAxisPainter.setVisible(false);
 
76
        scaleGridPainter.setVisible(false);
 
77
        controlPalette.addController(new ScaleAxisPainterController(scaleAxisPainter, scaleGridPainter));
 
78
        treeViewer.addScalePainter(scaleAxisPainter);
 
79
        treeViewer.setScaleGridPainter(scaleGridPainter);
 
80
 
 
81
        slideOpenPanel = new SlideOpenPanel(treeViewer);
 
82
 
 
83
        setLayout(new BorderLayout());
 
84
        add(slideOpenPanel, BorderLayout.CENTER);
 
85
        add(controlPalette.getPanel(), BorderLayout.WEST);
 
86
 
 
87
        treeViewer.addAnnotationsListener(new AnnotationsListener() {
 
88
            public void annotationsChanged() {
 
89
 
 
90
                tipLabelPainter.setupAttributes(treeViewer.getTrees());
 
91
                nodeLabelPainter.setupAttributes(treeViewer.getTrees());
 
92
                nodeBarPainter.setupAttributes(treeViewer.getTrees());
 
93
                branchLabelPainter.setupAttributes(treeViewer.getTrees());
 
94
            }
 
95
        });
 
96
    }
 
97
 
 
98
    public TreeViewer getTreeViewer() {
 
99
        return treeViewer;
 
100
    }
 
101
 
 
102
    public ControlPalette getControlPalette() {
 
103
        return controlPalette;
 
104
    }
 
105
 
 
106
    public void showUtilityPanel(JPanel utilityPanel) {
 
107
        if (utilityPanel == null) {
 
108
            return;
 
109
        }
 
110
                slideOpenPanel.showUtilityPanel(utilityPanel);
 
111
    }
 
112
 
 
113
        public void hideUtilityPanel() {
 
114
                slideOpenPanel.hideUtilityPanel();
 
115
        }
 
116
 
 
117
 
 
118
        public JPanel getUtilityPanel() {
 
119
                return slideOpenPanel.getUtilityPanel();
 
120
        }
 
121
 
 
122
    public void toggleMidpointRoot() {
 
123
        treesController.toggleMidpointRoot();
 
124
    }
 
125
 
 
126
    public void toggleIncreasingNodeOrder() {
 
127
        treesController.toggleIncreasingNodeOrder();
 
128
    }
 
129
 
 
130
    public void toggleDecreasingNodeOrder() {
 
131
        treesController.toggleDecreasingNodeOrder();
 
132
    }
 
133
 
 
134
    private final TreeViewer treeViewer;
 
135
    private final TreeViewerController treeViewerController;
 
136
    private final TreesController treesController;
 
137
    private final ControlPalette controlPalette;
 
138
    private final SlideOpenPanel slideOpenPanel;
 
139
}