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

📄 acltextarea.java

📁 java实现的P2P多agent中间件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/******************************************************************
 * JADE - Java Agent DEvelopment Framework is a framework to develop
 * multi-agent systems in compliance with the FIPA specifications.
 * Copyright (C) 2002 TILAB S.p.A.
 *
 * This file is donated by Acklin B.V. to the JADE project.
 *
 *
 * GNU Lesser General Public License
 *
 * 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,
 * version 2.1 of the License.
 *
 * 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 jade.tools.gui;

import java.awt.*;
import java.awt.Component;
import java.awt.Toolkit;
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.awt.event.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.lang.*;
import java.lang.reflect.*;
import java.util.EventObject;
import java.util.Hashtable;
import java.util.StringTokenizer;
import javax.swing.*;
import javax.swing.*;
import javax.swing.JPopupMenu;
import javax.swing.KeyStroke;

import javax.swing.border.EtchedBorder;
import javax.swing.event.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.*;

import jade.lang.acl.ACLMessage;
import jade.tools.sl.SLFormatter;

/**
 *  jEdit's text area component. The original file is written by Slava Pestov
 *  and altered to fit ACL/SL
 *
 * @author     Slava Pestov
 * @created    June 8, 2002
 * @version    $Id: ACLTextArea.java 5581 2005-02-23 08:59:06Z caire $
 */
public class ACLTextArea extends JComponent {
  /**
   *  Creates a new JEditTextArea with the default settings.
   */
  public ACLTextArea() {
    // Enable the necessary events
    enableEvents(AWTEvent.KEY_EVENT_MASK);

    // Initialize some misc. stuff
    painter = new ACLTextAreaPainter(this);
    AutoScroll scroller = new AutoScroll();
    scrollTimer = new Timer(200, scroller);
    documentHandler = new DocumentHandler();
    listenerList = new EventListenerList();
    caretEvent = new MutableCaretEvent();
    lineSegment = new Segment();
    bracketLine = bracketPosition = -1;
    blink = true;
    caretTimer = new Timer(500, new CaretBlinker());
    caretTimer.setInitialDelay(500);
    caretTimer.start();

    // Initialize the GUI
    setBorder(new EtchedBorder(EtchedBorder.LOWERED));
    setLayout(new java.awt.BorderLayout());

    add(painter, BorderLayout.CENTER);

    add(vertical = new JScrollBar(JScrollBar.VERTICAL), BorderLayout.EAST);
    add(horizontal = new JScrollBar(JScrollBar.HORIZONTAL), BorderLayout.SOUTH);
//    vertical.setVisibleAmount(20);
//    horizontal.setVisibleAmount(50);
    // Add some event listeners
    vertical.addAdjustmentListener(new AdjustHandler());
    horizontal.addAdjustmentListener(new AdjustHandler());
    painter.addComponentListener(new ComponentHandler());
    painter.addMouseListener(new MouseHandler());
    painter.addMouseMotionListener(scroller);
    addFocusListener(new FocusHandler());

    // Load the defaults
    InputHandler DEFAULT_INPUT_HANDLER = new InputHandler();
    DEFAULT_INPUT_HANDLER.addDefaultKeyBindings();

    setInputHandler(DEFAULT_INPUT_HANDLER);
    setDocument(new ACLSyntaxDocument());
    editable = true;
    caretVisible = true;
    caretBlinks = true;
    electricScroll = 3;

    // We don't seem to get the initial focus event?
    focusedComponent = this;

    //set tokenMarker
    setTokenMarker(new ACLSLTokenMarker());
  }


  /**
   *  Returns if this component can be traversed by pressing the Tab key. This
   *  returns false.
   *
   * @return    The ManagingFocus value
   */
  public final boolean isManagingFocus() {
    return true;
  }


  /**
   *  Returns the object responsible for painting this text area.
   *
   * @return    The Painter value
   */
  public final ACLTextAreaPainter getPainter() {
    return painter;
  }


  /**
   *  Returns the input handler.
   *
   * @return    The InputHandler value
   */
  public final InputHandler getInputHandler() {
    return inputHandler;
  }


  /**
   *  Returns true if the caret is blinking, false otherwise.
   *
   * @return    The CaretBlinkEnabled value
   */
  public final boolean isCaretBlinkEnabled() {
    return caretBlinks;
  }


  /**
   *  Returns true if the caret is visible, false otherwise.
   *
   * @return    The CaretVisible value
   */
  public final boolean isCaretVisible() {
    return (!caretBlinks || blink) && caretVisible;
  }


  /**
   *  Returns the number of lines from the top and button of the text area
   *  that are always visible.
   *
   * @return    The ElectricScroll value
   */
  public final int getElectricScroll() {
    return electricScroll;
  }


  /**
   *  Returns the line displayed at the text area's origin.
   *
   * @return    The FirstLine value
   */
  public final int getFirstLine() {
    return firstLine;
  }


  /**
   *  Returns the number of lines visible in this text area.
   *
   * @return    The VisibleLines value
   */
  public final int getVisibleLines() {
    return visibleLines;
  }


  /**
   *  Returns the horizontal offset of drawn lines.
   *
   * @return    The HorizontalOffset value
   */
  public final int getHorizontalOffset() {
    return horizontalOffset;
  }


  /**
   *  Returns the document this text area is editing.
   *
   * @return    The Document value
   */
  public final ACLSyntaxDocument getDocument() {
    return document;
  }


  /**
   *  Returns the document's token marker. Equivalent to calling <code>getDocument().getTokenMarker()</code>
   *  .
   *
   * @return    The TokenMarker value
   */
  public final ACLSLTokenMarker getTokenMarker() {
    return document.getTokenMarker();
  }


