[TASK] Finalize pretty-printing csparql results

This commit is contained in:
Jan Philipp Timme 2016-10-02 15:50:16 +02:00
parent 896fe022a8
commit e22e41d4f3
1 changed files with 32 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
import java.util.StringTokenizer;
@ -22,6 +23,8 @@ import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import com.sun.xml.internal.ws.resources.TubelineassemblyMessages;
import eu.larkc.csparql.cep.api.RdfQuadruple;
import eu.larkc.csparql.common.RDFTable;
import eu.larkc.csparql.common.RDFTuple;
@ -140,6 +143,7 @@ public class TextObserverWindow extends JFrame implements Observer {
JCheckBox autoscrollCheckbox = new JCheckBox();
autoscrollCheckbox.setText("Automatically scroll to bottom");
autoscrollCheckbox.setEnabled(true);
autoscrollCheckbox.setSelected(true);
autoscrollCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -201,29 +205,50 @@ public class TextObserverWindow extends JFrame implements Observer {
}
/**
* Method to actually print the results of a Csparql query
* Method to actually pretty-print the results of a Csparql query
* @param CsparqlQueryResultProxy result
* @param RDFTable table
*/
private void showCsparqlQueryResult(CsparqlQueryResultProxy result, RDFTable table) {
String queryTupleNames = table.getNames().toString();
long currentTime = System.currentTimeMillis();
Collection<String> tupleElementNames = table.getNames();
Collection<RDFTuple> tuples = table.getTuples();
this.showText(queryTupleNames, Color.BLACK);
Color[] palette = this.getColorPaletteWithSize(table.getNames().size());
this.showText("SystemTime=["+currentTime+"], Results=["+tuples.size()+"]", Color.BLACK);
// Show names in according color coding
this.showToken("Columns in order: [", Color.BLACK);
Iterator<String> elementNamesIterator = tupleElementNames.iterator();
int nameIndex = 0;
while(elementNamesIterator.hasNext()) {
String elementName = elementNamesIterator.next();
if(elementName == "") elementName = "[NO VALUE]";
if(elementNamesIterator.hasNext()) {
elementName += ", ";
}
this.showToken(elementName, palette[nameIndex]);
nameIndex++;
}
this.showText("]", Color.BLACK);
for(RDFTuple tuple : tuples) {
// This one is separated with \t. Due to the implementation of RDFTuple, it is
// implossible to access the list of its fields directly. Sorry for the mess. :-(
// impossible to access the list of its fields directly. Sorry for the mess. :-(
String tupleString = tuple.toString();
// Explode tupleString by \t and show each field with alternating color.
StringTokenizer tokenizer = new StringTokenizer(tupleString);
Color[] palette = this.getColorPaletteWithSize(tokenizer.countTokens());
int tokenIndex = 0;
while(tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken()+"\t";
String token = tokenizer.nextToken();
if(token == "") token = "[NO VALUE]";
if(tokenizer.hasMoreTokens()) {
token += "\t";
} else {
token += "\n";
}
this.showToken(token, palette[tokenIndex]);
tokenIndex++;
}
this.showText("\n", Color.BLACK);
}
this.showText("-------------------------------------------------------------------------------- \n", Color.BLACK);
}
/**