components/visual-panels/firewall/src/java/vpanels/app/firewall/com/oracle/solaris/vp/panels/firewall/client/swing/FirewallSettingsPanel.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) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panels.firewall.client.swing;
       
    27 
       
    28 import java.awt.EventQueue;
       
    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.panels.firewall.client.swing.AccessPolicy.Type;
       
    33 import com.oracle.solaris.vp.util.misc.ChangeableAggregator;
       
    34 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    35 import com.oracle.solaris.vp.util.misc.property.*;
       
    36 import com.oracle.solaris.vp.util.swing.*;
       
    37 import com.oracle.solaris.vp.util.swing.layout.*;
       
    38 import com.oracle.solaris.vp.util.swing.property.CheckBoxPropertySynchronizer;
       
    39 
       
    40 @SuppressWarnings({"serial"})
       
    41 public class FirewallSettingsPanel extends CommonEditPanel {
       
    42     //
       
    43     // Instance data
       
    44     //
       
    45 
       
    46     private FileSystemView fsView_;
       
    47     private MutableProperty<Boolean> enabledProperty;
       
    48 
       
    49     //
       
    50     // Constructors
       
    51     //
       
    52 
       
    53     public FirewallSettingsPanel(FileSystemView fsView, String panelDesc,
       
    54         Type... types) {
       
    55 	super(false, panelDesc);
       
    56 	fsView_ = fsView;
       
    57 	setUpPanel(types);
       
    58     }
       
    59 
       
    60     public FirewallSettingsPanel(FileSystemView fsView, String panelDesc) {
       
    61 	this(fsView, panelDesc, Type.DENY, Type.ALLOW, Type.NONE, Type.CUSTOM);
       
    62     }
       
    63 
       
    64     //
       
    65     // CommonEditPanel methods
       
    66     //
       
    67 
       
    68     @Override
       
    69     protected void setUpPanel(Type... types) {
       
    70 	if (fsView_ == null)
       
    71 	    setAccessProperty(new AccessProperty(false, types));
       
    72 	else
       
    73 	    setAccessProperty(new AccessProperty(types));
       
    74 
       
    75 	JPanel form;
       
    76 	if (fsView_ != null)
       
    77 	    form = getDefaultForm();
       
    78 	else
       
    79 	    form = createForm();
       
    80 
       
    81 	setContent(form, false, true);
       
    82     }
       
    83 
       
    84     //
       
    85     // FirewallSettingsPanel methods
       
    86     //
       
    87 
       
    88     public MutableProperty<Boolean> getEnableProperty() {
       
    89 	return enabledProperty;
       
    90     }
       
    91 
       
    92     public JPanel getDefaultForm() {
       
    93 	ChangeableAggregator aggregator = getChangeableAggregator();
       
    94 
       
    95 	AccessProperty accessProperty = getAccessProperty();
       
    96 	aggregator.addChangeables(accessProperty);
       
    97 
       
    98 	ChangeIndicator accessChange = new ChangeIndicator();
       
    99 	accessProperty.addChangeListener(accessChange);
       
   100 
       
   101 	enabledProperty = new BooleanProperty();
       
   102 	JCheckBox enableCheckBox = new JCheckBox(
       
   103 	    Finder.getString("settings.objects.default.enable"));
       
   104 	new CheckBoxPropertySynchronizer(enabledProperty, enableCheckBox);
       
   105 	aggregator.addChangeables(enabledProperty);
       
   106 
       
   107 	ChangeIndicator enableChange = new ChangeIndicator();
       
   108 	enabledProperty.addChangeListener(enableChange);
       
   109 
       
   110 	JPanel formPanel = new JPanel();
       
   111 	formPanel.setOpaque(false);
       
   112 	Form form = new Form(formPanel, VerticalAnchor.TOP);
       
   113 
       
   114 	int gap = GUIUtil.getHalfGap();
       
   115 
       
   116 	ColumnLayoutConstraint c = new ColumnLayoutConstraint(
       
   117 	    HorizontalAnchor.FILL, gap);
       
   118 	RowLayoutConstraint r = new RowLayoutConstraint(
       
   119 	    VerticalAnchor.TOP, gap);
       
   120 	r.setLayoutIfInvisible(true);
       
   121 
       
   122 	form.addRow(HorizontalAnchor.LEFT, c);
       
   123 	form.add(enableCheckBox, r);
       
   124 	form.add(enableChange, r);
       
   125 
       
   126 	form.addRow(HorizontalAnchor.LEFT, c);
       
   127 	form.add(accessProperty.getPanel(), r.clone().setGap(0));
       
   128 	form.add(accessChange, r);
       
   129 
       
   130         return formPanel;
       
   131     }
       
   132 
       
   133     public void init(FirewallPanelDescriptor desc) {
       
   134 	// Sanity check -- the UI should be updated only on the event thread
       
   135 	assert EventQueue.isDispatchThread();
       
   136 
       
   137 	//
       
   138 	// This is a global default panel so initialize custom file
       
   139 	// as well as enabled value.
       
   140 	//
       
   141 	AccessPanel p = getAccessProperty().getPanel();
       
   142 	p.getCustomFilePanel().getFileChooser().setFileSystemView(fsView_);
       
   143 
       
   144 	enabledProperty.update(
       
   145 	    desc.getEnabledProperty().getSavedValue(), false);
       
   146 	super.init(desc.getAccessPolicy());
       
   147     }
       
   148 }