components/visual-panels/apache/src/java/vpanels/app/apache/com/oracle/solaris/vp/panels/apache/client/swing/MimeTypePanel.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.EventQueue;
       
    29 import javax.swing.*;
       
    30 import com.oracle.solaris.vp.panel.swing.view.ChangeIndicator;
       
    31 import com.oracle.solaris.vp.util.misc.ChangeableAggregator;
       
    32 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    33 import com.oracle.solaris.vp.util.misc.property.*;
       
    34 import com.oracle.solaris.vp.util.swing.*;
       
    35 import com.oracle.solaris.vp.util.swing.layout.*;
       
    36 import com.oracle.solaris.vp.util.swing.property.
       
    37     TextComponentPropertySynchronizer;
       
    38 
       
    39 @SuppressWarnings({"serial"})
       
    40 public class MimeTypePanel extends SettingsPanel {
       
    41     //
       
    42     // Instance data
       
    43     //
       
    44 
       
    45     private MutableProperty<String> typeProperty = new StringProperty();
       
    46     private MutableProperty<String> subtypeProperty = new StringProperty();
       
    47     private MutableProperty<String[]> extensionsProperty =
       
    48 	new StringArrayProperty();
       
    49 
       
    50     {
       
    51 	ChangeableAggregator aggregator = getChangeableAggregator();
       
    52 	aggregator.addChangeables(typeProperty, subtypeProperty,
       
    53 	    extensionsProperty);
       
    54     }
       
    55 
       
    56     //
       
    57     // Constructors
       
    58     //
       
    59 
       
    60     public MimeTypePanel() {
       
    61 	JPanel form = createForm();
       
    62 	setContent(form, false, false);
       
    63     }
       
    64 
       
    65     //
       
    66     // MimeTypePanel methods
       
    67     //
       
    68 
       
    69     public MutableProperty<String[]> getExtensionsProperty() {
       
    70 	return extensionsProperty;
       
    71     }
       
    72 
       
    73     public MutableProperty<String> getSubtypeProperty() {
       
    74 	return subtypeProperty;
       
    75     }
       
    76 
       
    77     public MutableProperty<String> getTypeProperty() {
       
    78 	return typeProperty;
       
    79     }
       
    80 
       
    81     public void init(MimeType mimeType) {
       
    82 	// Sanity check -- the UI should be updated only on the event thread
       
    83 	assert EventQueue.isDispatchThread();
       
    84 
       
    85 	if (mimeType != null) {
       
    86 	    ApacheUtil.update(mimeType.getTypeProperty(), typeProperty);
       
    87 	    ApacheUtil.update(mimeType.getSubtypeProperty(), subtypeProperty);
       
    88 	    ApacheUtil.update(mimeType.getExtensionsProperty(),
       
    89 		extensionsProperty);
       
    90 	}
       
    91     }
       
    92 
       
    93     //
       
    94     // Private methods
       
    95     //
       
    96 
       
    97     private JPanel createForm() {
       
    98 	int gap = GUIUtil.getHalfGap();
       
    99 
       
   100 	JLabel typeLabel = new JLabel(
       
   101 	    Finder.getString("mimetype.edit.type"));
       
   102 
       
   103 	JTextField typeField = GUIUtil.createTextField();
       
   104 	new TextComponentPropertySynchronizer<String, JTextField>(
       
   105 	    typeProperty, typeField);
       
   106 	ChangeIndicator typeChange = new ChangeIndicator();
       
   107 	typeProperty.addChangeListener(typeChange);
       
   108 
       
   109 	JLabel subtypeLabel = new JLabel(
       
   110 	    Finder.getString("mimetype.edit.subtype"));
       
   111 
       
   112 	JTextField subtypeField = GUIUtil.createTextField();
       
   113 	new TextComponentPropertySynchronizer<String, JTextField>(
       
   114 	    subtypeProperty, subtypeField);
       
   115 	ChangeIndicator subtypeChange = new ChangeIndicator();
       
   116 	subtypeProperty.addChangeListener(subtypeChange);
       
   117 
       
   118 	JLabel extensionsLabel = new JLabel(
       
   119 	    Finder.getString("mimetype.edit.extensions"));
       
   120 
       
   121 	JTextField extensionsField = GUIUtil.createTextField();
       
   122 	new TextComponentPropertySynchronizer<String[], JTextField>(
       
   123 	    extensionsProperty, extensionsField);
       
   124 	ChangeIndicator extensionsChange = new ChangeIndicator();
       
   125 	extensionsProperty.addChangeListener(extensionsChange);
       
   126 
       
   127 	JPanel formPanel = new JPanel();
       
   128 	formPanel.setOpaque(false);
       
   129 	Form form = new Form(formPanel, VerticalAnchor.TOP);
       
   130 
       
   131 	ColumnLayoutConstraint c = new ColumnLayoutConstraint(
       
   132 	    HorizontalAnchor.FILL, gap);
       
   133 
       
   134 	HasAnchors a = new SimpleHasAnchors(
       
   135 	    HorizontalAnchor.LEFT, VerticalAnchor.CENTER);
       
   136 
       
   137 	form.addTable(3, gap, gap, HorizontalAnchor.LEFT, c);
       
   138 
       
   139 	form.add(typeLabel, a);
       
   140 	form.add(typeField, a);
       
   141 	form.add(typeChange, a);
       
   142 
       
   143 	form.add(subtypeLabel, a);
       
   144 	form.add(subtypeField, a);
       
   145 	form.add(subtypeChange, a);
       
   146 
       
   147 	form.add(extensionsLabel, a);
       
   148 	form.add(extensionsField, a);
       
   149 	form.add(extensionsChange, a);
       
   150 
       
   151 	return formPanel;
       
   152     }
       
   153 }