1 /*
2 * Copyright (c) 1997, 2013, 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
25
26 package com.sun.java.swing.plaf.motif;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import javax.swing.*;
31 import javax.swing.border.*;
32 import javax.swing.event.InternalFrameEvent;
33 import javax.swing.plaf.basic.*;
34 import java.util.EventListener;
35 import java.beans.PropertyChangeListener;
36 import java.beans.PropertyChangeEvent;
37 import java.beans.VetoableChangeListener;
38 import java.beans.PropertyVetoException;
39
40 /**
41 * Class that manages a Motif title bar
42 *
43 * @since 1.3
44 */
45 public class MotifInternalFrameTitlePane
46 extends BasicInternalFrameTitlePane implements LayoutManager, ActionListener, PropertyChangeListener
47 {
48 SystemButton systemButton;
49 MinimizeButton minimizeButton;
50 MaximizeButton maximizeButton;
51 JPopupMenu systemMenu;
52 Title title;
53 Color color;
54 Color highlight;
55 Color shadow;
56
57 // The width and height of a title pane button
58 public final static int BUTTON_SIZE = 19; // 17 + 1 pixel border
59
60
61 public MotifInternalFrameTitlePane(JInternalFrame frame) {
62 super(frame);
63 }
64
215 if(frame.isIconifiable()) {
216 minimizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE);
217 x -= BUTTON_SIZE;
218 } else if(minimizeButton.getParent() != null) {
219 minimizeButton.getParent().remove(minimizeButton);
220 }
221
222 title.setBounds(BUTTON_SIZE, 0, x, BUTTON_SIZE);
223 }
224
225 protected void showSystemMenu(){
226 systemMenu.show(systemButton, 0, BUTTON_SIZE);
227 }
228
229 protected void hideSystemMenu(){
230 systemMenu.setVisible(false);
231 }
232
233 static Dimension buttonDimension = new Dimension(BUTTON_SIZE, BUTTON_SIZE);
234
235 private abstract class FrameButton extends JButton {
236
237 FrameButton() {
238 super();
239 setFocusPainted(false);
240 setBorderPainted(false);
241 }
242
243 public boolean isFocusTraversable() {
244 return false;
245 }
246
247 public void requestFocus() {
248 // ignore request.
249 }
250
251 public Dimension getMinimumSize() {
252 return buttonDimension;
253 }
254
259 public void paintComponent(Graphics g) {
260 Dimension d = getSize();
261 int maxX = d.width - 1;
262 int maxY = d.height - 1;
263
264 // draw background
265 g.setColor(color);
266 g.fillRect(1, 1, d.width, d.height);
267
268 // draw border
269 boolean pressed = getModel().isPressed();
270 g.setColor(pressed ? shadow : highlight);
271 g.drawLine(0, 0, maxX, 0);
272 g.drawLine(0, 0, 0, maxY);
273 g.setColor(pressed ? highlight : shadow);
274 g.drawLine(1, maxY, maxX, maxY);
275 g.drawLine(maxX, 1, maxX, maxY);
276 }
277 }
278
279 private class MinimizeButton extends FrameButton {
280 public void paintComponent(Graphics g) {
281 super.paintComponent(g);
282 g.setColor(highlight);
283 g.drawLine(7, 8, 7, 11);
284 g.drawLine(7, 8, 10, 8);
285 g.setColor(shadow);
286 g.drawLine(8, 11, 10, 11);
287 g.drawLine(11, 9, 11, 11);
288 }
289 }
290
291 private class MaximizeButton extends FrameButton {
292 public void paintComponent(Graphics g) {
293 super.paintComponent(g);
294 int max = BUTTON_SIZE - 5;
295 boolean isMaxed = frame.isMaximum();
296 g.setColor(isMaxed ? shadow : highlight);
297 g.drawLine(4, 4, 4, max);
298 g.drawLine(4, 4, max, 4);
299 g.setColor(isMaxed ? highlight : shadow);
300 g.drawLine(5, max, max, max);
301 g.drawLine(max, 5, max, max);
302 }
303 }
304
305 private class SystemButton extends FrameButton {
306 public boolean isFocusTraversable() { return false; }
307 public void requestFocus() {}
308
309 public void paintComponent(Graphics g) {
310 super.paintComponent(g);
311 g.setColor(highlight);
312 g.drawLine(4, 8, 4, 11);
313 g.drawLine(4, 8, BUTTON_SIZE - 5, 8);
314 g.setColor(shadow);
315 g.drawLine(5, 11, BUTTON_SIZE - 5, 11);
316 g.drawLine(BUTTON_SIZE - 5, 9, BUTTON_SIZE - 5, 11);
317 }
318 }
319
320 private class Title extends FrameButton {
321 Title(String title) {
322 super();
323 setText(title);
324 setHorizontalAlignment(SwingConstants.CENTER);
325 setBorder(BorderFactory.createBevelBorder(
326 BevelBorder.RAISED,
327 UIManager.getColor("activeCaptionBorder"),
328 UIManager.getColor("inactiveCaptionBorder")));
329
330 // Forward mouse events to titlebar for moves.
331 addMouseMotionListener(new MouseMotionListener() {
332 public void mouseDragged(MouseEvent e) {
333 forwardEventToParent(e);
334 }
335 public void mouseMoved(MouseEvent e) {
336 forwardEventToParent(e);
337 }
338 });
339 addMouseListener(new MouseListener() {
|
1 /*
2 * Copyright (c) 1997, 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
25
26 package com.sun.java.swing.plaf.motif;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import javax.swing.*;
31 import javax.swing.border.*;
32 import javax.swing.event.InternalFrameEvent;
33 import javax.swing.plaf.basic.*;
34 import java.util.EventListener;
35 import java.beans.PropertyChangeListener;
36 import java.beans.PropertyChangeEvent;
37 import java.beans.VetoableChangeListener;
38 import java.beans.PropertyVetoException;
39
40 /**
41 * Class that manages a Motif title bar
42 *
43 * @since 1.3
44 */
45 @SuppressWarnings("serial") // Superclass is not serializable across versions
46 public class MotifInternalFrameTitlePane
47 extends BasicInternalFrameTitlePane implements LayoutManager, ActionListener, PropertyChangeListener
48 {
49 SystemButton systemButton;
50 MinimizeButton minimizeButton;
51 MaximizeButton maximizeButton;
52 JPopupMenu systemMenu;
53 Title title;
54 Color color;
55 Color highlight;
56 Color shadow;
57
58 // The width and height of a title pane button
59 public final static int BUTTON_SIZE = 19; // 17 + 1 pixel border
60
61
62 public MotifInternalFrameTitlePane(JInternalFrame frame) {
63 super(frame);
64 }
65
216 if(frame.isIconifiable()) {
217 minimizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE);
218 x -= BUTTON_SIZE;
219 } else if(minimizeButton.getParent() != null) {
220 minimizeButton.getParent().remove(minimizeButton);
221 }
222
223 title.setBounds(BUTTON_SIZE, 0, x, BUTTON_SIZE);
224 }
225
226 protected void showSystemMenu(){
227 systemMenu.show(systemButton, 0, BUTTON_SIZE);
228 }
229
230 protected void hideSystemMenu(){
231 systemMenu.setVisible(false);
232 }
233
234 static Dimension buttonDimension = new Dimension(BUTTON_SIZE, BUTTON_SIZE);
235
236 @SuppressWarnings("serial") // Superclass is not serializable across versions
237 private abstract class FrameButton extends JButton {
238
239 FrameButton() {
240 super();
241 setFocusPainted(false);
242 setBorderPainted(false);
243 }
244
245 public boolean isFocusTraversable() {
246 return false;
247 }
248
249 public void requestFocus() {
250 // ignore request.
251 }
252
253 public Dimension getMinimumSize() {
254 return buttonDimension;
255 }
256
261 public void paintComponent(Graphics g) {
262 Dimension d = getSize();
263 int maxX = d.width - 1;
264 int maxY = d.height - 1;
265
266 // draw background
267 g.setColor(color);
268 g.fillRect(1, 1, d.width, d.height);
269
270 // draw border
271 boolean pressed = getModel().isPressed();
272 g.setColor(pressed ? shadow : highlight);
273 g.drawLine(0, 0, maxX, 0);
274 g.drawLine(0, 0, 0, maxY);
275 g.setColor(pressed ? highlight : shadow);
276 g.drawLine(1, maxY, maxX, maxY);
277 g.drawLine(maxX, 1, maxX, maxY);
278 }
279 }
280
281 @SuppressWarnings("serial") // Superclass is not serializable across versions
282 private class MinimizeButton extends FrameButton {
283 public void paintComponent(Graphics g) {
284 super.paintComponent(g);
285 g.setColor(highlight);
286 g.drawLine(7, 8, 7, 11);
287 g.drawLine(7, 8, 10, 8);
288 g.setColor(shadow);
289 g.drawLine(8, 11, 10, 11);
290 g.drawLine(11, 9, 11, 11);
291 }
292 }
293
294 @SuppressWarnings("serial") // Superclass is not serializable across versions
295 private class MaximizeButton extends FrameButton {
296 public void paintComponent(Graphics g) {
297 super.paintComponent(g);
298 int max = BUTTON_SIZE - 5;
299 boolean isMaxed = frame.isMaximum();
300 g.setColor(isMaxed ? shadow : highlight);
301 g.drawLine(4, 4, 4, max);
302 g.drawLine(4, 4, max, 4);
303 g.setColor(isMaxed ? highlight : shadow);
304 g.drawLine(5, max, max, max);
305 g.drawLine(max, 5, max, max);
306 }
307 }
308
309 @SuppressWarnings("serial") // Superclass is not serializable across versions
310 private class SystemButton extends FrameButton {
311 public boolean isFocusTraversable() { return false; }
312 public void requestFocus() {}
313
314 public void paintComponent(Graphics g) {
315 super.paintComponent(g);
316 g.setColor(highlight);
317 g.drawLine(4, 8, 4, 11);
318 g.drawLine(4, 8, BUTTON_SIZE - 5, 8);
319 g.setColor(shadow);
320 g.drawLine(5, 11, BUTTON_SIZE - 5, 11);
321 g.drawLine(BUTTON_SIZE - 5, 9, BUTTON_SIZE - 5, 11);
322 }
323 }
324
325 @SuppressWarnings("serial") // Superclass is not serializable across versions
326 private class Title extends FrameButton {
327 Title(String title) {
328 super();
329 setText(title);
330 setHorizontalAlignment(SwingConstants.CENTER);
331 setBorder(BorderFactory.createBevelBorder(
332 BevelBorder.RAISED,
333 UIManager.getColor("activeCaptionBorder"),
334 UIManager.getColor("inactiveCaptionBorder")));
335
336 // Forward mouse events to titlebar for moves.
337 addMouseMotionListener(new MouseMotionListener() {
338 public void mouseDragged(MouseEvent e) {
339 forwardEventToParent(e);
340 }
341 public void mouseMoved(MouseEvent e) {
342 forwardEventToParent(e);
343 }
344 });
345 addMouseListener(new MouseListener() {
|