1 /*
2 * Copyright (c) 2002, 2010, 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
177 } else {
178 super.installDesktopManager();
179 }
180 }
181
182 /**
183 * {@inheritDoc}
184 */
185 @Override
186 protected void uninstallDesktopManager() {
187 if (oldDesktopManager != null && !(oldDesktopManager instanceof UIResource)) {
188 desktopManager = desktop.getDesktopManager();
189 if (desktopManager == null || desktopManager instanceof UIResource) {
190 desktop.setDesktopManager(oldDesktopManager);
191 }
192 }
193 oldDesktopManager = null;
194 super.uninstallDesktopManager();
195 }
196
197 static class TaskBar extends JPanel implements ComponentListener, ContainerListener {
198 TaskBar() {
199 setOpaque(true);
200 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0) {
201 public void layoutContainer(Container target) {
202 // First shrink buttons to fit
203 Component[] comps = target.getComponents();
204 int n = comps.length;
205 if (n > 0) {
206 // Start with the largest preferred width
207 int prefWidth = 0;
208 for (Component c : comps) {
209 c.setPreferredSize(null);
210 Dimension prefSize = c.getPreferredSize();
211 if (prefSize.width > prefWidth) {
212 prefWidth = prefSize.width;
213 }
214 }
215 // Shrink equally to fit if needed
216 Insets insets = target.getInsets();
304 if (getComponentCount() == 1) {
305 adjustSize();
306 }
307 }
308 }
309
310 public void componentRemoved(ContainerEvent e) {
311 if (e.getChild() instanceof JInternalFrame) {
312 JInternalFrame f = (JInternalFrame)e.getChild();
313 if (!f.isIcon()) {
314 // Frame was removed without using setClosed(true)
315 remove(f.getDesktopIcon());
316 f.removeComponentListener(this);
317 revalidate();
318 repaint();
319 }
320 }
321 }
322 }
323
324
325 class SynthDesktopManager extends DefaultDesktopManager implements UIResource {
326
327 public void maximizeFrame(JInternalFrame f) {
328 if (f.isIcon()) {
329 try {
330 f.setIcon(false);
331 } catch (PropertyVetoException e2) {
332 }
333 } else {
334 f.setNormalBounds(f.getBounds());
335 Component desktop = f.getParent();
336 setBoundsForFrame(f, 0, 0,
337 desktop.getWidth(),
338 desktop.getHeight() - taskBar.getHeight());
339 }
340
341 try {
342 f.setSelected(true);
343 } catch (PropertyVetoException e2) {
344 }
|
1 /*
2 * Copyright (c) 2002, 2014, 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
177 } else {
178 super.installDesktopManager();
179 }
180 }
181
182 /**
183 * {@inheritDoc}
184 */
185 @Override
186 protected void uninstallDesktopManager() {
187 if (oldDesktopManager != null && !(oldDesktopManager instanceof UIResource)) {
188 desktopManager = desktop.getDesktopManager();
189 if (desktopManager == null || desktopManager instanceof UIResource) {
190 desktop.setDesktopManager(oldDesktopManager);
191 }
192 }
193 oldDesktopManager = null;
194 super.uninstallDesktopManager();
195 }
196
197 @SuppressWarnings("serial") // Same-version serialization only and
198 // internal anonymous classes
199 static class TaskBar extends JPanel implements ComponentListener, ContainerListener {
200 TaskBar() {
201 setOpaque(true);
202 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0) {
203 public void layoutContainer(Container target) {
204 // First shrink buttons to fit
205 Component[] comps = target.getComponents();
206 int n = comps.length;
207 if (n > 0) {
208 // Start with the largest preferred width
209 int prefWidth = 0;
210 for (Component c : comps) {
211 c.setPreferredSize(null);
212 Dimension prefSize = c.getPreferredSize();
213 if (prefSize.width > prefWidth) {
214 prefWidth = prefSize.width;
215 }
216 }
217 // Shrink equally to fit if needed
218 Insets insets = target.getInsets();
306 if (getComponentCount() == 1) {
307 adjustSize();
308 }
309 }
310 }
311
312 public void componentRemoved(ContainerEvent e) {
313 if (e.getChild() instanceof JInternalFrame) {
314 JInternalFrame f = (JInternalFrame)e.getChild();
315 if (!f.isIcon()) {
316 // Frame was removed without using setClosed(true)
317 remove(f.getDesktopIcon());
318 f.removeComponentListener(this);
319 revalidate();
320 repaint();
321 }
322 }
323 }
324 }
325
326 @SuppressWarnings("serial") // Same-version serialization only
327 class SynthDesktopManager extends DefaultDesktopManager implements UIResource {
328
329 public void maximizeFrame(JInternalFrame f) {
330 if (f.isIcon()) {
331 try {
332 f.setIcon(false);
333 } catch (PropertyVetoException e2) {
334 }
335 } else {
336 f.setNormalBounds(f.getBounds());
337 Component desktop = f.getParent();
338 setBoundsForFrame(f, 0, 0,
339 desktop.getWidth(),
340 desktop.getHeight() - taskBar.getHeight());
341 }
342
343 try {
344 f.setSelected(true);
345 } catch (PropertyVetoException e2) {
346 }
|