1 /*
2 * Copyright (c) 2011, 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
150 }
151
152 public void mouseClicked(final MouseEvent e) { }
153
154 public void mouseDragged(final MouseEvent e) { }
155
156 public void mouseMoved(final MouseEvent e) { }
157
158 public void componentHidden(final ComponentEvent e) { }
159
160 public void componentMoved(final ComponentEvent e) { }
161
162 public void componentResized(final ComponentEvent e) {
163 fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, null);
164 }
165
166 public void componentShown(final ComponentEvent e) {
167 fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, null);
168 }
169
170 class ScaledImageLabel extends JLabel {
171 ScaledImageLabel() {
172 super(null, null, CENTER);
173 }
174
175 void updateIcon() {
176 final Object priorIcon = fFrame.getClientProperty(CACHED_FRAME_ICON_KEY);
177 if (priorIcon instanceof ImageIcon) {
178 setIcon((ImageIcon)priorIcon);
179 return;
180 }
181
182 int width = fFrame.getWidth();
183 int height = fFrame.getHeight();
184
185 // Protect us from unsized frames, like in JCK test DefaultDesktopManager2008
186 if (width <= 0 || height <= 0) {
187 width = 128;
188 height = 128;
189 }
209 super.paint(g);
210 return;
211 }
212
213 final ImageIcon prev = (ImageIcon)getIcon();
214 final ImageIcon pressedIcon = new ImageIcon(AquaUtils.generateSelectedDarkImage(prev.getImage()));
215 setIcon(pressedIcon);
216 super.paint(g);
217 setIcon(prev);
218 }
219
220 boolean mouseInIcon(final MouseEvent e) {
221 return getBounds().contains(e.getX(), e.getY());
222 }
223
224 public Dimension getPreferredSize() {
225 return new Dimension(64, 64); //$ Dock preferred size
226 }
227 }
228
229 class DockLabel extends JLabel {
230 final static int NUB_HEIGHT = 7;
231 final static int ROUND_ADDITIONAL_HEIGHT = 8;
232 final static int ROUND_ADDITIONAL_WIDTH = 12;
233
234 DockLabel(final String text) {
235 super(text);
236 setBorder(null);
237 setOpaque(false);
238 setFont(AquaFonts.getDockIconFont());
239
240 final FontMetrics metrics = getFontMetrics(getFont());
241 setSize(SwingUtilities.computeStringWidth(metrics, getText()) + ROUND_ADDITIONAL_WIDTH * 2, metrics.getAscent() + NUB_HEIGHT + ROUND_ADDITIONAL_HEIGHT);
242 }
243
244 public void paint(final Graphics g) {
245 final int width = getWidth();
246 final int height = getHeight();
247
248 final Font font = getFont();
|
1 /*
2 * Copyright (c) 2011, 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
150 }
151
152 public void mouseClicked(final MouseEvent e) { }
153
154 public void mouseDragged(final MouseEvent e) { }
155
156 public void mouseMoved(final MouseEvent e) { }
157
158 public void componentHidden(final ComponentEvent e) { }
159
160 public void componentMoved(final ComponentEvent e) { }
161
162 public void componentResized(final ComponentEvent e) {
163 fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, null);
164 }
165
166 public void componentShown(final ComponentEvent e) {
167 fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, null);
168 }
169
170 @SuppressWarnings("serial") // Superclass is not serializable across versions
171 class ScaledImageLabel extends JLabel {
172 ScaledImageLabel() {
173 super(null, null, CENTER);
174 }
175
176 void updateIcon() {
177 final Object priorIcon = fFrame.getClientProperty(CACHED_FRAME_ICON_KEY);
178 if (priorIcon instanceof ImageIcon) {
179 setIcon((ImageIcon)priorIcon);
180 return;
181 }
182
183 int width = fFrame.getWidth();
184 int height = fFrame.getHeight();
185
186 // Protect us from unsized frames, like in JCK test DefaultDesktopManager2008
187 if (width <= 0 || height <= 0) {
188 width = 128;
189 height = 128;
190 }
210 super.paint(g);
211 return;
212 }
213
214 final ImageIcon prev = (ImageIcon)getIcon();
215 final ImageIcon pressedIcon = new ImageIcon(AquaUtils.generateSelectedDarkImage(prev.getImage()));
216 setIcon(pressedIcon);
217 super.paint(g);
218 setIcon(prev);
219 }
220
221 boolean mouseInIcon(final MouseEvent e) {
222 return getBounds().contains(e.getX(), e.getY());
223 }
224
225 public Dimension getPreferredSize() {
226 return new Dimension(64, 64); //$ Dock preferred size
227 }
228 }
229
230 @SuppressWarnings("serial") // Superclass is not serializable across versions
231 class DockLabel extends JLabel {
232 final static int NUB_HEIGHT = 7;
233 final static int ROUND_ADDITIONAL_HEIGHT = 8;
234 final static int ROUND_ADDITIONAL_WIDTH = 12;
235
236 DockLabel(final String text) {
237 super(text);
238 setBorder(null);
239 setOpaque(false);
240 setFont(AquaFonts.getDockIconFont());
241
242 final FontMetrics metrics = getFontMetrics(getFont());
243 setSize(SwingUtilities.computeStringWidth(metrics, getText()) + ROUND_ADDITIONAL_WIDTH * 2, metrics.getAscent() + NUB_HEIGHT + ROUND_ADDITIONAL_HEIGHT);
244 }
245
246 public void paint(final Graphics g) {
247 final int width = getWidth();
248 final int height = getHeight();
249
250 final Font font = getFont();
|