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

// $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java,v 1.5 2004/02/11 17:29:14 jsalvata Exp $
/*
 * Copyright 2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jmeter.testbeans.gui;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import java.beans.BeanInfo;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyDescriptor;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;

import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

/**
 * The GenericTestBeanCustomizer is designed to provide developers with a
 * mechanism to quickly implement GUIs for new components.
 * 

* It allows editing each of the public exposed properties of the * edited type 'a la JavaBeans': as far as the types of those properties * have an associated editor, there's no GUI development required. *

* This class understands the following PropertyDescriptor attributes: *

*
group: String
*
Group under which the property should be shown in the GUI. The string is * also used as a group title (but see comment on resourceBundle below). The * default group is "".
*
order: Integer
*
Order in which the property will be shown in its group. A smaller * integer means higher up in the GUI. The default order is 0. Properties * of equal order are sorted alphabetically.
*
tags: String[]
*
List of values to be offered for the property in addition to those * offered by its property editor.
*
notUndefined: Boolean
*
If true, the property should not be left undefined. A default * attribute must be provided if this is set.
*
notExpression: Boolean
*
If true, the property content should always be constant: JMeter * 'expressions' (strings using ${var}, etc...) can't be used. *
notOther: Boolean
*
If true, the property content must always be one of the tags values or * null. *
default: Object
*
Initial value for the property's GUI. Must be provided and be non-null * if notUndefined is set. Must be one of the provided tags (or null) if * notOther is set. *
*

* The following BeanDescriptor attributes are also understood: *

*
group.group.order: Integer
*
where group is a group name used in a group * attribute in one or more PropertyDescriptors. Defines the order in which * the group will be shown in the GUI. A smaller integer means higher up * in the GUI. The default order is 0. Groups of equal order are sorted * alphabetically.
*
resourceBundle: ResourceBundle
*
A resource bundle to be used for GUI localization: group display names * will be obtained from property "group.displayName" if * available (where group is the group name). *
* * @author Jordi Salvat i Alabart * @version $Revision: 1.5 $ updated on $Date: 2004/02/11 17:29:14 $ */ public class GenericTestBeanCustomizer extends JPanel implements SharedCustomizer, PropertyChangeListener { private static Logger log = LoggingManager.getLoggerForClass(); public static final String GROUP= "group"; public static final String ORDER= "order"; public static final String TAGS= "tags"; public static final String NOT_UNDEFINED= "notUndefined"; public static final String NOT_EXPRESSION= "notExpression"; public static final String NOT_OTHER= "notOther"; public static final String DEFAULT= "default"; public static final String RESOURCE_BUNDLE= "resourceBundle"; public static final String ORDER(String group) { return "group."+group+".order"; } public static final String DEFAULT_GROUP= ""; /** * BeanInfo object for the class of the objects being edited. */ private BeanInfo beanInfo; /** * Property descriptors from the beanInfo. */ private PropertyDescriptor[] descriptors; /** * Property editors -- or null if the property can't be edited. * Unused if customizerClass==null. */ private PropertyEditor[] editors; /** * Message format for property field labels: */ private MessageFormat propertyFieldLabelMessage; /** * Message format for property tooltips: */ private MessageFormat propertyToolTipMessage; /** * The Map we're currently customizing. Set by setObject(). */ private Map propertyMap; /** * Create a customizer for a given test bean type. * * @param testBeanClass a subclass of TestBean * @see org.apache.jmeter.testbeans.TestBean */ GenericTestBeanCustomizer(BeanInfo beanInfo) { super(); this.beanInfo= beanInfo; // Get and sort the property descriptors: descriptors= beanInfo.getPropertyDescriptors(); Arrays.sort(descriptors, new PropertyComparator()); // Obtain the propertyEditors: editors= new PropertyEditor[descriptors.length]; for (int i=0; i
... 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.