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) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panels.coreadm.client.swing; |
|
27 |
|
28 import java.awt.*; |
|
29 import java.util.*; |
|
30 import javax.swing.*; |
|
31 import javax.swing.border.Border; |
|
32 import com.oracle.solaris.vp.panel.swing.view.ChangeIndicator; |
|
33 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
34 import com.oracle.solaris.vp.util.misc.property.*; |
|
35 import com.oracle.solaris.vp.util.swing.*; |
|
36 import com.oracle.solaris.vp.util.swing.layout.*; |
|
37 |
|
38 @SuppressWarnings({"serial"}) |
|
39 public class CoreAdmSettingsPanel extends SettingsPanel { |
|
40 // |
|
41 // Instance data |
|
42 // |
|
43 |
|
44 private MutableProperty<CoreConfig> configProperty; |
|
45 private JButton customEditButton; |
|
46 |
|
47 // |
|
48 // Constructors |
|
49 // |
|
50 |
|
51 public CoreAdmSettingsPanel() { |
|
52 JPanel form = createForm(); |
|
53 setContent(form); |
|
54 } |
|
55 |
|
56 // |
|
57 // CoreAdmSettingsPanel methods |
|
58 // |
|
59 |
|
60 protected JPanel createForm() { |
|
61 JPanel mainForm = createMainForm(); |
|
62 ChangeIndicator choiceChange = new ChangeIndicator(); |
|
63 configProperty.addChangeListener(choiceChange); |
|
64 |
|
65 JPanel formPanel = new JPanel(); |
|
66 formPanel.setOpaque(false); |
|
67 |
|
68 formPanel.setLayout(new RowLayout()); |
|
69 |
|
70 int hGap = GUIUtil.getHalfGap(); |
|
71 |
|
72 RowLayoutConstraint r = new RowLayoutConstraint( |
|
73 VerticalAnchor.TOP, hGap); |
|
74 r.setLayoutIfInvisible(true); |
|
75 |
|
76 formPanel.add(choiceChange, r); |
|
77 formPanel.add(mainForm, r); |
|
78 |
|
79 return formPanel; |
|
80 } |
|
81 |
|
82 protected JPanel createMainForm() { |
|
83 JPanel formPanel = new JPanel(); |
|
84 formPanel.setOpaque(false); |
|
85 |
|
86 String title = Finder.getString("settings.scheme.title"); |
|
87 Border empty = GUIUtil.getEmptyHalfBorder(); |
|
88 Border titled = BorderFactory.createTitledBorder(title); |
|
89 Border compound = BorderFactory.createCompoundBorder(titled, empty); |
|
90 formPanel.setBorder(compound); |
|
91 |
|
92 Form form = new Form(formPanel, VerticalAnchor.TOP); |
|
93 |
|
94 int hGap = GUIUtil.getHalfGap(); |
|
95 int vGap = GUIUtil.getGap(); |
|
96 |
|
97 ColumnLayoutConstraint c = new ColumnLayoutConstraint( |
|
98 HorizontalAnchor.FILL, vGap); |
|
99 |
|
100 RowLayoutConstraint r = new RowLayoutConstraint( |
|
101 VerticalAnchor.TOP, hGap); |
|
102 r.setLayoutIfInvisible(true); |
|
103 |
|
104 AbstractButton custom = null; |
|
105 Map<AbstractButton, CoreConfig> map = |
|
106 new HashMap<AbstractButton, CoreConfig>(); |
|
107 |
|
108 for (CoreScheme choice : CoreScheme.values()) { |
|
109 String resource = |
|
110 "settings.scheme." + choice.toString().toLowerCase(); |
|
111 String option = Finder.getString(resource); |
|
112 String caption = Finder.getString(resource + ".caption"); |
|
113 |
|
114 AbstractButton button = new JRadioButton(option); |
|
115 if (choice == CoreScheme.CUSTOM) { |
|
116 custom = button; |
|
117 } |
|
118 map.put(button, choice.getConfig()); |
|
119 |
|
120 form.addRow(HorizontalAnchor.LEFT, c); |
|
121 form.add(button, r); |
|
122 |
|
123 if (caption != null) { |
|
124 int indent = GUIUtil.getTextXOffset(button); |
|
125 JLabel label = new JLabel(caption); |
|
126 |
|
127 Font bFont = button.getFont(); |
|
128 float size = bFont.getSize() * .85f; |
|
129 Font lFont = bFont.deriveFont(size); |
|
130 label.setFont(lFont); |
|
131 |
|
132 form.addRow(HorizontalAnchor.LEFT, c.clone().setGap(0)); |
|
133 form.add(label, |
|
134 r.clone().setGap(indent).setIgnoreFirstGap(false)); |
|
135 } |
|
136 } |
|
137 |
|
138 assert custom != null; |
|
139 configProperty = new BasicMutableProperty<CoreConfig>(); |
|
140 new CustomizedChoicePropertySynchronizer<CoreConfig>(configProperty, |
|
141 map, custom); |
|
142 getChangeableAggregator().addChangeables(configProperty); |
|
143 |
|
144 customEditButton = new JButton(Finder.getString( |
|
145 "settings.scheme.custom.edit")); |
|
146 form.addRow(HorizontalAnchor.RIGHT, c); |
|
147 form.add(customEditButton, r); |
|
148 |
|
149 return formPanel; |
|
150 } |
|
151 |
|
152 public MutableProperty<CoreConfig> getConfigProperty() { |
|
153 return configProperty; |
|
154 } |
|
155 |
|
156 public JButton getCustomEditButton() { |
|
157 return customEditButton; |
|
158 } |
|
159 |
|
160 public void init(CoreAdmPanelDescriptor descriptor) { |
|
161 // Sanity check -- the UI should be updated only on the event thread |
|
162 assert EventQueue.isDispatchThread(); |
|
163 |
|
164 configProperty.setValue(descriptor.getCoreConfig()); |
|
165 configProperty.save(); |
|
166 } |
|
167 } |
|