Debian Codegraph @

src/dr/app/beauti/alignmentviewer/AlignmentViewer.java

raw symbols SCIP
1 /*
2 * AlignmentViewer.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Andrew Rambaut
35 * @version $Id: AlignmentViewer.java,v 1.2 2005/11/11 16:40:41 rambaut Exp $
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 /** Creates new AlignmentPanel */
53 public AlignmentViewer() {
54 this(null);
55 }
56
57 /** Creates new AlignmentPanel */
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 // This is used for drag-to-scroll in combination with mouseDragged
108 // in the MouseMotionListener, below.
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 // Calculate how far the mouse has been dragged from the point clicked in
120 // mousePressed, above.
121 int deltaX = mouseEvent.getX() - dragPoint.x;
122 int deltaY = mouseEvent.getY() - dragPoint.y;
123
124 // Get the currently visible window
125 Rectangle visRect = alignmentPane.getVisibleRect();
126
127 // Calculate how much we need to scroll
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 // Scroll the visible region
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 }