JAL-2388 New rendering code, extensions to support hiding hidden cols
[jalview.git] / src / jalview / viewmodel / OverviewDimensions.java
1 package jalview.viewmodel;
2
3 import jalview.datamodel.AlignmentColsCollection;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.AlignmentRowsCollection;
6 import jalview.datamodel.ColumnSelection;
7 import jalview.datamodel.HiddenSequences;
8
9 import java.awt.Graphics;
10
11 public abstract class OverviewDimensions
12 {
13
14   private static final int DEFAULT_GRAPH_HEIGHT = 20;
15   protected static final int MAX_WIDTH = 400;
16   protected static final int MIN_WIDTH = 120;
17   protected static final int MIN_SEQ_HEIGHT = 40;
18   protected static final int MAX_SEQ_HEIGHT = 300;
19   protected int width;
20   protected int sequencesHeight;
21   protected int graphHeight = DEFAULT_GRAPH_HEIGHT;
22   protected int boxX = -1;
23   protected int boxY = -1;
24   protected int boxWidth = -1;
25   protected int boxHeight = -1;
26   protected int scrollCol = -1;
27   protected int scrollRow = -1;
28
29   public OverviewDimensions(ViewportRanges ranges,
30           boolean showAnnotationPanel)
31   {
32     // scale the initial size of overviewpanel to shape of alignment
33     float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
34             / (float) ranges.getAbsoluteAlignmentHeight();
35
36     if (!showAnnotationPanel)
37     {
38       graphHeight = 0;
39     }
40
41     if (ranges.getAbsoluteAlignmentWidth() > ranges
42             .getAbsoluteAlignmentHeight())
43     {
44       // wider
45       width = MAX_WIDTH;
46       sequencesHeight = Math.round(MAX_WIDTH / initialScale);
47       if (sequencesHeight < MIN_SEQ_HEIGHT)
48       {
49         sequencesHeight = MIN_SEQ_HEIGHT;
50       }
51     }
52     else
53     {
54       // taller
55       width = Math.round(MAX_WIDTH * initialScale);
56       sequencesHeight = MAX_SEQ_HEIGHT;
57
58       if (width < MIN_WIDTH)
59       {
60         width = MIN_WIDTH;
61       }
62     }
63   }
64
65   /**
66    * Draw the overview panel's viewport box on a graphics object
67    * 
68    * @param g
69    *          the graphics object to draw on
70    */
71   public void drawBox(Graphics g)
72   {
73     g.drawRect(boxX, boxY, boxWidth, boxHeight);
74     g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
75   }
76
77   public int getScrollCol()
78   {
79     return scrollCol;
80   }
81
82   public int getScrollRow()
83   {
84     return scrollRow;
85   }
86
87   public int getBoxX()
88   {
89     return boxX;
90   }
91
92   public int getBoxY()
93   {
94     return boxY;
95   }
96
97   public int getBoxWidth()
98   {
99     return boxWidth;
100   }
101
102   public int getBoxHeight()
103   {
104     return boxHeight;
105   }
106
107   public void setWidth(int w)
108   {
109     width = w;
110   }
111
112   public void setHeight(int h)
113   {
114     sequencesHeight = h - graphHeight;
115   }
116
117   public int getWidth()
118   {
119     return width;
120   }
121
122   public int getHeight()
123   {
124     return sequencesHeight + graphHeight;
125   }
126
127   public int getSequencesHeight()
128   {
129     return sequencesHeight;
130   }
131
132   public int getGraphHeight()
133   {
134     return graphHeight;
135   }
136
137   public abstract void updateViewportFromMouse(int mousex, int mousey,
138           HiddenSequences hiddenSeqs, ColumnSelection hiddenCols,
139           ViewportRanges ranges);
140
141   public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
142           ColumnSelection hiddenCols, ViewportRanges ranges);
143
144   public abstract AlignmentColsCollection getColumns(
145           ViewportRanges ranges, ColumnSelection hiddenCols);
146
147   public abstract AlignmentRowsCollection getRows(
148           ViewportRanges ranges, AlignmentI al);
149
150   public abstract float getPixelsPerCol();
151
152   public abstract float getPixelsPerSeq();
153 }