  /**
   *  Returns the length of the document. Equivalent to calling <code>getDocument().getLength()</code>
   *  .
   *
   * @return    The DocumentLength value
   */
  public final int getDocumentLength() {
    return document.getLength();
  }


  /**
   *  Returns the number of lines in the document.
   *
   * @return    The LineCount value
   */
  public final int getLineCount() {
    return document.getDefaultRootElement().getElementCount();
  }


  /**
   *  Returns the line containing the specified offset.
   *
   * @param  offset  The offset
   * @return         The LineOfOffset value
   */
  public final int getLineOfOffset(int offset) {
    return document.getDefaultRootElement().getElementIndex(offset);
  }


  /**
   *  Returns the specified substring of the document.
   *
   * @param  start  The start offset
   * @param  len    The length of the substring
   * @return        The substring, or null if the offsets are invalid
   */
  public final String getText(int start, int len) {
    try {
      return document.getText(start, len);
    }
    catch (BadLocationException bl) {
      return null;
    }
  }


  /**
   *  Copies the specified substring of the document into a segment. If the
   *  offsets are invalid, the segment will contain a null string.
   *
   * @param  start    The start offset
   * @param  len      The length of the substring
   * @param  segment  The segment
   */
  public final void getText(int start, int len, Segment segment) {
    try {
      document.getText(start, len, segment);
    }
    catch (BadLocationException bl) {
      segment.offset = segment.count = 0;
    }
  }


  /**
   *  Returns the text on the specified line.
   *
   * @param  lineIndex  The line
   * @return            The text, or null if the line is invalid
   */
  public final String getLineText(int lineIndex) {
    int start = getLineStartOffset(lineIndex);
    return getText(start, getLineEndOffset(lineIndex) - start - 1);
  }


  /**
   *  Copies the text on the specified line into a segment. If the line is
   *  invalid, the segment will contain a null string.
   *
   * @param  lineIndex  The line
   * @param  segment    Description of Parameter
   */
  public final void getLineText(int lineIndex, Segment segment) {
    int start = getLineStartOffset(lineIndex);
    getText(start, getLineEndOffset(lineIndex) - start - 1, segment);
  }


  /**
   *  Returns the selection start offset.
   *
   * @return    The SelectionStart value
   */
  public final int getSelectionStart() {
    return selectionStart;
  }


  /**
   *  Returns the selection start line.
   *
   * @return    The SelectionStartLine value
   */
  public final int getSelectionStartLine() {
    return selectionStartLine;
  }


  /**
   *  Returns the selection end offset.
   *
   * @return    The SelectionEnd value
   */
  public final int getSelectionEnd() {
    return selectionEnd;
  }


  /**
   *  Returns the selection end line.
   *
   * @return    The SelectionEndLine value
   */
  public final int getSelectionEndLine() {
    return selectionEndLine;
  }


  /**
   *  Returns the caret position. This will either be the selection start or
   *  the selection end, depending on which direction the selection was made
   *  in.
   *
   * @return    The CaretPosition value
   */
  public final int getCaretPosition() {
    return (biasLeft ? selectionStart : selectionEnd);
  }


  /**
   *  Returns the caret line.
   *
   * @return    The CaretLine value
   */
  public final int getCaretLine() {
    return (biasLeft ? selectionStartLine : selectionEndLine);
  }


  /**
   *  Returns the mark position. This will be the opposite selection bound to
   *  the caret position.
   *
   * @return    The MarkPosition value
   * @see       #getCaretPosition()
   */
  public final int getMarkPosition() {
    return (biasLeft ? selectionEnd : selectionStart);
  }


  /**
   *  Returns the mark line.
   *
   * @return    The MarkLine value
   */
  public final int getMarkLine() {
    return (biasLeft ? selectionEndLine : selectionStartLine);
  }


  /**
   *  Returns the selected text, or null if no selection is active.
   *
   * @return    The SelectedText value
   */
  public final String getSelectedText() {
    if (selectionStart == selectionEnd) {
      return null;
    }
    return getText(selectionStart,
      selectionEnd - selectionStart);
  }


  /**
   *  Returns true if this text area is editable, false otherwise.
   *
   * @return    The Editable value
   */
  public final boolean isEditable() {
    return editable;
  }


  /**
   *  Returns the right click popup menu.
   *
   * @return    The RightClickPopup value
   */
  public final JPopupMenu getRightClickPopup() {
    return popup;
  }


  /**
   *  Returns the `magic' caret position. This can be used to preserve the
   *  column position when moving up and down lines.
   *
   * @return    The MagicCaretPosition value
   */
  public final int getMagicCaretPosition() {
    return magicCaret;
  }


  /**
   *  Returns true if overwrite mode is enabled, false otherwise.
   *
   * @return    The OverwriteEnabled value
   */
  public final boolean isOverwriteEnabled() {
    return overwrite;
  }


  /**
   *  Returns the position of the highlighted bracket (the bracket matching
   *  the one before the caret)
   *
   * @return    The BracketPosition value
   */
  public final int getBracketPosition() {
    return bracketPosition;
  }


  /**
   *  Returns the line of the highlighted bracket (the bracket matching the
   *  one before the caret)
   *
   * @return    The BracketLine value
   */
  public final int getBracketLine() {
    return bracketLine;
  }


  /**
   *  Sets the number of lines from the top and bottom of the text area that
   *  are always visible
   *
   * @param  electricScroll  The number of lines always visible from the top
   *      or bottom
   */
  public final void setElectricScroll(int electricScroll) {
    this.electricScroll = electricScroll;
  }


  /**
   *  Sets the document's token marker. Equivalent to caling <code>getDocument().setTokenMarker()</code>
   *  .
   *
   * @param  tokenMarker  The token marker

⌨️ 快捷键说明

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