components/visual-panels/apache/src/java/vpanels/app/apache/com/oracle/solaris/vp/panels/apache/client/swing/GlobalPanel.java
changeset 3553 f1d133b09a8c
parent 3552 077ebe3d0d24
child 3554 ef58713bafc4
equal deleted inserted replaced
3552:077ebe3d0d24 3553:f1d133b09a8c
     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.apache.client.swing;
       
    27 
       
    28 import java.awt.*;
       
    29 import javax.swing.*;
       
    30 import javax.swing.filechooser.FileSystemView;
       
    31 import com.oracle.solaris.vp.panel.swing.view.ChangeIndicator;
       
    32 import com.oracle.solaris.vp.util.misc.ChangeableAggregator;
       
    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 import com.oracle.solaris.vp.util.swing.property.*;
       
    38 
       
    39 @SuppressWarnings({"serial"})
       
    40 public class GlobalPanel extends SettingsPanel {
       
    41     //
       
    42     // Instance data
       
    43     //
       
    44 
       
    45     private MutableProperty<Boolean> enabledProperty = new BooleanProperty();
       
    46     private MutableProperty<Boolean> customEnabledProperty =
       
    47 	new BooleanProperty();
       
    48     private MutableProperty<String> customFileProperty = new StringProperty();
       
    49     private JFileChooser fileChooser;
       
    50 
       
    51     {
       
    52 	ChangeableAggregator aggregator = getChangeableAggregator();
       
    53         aggregator.addChangeables(enabledProperty, customEnabledProperty,
       
    54 	    customFileProperty);
       
    55     }
       
    56 
       
    57     private ChangeButton mimeTypesButton;
       
    58     private ChangeButton modulesButton;
       
    59 
       
    60     //
       
    61     // Constructors
       
    62     //
       
    63 
       
    64     public GlobalPanel() {
       
    65 	JPanel form = createForm();
       
    66 	setContent(form, false, false);
       
    67     }
       
    68 
       
    69     //
       
    70     // GlobalPanel methods
       
    71     //
       
    72 
       
    73     public MutableProperty<Boolean> getEnabledProperty() {
       
    74 	return enabledProperty;
       
    75     }
       
    76 
       
    77     public MutableProperty<Boolean> getCustomEnabledProperty() {
       
    78 	return customEnabledProperty;
       
    79     }
       
    80 
       
    81     public MutableProperty<String> getCustomFileProperty() {
       
    82 	return customFileProperty;
       
    83     }
       
    84 
       
    85     public ChangeButton getMimeTypesButton() {
       
    86 	return mimeTypesButton;
       
    87     }
       
    88 
       
    89     public ChangeButton getModulesButton() {
       
    90 	return modulesButton;
       
    91     }
       
    92 
       
    93     public void init(ApachePanelDescriptor descriptor) {
       
    94 	// Sanity check -- the UI should be updated only on the event thread
       
    95 	assert EventQueue.isDispatchThread();
       
    96 
       
    97 	FileSystemView fsView;
       
    98 
       
    99 	if (descriptor == null) {
       
   100             fsView = FileSystemView.getFileSystemView();
       
   101 	} else {
       
   102 	    ApacheUtil.update(descriptor.getEnabledProperty(), enabledProperty);
       
   103 
       
   104 	    ApacheUtil.update(descriptor.getCustomEnabledProperty(),
       
   105 		customEnabledProperty);
       
   106 
       
   107 	    ApacheUtil.update(descriptor.getCustomFileProperty(),
       
   108 		customFileProperty);
       
   109 
       
   110 	    fsView = descriptor.getFileSystemView();
       
   111 	}
       
   112 
       
   113 	fileChooser.setFileSystemView(fsView);
       
   114     }
       
   115 
       
   116     //
       
   117     // Private methods
       
   118     //
       
   119 
       
   120     private JPanel createForm() {
       
   121 	JCheckBox enableCheckBox = new JCheckBox(
       
   122 	    Finder.getString("global.edit.enable"));
       
   123 	new CheckBoxPropertySynchronizer(enabledProperty, enableCheckBox);
       
   124 	ChangeIndicator enableChange = new ChangeIndicator();
       
   125 	enabledProperty.addChangeListener(enableChange);
       
   126 
       
   127 	JCheckBox customEnabledFileCheckBox = new JCheckBox(
       
   128 	    Finder.getString("global.edit.customfile"));
       
   129 
       
   130 	new CheckBoxPropertySynchronizer(customEnabledProperty,
       
   131 	    customEnabledFileCheckBox);
       
   132 	ChangeIndicator customEnabledChange = new ChangeIndicator();
       
   133 	customEnabledProperty.addChangeListener(customEnabledChange);
       
   134 
       
   135 	InfoLabel customEnabledHelp = new InfoLabel(
       
   136 	    Finder.getString("global.edit.customfile.help"));
       
   137 
       
   138 	BrowsableFilePanel customFilePanel = new BrowsableFilePanel();
       
   139 	customFilePanel.setOpaque(false);
       
   140 	fileChooser = customFilePanel.getFileChooser();
       
   141 
       
   142 	new TextComponentPropertySynchronizer<String, JTextField>(
       
   143 	    customFileProperty, customFilePanel.getField());
       
   144 	ChangeIndicator customFileChange = new ChangeIndicator();
       
   145 	customFileProperty.addChangeListener(customFileChange);
       
   146 
       
   147 	GUIUtil.setEnableStateOnSelect(
       
   148 	    customEnabledFileCheckBox, true, true, customFilePanel);
       
   149 
       
   150 	mimeTypesButton = new ChangeButton(Finder.getString(
       
   151 	    "global.edit.mimetypes"));
       
   152 	modulesButton = new ChangeButton(Finder.getString(
       
   153 	    "global.edit.modules"));
       
   154 
       
   155 	int bGap = GUIUtil.getButtonGap();
       
   156 
       
   157 	JPanel buttonPanel = new JPanel(new GridLayout(1, 2, bGap, 0));
       
   158 	buttonPanel.setOpaque(false);
       
   159 	buttonPanel.add(mimeTypesButton);
       
   160 	buttonPanel.add(modulesButton);
       
   161 
       
   162 	JPanel formPanel = new JPanel();
       
   163 	formPanel.setOpaque(false);
       
   164 	Form form = new Form(formPanel, VerticalAnchor.FILL);
       
   165 
       
   166 	int hGap = GUIUtil.getHalfGap();
       
   167 	int sGap = 3 * hGap;
       
   168 	int indent = GUIUtil.getTextXOffset(customEnabledFileCheckBox);
       
   169 
       
   170 	ColumnLayoutConstraint c = new ColumnLayoutConstraint(
       
   171 	    HorizontalAnchor.FILL, hGap);
       
   172 
       
   173 	RowLayoutConstraint r = new RowLayoutConstraint(
       
   174 	    VerticalAnchor.CENTER, hGap);
       
   175 	r.setLayoutIfInvisible(true);
       
   176 
       
   177 	form.addRow(HorizontalAnchor.LEFT, c);
       
   178 	form.add(enableCheckBox, r);
       
   179 	form.add(enableChange, r);
       
   180 
       
   181 	form.addRow(HorizontalAnchor.LEFT, c.clone().setGap(sGap));
       
   182 	form.add(customEnabledFileCheckBox, r);
       
   183 	form.add(customEnabledHelp, r);
       
   184 	form.add(customEnabledChange, r);
       
   185 
       
   186 	form.addRow(HorizontalAnchor.LEFT, c);
       
   187 	form.add(customFilePanel, r.clone().setGap(indent).
       
   188 	    setIgnoreFirstGap(false));
       
   189 	form.add(customFileChange, r);
       
   190 
       
   191 	form.addRow(HorizontalAnchor.FILL, c.setGap(sGap).setWeight(1).
       
   192 	    setVerticalAnchor(VerticalAnchor.BOTTOM));
       
   193 
       
   194 	form.add(buttonPanel, r.clone().setWeight(1).setHorizontalAnchor(
       
   195 	    HorizontalAnchor.RIGHT));
       
   196 
       
   197 	return formPanel;
       
   198     }
       
   199 }