Пример #1
0
  /**
   * Default constructor.
   *
   * @param edit editable flag
   * @param win parent window
   */
  public BaseXEditor(final boolean edit, final Window win) {
    super(win);
    setFocusable(true);
    setFocusTraversalKeysEnabled(!edit);

    addMouseMotionListener(this);
    addMouseWheelListener(this);
    addComponentListener(this);
    addMouseListener(this);
    addKeyListener(this);

    addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(final FocusEvent e) {
            if (isEnabled()) cursor(true);
          }

          @Override
          public void focusLost(final FocusEvent e) {
            cursor(false);
            rend.cursor(false);
            rend.repaint();
          }
        });

    layout(new BorderLayout(4, 0));
    scroll = new BaseXBar(this);
    rend = new BaseXTextRenderer(text, scroll);

    add(rend, BorderLayout.CENTER);
    add(scroll, BorderLayout.EAST);

    Undo un = null;
    if (edit) {
      setBackground(Color.white);
      setBorder(new MatteBorder(1, 1, 0, 0, GUIConstants.color(6)));
      un = new Undo();
    } else {
      mode(Fill.NONE);
    }
    undo = un;

    new BaseXPopup(
        this,
        edit
            ? new GUICommand[] {
              new UndoCmd(),
              new RedoCmd(),
              null,
              new CutCmd(),
              new CopyCmd(),
              new PasteCmd(),
              new DelCmd(),
              null,
              new AllCmd()
            }
            : new GUICommand[] {new CopyCmd(), null, new AllCmd()});
  }
Пример #2
0
  /**
   * Default constructor.
   *
   * @param txt initial text
   * @param editable editable flag
   * @param win parent window
   */
  public TextPanel(final String txt, final boolean editable, final Window win) {
    super(win);
    this.editable = editable;
    editor = new TextEditor(gui);

    setFocusable(true);
    setFocusTraversalKeysEnabled(!editable);
    setBackground(BACK);
    setOpaque(editable);

    addMouseMotionListener(this);
    addMouseWheelListener(this);
    addComponentListener(this);
    addMouseListener(this);
    addKeyListener(this);

    addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(final FocusEvent e) {
            if (isEnabled()) caret(true);
          }

          @Override
          public void focusLost(final FocusEvent e) {
            caret(false);
            rend.caret(false);
          }
        });

    setFont(dmfont);
    layout(new BorderLayout());

    scroll = new BaseXScrollBar(this);
    rend = new TextRenderer(editor, scroll, editable, gui);

    add(rend, BorderLayout.CENTER);
    add(scroll, BorderLayout.EAST);

    setText(txt);
    hist = new History(editable ? editor.text() : null);

    new BaseXPopup(
        this,
        editable
            ? new GUICommand[] {
              new FindCmd(),
              new FindNextCmd(),
              new FindPrevCmd(),
              null,
              new GotoCmd(),
              null,
              new UndoCmd(),
              new RedoCmd(),
              null,
              new AllCmd(),
              new CutCmd(),
              new CopyCmd(),
              new PasteCmd(),
              new DelCmd()
            }
            : new GUICommand[] {
              new FindCmd(),
              new FindNextCmd(),
              new FindPrevCmd(),
              null,
              new GotoCmd(),
              null,
              new AllCmd(),
              new CopyCmd()
            });
  }