File Source: MDIBar.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.MDIBar__static_init
*/
1 /*
2 *
3 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 package com.dmdirc.addons.ui_swing.components;
25
26 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27 import com.dmdirc.FrameContainer;
28 import com.dmdirc.config.ConfigManager;
29 import com.dmdirc.config.IdentityManager;
30 import com.dmdirc.interfaces.ConfigChangeListener;
31 import com.dmdirc.ui.IconManager;
32 import com.dmdirc.ui.WindowManager;
33 import com.dmdirc.ui.interfaces.FrameManager;
34 import com.dmdirc.ui.interfaces.Window;
35 import com.dmdirc.addons.ui_swing.MainFrame;
36 import com.dmdirc.addons.ui_swing.UIUtilities;
37
38 import com.dmdirc.interfaces.SelectionListener;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.beans.PropertyChangeEvent;
42 import java.beans.PropertyChangeListener;
43
44 import javax.swing.JComponent;
45 import javax.swing.JInternalFrame;
46 import javax.swing.JPanel;
47
48 import net.miginfocom.swing.MigLayout;
49
50 /**
51 * Provides an MDI style bar for restore/minimise/close.
52 */
/*
P/P * Method: String access$100(MDIBar)
*
* Preconditions:
* x0 != null
* init'ed(x0.visibility)
*
* Postconditions:
* return_value == x0.visibility
* init'ed(return_value)
*/
53 public class MDIBar extends JPanel implements FrameManager, SelectionListener,
54 PropertyChangeListener, ActionListener, ConfigChangeListener {
55
56 private static final long serialVersionUID = -8028057596226636245L;
57 private static final int ICON_SIZE = 12;
58 private NoFocusButton closeButton;
59 private NoFocusButton minimiseButton;
60 private NoFocusButton restoreButton;
61 private MainFrame mainFrame;
62 private ConfigManager config;
63 private String visibility;
64 /** Active frame. */
65 private Window activeFrame;
66
67 /**
68 * Instantiates a new MDI bar.
69 *
70 * @param mainFrame Main frame instance
71 */
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.MDIBar(MainFrame)
*
* Presumptions:
* com.dmdirc.config.IdentityManager:getGlobalConfig(...)@74 != null
* com.dmdirc.ui.IconManager:getIconManager(...)@77 != null
* com.dmdirc.ui.IconManager:getIconManager(...)@79 != null
* com.dmdirc.ui.IconManager:getIconManager(...)@81 != null
*
* Postconditions:
* this.closeButton == &new NoFocusButton(MDIBar#1)
* this.config != null
* this.mainFrame == mainFrame
* init'ed(this.mainFrame)
* this.minimiseButton == &new NoFocusButton(MDIBar#2)
* this.restoreButton == &new NoFocusButton(MDIBar#3)
* init'ed(this.visibility)
* new NoFocusButton(MDIBar#1) num objects == 1
* new NoFocusButton(MDIBar#2) num objects == 1
* new NoFocusButton(MDIBar#3) num objects == 1
*/
72 public MDIBar(final MainFrame mainFrame) {
73 this.mainFrame = mainFrame;
74 this.config = IdentityManager.getGlobalConfig();
75 visibility = config.getOption("ui", "mdiBarVisibility");
76
77 closeButton = new NoFocusButton(IconManager.getIconManager().
78 getScaledIcon("close-12", ICON_SIZE, ICON_SIZE));
79 minimiseButton = new NoFocusButton(IconManager.getIconManager().
80 getScaledIcon("minimise-12", ICON_SIZE, ICON_SIZE));
81 restoreButton = new NoFocusButton(IconManager.getIconManager().
82 getScaledIcon("maximise-12", ICON_SIZE, ICON_SIZE));
83
84 setOpaque(false);
85 setLayout(new MigLayout("hmax 17, ins 1 0 0 0, fill"));
86 add(minimiseButton, "w 17!, h 17!, right");
87 add(restoreButton, "w 17!, h 17!, right");
88 add(closeButton, "w 17!, h 17!, right");
89
90
91 WindowManager.addFrameManager(this);
92 WindowManager.addSelectionListener(this);
93 closeButton.addActionListener(this);
94 minimiseButton.addActionListener(this);
95 restoreButton.addActionListener(this);
96 config.addChangeListener("ui", "mdiBarVisibility", this);
97
98 check();
99 }
100
101 /** {@inheritDoc} */
102 @Override
103 public void setEnabled(final boolean enabled) {
/*
P/P * Method: void setEnabled(bool)
*
* Preconditions:
* this.closeButton != null
* this.minimiseButton != null
* this.restoreButton != null
*/
104 closeButton.setEnabled(enabled);
105 minimiseButton.setEnabled(enabled);
106 restoreButton.setEnabled(enabled);
107 }
108
109 private void check() {
/*
P/P * Method: void check()
*/
110 UIUtilities.invokeLater(new Runnable() {
111
112 @Override
113 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* init'ed(this.mainFrame)
* (soft) this.closeButton != null
* (soft) this.mainFrame.desktopPane != null
* (soft) this.minimiseButton != null
* (soft) this.restoreButton != null
* (soft) init'ed(this.visibility)
*
* Presumptions:
* javax.swing.JDesktopPane:getAllFrames(...)@119 != null
* javax.swing.JDesktopPane:getAllFrames(...)@126 != null
*
* Test Vectors:
* this.mainFrame: Inverse{null}, Addr_Set{null}
* java.lang.String:equalsIgnoreCase(...)@118: {0}, {1}
* java.lang.String:equalsIgnoreCase(...)@120: {0}, {1}
* java.lang.String:equalsIgnoreCase(...)@122: {0}, {1}
*/
114 boolean show = true;
115 if (mainFrame == null) {
116 show = false;
117 return;
118 } else if ("alwaysShow".equalsIgnoreCase(visibility)) {
119 show = mainFrame.getDesktopPane().getAllFrames().length > 0;
120 } else if ("neverShow".equalsIgnoreCase(visibility)) {
121 show = false;
122 } else if ("showWhenMaximised".equalsIgnoreCase(visibility)) {
123 show = mainFrame.getMaximised();
124 }
125 setVisible(show);
126 setEnabled(mainFrame.getDesktopPane().getAllFrames().length > 0);
127 }
128 });
129 }
130
131 /** {@inheritDoc} */
132 @Override
133 public void setParent(final JComponent parent) {
134 //Ignore
/*
P/P * Method: void setParent(JComponent)
*/
135 }
136
137 /** {@inheritDoc} */
138 @Override
139 public boolean canPositionVertically() {
/*
P/P * Method: bool canPositionVertically()
*
* Postconditions:
* return_value == 1
*/
140 return true;
141 }
142
143 /** {@inheritDoc} */
144 @Override
145 public boolean canPositionHorizontally() {
/*
P/P * Method: bool canPositionHorizontally()
*
* Postconditions:
* return_value == 1
*/
146 return true;
147 }
148
149 /** {@inheritDoc} */
150 @Override
151 public void addWindow(final FrameContainer window) {
/*
P/P * Method: void addWindow(FrameContainer)
*
* Preconditions:
* window != null
*
* Presumptions:
* com.dmdirc.FrameContainer:getFrame(...)@153 != null
*/
152 if (window.getFrame() instanceof JInternalFrame) {
153 ((JInternalFrame) window.getFrame()).addPropertyChangeListener(
154 "maximum", this);
155 }
156 check();
157 }
158
159 /** {@inheritDoc} */
160 @Override
161 public void delWindow(final FrameContainer window) {
/*
P/P * Method: void delWindow(FrameContainer)
*
* Preconditions:
* window != null
*
* Presumptions:
* com.dmdirc.FrameContainer:getFrame(...)@163 != null
*/
162 if (window.getFrame() instanceof JInternalFrame) {
163 ((JInternalFrame) window.getFrame()).removePropertyChangeListener(
164 this);
165 }
166 check();
167 }
168
169 /** {@inheritDoc} */
170 @Override
171 public void addWindow(final FrameContainer parent,
172 final FrameContainer window) {
/*
P/P * Method: void addWindow(FrameContainer, FrameContainer)
*
* Preconditions:
* window != null
*/
173 addWindow(window);
174 }
175
176 /** {@inheritDoc} */
177 @Override
178 public void delWindow(final FrameContainer parent,
179 final FrameContainer window) {
/*
P/P * Method: void delWindow(FrameContainer, FrameContainer)
*
* Preconditions:
* window != null
*/
180 delWindow(window);
181 }
182
183 /** {@inheritDoc} */
184 @Override
185 public void propertyChange(final PropertyChangeEvent evt) {
/*
P/P * Method: void propertyChange(PropertyChangeEvent)
*
* Preconditions:
* evt != null
* this.restoreButton != null
*
* Presumptions:
* com.dmdirc.ui.IconManager:getIconManager(...)@187 != null
* com.dmdirc.ui.IconManager:getIconManager(...)@190 != null
* java.beans.PropertyChangeEvent:getNewValue(...)@186 != null
*
* Test Vectors:
* java.lang.Boolean:booleanValue(...)@186: {0}, {1}
*/
186 if ((Boolean) evt.getNewValue()) {
187 restoreButton.setIcon(IconManager.getIconManager().getScaledIcon(
188 "restore-12", ICON_SIZE, ICON_SIZE));
189 } else {
190 restoreButton.setIcon(IconManager.getIconManager().getScaledIcon(
191 "maximise-12", ICON_SIZE, ICON_SIZE));
192 }
193 check();
194 }
195
196 /**
197 * {@inheritDoc}
198 *
199 * @param e Action event
200 */
201 @Override
202 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* init'ed(this.activeFrame)
* (soft) e != null
* (soft) this.closeButton != null
* (soft) this.minimiseButton != null
* (soft) this.restoreButton != null
*
* Test Vectors:
* this.activeFrame: Inverse{null}, Addr_Set{null}
* java.lang.Object:equals(...)@206: {0}, {1}
* java.lang.Object:equals(...)@208: {0}, {1}
* java.lang.Object:equals(...)@210: {0}, {1}
*/
203 if (activeFrame == null) {
204 return;
205 }
206 if (closeButton.equals(e.getSource())) {
207 activeFrame.close();
208 } else if (minimiseButton.equals(e.getSource())) {
209 ((TextFrame) activeFrame).minimise();
210 } else if (restoreButton.equals(e.getSource())) {
211 activeFrame.toggleMaximise();
212 }
213 }
214
215 /** {@inheritDoc} */
216 @Override
217 public void configChanged(final String domain, final String key) {
/*
P/P * Method: void configChanged(String, String)
*
* Preconditions:
* this.config != null
*
* Postconditions:
* init'ed(this.visibility)
*/
218 visibility = config.getOption("ui", "mdiBarVisibility");
219 check();
220 }
221
222 @Override
223 public void selectionChanged(Window window) {
/*
P/P * Method: void selectionChanged(Window)
*
* Postconditions:
* this.activeFrame == window
* init'ed(this.activeFrame)
*/
224 activeFrame = window;
225 }
226 }
SofCheck Inspector Build Version : 2.17854
| MDIBar.java |
2009-Jun-25 01:54:24 |
| MDIBar.class |
2009-Sep-02 17:04:15 |
| MDIBar$1.class |
2009-Sep-02 17:04:15 |