Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File AquaInternalFrameManager.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

28
52
10
1
258
141
27
0.52
5.2
10
2.7

Classes

Class Line # Actions
AquaInternalFrameManager 65 52 27
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation. Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10    *
11    * This code is distributed in the hope that it will be useful, but WITHOUT
12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13    * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14    * version 2 for more details (a copy is included in the LICENSE file that
15    * accompanied this code).
16    *
17    * You should have received a copy of the GNU General Public License version
18    * 2 along with this work; if not, write to the Free Software Foundation,
19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20    *
21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22    * or visit www.oracle.com if you need additional information or have any
23    * questions.
24    */
25   
26    package jalview.gui;
27   
28    import java.awt.Container;
29    import java.beans.PropertyVetoException;
30    import java.util.Vector;
31   
32    import javax.swing.DefaultDesktopManager;
33    import javax.swing.DesktopManager;
34    import javax.swing.JInternalFrame;
35   
36    /**
37    * Based on AquaInternalFrameManager
38    *
39    * DesktopManager implementation for Aqua
40    *
41    * Mac is more like Windows than it's like Motif/Basic
42    *
43    * From WindowsDesktopManager:
44    *
45    * This class implements a DesktopManager which more closely follows the MDI
46    * model than the DefaultDesktopManager. Unlike the DefaultDesktopManager
47    * policy, MDI requires that the selected and activated child frames are the
48    * same, and that that frame always be the top-most window.
49    * <p>
50    * The maximized state is managed by the DesktopManager with MDI, instead of
51    * just being a property of the individual child frame. This means that if the
52    * currently selected window is maximized and another window is selected, that
53    * new window will be maximized.
54    *
55    * Downloaded from
56    * https://raw.githubusercontent.com/frohoff/jdk8u-jdk/master/src/macosx/classes/com/apple/laf/AquaInternalFrameManager.java
57    *
58    * Patch from Jim Procter - when the most recently opened frame is closed,
59    * correct behaviour is to go to the next most recent frame, rather than wrap
60    * around to the bottom of the window stack (as the original implementation
61    * does)
62    *
63    * see com.sun.java.swing.plaf.windows.WindowsDesktopManager
64    */
 
65    public class AquaInternalFrameManager extends DefaultDesktopManager
66    {
67    // Variables
68   
69    /* The frame which is currently selected/activated.
70    * We store this value to enforce Mac's single-selection model.
71    */
72    JInternalFrame fCurrentFrame;
73   
74    JInternalFrame fInitialFrame;
75   
76    /* The list of frames, sorted by order of creation.
77    * This list is necessary because by default the order of
78    * child frames in the JDesktopPane changes during frame
79    * activation (the activated frame is moved to index 0).
80    * We preserve the creation order so that "next" and "previous"
81    * frame actions make sense.
82    */
83    Vector<JInternalFrame> fChildFrames = new Vector<>(1);
84   
85    /**
86    * keep a reference to the original LAF manager so we can iconise/de-iconise
87    * correctly
88    */
89    private DesktopManager ourManager;
90   
 
91  0 toggle public AquaInternalFrameManager(DesktopManager desktopManager)
92    {
93  0 ourManager = desktopManager;
94    }
95   
 
96  0 toggle @Override
97    public void closeFrame(final JInternalFrame f)
98    {
99  0 if (f == fCurrentFrame)
100    {
101  0 boolean mostRecentFrame = fChildFrames
102    .indexOf(f) == fChildFrames.size() - 1;
103  0 if (!mostRecentFrame)
104    {
105  0 activateNextFrame();
106    }
107    else
108    {
109  0 activatePreviousFrame();
110    }
111    }
112  0 fChildFrames.removeElement(f);
113  0 super.closeFrame(f);
114    }
115   
 
116  0 toggle @Override
117    public void deiconifyFrame(final JInternalFrame f)
118    {
119  0 JInternalFrame.JDesktopIcon desktopIcon;
120   
121  0 desktopIcon = f.getDesktopIcon();
122    // If the icon moved, move the frame to that spot before expanding it
123    // reshape does delta checks for us
124  0 f.reshape(desktopIcon.getX(), desktopIcon.getY(), f.getWidth(),
125    f.getHeight());
126  0 ourManager.deiconifyFrame(f);
127    }
128   
 
129  0 toggle void addIcon(final Container c,
130    final JInternalFrame.JDesktopIcon desktopIcon)
131    {
132  0 c.add(desktopIcon);
133    }
134   
135    /**
136    * Removes the frame from its parent and adds its desktopIcon to the parent.
137    */
 
138  0 toggle @Override
139    public void iconifyFrame(final JInternalFrame f)
140    {
141  0 ourManager.iconifyFrame(f);
142    }
143   
144    // WindowsDesktopManager code
 
145  0 toggle @Override
146    public void activateFrame(final JInternalFrame f)
147    {
148  0 try
149    {
150  0 if (f != null)
151    {
152  0 super.activateFrame(f);
153    }
154   
155    // add or relocate to top of stack
156  0 if (fChildFrames.indexOf(f) != -1)
157    {
158  0 fChildFrames.remove(f);
159    }
160  0 fChildFrames.addElement(f);
161   
162  0 if (fCurrentFrame != null && f != fCurrentFrame)
163    {
164  0 if (fCurrentFrame.isSelected())
165    {
166  0 fCurrentFrame.setSelected(false);
167    }
168    }
169   
170  0 if (f != null && !f.isSelected())
171    {
172  0 f.setSelected(true);
173    }
174   
175  0 fCurrentFrame = f;
176    } catch (final PropertyVetoException e)
177    {
178    }
179    }
180   
 
181  0 toggle private void switchFrame(final boolean next)
182    {
183  0 if (fCurrentFrame == null)
184    {
185    // initialize first frame we find
186  0 if (fInitialFrame != null)
187    {
188  0 activateFrame(fInitialFrame);
189    }
190  0 return;
191    }
192   
193  0 final int count = fChildFrames.size();
194  0 if (count <= 1)
195    {
196    // No other child frames.
197  0 return;
198    }
199   
200  0 final int currentIndex = fChildFrames.indexOf(fCurrentFrame);
201  0 if (currentIndex == -1)
202    {
203    // the "current frame" is no longer in the list
204  0 fCurrentFrame = null;
205  0 return;
206    }
207   
208  0 int nextIndex;
209  0 if (next)
210    {
211  0 nextIndex = currentIndex + 1;
212  0 if (nextIndex == count)
213    {
214  0 nextIndex = 0;
215    }
216    }
217    else
218    {
219  0 nextIndex = currentIndex - 1;
220  0 if (nextIndex == -1)
221    {
222  0 nextIndex = count - 1;
223    }
224    }
225  0 final JInternalFrame f = fChildFrames.elementAt(nextIndex);
226  0 activateFrame(f);
227  0 fCurrentFrame = f;
228    }
229   
230    /**
231    * Activate the next child JInternalFrame, as determined by the frames'
232    * Z-order. If there is only one child frame, it remains activated. If there
233    * are no child frames, nothing happens.
234    */
 
235  0 toggle public void activateNextFrame()
236    {
237  0 switchFrame(true);
238    }
239   
240    /**
241    * same as above but will activate a frame if none have been selected
242    */
 
243  0 toggle public void activateNextFrame(final JInternalFrame f)
244    {
245  0 fInitialFrame = f;
246  0 switchFrame(true);
247    }
248   
249    /**
250    * Activate the previous child JInternalFrame, as determined by the frames'
251    * Z-order. If there is only one child frame, it remains activated. If there
252    * are no child frames, nothing happens.
253    */
 
254  0 toggle public void activatePreviousFrame()
255    {
256  0 switchFrame(false);
257    }
258    }