⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 templateeditorpane.java

📁 报表设计软件,很好的
💻 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.
 *
 * ------------------------------
 * TemplateEditorPane.java
 * ------------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: TemplateEditorPane.java,v 1.2 2004/04/20 18:55:01 taqua Exp $
 *
 * Changes
 * -------------------------
 * 08.11.2003 : Initial version
 *
 */

package org.jfree.designer.visualeditor.elementeditor;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Iterator;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jfree.report.filter.templates.NumberFieldTemplate;
import org.jfree.report.filter.templates.Template;
import org.jfree.report.modules.parser.ext.factory.templates.DefaultTemplateCollection;
import org.jfree.report.modules.parser.ext.factory.templates.TemplateCollection;
import org.jfree.report.modules.parser.ext.factory.templates.TemplateCollector;
import org.jfree.report.modules.parser.ext.factory.templates.TemplateDescription;
import org.jfree.report.util.Log;
import org.jfree.xml.factory.objects.ObjectFactoryException;

public final class TemplateEditorPane
        extends JPanel
        implements ChangeListener
{
  private Template template;
  private TemplateDescription templateDescription;
  private final TemplateCollector templateCollection;

  public TemplateEditorPane ()
  {
    templateCollection = new TemplateCollector();
    addTemplateCollection(new DefaultTemplateCollection());
    setLayout(new GridBagLayout());
  }

  public final void addTemplateCollection (final TemplateCollection collection)
  {
    templateCollection.addTemplateCollection(collection);
  }

  public final Template getTemplate ()
  {
    return template;
  }

  /**
   * Invoked when the target of the listener has changed its state.
   *
   * @param e a ChangeEvent object
   */
  public final void stateChanged (final ChangeEvent e)
  {
    if (this.template == null)
    {
      return;
    }

    try
    {
      final Template oldValue = this.template;
      this.template = templateDescription.createTemplate();
      firePropertyChange("template", oldValue, template);
    }
    catch (Exception ex)
    {
      // ignore me if failed.
    }
  }

  public final void setTemplate (final Template template)
  {
    final Template oldValue = this.template;
    this.template = template;

    removeAll();
    if (template != null)
    {
      templateDescription = templateCollection.getDescription(template);
    }
    if (template == null || templateDescription == null)
    {
      final GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.anchor = GridBagConstraints.WEST;
      add(new JLabel("Unsupported template or no template at all."), gbc);

      this.template = null;
    }
    else
    {
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.anchor = GridBagConstraints.WEST;
      add(new JLabel("Template: " + templateDescription.getName()), gbc);

      try
      {
        templateDescription.setParameterFromObject(template);
      }
      catch (ObjectFactoryException ofe)
      {
        Log.error("Unable to handle template", ofe);
        throw new IllegalArgumentException();
      }

      int i = 1;
      final Iterator it = templateDescription.getParameterNames();
      while (it.hasNext())
      {
        final String name = (String) it.next();
        final Class parameterType = templateDescription.getParameterDefinition(name);
        final Object value = templateDescription.getParameter(name);

        final PropertyEditorContainer container = new PropertyEditorContainer(parameterType);
        container.setValue(value);

        final TemplateParameterCarrier carrier =
                new TemplateParameterCarrier(name, templateDescription, container);
        carrier.setListener(this);

        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = i;
        gbc.anchor = GridBagConstraints.WEST;
        add(carrier.getLabel(), gbc);

        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = i;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1;
        gbc.anchor = GridBagConstraints.WEST;
        add(carrier.getContainer(), gbc);

        i += 1;
      }
    }
    firePropertyChange("template", oldValue, this.template);
  }

  public static void main (final String[] args)
  {
    final JDialog dialog = new JDialog();

    NumberFieldTemplate template = new NumberFieldTemplate();

    final TemplateEditorPane ep = new TemplateEditorPane();
    ep.setTemplate(template);
    dialog.setContentPane(ep);
    dialog.pack();
    dialog.setModal(true);
    dialog.setVisible(true);
    template = (NumberFieldTemplate) ep.getTemplate();
    Log.debug(template.getField());
    System.exit(0);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -