created mirror
This commit is contained in:
106
Java/ZZTextView.java
Normal file
106
Java/ZZTextView.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
ZZTextView.java
|
||||
*
|
||||
* Copyright (c) 1999, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software 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 README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Tuomas Lukka, rewritten to use AWT by Benja Fallenstein
|
||||
*/
|
||||
package org.gzigzag;
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
|
||||
/** A text view showing the contents of one cell (the cursor).
|
||||
* This is shown in a window of its own, using the AWT TextArea component,
|
||||
* to allow copy-and-paste functions as you know them from PUIs. Basically,
|
||||
* it's a dirty hack, because it's outside the usual GZZ framework.
|
||||
*/
|
||||
|
||||
public class ZZTextView extends Frame implements ZZView {
|
||||
public static final String rcsid = "$Id: ZZTextView.java,v 1.16.2.3 2001/08/16 13:50:01 bfallenstein Exp $";
|
||||
static final boolean dbg = false;
|
||||
static final void p(String s) { if(dbg) System.out.println(s); }
|
||||
static final void pa(String s) { System.out.println(s); }
|
||||
|
||||
ZZCell windowCell;
|
||||
|
||||
/** The cell we show (i.e., the cell currently accursed).
|
||||
* If reraster is called, but the cell and its text haven't changed, we do
|
||||
* nothing, so that the cursor position will not be screwed. (The text
|
||||
* is not cached, instead the text in the TextArea component is used: this
|
||||
* way, if the TextArea itself is used for editing, the text we find there
|
||||
* will be the new text in the cell, so we will not screw the cursor
|
||||
* position either.)
|
||||
* <p>
|
||||
* Note that we simply ignore updates when we have the focus.
|
||||
*/
|
||||
ZZCell shown;
|
||||
|
||||
/** Whether we're updating the content of the TextArea right now.
|
||||
* When we're updating (i.e., write stuff from the structure into
|
||||
* the text area), we obviously ignore events telling us the content
|
||||
* of the text area has changed.
|
||||
*/
|
||||
boolean isUpdating = false;
|
||||
|
||||
/** Whether the text component currently has the focus. */
|
||||
boolean hasFocus;
|
||||
|
||||
public ZZCell getViewcell() { return windowCell; }
|
||||
public void paintNow(float fract) {}
|
||||
|
||||
TextArea txt = new TextArea("", 100, 100,
|
||||
TextArea.SCROLLBARS_VERTICAL_ONLY);
|
||||
|
||||
public ZZTextView(ZZCell c) {
|
||||
windowCell = c;
|
||||
setLayout(new BorderLayout());
|
||||
add(txt, "Center");
|
||||
ZZUpdateManager.addView(this);
|
||||
txt.addTextListener(new TextListener() {
|
||||
public void textValueChanged(TextEvent e) {
|
||||
if(isUpdating) return;
|
||||
shown.setText(txt.getText());
|
||||
ZZCursorReal.setOffs(windowCell, txt.getCaretPosition());
|
||||
}
|
||||
});
|
||||
txt.addFocusListener(new FocusListener() {
|
||||
public void focusGained(FocusEvent e) { hasFocus = true; }
|
||||
public void focusLost(FocusEvent e) { hasFocus = false; }
|
||||
});
|
||||
setBounds(0, 0, 200, 300);
|
||||
setVisible(true);
|
||||
reraster();
|
||||
}
|
||||
|
||||
public boolean reraster() {
|
||||
ZZCell accursed = ZZCursorReal.get(windowCell);
|
||||
if(!hasFocus && (!accursed.equals(shown) ||
|
||||
!accursed.getText().equals(txt.getText()))) {
|
||||
isUpdating = true;
|
||||
txt.setText(accursed.getText());
|
||||
int offs = ZZCursorReal.getOffs(windowCell);
|
||||
if(offs == ZZCursorReal.NO_OFFSET)
|
||||
txt.setCaretPosition(0);
|
||||
else
|
||||
txt.setCaretPosition(offs);
|
||||
shown = accursed;
|
||||
isUpdating = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user