alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.explorer.propertysheet.editors;

import java.beans.*;
import java.awt.*;


/** A property editor for Color class.
* @author   Jan Jancura, Ian Formanek
* @version  0.10, 09 Mar 1998
*/
public class ChoicePropertyEditor implements PropertyEditor {


    // variables ..................................................................................

    private PropertyChangeSupport support;

    private int[] constants;
    private String[] names;
    private int index;
    private String name;


    // init .......................................................................................

    public ChoicePropertyEditor (int[] constants, String[] names) {
        support = new PropertyChangeSupport (this);
        this.constants = constants;
        this.names = names;
    }


    // main methods .......................................................................................

    public Object getValue () {
        return new Integer (constants [index]);
    }

    public void setValue (Object object) {
        if (!(object instanceof Integer)) throw new IllegalArgumentException ();
        int ii = ((Integer)object).intValue ();
        int i, k = constants.length;
        for (i = 0; i < k; i++) if (constants [i] == ii) break;
        if (i == k)  throw new IllegalArgumentException ();
        index = i;
        name = names [i];
        support.firePropertyChange (null, null, null);
    }

    public String getAsText () {
        return name;
    }

    public void setAsText (String string)
    throws IllegalArgumentException {
        int i, k = names.length;
        for (i = 0; i < k; i++) if (names [i].equals (string)) break;
        if (i == k)  throw new IllegalArgumentException ();
        index = i;
        name = names [i];
        support.firePropertyChange (null, null, null);
    }

    public String getJavaInitializationString () {
        return "" + index; // NOI18N
    }

    public String[] getTags () {
        return names;
    }

    public boolean isPaintable () {
        return false;
    }

    public void paintValue (Graphics g, Rectangle rectangle) {
    }

    public boolean supportsCustomEditor () {
        return false;
    }

    public Component getCustomEditor () {
        return null;
    }

    public void addPropertyChangeListener (PropertyChangeListener propertyChangeListener) {
        support.addPropertyChangeListener (propertyChangeListener);
    }

    public void removePropertyChangeListener (PropertyChangeListener propertyChangeListener) {
        support.removePropertyChangeListener (propertyChangeListener);
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.