001    /*
002     * LAPIS lightweight structured text processing system
003     *
004     * Copyright (C) 1998-2002 Carnegie Mellon University,
005     * Copyright (C) 2003 Massachusetts Institute of Technology.
006     * All rights reserved.
007     *
008     * This library is free software; you can redistribute it
009     * and/or modify it under the terms of the GNU General
010     * Public License as published by the Free Software
011     * Foundation, version 2.
012     *
013     * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/
014     */
015    
016    package lapisx.swing;
017    
018    import java.beans.*;
019    import javax.swing.*;
020    
021    public class LineBeanInfo extends SimpleBeanInfo {
022        public BeanDescriptor getBeanDescriptor () {
023            return new BeanDescriptor (Line.class);
024        }
025    
026        public PropertyDescriptor[] getPropertyDescriptors () {
027            try {
028                PropertyDescriptor[] props  =
029                    new PropertyDescriptor [] {
030                        new PropertyDescriptor ("foreground", Line.class),
031                        new PropertyDescriptor ("orientation", Line.class),
032                    };
033                props[1].setPropertyEditorClass (OrientationEditor.class);
034                return props;
035            } catch (IntrospectionException e) {
036                return super.getPropertyDescriptors ();
037            }
038        }
039    
040        public static class OrientationEditor extends PropertyEditorSupport {
041            public String[] getTags () {
042                return new String[] { "horizontal", "vertical" };
043            }
044    
045            public void setAsText (String s) {
046                if ("horizontal".equalsIgnoreCase (s))
047                    setValue (new Integer (SwingConstants.HORIZONTAL));
048                else if ("vertical".equalsIgnoreCase (s))
049                    setValue (new Integer (SwingConstants.VERTICAL));
050                else
051                    throw new IllegalArgumentException (s);
052            }
053           
054            public String getAsText () {
055                switch (((Number) getValue ()).intValue ()) {
056                default:
057                case SwingConstants.HORIZONTAL:
058                    return "horizontal";
059                case SwingConstants.VERTICAL:
060                    return "vertical";
061                }
062            }
063                
064            public String getJavaInitializationString () {
065                switch (((Number) getValue ()).intValue ()) {
066                default:
067                case SwingConstants.HORIZONTAL:
068                    return "javax.swing.SwingConstants.HORIZONTAL";
069                case SwingConstants.VERTICAL:
070                    return "javax.swing.SwingConstants.VERTICAL";
071                }
072            }
073        }
074        
075    }