Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package jalview.jbgui

File GSplitFrame.java

 

Coverage histogram

../../img/srcFileCovDistChart5.png
33% of files have more coverage

Code metrics

16
46
11
1
227
126
19
0.41
4.18
11
1.73

Classes

Class Line # Actions
GSplitFrame 34 46 19
0.4246575242.5%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.jbgui;
22   
23    import java.awt.Component;
24    import java.awt.MouseInfo;
25    import java.awt.Point;
26    import java.awt.Rectangle;
27   
28    import javax.swing.JInternalFrame;
29    import javax.swing.JSplitPane;
30    import javax.swing.plaf.basic.BasicInternalFrameUI;
31   
32    import jalview.util.Platform;
33   
 
34    public class GSplitFrame extends JInternalFrame
35    {
36    protected static final int DIVIDER_SIZE = 5;
37   
38    private static final long serialVersionUID = 1L;
39   
40    private GAlignFrame topFrame;
41   
42    private GAlignFrame bottomFrame;
43   
44    private JSplitPane splitPane;
45   
46    /*
47    * proportional position of split divider; saving this allows it to be
48    * restored after hiding one half and resizing
49    */
50    private double dividerRatio;
51   
52    /**
53    * Constructor
54    *
55    * @param top
56    * @param bottom
57    */
 
58  1 toggle public GSplitFrame(GAlignFrame top, GAlignFrame bottom)
59    {
60  1 setFrameIcon(null);
61  1 setName("jalview-splitframe");
62  1 this.topFrame = top;
63  1 this.bottomFrame = bottom;
64   
65  1 hideTitleBars();
66   
67  1 addSplitPane();
68    }
69   
70    /**
71    * Create and add the split pane containing the top and bottom components.
72    */
 
73  1 toggle protected void addSplitPane()
74    {
75  1 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topFrame,
76    bottomFrame);
77  1 splitPane.setVisible(true);
78   
79    /*
80    * set divider split at 50:50, or restore saved split if loading from
81    * project
82    */
83  1 int topFrameHeight = topFrame.getHeight();
84  1 splitPane.setDividerSize(DIVIDER_SIZE);
85  1 if (topFrameHeight == 0)
86    {
87  0 setRelativeDividerLocation(0.5d); // as a proportion
88    }
89    else
90    {
91  1 int dividerPosition = topFrameHeight + DIVIDER_SIZE / 2;
92  1 splitPane.setDividerLocation(dividerPosition); // absolute position
93    }
94  1 splitPane.setResizeWeight(0.5d);
95  1 add(splitPane);
96    }
97   
98    /**
99    * Try to hide the title bars as a waste of precious space.
100    *
101    * @see http
102    * ://stackoverflow.com/questions/7218971/java-method-works-on-windows
103    * -but-not-macintosh -java
104    */
 
105  1 toggle protected void hideTitleBars()
106    {
107  1 if (Platform.isAMacAndNotJS())
108    {
109    // this saves some space - but doesn't hide the title bar
110  0 topFrame.putClientProperty("JInternalFrame.isPalette", true);
111    // topFrame.getRootPane().putClientProperty("Window.style", "small");
112  0 bottomFrame.putClientProperty("JInternalFrame.isPalette", true);
113    }
114    else
115    {
116  1 ((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null);
117  1 ((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null);
118    }
119    }
120   
 
121  24 toggle public GAlignFrame getTopFrame()
122    {
123  24 return topFrame;
124    }
125   
 
126  21 toggle public GAlignFrame getBottomFrame()
127    {
128  21 return bottomFrame;
129    }
130   
131    /**
132    * Returns the split pane component the mouse is in, or null if neither.
133    *
134    * @return
135    */
 
136  0 toggle protected GAlignFrame getFrameAtMouse()
137    {
138  0 Point loc = MouseInfo.getPointerInfo().getLocation();
139   
140  0 if (isIn(loc, splitPane.getTopComponent()))
141    {
142  0 return getTopFrame();
143    }
144  0 else if (isIn(loc, splitPane.getBottomComponent()))
145    {
146  0 return getBottomFrame();
147    }
148  0 return null;
149    }
150   
 
151  0 toggle private boolean isIn(Point loc, Component comp)
152    {
153  0 if (!comp.isVisible())
154    {
155  0 return false;
156    }
157  0 Point p = comp.getLocationOnScreen();
158  0 Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(),
159    comp.getHeight());
160  0 return r.contains(loc);
161    }
162   
163    /**
164    * Makes the complement of the specified split component visible or hidden,
165    * restoring or saving the position of the split divide.
166    */
 
167  0 toggle public void setComplementVisible(Object alignFrame, boolean show)
168    {
169    /*
170    * save divider ratio on hide, restore on show
171    */
172  0 if (show)
173    {
174  0 setRelativeDividerLocation(dividerRatio);
175    }
176    else
177    {
178  0 this.dividerRatio = splitPane.getDividerLocation()
179    / (double) (splitPane.getHeight()
180    - splitPane.getDividerSize());
181    }
182   
183  0 if (alignFrame == this.topFrame)
184    {
185  0 this.bottomFrame.setVisible(show);
186    }
187  0 else if (alignFrame == this.bottomFrame)
188    {
189  0 this.topFrame.setVisible(show);
190    }
191   
192  0 validate();
193    }
194   
195    /**
196    * Set the divider location as a proportion (0 <= r <= 1) of the height <br>
197    * Warning: this overloads setDividerLocation(int), and getDividerLocation()
198    * returns the int (pixel count) value
199    *
200    * @param r
201    */
 
202  0 toggle public void setRelativeDividerLocation(double r)
203    {
204  0 this.dividerRatio = r;
205  0 splitPane.setDividerLocation(r);
206    }
207   
208    /**
209    * Sets the divider location (in pixels from top)
210    *
211    * @return
212    */
 
213  1 toggle protected void setDividerLocation(int p)
214    {
215  1 splitPane.setDividerLocation(p);
216    }
217   
218    /**
219    * Returns the divider location (in pixels from top)
220    *
221    * @return
222    */
 
223  1 toggle protected int getDividerLocation()
224    {
225  1 return splitPane.getDividerLocation();
226    }
227    }