|
What this is
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-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.editor.options; import java.awt.*; import java.beans.*; import java.util.Set; import java.util.Iterator; import java.util.HashMap; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Vector; import javax.swing.SwingUtilities; import org.openide.explorer.propertysheet.PropertyPanel; import org.openide.explorer.propertysheet.PropertyModel; import org.netbeans.editor.Coloring; import org.netbeans.editor.LocaleSupport; import org.netbeans.editor.SettingsNames; import org.openide.util.Lookup; import org.openide.util.NbBundle; /** * ColoringArrayEditorPanel is custom property editor operating over HashMap * containing (String)name:(Coloring)value pairs. Special name=null is used * to identify default coloring. * * @author Petr Nejedly * @version 1.0 */ public class ColoringArrayEditorPanel extends javax.swing.JPanel { /** Editor interface for visual editing of single coloring */ PropertyModel coloringModel; /** Index of Coloring actually edited/displayed by coloringModel */ int actValueIndex; // Bug #18539 temporary index value int newValueIndex; /** Name of the the type of the kit, which coloring we're editing */ private String typeName; /** Names of coloring obtained from HashMap, names[0] is 'default' in given locale */ private String names[]; /** Table of all edited colorings, colorings[0] is default coloring */ // private Coloring[] colorings; /** HashMap hodling our value. Changes are made by modifying this HashMap */ private HashMap value; /** Creates new form ColoringArrayEditorPanel */ public ColoringArrayEditorPanel() { typeName = BaseOptions.BASE; value = new HashMap(); names = new String[] { SettingsNames.DEFAULT_COLORING }; actValueIndex = 0; value.put(names[0], new Coloring( Font.decode( null ), Color.red, Color.blue ) ); initComponents (); getAccessibleContext().setAccessibleDescription(getBundleString("ACSD_CAEP_Panel")); // NOI18N syntaxLabel.setDisplayedMnemonic (getBundleString("CAEP_SyntaxLabel_Mnemonic").charAt (0)); // NOI18N syntaxList.getAccessibleContext().setAccessibleDescription(getBundleString("ACSD_CAEP_Syntax")); // NOI18N coloringModel = new PropertyModelSupport( ColoringBean.class, ColoringEditor.class); coloringModel.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange( PropertyChangeEvent evt ) { try { Coloring newColoring = ((ColoringBean)coloringModel.getValue()).coloring; if( ! newColoring.equals( value.get( names[actValueIndex] ) ) ) { //System.err.println("updating coloring[" + actValueIndex + "] from " + value.get( names[actValueIndex] ) + " to " + newColoring ); // NOI18N //Need to recreate value here (because of equals(), then set! value = (HashMap)value.clone(); value.put( names[actValueIndex], newColoring ); // Bug #18539 Hack to prevent changing selected index by firePropertyChange fired below actValueIndex = newValueIndex; ColoringArrayEditorPanel.this.firePropertyChange( "value", null, null ); // NOI18N } } catch( InvocationTargetException e ) { if( Boolean.getBoolean( "org.netbeans.exceptions" ) ) e.printStackTrace(); // NOI18N } } }); syntaxList.setSelectedIndex( actValueIndex ); // setEditorValue( actValueIndex ); PropertyPanel editorPanel = new PropertyPanel( coloringModel, PropertyPanel.PREF_CUSTOM_EDITOR ); detailPanel.add( editorPanel, BorderLayout.CENTER ); } private String getBundleString(String s) { return NbBundle.getMessage(ColoringArrayEditorPanel.class, s); } public HashMap getValue() { return value; } public void setValue( HashMap map ) { if( map == null ) return; int oldIndex = actValueIndex; value = map; // Obtain name of the kits type try { ClassLoader l = (ClassLoader)Lookup.getDefault().lookup(ClassLoader.class); Class kitClass = Class.forName( (String)map.get( null ), true, l ); typeName = OptionSupport.getTypeName( kitClass ); } catch( ClassNotFoundException e ) { org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, e); return; } Set keySet = map.keySet(); HashMap tempMap = new HashMap(keySet.size() - 1); String[] names = new String[keySet.size() - 1]; Iterator iter = keySet.iterator(); String defaultName = null; while (iter.hasNext()){ String name = (String) iter.next(); if (name == null) continue; String visualName = LocaleSupport.getString( "NAME_coloring_" + name ); // NOI18N if( visualName == null ) visualName = LocaleSupport.getString("NAME_coloring_" + BaseOptions.BASE + "-" + name, name ); // NOI18N if (name == SettingsNames.DEFAULT_COLORING) defaultName = visualName; tempMap.put(visualName, name); } List visualNamesList = new ArrayList(tempMap.keySet()); Collections.sort(visualNamesList); if (defaultName!=null){ boolean removed = visualNamesList.remove(defaultName); if (removed){ visualNamesList.add(0, defaultName); } } for (int i = 0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.