|
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-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.apache.tools.ant.module; import java.awt.Image; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.beans.PropertyEditorSupport; import java.beans.SimpleBeanInfo; import java.io.File; import org.openide.util.NbBundle; public class AntSettingsBeanInfo extends SimpleBeanInfo { public PropertyDescriptor[] getPropertyDescriptors () { try { PropertyDescriptor verbosity = new PropertyDescriptor ("verbosity", AntSettings.class); verbosity.setDisplayName (NbBundle.getMessage (AntSettingsBeanInfo.class, "PROP_verbosity")); verbosity.setShortDescription (NbBundle.getMessage (AntSettingsBeanInfo.class, "HINT_verbosity")); verbosity.setPropertyEditorClass (VerbosityEditor.class); PropertyDescriptor properties = new PropertyDescriptor ("properties", AntSettings.class); properties.setDisplayName (NbBundle.getMessage (AntSettingsBeanInfo.class, "PROP_properties")); properties.setShortDescription (NbBundle.getMessage (AntSettingsBeanInfo.class, "HINT_properties")); PropertyDescriptor saveAll = new PropertyDescriptor ("saveAll", AntSettings.class); saveAll.setDisplayName (NbBundle.getMessage (AntSettingsBeanInfo.class, "PROP_saveAll")); saveAll.setShortDescription (NbBundle.getMessage (AntSettingsBeanInfo.class, "HINT_saveAll")); PropertyDescriptor customDefs = new PropertyDescriptor ("customDefs", AntSettings.class); customDefs.setHidden (true); PropertyDescriptor antVersion = new PropertyDescriptor("antVersion", AntSettings.class, "getAntVersion", null); antVersion.setDisplayName(NbBundle.getMessage(AntSettingsBeanInfo.class, "PROP_antVersion")); antVersion.setShortDescription(NbBundle.getMessage(AntSettingsBeanInfo.class, "HINT_antVersion")); antVersion.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N PropertyDescriptor antHome = new PropertyDescriptor("antHome", AntSettings.class); // NOI18N antHome.setDisplayName(NbBundle.getMessage(AntSettingsBeanInfo.class, "PROP_antHome")); // NOI18N antHome.setShortDescription(NbBundle.getMessage(AntSettingsBeanInfo.class, "HINT_antHome")); // NOI18N antHome.setPropertyEditorClass(AntHomeEd.class); PropertyDescriptor extraClasspath = new PropertyDescriptor("extraClasspath", AntSettings.class); // NOI18N extraClasspath.setDisplayName(NbBundle.getMessage(AntSettingsBeanInfo.class, "PROP_extraClasspath")); // NOI18N extraClasspath.setShortDescription(NbBundle.getMessage(AntSettingsBeanInfo.class, "HINT_extraClasspath")); // NOI18N PropertyDescriptor automaticExtraClasspath = new PropertyDescriptor("automaticExtraClasspath", AntSettings.class, "getAutomaticExtraClasspath", null); // NOI18N automaticExtraClasspath.setDisplayName(NbBundle.getMessage(AntSettingsBeanInfo.class, "PROP_automaticExtraClasspath")); // NOI18N automaticExtraClasspath.setShortDescription(NbBundle.getMessage(AntSettingsBeanInfo.class, "HINT_automaticExtraClasspath")); // NOI18N PropertyDescriptor autoCloseTabs = new PropertyDescriptor("autoCloseTabs", AntSettings.class); // NOI18N autoCloseTabs.setDisplayName(NbBundle.getMessage(AntSettingsBeanInfo.class, "PROP_autoCloseTabs")); // NOI18N autoCloseTabs.setShortDescription(NbBundle.getMessage(AntSettingsBeanInfo.class, "HINT_autoCloseTabs")); // NOI18N return new PropertyDescriptor[] { verbosity, properties, saveAll, customDefs, antVersion, antHome, extraClasspath, automaticExtraClasspath, autoCloseTabs, }; } catch (IntrospectionException ie) { AntModule.err.notify(ie); return null; } } public Image getIcon (int type) { if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) { return org.openide.util.Utilities.loadImage ("org/apache/tools/ant/module/resources/AntIcon.gif"); } else { return null; } } public static class VerbosityEditor extends PropertyEditorSupport { private static final String[] tags = { /* #45482: this one is really useless: NbBundle.getMessage (AntSettingsBeanInfo.class, "LBL_verbosity_err"), */ NbBundle.getMessage (AntSettingsBeanInfo.class, "LBL_verbosity_warn"), NbBundle.getMessage (AntSettingsBeanInfo.class, "LBL_verbosity_info"), NbBundle.getMessage (AntSettingsBeanInfo.class, "LBL_verbosity_verbose"), NbBundle.getMessage (AntSettingsBeanInfo.class, "LBL_verbosity_debug"), }; private static final int[] levels = { // no Project.MSG_ERR exposed in GUI 1 /*Project.MSG_WARN*/, 2 /*Project.MSG_INFO*/, 3 /*Project.MSG_VERBOSE*/, 4 /*Project.MSG_DEBUG*/, }; public String[] getTags () { return tags; } public String getAsText () { int l = ((Integer) getValue ()).intValue (); for (int i = 0; i < levels.length; i++) { if (l == levels[i]) { return tags[i]; } } return "???"; // NOI18N } public void setAsText (String text) throws IllegalArgumentException { for (int i = 0; i < tags.length; i++) { if (tags[i].equals (text)) { setValue (new Integer (levels[i])); return; } } throw new IllegalArgumentException (); } } public static final class AntHomeEd extends PropertyEditorSupport { private static boolean ok(File f) { return f.isDirectory() && new File(new File(f, "lib"), "ant.jar").isFile(); } public String getAsText() { File f = (File)getValue(); if (f == null) { // Cf. #43522. Have to deal with default value too. f = AntSettings.getDefaultAntHome(); } return f.getAbsolutePath(); } public void setAsText(String s) throws IllegalArgumentException { File f = new File(s); if (!ok(f)) { IllegalArgumentException iae = new IllegalArgumentException("no lib/ant.jar in " + f); // NOI18N AntModule.err.annotate(iae, NbBundle.getMessage(AntSettingsBeanInfo.class, "ERR_not_ant_home", f)); throw iae; } if (f.equals(AntSettings.getDefaultAntHome())) { setValue(null); } else { setValue(f); } } // No custom prop ed component for now. Using JFileChooser from the standard // FileEditor was a *disaster* - it would try to select each directory you came // across and set the value! To do it right, should display a JFileChooser, show // all directories (no files), and permit you to select only one matching ok(). // Only when you press OK should the value actually be set. } } |
... 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.