/*
 * @(#)QueryDocument.java	0.1 2001/08/27
 *
 * Copyright 2001 by Carnegie Mellon, All rights reserved.
 */

package ksdb;

import javax.swing.text.*;

/**
 * This is a document that disallows changing of newlines through inserts
 * and deletes.
 */
public class QueryDocument extends edu.cmu.lti.kantoo.clc.text.SegmentedDocument {

  private String newline = "\n";

  private boolean lineBreaksDisabled = false;

  public boolean setLineBreaksDisabled(boolean flag) {
    return this.lineBreaksDisabled = flag;
  }


  public void remove(int offs, int len) throws BadLocationException {
    if (lineBreaksDisabled && (getText( offs, len).indexOf( newline) >= 0))
      return;
    super.remove( offs, len);
  }

  public void insertString(int offs, String str, AttributeSet a)
    throws BadLocationException {
    if (lineBreaksDisabled && (str.indexOf( newline) >= 0))
      return;
    super.insertString( offs, str, a);
  }
}

