📄 propertyeditorutil.java
字号:
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner (taquera@sherito.org);
*
* (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ------------------------------
* PropertyEditorUtil.java
* ------------------------------
* (C)opyright 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: PropertyEditorUtil.java,v 1.2 2004/04/20 18:54:42 taqua Exp $
*
* Changes
* -------------------------
* 25.10.2003 : Initial version
*
*/
package org.jfree.designer.propertyeditors;
import java.awt.Color;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import org.jfree.report.ElementAlignment;
import org.jfree.report.layout.BandLayoutManager;
import org.jfree.report.util.Log;
public final class PropertyEditorUtil
{
private static PropertyEditorUtil instance;
private final HashMap propertyEditors;
private void registerPropertyEditors ()
{
Log.info("Registering property editors...");
PropertyEditorManager.registerEditor(Color.class, ColorPropertyEditor.class);
PropertyEditorManager.registerEditor(Boolean.class, BooleanPropertyEditor.class);
PropertyEditorManager.registerEditor(String.class, StringPropertyEditor.class);
PropertyEditorManager.registerEditor(Integer.class, IntegerPropertyEditor.class);
PropertyEditorManager.registerEditor
(ElementAlignment.class, ElementAlignmentPropertyEditor.class);
PropertyEditorManager.registerEditor
(BandLayoutManager.class, BandLayoutManagerPropertyEditor.class);
registerCustomPropertyEditor(Dimension2D.class, Dimension2DPropertyEditor.class);
registerCustomPropertyEditor(Rectangle2D.class, Rectangle2DPropertyEditor.class);
registerCustomPropertyEditor(Point2D.class, Point2DPropertyEditor.class);
}
private PropertyEditorUtil ()
{
propertyEditors = new HashMap();
}
private static PropertyEditorUtil getInstance ()
{
if (instance == null)
{
instance = new PropertyEditorUtil();
instance.registerPropertyEditors();
}
return instance;
}
public static void registerCustomPropertyEditor (final Class type, final Class editor)
{
if (hasDefaultConstructor(editor) == false)
{
throw new IllegalArgumentException
("The given property editor has no public default constructor.");
}
getInstance().propertyEditors.put(type, editor);
}
public static PropertyEditor findPropertyEditor (final Class type)
{
final Class editor = findRegisteredEditor(type);
if (editor != null)
{
try
{
return (PropertyEditor) editor.newInstance();
}
catch (Exception e)
{
Log.warn("PropertyEditorUtil: ", e);
}
}
return PropertyEditorManager.findEditor(type);
}
private static Class findRegisteredEditor (final Class type)
{
final PropertyEditorUtil util = getInstance();
Class currentSearchType = type;
while (currentSearchType != null)
{
final Class edClass = (Class) util.propertyEditors.get(currentSearchType);
if (edClass != null)
{
return edClass;
}
currentSearchType = currentSearchType.getSuperclass();
}
return null;
}
public static boolean hasDefaultConstructor (final Class type)
{
try
{
final Constructor con = type.getConstructor(new Class[0]);
return Modifier.isPublic(con.getModifiers());
}
catch (Exception e)
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -