| 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.beauti.alignmentviewer; |
| 27 |
|
| 28 |
import javax.swing.*; |
| 29 |
import java.awt.*; |
| 30 |
import java.awt.event.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class AlignmentViewer extends JPanel { |
| 38 |
private TaxonPane taxonPane; |
| 39 |
private JScrollPane taxonScrollPane; |
| 40 |
|
| 41 |
private RulerPane rulerPane; |
| 42 |
private JScrollPane rulerScrollPane; |
| 43 |
|
| 44 |
private PlotPane plotPane; |
| 45 |
private JScrollPane plotScrollPane; |
| 46 |
|
| 47 |
private AlignmentPane alignmentPane; |
| 48 |
private JScrollPane alignmentScrollPane; |
| 49 |
|
| 50 |
private JSplitPane splitPane; |
| 51 |
|
| 52 |
|
| 53 |
public AlignmentViewer() { |
| 54 |
this(null); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
public AlignmentViewer(PlotPane plotPane) { |
| 59 |
|
| 60 |
setOpaque(false); |
| 61 |
setMinimumSize(new Dimension(300,150)); |
| 62 |
setLayout(new BorderLayout(6,6)); |
| 63 |
|
| 64 |
taxonPane = new TaxonPane(); |
| 65 |
taxonScrollPane = new JScrollPane(taxonPane, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
| 66 |
taxonScrollPane.setBorder(null); |
| 67 |
|
| 68 |
JPanel leftPanel = new JPanel(new BorderLayout(6,6)); |
| 69 |
leftPanel.add(taxonScrollPane, BorderLayout.CENTER); |
| 70 |
JPanel emptyPanel = new JPanel(); |
| 71 |
emptyPanel.setPreferredSize(new Dimension(16, 16)); |
| 72 |
leftPanel.add(emptyPanel, BorderLayout.NORTH); |
| 73 |
|
| 74 |
rulerPane = new RulerPane(); |
| 75 |
rulerPane.setOpaque(false); |
| 76 |
rulerScrollPane = new JScrollPane(rulerPane, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 77 |
rulerScrollPane.setBorder(null); |
| 78 |
|
| 79 |
alignmentPane = new AlignmentPane(taxonPane, rulerPane); |
| 80 |
alignmentScrollPane = new JScrollPane(alignmentPane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
| 81 |
alignmentScrollPane.setBorder(null); |
| 82 |
|
| 83 |
taxonScrollPane.getVerticalScrollBar().setModel(alignmentScrollPane.getVerticalScrollBar().getModel()); |
| 84 |
rulerScrollPane.getHorizontalScrollBar().setModel(alignmentScrollPane.getHorizontalScrollBar().getModel()); |
| 85 |
|
| 86 |
JPanel rightPanel = new JPanel(new BorderLayout(6,6)); |
| 87 |
rightPanel.add(alignmentScrollPane, BorderLayout.CENTER); |
| 88 |
rightPanel.add(rulerScrollPane, BorderLayout.NORTH); |
| 89 |
|
| 90 |
if (plotPane != null) { |
| 91 |
plotScrollPane = new JScrollPane(plotPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 92 |
plotScrollPane.getHorizontalScrollBar().setModel(alignmentScrollPane.getHorizontalScrollBar().getModel()); |
| 93 |
rightPanel.add(plotScrollPane, BorderLayout.SOUTH); |
| 94 |
} |
| 95 |
|
| 96 |
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); |
| 97 |
splitPane.setDividerLocation(120); |
| 98 |
|
| 99 |
add(splitPane, BorderLayout.CENTER); |
| 100 |
|
| 101 |
|
| 102 |
alignmentPane.addMouseListener(new MouseAdapter() { |
| 103 |
public void mouseClicked(MouseEvent mouseEvent) { |
| 104 |
} |
| 105 |
|
| 106 |
public void mousePressed(MouseEvent mouseEvent) { |
| 107 |
|
| 108 |
|
| 109 |
dragPoint = mouseEvent.getPoint(); |
| 110 |
} |
| 111 |
|
| 112 |
}); |
| 113 |
|
| 114 |
alignmentPane.addMouseMotionListener(new MouseMotionAdapter() { |
| 115 |
public void mouseMoved(MouseEvent mouseEvent) { |
| 116 |
} |
| 117 |
|
| 118 |
public void mouseDragged(MouseEvent mouseEvent) { |
| 119 |
|
| 120 |
|
| 121 |
int deltaX = mouseEvent.getX() - dragPoint.x; |
| 122 |
int deltaY = mouseEvent.getY() - dragPoint.y; |
| 123 |
|
| 124 |
|
| 125 |
Rectangle visRect = alignmentPane.getVisibleRect(); |
| 126 |
|
| 127 |
|
| 128 |
if (deltaX > 0) { |
| 129 |
deltaX = visRect.x - deltaX; |
| 130 |
} else { |
| 131 |
deltaX = visRect.x + visRect.width - deltaX; |
| 132 |
} |
| 133 |
|
| 134 |
if (deltaY > 0) { |
| 135 |
deltaY = visRect.y - deltaY; |
| 136 |
} else { |
| 137 |
deltaY = visRect.y + visRect.height - deltaY; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
Rectangle r = new Rectangle(deltaX, deltaY, 1, 1); |
| 142 |
alignmentPane.scrollRectToVisible(r); |
| 143 |
} |
| 144 |
}); |
| 145 |
} |
| 146 |
|
| 147 |
public void setAlignmentBuffer(AlignmentBuffer alignmentBuffer) { |
| 148 |
rulerPane.setAlignmentBuffer(alignmentBuffer); |
| 149 |
taxonPane.setAlignmentBuffer(alignmentBuffer); |
| 150 |
alignmentPane.setAlignmentBuffer(alignmentBuffer); |
| 151 |
} |
| 152 |
|
| 153 |
public void setRowDecorator(RowDecorator rowDecorator) { |
| 154 |
alignmentPane.setRowDecorator(rowDecorator); |
| 155 |
} |
| 156 |
|
| 157 |
public void setColumnDecorator(ColumnDecorator columnDecorator) { |
| 158 |
alignmentPane.setColumnDecorator(columnDecorator); |
| 159 |
rulerPane.setColumnDecorator(columnDecorator); |
| 160 |
} |
| 161 |
|
| 162 |
public void setCellDecorator(CellDecorator cellDecorator) { |
| 163 |
alignmentPane.setCellDecorator(cellDecorator); |
| 164 |
} |
| 165 |
|
| 166 |
public void addHorizontalScrollbarListener(AdjustmentListener adjustmentListener) { |
| 167 |
alignmentScrollPane.getHorizontalScrollBar().addAdjustmentListener(adjustmentListener); |
| 168 |
} |
| 169 |
|
| 170 |
public void addVerticalScrollbarListener(AdjustmentListener adjustmentListener) { |
| 171 |
alignmentScrollPane.getVerticalScrollBar().addAdjustmentListener(adjustmentListener); |
| 172 |
} |
| 173 |
|
| 174 |
public void addComponentListener(ComponentListener componentListener) { |
| 175 |
alignmentScrollPane.addComponentListener(componentListener); |
| 176 |
} |
| 177 |
|
| 178 |
public Rectangle getTaxonPaneBounds() { |
| 179 |
return taxonScrollPane.getViewportBorderBounds(); |
| 180 |
} |
| 181 |
|
| 182 |
public Rectangle getAlignmentPaneBounds() { |
| 183 |
return alignmentScrollPane.getViewportBorderBounds(); |
| 184 |
} |
| 185 |
|
| 186 |
public Rectangle getVisibleArea() { |
| 187 |
return alignmentPane.getVisibleArea(); |
| 188 |
} |
| 189 |
|
| 190 |
public void setTopRow(int row) { |
| 191 |
alignmentPane.setTopRow(row); |
| 192 |
} |
| 193 |
|
| 194 |
public void setLeftColumn(int col) { |
| 195 |
alignmentPane.setLeftColumn(col); |
| 196 |
} |
| 197 |
|
| 198 |
public void setCentreColumn(int col) { |
| 199 |
alignmentPane.setCentreColumn(col); |
| 200 |
} |
| 201 |
|
| 202 |
public void setRightColumn(int col) { |
| 203 |
alignmentPane.setRightColumn(col); |
| 204 |
} |
| 205 |
|
| 206 |
private Point dragPoint = null; |
| 207 |
} |