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.netbeans.core;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.beans.PropertyEditorSupport;

//import org.netbeans.core.windows.WindowManagerImpl; // TEMP

import org.openide.util.NbBundle;

/** This is a property editor for possible UI modes of the IDE. (SDI. MDI..)
 *
 * @author  Dafe Simonek
 */
public final class UIModePropertyEditor extends PropertyEditorSupport {

    /*  ui mode - display name mappings */
    private Map modes2Names;
    /*  display name - ui mode mappings */
    private Map names2Modes;
    
    public UIModePropertyEditor () {
    }

    /** @return names of the possible UI modes */
    public String[] getTags () {
        return (String[])names2Modes().keySet().toArray(new String[names2Modes.size()]);
    }
    
    public String getAsText () {
        return (String)modes2Names().get(getValue());
    }

    public void setAsText (String text) throws IllegalArgumentException {
        Object value = names2Modes().get(text);
        if (value != null) {
            setValue(value);
        } else {
            throw new IllegalArgumentException();
        }
    }

    /** Safe accessor for names to modes map */
    private Map names2Modes () {
        if (names2Modes == null) {
            names2Modes = new HashMap();
            
            // PENDING move the bundle keys to this package.
            names2Modes.put(
                NbBundle.getMessage(UIModePropertyEditor.class, "CTL_SdiMode"), 
//                new Integer(WindowManagerImpl.UI_MODE_SDI) // TEMP
                new Integer(1) // TEMP
            );
            names2Modes.put(
                NbBundle.getMessage(UIModePropertyEditor.class, "CTL_MdiMode"), 
//                new Integer(WindowManagerImpl.UI_MODE_MDI) // TEMP
                new Integer(2) // TEMP
            );
        }
        return names2Modes;
    }

    /** Safe accessor for modes to names map */
    private Map modes2Names () {
        if (modes2Names == null) {
            Map names2Modes = names2Modes();
            // swap names and mode integer constants
            modes2Names = new HashMap(10);
            Iterator iter = names2Modes.entrySet().iterator();
            Map.Entry curEntry = null;
            while (iter.hasNext()) {
                curEntry = (Map.Entry)iter.next();
                modes2Names.put(curEntry.getValue(), curEntry.getKey());
            }
        }
        return modes2Names;
    }
}
... 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.