|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.control; |
|
27 |
|
28 import java.awt.*; |
|
29 import javax.swing.*; |
|
30 import javax.swing.border.Border; |
|
31 import com.oracle.solaris.vp.panel.common.control.Navigator; |
|
32 import com.oracle.solaris.vp.panel.common.model.PanelDescriptor; |
|
33 import com.oracle.solaris.vp.util.swing.*; |
|
34 |
|
35 public class DialogControl<P extends PanelDescriptor> |
|
36 extends WindowControl<P, JDialog> { |
|
37 |
|
38 // |
|
39 // Static data |
|
40 // |
|
41 |
|
42 public static final String ID = "dialog"; |
|
43 |
|
44 // |
|
45 // Constructors |
|
46 // |
|
47 |
|
48 public DialogControl(String id, String name, P descriptor) { |
|
49 super(id, name, descriptor); |
|
50 } |
|
51 |
|
52 public DialogControl(P descriptor) { |
|
53 this(ID, null, descriptor); |
|
54 } |
|
55 |
|
56 // |
|
57 // SwingControl methods |
|
58 // |
|
59 |
|
60 @Override |
|
61 protected JDialog createComponent() { |
|
62 // Modality can be changed by subclasses before dialog is shown |
|
63 JDialog dialog = new JDialog(getOwner(), |
|
64 Dialog.ModalityType.DOCUMENT_MODAL); |
|
65 |
|
66 ReplacingStackPanel stack = new ReplacingStackPanel(); |
|
67 stack.setBorder(getDefaultBorder()); |
|
68 |
|
69 Container cont = dialog.getContentPane(); |
|
70 cont.setLayout(new BorderLayout()); |
|
71 cont.add(stack, BorderLayout.CENTER); |
|
72 |
|
73 dialog.setTitle(getName()); |
|
74 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
75 dialog.pack(); |
|
76 |
|
77 setComponentStack(stack); |
|
78 return dialog; |
|
79 } |
|
80 |
|
81 // |
|
82 // WindowControl methods |
|
83 // |
|
84 |
|
85 @Override |
|
86 protected String getWindowTitle() { |
|
87 return getComponent().getTitle(); |
|
88 } |
|
89 |
|
90 @Override |
|
91 protected void setVisible() { |
|
92 JDialog dialog = getComponent(); |
|
93 Window owner = dialog.getOwner(); |
|
94 if (owner != null) { |
|
95 dialog.setLocationRelativeTo(owner); |
|
96 } |
|
97 |
|
98 super.setVisible(); |
|
99 } |
|
100 |
|
101 @Override |
|
102 protected void setWindowTitle(String title) { |
|
103 getComponent().setTitle(title); |
|
104 } |
|
105 |
|
106 // |
|
107 // DialogControl methods |
|
108 // |
|
109 |
|
110 /** |
|
111 * Gets the owner of the this {@code DialogControl}'s {@code JDialog}. This |
|
112 * default implementation searches backwards through the navigation stack |
|
113 * for a {@link SwingControl} with a {@code Component} in a mapped {@code |
|
114 * Window}. |
|
115 * |
|
116 * @return a {@code Window}, or {@code null} if the {@code JDialog} has |
|
117 * no owner |
|
118 */ |
|
119 public Window getOwner() { |
|
120 Window owner = null; |
|
121 Navigator navigator = getNavigator(); |
|
122 if (navigator != null) { |
|
123 owner = SwingNavigator.getLastWindow(navigator); |
|
124 } |
|
125 return owner; |
|
126 } |
|
127 |
|
128 /** |
|
129 * Returns a {@code Border} to use on the outermost {@code Containter} |
|
130 * within the {@code Dialog}, or {@code null} to use no {@code Border}. |
|
131 * </p> |
|
132 * This default implementation returns {@link GUIUtil#getEmptyBorder}. |
|
133 */ |
|
134 protected Border getDefaultBorder() { |
|
135 return GUIUtil.getEmptyBorder(); |
|
136 } |
|
137 } |