| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.gui.tree; |
| 27 |
|
| 28 |
import dr.evolution.tree.Tree; |
| 29 |
|
| 30 |
import javax.swing.*; |
| 31 |
import java.awt.*; |
| 32 |
import java.awt.event.ActionEvent; |
| 33 |
import java.awt.event.ActionListener; |
| 34 |
import java.util.ArrayList; |
| 35 |
|
| 36 |
public class JTreePanel extends JPanel { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private static final long serialVersionUID = 914666063619563914L; |
| 42 |
public JTreePanel(JTreeDisplay treeDisplay) { |
| 43 |
|
| 44 |
setOpaque(false); |
| 45 |
setLayout(new BorderLayout(0,0)); |
| 46 |
|
| 47 |
this.treeDisplay = treeDisplay; |
| 48 |
if (treeDisplay != null) { |
| 49 |
add(treeDisplay, BorderLayout.CENTER); |
| 50 |
} |
| 51 |
|
| 52 |
JToolBar toolBar = new JToolBar(); |
| 53 |
toolBar.setOpaque(true); |
| 54 |
toolBar.setBorder(BorderFactory.createCompoundBorder( |
| 55 |
BorderFactory.createMatteBorder(0,0,1,0,Color.gray), |
| 56 |
BorderFactory.createEmptyBorder(6,6,6,6))); |
| 57 |
|
| 58 |
Icon firstIcon = null; |
| 59 |
Icon prevIcon = null; |
| 60 |
Icon nextIcon = null; |
| 61 |
Icon lastIcon = null; |
| 62 |
try { |
| 63 |
firstIcon = new ImageIcon(dr.app.util.Utils.getImage(this, "/images/first.png")); |
| 64 |
prevIcon = new ImageIcon(dr.app.util.Utils.getImage(this, "/images/prev.png")); |
| 65 |
nextIcon = new ImageIcon(dr.app.util.Utils.getImage(this, "/images/next.png")); |
| 66 |
lastIcon = new ImageIcon(dr.app.util.Utils.getImage(this, "/images/last.png")); |
| 67 |
} catch (Exception e) { } |
| 68 |
|
| 69 |
|
| 70 |
firstButton = new JButton("First Tree"); |
| 71 |
firstButton.putClientProperty("JButton.buttonType", "toolbar"); |
| 72 |
firstButton.addActionListener(new ActionListener() { |
| 73 |
public void actionPerformed(ActionEvent e) { |
| 74 |
firstTree(); |
| 75 |
} |
| 76 |
}); |
| 77 |
firstButton.setOpaque(false); |
| 78 |
firstButton.setEnabled(true); |
| 79 |
|
| 80 |
|
| 81 |
prevButton = new JButton("Previous Tree"); |
| 82 |
prevButton.putClientProperty("JButton.buttonType", "toolbar"); |
| 83 |
prevButton.addActionListener(new ActionListener() { |
| 84 |
public void actionPerformed(ActionEvent e) { |
| 85 |
prevTree(); |
| 86 |
} |
| 87 |
}); |
| 88 |
prevButton.setOpaque(false); |
| 89 |
prevButton.setEnabled(true); |
| 90 |
|
| 91 |
|
| 92 |
nextButton = new JButton("Next Tree"); |
| 93 |
nextButton.putClientProperty("JButton.buttonType", "toolbar"); |
| 94 |
nextButton.addActionListener(new ActionListener() { |
| 95 |
public void actionPerformed(ActionEvent e) { |
| 96 |
nextTree(); |
| 97 |
} |
| 98 |
}); |
| 99 |
nextButton.setOpaque(false); |
| 100 |
nextButton.setEnabled(true); |
| 101 |
|
| 102 |
|
| 103 |
lastButton = new JButton("Last Tree"); |
| 104 |
lastButton.putClientProperty("JButton.buttonType", "toolbar"); |
| 105 |
lastButton.addActionListener(new ActionListener() { |
| 106 |
public void actionPerformed(ActionEvent e) { |
| 107 |
lastTree(); |
| 108 |
} |
| 109 |
}); |
| 110 |
lastButton.setOpaque(false); |
| 111 |
lastButton.setEnabled(true); |
| 112 |
|
| 113 |
statusField = new JLabel(); |
| 114 |
|
| 115 |
|
| 116 |
toolBar.add(firstButton); |
| 117 |
toolBar.add(prevButton); |
| 118 |
toolBar.add(nextButton); |
| 119 |
toolBar.add(lastButton); |
| 120 |
toolBar.add(new JToolBar.Separator()); |
| 121 |
toolBar.add(statusField); |
| 122 |
toolBar.add(new JToolBar.Separator()); |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
public void setTrees(ArrayList trees) { |
| 129 |
|
| 130 |
boolean isLast = (currentTree == this.trees.size() - 1); |
| 131 |
|
| 132 |
this.trees = trees; |
| 133 |
|
| 134 |
if (this.trees == null) { |
| 135 |
|
| 136 |
this.trees = new ArrayList(); |
| 137 |
} |
| 138 |
|
| 139 |
if (isLast) { |
| 140 |
currentTree = trees.size() - 1; |
| 141 |
} else { |
| 142 |
currentTree = 0; |
| 143 |
} |
| 144 |
|
| 145 |
showTree(currentTree); |
| 146 |
} |
| 147 |
|
| 148 |
public void firstTree() { |
| 149 |
currentTree = 0; |
| 150 |
showTree(currentTree); |
| 151 |
} |
| 152 |
|
| 153 |
public void nextTree() { |
| 154 |
if (currentTree < trees.size() - 1) { |
| 155 |
currentTree++; |
| 156 |
showTree(currentTree); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
public void prevTree() { |
| 161 |
if (currentTree > 0) { |
| 162 |
currentTree--; |
| 163 |
showTree(currentTree); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
public void lastTree() { |
| 168 |
currentTree = trees.size() - 1; |
| 169 |
showTree(currentTree); |
| 170 |
} |
| 171 |
|
| 172 |
public void showTree(int index) { |
| 173 |
if (index < 0 || index >= trees.size()) { |
| 174 |
treeDisplay.setTree(null); |
| 175 |
statusField.setText("0/0"); |
| 176 |
} else { |
| 177 |
treeDisplay.setTree((Tree)trees.get(index)); |
| 178 |
statusField.setText(Integer.toString(index+1) + "/" + Integer.toString(trees.size())); |
| 179 |
} |
| 180 |
repaint(); |
| 181 |
} |
| 182 |
|
| 183 |
private JTreeDisplay treeDisplay = null; |
| 184 |
private int currentTree = 0; |
| 185 |
private ArrayList trees = new ArrayList(); |
| 186 |
private JButton firstButton = null; |
| 187 |
private JButton prevButton = null; |
| 188 |
private JButton nextButton = null; |
| 189 |
private JButton lastButton = null; |
| 190 |
private JLabel statusField = null; |
| 191 |
} |