JAL-2388 Make sure resizing still works
[jalview.git] / src / jalview / viewmodel / OverviewDimensions.java
1 package jalview.viewmodel;
2
3 import jalview.api.AlignmentColsCollectionI;
4 import jalview.api.AlignmentRowsCollectionI;
5 import jalview.datamodel.AlignmentI;
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   protected int alwidth;
30
31   protected int alheight;
32
33   public OverviewDimensions(ViewportRanges ranges,
34           boolean showAnnotationPanel)
35   {
36     // scale the initial size of overviewpanel to shape of alignment
37     float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
38             / (float) ranges.getAbsoluteAlignmentHeight();
39
40     if (!showAnnotationPanel)
41     {
42       graphHeight = 0;
43     }
44
45     if (ranges.getAbsoluteAlignmentWidth() > ranges
46             .getAbsoluteAlignmentHeight())
47     {
48       // wider
49       width = MAX_WIDTH;
50       sequencesHeight = Math.round(MAX_WIDTH / initialScale);
51       if (sequencesHeight < MIN_SEQ_HEIGHT)
52       {
53         sequencesHeight = MIN_SEQ_HEIGHT;
54       }
55     }
56     else
57     {
58       // taller
59       width = Math.round(MAX_WIDTH * initialScale);
60       sequencesHeight = MAX_SEQ_HEIGHT;
61
62       if (width < MIN_WIDTH)
63       {
64         width = MIN_WIDTH;
65       }
66     }
67   }
68
69   /**
70    * Draw the overview panel's viewport box on a graphics object
71    * 
72    * @param g
73    *          the graphics object to draw on
74    */
75   public void drawBox(Graphics g)
76   {
77     g.drawRect(boxX, boxY, boxWidth, boxHeight);
78     g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
79   }
80
81   public int getScrollCol()
82   {
83     return scrollCol;
84   }
85
86   public int getScrollRow()
87   {
88     return scrollRow;
89   }
90
91   public int getBoxX()
92   {
93     return boxX;
94   }
95
96   public int getBoxY()
97   {
98     return boxY;
99   }
100
101   public int getBoxWidth()
102   {
103     return boxWidth;
104   }
105
106   public int getBoxHeight()
107   {
108     return boxHeight;
109   }
110
111   public int getWidth()
112   {
113     return width;
114   }
115
116   public int getHeight()
117   {
118     return sequencesHeight + graphHeight;
119   }
120
121   public int getSequencesHeight()
122   {
123     return sequencesHeight;
124   }
125
126   public int getGraphHeight()
127   {
128     return graphHeight;
129   }
130
131   public float getPixelsPerCol()
132   {
133     return (float) width / alwidth;
134   }
135
136   public float getPixelsPerSeq()
137   {
138     return (float) sequencesHeight / alheight;
139   }
140
141   public void setWidth(int w)
142   {
143     width = w;
144   }
145
146   public void setHeight(int h)
147   {
148     sequencesHeight = h - graphHeight;
149   }
150
151   public abstract void updateViewportFromMouse(int mousex, int mousey,
152           HiddenSequences hiddenSeqs, ColumnSelection hiddenCols,
153           ViewportRanges ranges);
154
155   public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
156           ColumnSelection hiddenCols, ViewportRanges ranges);
157
158   public abstract AlignmentColsCollectionI getColumns(
159           ViewportRanges ranges, ColumnSelection hiddenCols);
160
161   public abstract AlignmentRowsCollectionI getRows(
162           ViewportRanges ranges, AlignmentI al);
163 }