From e22e41d4f3de0b704955737e2ab76cbe9926f50f Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 2 Oct 2016 15:50:16 +0200 Subject: [PATCH] [TASK] Finalize pretty-printing csparql results --- .../csparqltest/gui/TextObserverWindow.java | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/lu/jpt/csparqltest/gui/TextObserverWindow.java b/src/main/java/lu/jpt/csparqltest/gui/TextObserverWindow.java index e8bdd9d..8089196 100644 --- a/src/main/java/lu/jpt/csparqltest/gui/TextObserverWindow.java +++ b/src/main/java/lu/jpt/csparqltest/gui/TextObserverWindow.java @@ -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 tupleElementNames = table.getNames(); Collection 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 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); } /**