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

📄 texteditpanel.java

📁 报表设计软件,很好的
💻 JAVA
字号:
/**
 * ========================================================================================
 * JFreeReport Designer : a graphical designer for JFreeReport - a free Java report library
 * ========================================================================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner (taquera@sherito.org);
 *
 * (C) Copyright 2003, by Heiko Evermann (heiko@evermann.de) 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.
 *
 */

package org.jfree.designer.text;

import java.awt.BorderLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import org.jfree.designer.JFreeReportDesigner;
import org.jfree.designer.ReportDefinitionManager;
import org.jfree.designer.RootEditor;
import org.jfree.designer.resources.ResourceBundleUtils;
import org.jfree.designer.text.jedit.JEditTextArea;
import org.jfree.designer.text.jedit.syntax.XMLTokenMarker;
import org.jfree.designer.util.AbstractDesignerAction;
import org.jfree.designer.util.DowngradeActionMap;
import org.jfree.report.modules.gui.base.components.ActionButton;
import org.jfree.report.modules.gui.base.components.ActionDowngrade;
import org.jfree.report.modules.gui.base.components.FloatingButtonEnabler;
import org.jfree.report.util.Log;

public final class TextEditPanel
        extends JPanel
        implements FindHandler, RootEditor
{
  private static final String RESOURCE_BASE_NAME =
          "org.jfree.designer.resources.designer-resources";


  private final class FindAction
          extends AbstractDesignerAction
  {
    /**
     * Defines an <code>Action</code> object with a default description string and default
     * icon.
     */
    public FindAction ()
    {
      putValue(ActionDowngrade.NAME, resources.getString("action.text.find.Name"));
      putValue(ActionDowngrade.SMALL_ICON,
              ResourceBundleUtils.getIcon(resources.getString("action.text.find.SmallIcon")));
      putValue(ActionDowngrade.ACCELERATOR_KEY,
              ResourceBundleUtils.createMenuKeystroke(resources.getString("action.text.find.KeyStroke")));
    }

    /**
     * Invoked when an action occurs.
     */
    public final void actionPerformed (final ActionEvent e)
    {
      final FindDialog d = new FindDialog(TextEditPanel.this);
      d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      d.setLocationRelativeTo(TextEditPanel.this);
      d.showDialog();
    }
  }

  private JEditTextArea textArea;
  private boolean active;
  private JMenu[] editorMenus;
  private ReportDefinitionManager manager;
  private JToolBar toolBar;

  private ResourceBundle resources;

  public TextEditPanel (final ReportDefinitionManager manager)
  {
    this.resources = ResourceBundle.getBundle(RESOURCE_BASE_NAME);
    this.manager = manager;

    final DowngradeActionMap map = manager.getGlobalActions();

    this.toolBar = new JToolBar();
    this.toolBar.add(createButton(map.get(JFreeReportDesigner.NEW_REPORT_ACTION_KEY)));
    this.toolBar.add(createButton(map.get(JFreeReportDesigner.OPEN_REPORT_ACTION_KEY)));
    this.toolBar.add(createButton(map.get(JFreeReportDesigner.SAVE_ACTION_KEY)));
    this.toolBar.add(createButton(map.get(JFreeReportDesigner.SAVE_AS_ACTION_KEY)));
    this.toolBar.addSeparator();
    this.toolBar.add(createButton(new FindAction()));
    textArea = new JEditTextArea();

    textArea.getPainter().setEOLMarkersPainted(false);
    textArea.getPainter().setLineHighlightEnabled(false);
    textArea.setTokenMarker(new XMLTokenMarker());
    textArea.setBorder(new TitledBorder(new EtchedBorder(), "XML Design"));

    this.setLayout(new BorderLayout());
    this.add(textArea, BorderLayout.CENTER);

    editorMenus = new JMenu[1];
    editorMenus[0] = new JMenu(resources.getString("designer.menu.Edit"));
    editorMenus[0].add(new FindAction());

  }

  public final String getXML ()
  {
    final String xml = textArea.getText();
    return xml;
  }

  public final void setXML (final String xml)
  {
    textArea.setText(xml);
    textArea.setCaretPosition(0);
    textArea.requestFocus();
  }

  // -1 for not found
  public final int findText (final String searchText, final int fromPosition)
  {
    final String documentText = textArea.getText();
    final int position = documentText.indexOf(searchText, fromPosition);
    if (position == -1)
    {
      return -1;
    }
    textArea.setSelectionStart(position);
    textArea.setSelectionEnd(position + searchText.length());
    return position;
  }

  public final int getTextSize ()
  {
    return textArea.getDocumentLength();
  }

  public final JMenu[] getEditorMenus ()
  {
    return editorMenus;
  }

  public final boolean isActive ()
  {
    return active;
  }

  public final void setActive (final boolean active)
  {
    final boolean oldActive = this.active;
    this.active = active;
    if (active != oldActive)
    {
      if (active == true)
      {
        onActivate();
      }
      else
      {
        onDeactivate();
      }
    }
    Log.debug("SetActive Called: " + oldActive + " -> " + active);
  }

  private void onActivate ()
  {
    // the text is nnot null..
    Log.debug("is set: " + manager.getReportDefinitionText());
    setXML(manager.getReportDefinitionText());
  }

  private void onDeactivate ()
  {
    if (getXML().trim().length() != 0)
    {
      manager.setReportDefinitionText(getXML());
    }
  }


  public final JComponent getEditorComponent ()
  {
    return this;
  }

  public final String getEditorName ()
  {
    return "Editor";
  }

  public final JToolBar getToolbar ()
  {
    return toolBar;
  }

  /**
   * Creates a button using the given action properties for the button's initialisation.
   *
   * @param action the action used to set up the button.
   * @return a button based on the supplied action.
   */
  protected final JButton createButton (final Action action)
  {
    final JButton button = new ActionButton(action);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setText(null);
    FloatingButtonEnabler.getInstance().addButton(button);
    return button;
  }
}

⌨️ 快捷键说明

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