001/* A GUI property that encloses a JSeparator component. 002 003 Copyright (c) 2008-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.actor.gui.properties; 029 030import javax.swing.JComponent; 031import javax.swing.JSeparator; 032import javax.swing.SwingConstants; 033 034import ptolemy.data.expr.StringParameter; 035import ptolemy.kernel.util.Attribute; 036import ptolemy.kernel.util.IllegalActionException; 037import ptolemy.kernel.util.NameDuplicationException; 038import ptolemy.kernel.util.NamedObj; 039 040////////////////////////////////////////////////////////////////////////// 041//// Separator 042 043/** 044 A GUI property that encloses a JSeparator component. 045 046 @author Thomas Huining Feng 047 @version $Id$ 048 @since Ptolemy II 8.0 049 @Pt.ProposedRating Red (tfeng) 050 @Pt.AcceptedRating Red (tfeng) 051 */ 052public class Separator extends GUIProperty { 053 054 /** Construct a GUI property with the given name contained by the specified 055 * entity. The container argument must not be null, or a 056 * NullPointerException will be thrown. This attribute will use the 057 * workspace of the container for synchronization and version counts. 058 * If the name argument is null, then the name is set to the empty string. 059 * Increment the version of the workspace. 060 * @param container The container. 061 * @param name The name of this attribute. 062 * @exception IllegalActionException If the attribute is not of an 063 * acceptable class for the container, or if the name contains a period. 064 * @exception NameDuplicationException If the name coincides with 065 * an attribute already in the container. 066 */ 067 public Separator(NamedObj container, String name) 068 throws IllegalActionException, NameDuplicationException { 069 super(container, name); 070 _init(); 071 } 072 073 /** Construct a GUI property with the given name contained by the specified 074 * entity with the given Java Swing component. The container argument must 075 * not be null, or a NullPointerException will be thrown. This attribute 076 * will use the workspace of the container for synchronization and version 077 * counts. If the name argument is null, then the name is set to the empty 078 * string. Increment the version of the workspace. 079 * @param container The container. 080 * @param name The name of this attribute. 081 * @param component The Java Swing component. 082 * @exception IllegalActionException If the attribute is not of an 083 * acceptable class for the container, or if the name contains a period. 084 * @exception NameDuplicationException If the name coincides with 085 * an attribute already in the container. 086 */ 087 public Separator(NamedObj container, String name, JComponent component) 088 throws IllegalActionException, NameDuplicationException { 089 super(container, name, component); 090 _init(); 091 } 092 093 /** Construct a GUI property with the given name contained by the specified 094 * entity with the given Java Swing component and the given layout 095 * constraint. The container argument must not be null, or a 096 * NullPointerException will be thrown. This attribute 097 * will use the workspace of the container for synchronization and version 098 * counts. If the name argument is null, then the name is set to the empty 099 * string. Increment the version of the workspace. 100 * @param container The container. 101 * @param name The name of this attribute. 102 * @param component The Java Swing component. 103 * @param constraint The layout constraint. 104 * @exception IllegalActionException If the attribute is not of an 105 * acceptable class for the container, or if the name contains a period. 106 * @exception NameDuplicationException If the name coincides with 107 * an attribute already in the container. 108 */ 109 public Separator(NamedObj container, String name, JComponent component, 110 Object constraint) 111 throws IllegalActionException, NameDuplicationException { 112 super(container, name, component, constraint); 113 _init(); 114 } 115 116 /** Construct a GUI property with the given name contained by the specified 117 * entity with the given layout 118 * constraint. The container argument must not be null, or a 119 * NullPointerException will be thrown. This attribute 120 * will use the workspace of the container for synchronization and version 121 * counts. If the name argument is null, then the name is set to the empty 122 * string. Increment the version of the workspace. 123 * @param container The container. 124 * @param name The name of this attribute. 125 * @param constraint The layout constraint. 126 * @exception IllegalActionException If the attribute is not of an 127 * acceptable class for the container, or if the name contains a period. 128 * @exception NameDuplicationException If the name coincides with 129 * an attribute already in the container. 130 */ 131 public Separator(NamedObj container, String name, Object constraint) 132 throws IllegalActionException, NameDuplicationException { 133 super(container, name, constraint); 134 _init(); 135 } 136 137 /** React to a change in an attribute. This method is called by 138 * a contained attribute when its value changes. If the changed attribute 139 * is {@link #orientation}, then the orientation of the JSeparator 140 * component in this GUI property is adjusted accordingly. 141 * @param attribute The attribute that changed. 142 * @exception IllegalActionException If the change is not acceptable 143 * to this container (not thrown in this base class). 144 */ 145 @Override 146 public void attributeChanged(Attribute attribute) 147 throws IllegalActionException { 148 if (attribute == orientation) { 149 String value = orientation.stringValue(); 150 if (value.equalsIgnoreCase("Horizontal")) { 151 ((JSeparator) getComponent()) 152 .setOrientation(SwingConstants.HORIZONTAL); 153 } else if (value.equalsIgnoreCase("Vertical")) { 154 ((JSeparator) getComponent()) 155 .setOrientation(SwingConstants.VERTICAL); 156 } else { 157 throw new IllegalActionException(this, 158 "Orientation of a " 159 + "separator must be either \"Horozontal\" or " 160 + "\"Vertical\"."); 161 } 162 } else { 163 super.attributeChanged(attribute); 164 } 165 } 166 167 /** The orientation of the JSeparator, which should be either "Horizontal" 168 * or "Vertical". 169 */ 170 public StringParameter orientation; 171 172 /** Create a new JSeparator component. 173 * 174 * @return A Swing component that can be enclosed in this GUI property. 175 * @exception IllegalActionException Not thrown in this base class. 176 */ 177 @Override 178 protected JComponent _createComponent() throws IllegalActionException { 179 return new JSeparator(); 180 } 181 182 /** Initialize this separator. 183 * 184 * @exception IllegalActionException If the parameter is not of an 185 * acceptable class for the container. 186 * @exception NameDuplicationException If the name coincides with 187 * a parameter already in the container. 188 */ 189 private void _init() 190 throws IllegalActionException, NameDuplicationException { 191 orientation = new StringParameter(this, "orientation"); 192 orientation.setExpression("Horizontal"); 193 } 194}