components/visual-panels/apache/src/java/vpanels/app/apache/com/oracle/solaris/vp/panels/apache/client/swing/ModulePanel.java
changeset 827 0944d8c0158b
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     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 javax.swing.text.JTextComponent;
       
    32 import com.oracle.solaris.vp.panel.swing.view.ChangeIndicator;
       
    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.
       
    39     TextComponentPropertySynchronizer;
       
    40 
       
    41 @SuppressWarnings({"serial"})
       
    42 public class ModulePanel extends SettingsPanel {
       
    43     //
       
    44     // Instance data
       
    45     //
       
    46 
       
    47     private MutableProperty<String> nameProperty = new StringProperty();
       
    48     private MutableProperty<String> fileProperty = new StringProperty();
       
    49 
       
    50     {
       
    51 	ChangeableAggregator aggregator = getChangeableAggregator();
       
    52 	aggregator.addChangeables(nameProperty, fileProperty);
       
    53     }
       
    54 
       
    55     private JFileChooser fileChooser;
       
    56 
       
    57     //
       
    58     // Constructors
       
    59     //
       
    60 
       
    61     public ModulePanel() {
       
    62 	JPanel form = createForm();
       
    63 	setContent(form, false, false);
       
    64     }
       
    65 
       
    66     //
       
    67     // ModulePanel methods
       
    68     //
       
    69 
       
    70     public MutableProperty<String> getFileProperty() {
       
    71 	return fileProperty;
       
    72     }
       
    73 
       
    74     public MutableProperty<String> getNameProperty() {
       
    75 	return nameProperty;
       
    76     }
       
    77 
       
    78     public void init(Module module) {
       
    79 	// Sanity check -- the UI should be updated only on the event thread
       
    80 	assert EventQueue.isDispatchThread();
       
    81 
       
    82 	FileSystemView fsView;
       
    83 
       
    84 	if (module == null) {
       
    85             fsView = FileSystemView.getFileSystemView();
       
    86 	} else {
       
    87 	    ApacheUtil.update(module.getNameProperty(), nameProperty);
       
    88 	    ApacheUtil.update(module.getFileProperty(), fileProperty);
       
    89 
       
    90 	    fsView = module.getParent().getApacheInfo().getPanelDescriptor().
       
    91 		getFileSystemView();
       
    92 	}
       
    93 
       
    94 	fileChooser.setFileSystemView(fsView);
       
    95     }
       
    96 
       
    97     //
       
    98     // Private methods
       
    99     //
       
   100 
       
   101     private JPanel createForm() {
       
   102 	int gap = GUIUtil.getHalfGap();
       
   103 
       
   104 	JLabel nameLabel = new JLabel(
       
   105 	    Finder.getString("module.edit.name"));
       
   106 
       
   107 	JTextField nameField = GUIUtil.createTextField();
       
   108 	new TextComponentPropertySynchronizer<String, JTextComponent>(
       
   109 	    nameProperty, nameField);
       
   110 	ChangeIndicator nameChange = new ChangeIndicator();
       
   111 	nameProperty.addChangeListener(nameChange);
       
   112 
       
   113 	JLabel fileLabel = new JLabel(
       
   114 	    Finder.getString("module.edit.file"));
       
   115 
       
   116 	BrowsableFilePanel fileField = new BrowsableFilePanel();
       
   117 	fileField.setOpaque(false);
       
   118 	fileChooser = fileField.getFileChooser();
       
   119 
       
   120 	new TextComponentPropertySynchronizer<String, JTextComponent>(
       
   121 	    fileProperty, fileField.getField());
       
   122 	ChangeIndicator fileChange = new ChangeIndicator();
       
   123 	fileProperty.addChangeListener(fileChange);
       
   124 
       
   125 	JPanel filePanel = new JPanel(new BorderLayout(gap, 0));
       
   126 	filePanel.setOpaque(false);
       
   127 	filePanel.add(fileField, BorderLayout.CENTER);
       
   128 	filePanel.add(fileChange, BorderLayout.EAST);
       
   129 
       
   130 	JPanel formPanel = new JPanel();
       
   131 	formPanel.setOpaque(false);
       
   132 	Form form = new Form(formPanel, VerticalAnchor.TOP);
       
   133 
       
   134 	ColumnLayoutConstraint c = new ColumnLayoutConstraint(
       
   135 	    HorizontalAnchor.FILL, gap);
       
   136 
       
   137 	HasAnchors a = new SimpleHasAnchors(
       
   138 	    HorizontalAnchor.LEFT, VerticalAnchor.CENTER);
       
   139 
       
   140 	form.addTable(3, gap, gap, HorizontalAnchor.LEFT, c);
       
   141 
       
   142 	form.add(nameLabel, a);
       
   143 	form.add(nameField, a);
       
   144 	form.add(nameChange, a);
       
   145 
       
   146 	form.add(fileLabel, a);
       
   147 	form.add(filePanel, a);
       
   148 	form.add(fileChange, a);
       
   149 
       
   150 	return formPanel;
       
   151     }
       
   152 }