118 lines
3.6 KiB
Java
118 lines
3.6 KiB
Java
/*
|
|
ZZText.java
|
|
*
|
|
* Copyright (c) 2000, 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
|
|
*/
|
|
package org.gzigzag;
|
|
import java.awt.*;
|
|
|
|
/** An interface for getting or putting text in cells.
|
|
* Used e.g. to implement multilingual text.
|
|
* Handles referential text as well.
|
|
*/
|
|
|
|
public abstract class ZZText {
|
|
public static final String rcsid = "$Id: ZZText.java,v 1.2 2000/10/19 17:04:26 tjl Exp $";
|
|
|
|
/** Get the string in a given cell, whether referential or non-referential.
|
|
*/
|
|
public abstract String getText(ZZCell c);
|
|
|
|
/** Set the string in the given cell non-referentially.
|
|
*/
|
|
public abstract void setText(ZZCell c, String s);
|
|
|
|
/** Whether a given cell is referential.
|
|
*/
|
|
public abstract boolean isRef(ZZCell c);
|
|
|
|
/** Insert the given text into the cell.
|
|
* If the cell is referential, insert referentially by creating
|
|
* a new Span for this text. Else just handle characters.
|
|
*/
|
|
public void insert(ZZCell c, String txt, int offs) {
|
|
if(isRef(c)) {
|
|
insertNewRef(c, txt, offs);
|
|
} else {
|
|
String s = getText(c);
|
|
setText(c, s.substring(0, offs) + txt + s.substring(offs));
|
|
}
|
|
}
|
|
|
|
/** Delete a span of text from this cell.
|
|
*/
|
|
public abstract void delete(ZZCell c, int start);
|
|
|
|
/** Delete a span of text from this cell.
|
|
*/
|
|
public abstract void delete(ZZCell c, int start, int end);
|
|
|
|
/** Split a cell into two along a dimension.
|
|
* 0..offs-1 goes into first, offs..end goes to next.
|
|
* All connections remain in the first cell.
|
|
*/
|
|
public void split(ZZCell c, int offs, String dim) {
|
|
ZZCell n = c.N(dim);
|
|
if(isRef(c)) {
|
|
Span[] sps = getSpans(c, offs);
|
|
setSpans(n, sps);
|
|
delete(c, offs);
|
|
} else {
|
|
String s = getText(c);
|
|
setText(c, s.substring(0, offs));
|
|
setText(n, s.substring(offs));
|
|
}
|
|
}
|
|
|
|
/** Insert a string of typed-in text referentially.
|
|
* A Span in the current cell's space is automatically constructed, etc.
|
|
* This is at this level because we *may* want to fudge things later if
|
|
* the user corrects typing errors before saving. However, that's a
|
|
* bit tricky
|
|
* so we won't try it yet.
|
|
* <p>
|
|
* Calling this function on a cell that only has text content
|
|
* makes the whole
|
|
* current text content referential as well.
|
|
*/
|
|
public abstract void insertNewRef(ZZCell c, String txt, int offs);
|
|
|
|
/** Insert a referential span of text.
|
|
* <p>
|
|
* Calling this function on a cell that only has text content
|
|
* makes the whole
|
|
* current text content referential as well.
|
|
*/
|
|
public abstract void insertRef(ZZCell c, Span sp, int offs);
|
|
|
|
/** Obtain the referential contents of this cell.
|
|
* @return List of spans, or null if not referential.
|
|
*/
|
|
public abstract Span[] getSpans(ZZCell c);
|
|
public abstract Span[] getSpans(ZZCell c, int start);
|
|
public abstract Span[] getSpans(ZZCell c, int start, int end);
|
|
|
|
/** Set the spans of the cell to the given spans.
|
|
*/
|
|
public abstract void setSpans(ZZCell c, Span[] spans);
|
|
|
|
|
|
}
|