org.semanticweb.HermiT.debugger.ConsoleTextArea Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.semanticweb.hermit Show documentation
Show all versions of org.semanticweb.hermit Show documentation
HermiT is reasoner for ontologies written using the Web
Ontology Language (OWL). Given an OWL file, HermiT can determine whether or
not the ontology is consistent, identify subsumption relationships between
classes, and much more.
This is the maven build of HermiT and is designed for people who wish to use
HermiT from within the OWL API. It is now versioned in the main HermiT
version repository, although not officially supported by the HermiT
developers.
The version number of this package is a composite of the HermiT version and
an value representing releases of this packaged version. So, 1.3.7.1 is the
first release of the mavenized version of HermiT based on the 1.3.7 release
of HermiT.
This package includes the Jautomata library
(http://jautomata.sourceforge.net/), and builds with it directly. This
library appears to be no longer under active development, and so a "fork"
seems appropriate. No development is intended or anticipated on this code
base.
/* Copyright 2008, 2009, 2010 by the Oxford University Computing Laboratory
This file is part of HermiT.
HermiT 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, either version 3 of the License, or
(at your option) any later version.
HermiT 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 HermiT. If not, see .
*/
package org.semanticweb.HermiT.debugger;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
@SuppressWarnings("serial")
public class ConsoleTextArea extends JTextArea {
protected final ConsoleWriter m_writer;
protected final ConsoleReader m_reader;
protected int m_userTypedTextStart;
public ConsoleTextArea() {
setDocument(new ConsoleDocument());
m_writer=new ConsoleWriter();
m_reader=new ConsoleReader();
enableEvents(KeyEvent.KEY_EVENT_MASK);
}
public Writer getWriter() {
return m_writer;
}
public Reader getReader() {
return m_reader;
}
public void clear() {
m_userTypedTextStart=0;
setText("");
}
protected void moveToEndIfNecessary() {
int selectionStart=getSelectionStart();
int selectionEnd=getSelectionEnd();
if (selectionEnd=m_userTypedTextStart)
super.remove(offset,length);
}
public void insertString(int offset,String string,AttributeSet attributeSet) throws BadLocationException {
if (offset>=m_userTypedTextStart)
super.insertString(offset,string,attributeSet);
}
}
protected class ConsoleWriter extends Writer implements ActionListener {
protected final char[] m_buffer;
protected final Timer m_timer;
protected int m_firstFreeChar;
public ConsoleWriter() {
m_buffer=new char[4096];
m_timer=new Timer(500,this);
m_timer.setRepeats(false);
m_firstFreeChar=0;
}
public void close() {
flush();
}
public void flush() {
synchronized (lock) {
if (m_firstFreeChar>0) {
final String string=new String(m_buffer,0,m_firstFreeChar);
m_firstFreeChar=0;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
replaceSelection(string);
m_userTypedTextStart=getDocument().getLength();
select(m_userTypedTextStart,m_userTypedTextStart);
}
});
m_timer.stop();
}
}
}
public void write(char[] buffer,int offset,int count) {
synchronized (lock) {
int lastPosition=offset+count;
while (offset!=lastPosition) {
int toCopy=Math.min(m_buffer.length-m_firstFreeChar,count);
if (toCopy!=0) {
System.arraycopy(buffer,offset,m_buffer,m_firstFreeChar,toCopy);
count-=toCopy;
offset+=toCopy;
boolean bufferWasEmpty=(m_firstFreeChar==0);
m_firstFreeChar+=toCopy;
if (m_firstFreeChar>=m_buffer.length)
flush();
else if (bufferWasEmpty)
m_timer.start();
}
}
}
}
public void actionPerformed(ActionEvent e) {
flush();
}
}
protected class ConsoleReader extends Reader {
protected char[] m_buffer;
protected int m_nextCharToRead;
protected int m_firstFreeChar;
public ConsoleReader() {
m_buffer=new char[4096];
m_nextCharToRead=0;
m_firstFreeChar=0;
}
public void addToBuffer(String string) {
synchronized (lock) {
if (m_nextCharToRead==m_firstFreeChar) {
m_nextCharToRead=0;
m_firstFreeChar=0;
}
else {
if (m_nextCharToRead!=0) {
System.arraycopy(m_buffer,m_nextCharToRead,m_buffer,0,m_firstFreeChar-m_nextCharToRead);
m_nextCharToRead=0;
m_firstFreeChar=0;
}
}
if (m_firstFreeChar+string.length()>m_buffer.length) {
char[] newBuffer=new char[m_firstFreeChar+string.length()];
System.arraycopy(m_buffer,0,newBuffer,0,m_buffer.length);
m_buffer=newBuffer;
}
string.getChars(0,string.length(),m_buffer,m_firstFreeChar);
m_firstFreeChar+=string.length();
notifyAll();
}
}
public void close() throws IOException {
}
public int read(char[] buffer,int offset,int length) throws IOException {
m_writer.flush();
synchronized (lock) {
while (m_nextCharToRead==m_firstFreeChar)
try {
lock.wait();
}
catch (InterruptedException error) {
throw new IOException("Read interruipted.");
}
int toCopy=Math.min(m_firstFreeChar-m_nextCharToRead,length);
System.arraycopy(m_buffer,m_nextCharToRead,buffer,offset,toCopy);
m_nextCharToRead+=toCopy;
return toCopy;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy