[TASK] Fix various exceptions
This commit is contained in:
parent
7269663572
commit
1dfb6d1542
@ -12,7 +12,6 @@ import eu.larkc.csparql.core.engine.CsparqlEngine;
|
|||||||
import eu.larkc.csparql.core.engine.CsparqlEngineImpl;
|
import eu.larkc.csparql.core.engine.CsparqlEngineImpl;
|
||||||
import eu.larkc.csparql.core.engine.CsparqlQueryResultProxy;
|
import eu.larkc.csparql.core.engine.CsparqlQueryResultProxy;
|
||||||
import lu.jpt.csparqlproject.gui.FancyTextObserverWindow;
|
import lu.jpt.csparqlproject.gui.FancyTextObserverWindow;
|
||||||
import lu.jpt.csparqlproject.gui.RawTextObserverWindow;
|
|
||||||
import lu.jpt.csparqlproject.rentacar.RentACarSimulation;
|
import lu.jpt.csparqlproject.rentacar.RentACarSimulation;
|
||||||
import lu.jpt.csparqlproject.util.CsparqlQueryHelper;
|
import lu.jpt.csparqlproject.util.CsparqlQueryHelper;
|
||||||
|
|
||||||
@ -185,11 +184,13 @@ public class SimulationContext {
|
|||||||
*/
|
*/
|
||||||
private Observer createResultObserverWindow(String queryName) {
|
private Observer createResultObserverWindow(String queryName) {
|
||||||
Observer observer = null;
|
Observer observer = null;
|
||||||
|
/*
|
||||||
if(false && queryName.equals("getEvents")) {
|
if(false && queryName.equals("getEvents")) {
|
||||||
observer = new RawTextObserverWindow("[ResultProxy] " + queryName);
|
observer = new RawTextObserverWindow("[ResultProxy] " + queryName);
|
||||||
} else {
|
} else {
|
||||||
observer = new FancyTextObserverWindow("[ResultProxy] " + queryName);
|
observer = new FancyTextObserverWindow("[ResultProxy] " + queryName);
|
||||||
}
|
}*/
|
||||||
|
observer = new FancyTextObserverWindow("[ResultProxy] " + queryName);
|
||||||
return observer;
|
return observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.EventQueue;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -52,6 +53,7 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
|
|||||||
private JTextPane textPane;
|
private JTextPane textPane;
|
||||||
private volatile boolean autoScrollToBottom = true;
|
private volatile boolean autoScrollToBottom = true;
|
||||||
private volatile boolean usePrefixManager = true;
|
private volatile boolean usePrefixManager = true;
|
||||||
|
private volatile boolean clearInsteadOfEleminatingLines = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -70,6 +72,15 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
|
|||||||
this.autoScrollToBottom = autoScrollToBottom;
|
this.autoScrollToBottom = autoScrollToBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the window contents shall be cleared instead of being
|
||||||
|
* maintained line by line to enforce a line limit.
|
||||||
|
* @param clear
|
||||||
|
*/
|
||||||
|
public void setClearInsteadOfEliminatingLines(boolean clear) {
|
||||||
|
this.clearInsteadOfEleminatingLines = clear;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether or not the PrefixManager shall be used to shorten
|
* Set whether or not the PrefixManager shall be used to shorten
|
||||||
* uris in strings to prefixes.
|
* uris in strings to prefixes.
|
||||||
@ -247,12 +258,25 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method to append text to the textpane
|
* Internal man-in-the-middle method to pass the task to the AWT EventQueue
|
||||||
* @param text to show within the window
|
* @param text to show within the window
|
||||||
* @param addLinebreak whether or not to add a linebreak (usually yes is better)
|
* @param addLinebreak whether or not to add a linebreak (usually yes is better)
|
||||||
* @param color to display the text in
|
* @param color to display the text in
|
||||||
*/
|
*/
|
||||||
private void appendToTextPane(String text, boolean addLinebreak, Color color) {
|
private void appendToTextPane(String text, boolean addLinebreak, Color color) {
|
||||||
|
final FancyTextObserverWindow me = this;
|
||||||
|
EventQueue.invokeLater(() -> {
|
||||||
|
me.actuallyAppendTextToTextPane(text, addLinebreak, color);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to append text to the textpane
|
||||||
|
* @param text to show within the window
|
||||||
|
* @param addLinebreak whether or not to add a linebreak (usually yes is better)
|
||||||
|
* @param color to display the text in
|
||||||
|
*/
|
||||||
|
private void actuallyAppendTextToTextPane(String text, boolean addLinebreak, Color color) {
|
||||||
if (addLinebreak) text += "\n";
|
if (addLinebreak) text += "\n";
|
||||||
StyleContext styleContext = StyleContext.getDefaultStyleContext();
|
StyleContext styleContext = StyleContext.getDefaultStyleContext();
|
||||||
AttributeSet attributeSet = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
|
AttributeSet attributeSet = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
|
||||||
@ -271,35 +295,47 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
|
|||||||
}
|
}
|
||||||
} while(!success);
|
} while(!success);
|
||||||
// This is the place to enforce a line limit
|
// This is the place to enforce a line limit
|
||||||
//this.enforceLineLimit();
|
this.enforceLineLimit();
|
||||||
// TODO: Fix behaviour when autoscroll is disabled!
|
// TODO: Fix behaviour when autoscroll is disabled!
|
||||||
if(this.autoScrollToBottom) {
|
if(this.autoScrollToBottom) {
|
||||||
Document textPaneDocument = this.textPane.getDocument();
|
Document textPaneDocument = this.textPane.getDocument();
|
||||||
this.textPane.select(textPaneDocument.getLength(), textPaneDocument.getLength());
|
this.textPane.select(textPaneDocument.getLength(), textPaneDocument.getLength());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to enforce a line limit for the window.
|
* Helper method to enforce a line limit for the window.
|
||||||
*/
|
*/
|
||||||
private void enforceLineLimit() {
|
private void enforceLineLimit() {
|
||||||
int MAX_LINES = 50;
|
int MAX_LINES = 300;
|
||||||
String[] lines = this.textPane.getText().split("\n");
|
String[] lines = this.textPane.getText().split("\n");
|
||||||
int totalLines = lines.length;
|
int totalLines = lines.length;
|
||||||
int characters = 0;
|
int characters = 0;
|
||||||
if(totalLines > MAX_LINES) {
|
if(totalLines > MAX_LINES) {
|
||||||
int linesToRemove = (totalLines - MAX_LINES) - 1;
|
if(clearInsteadOfEleminatingLines) {
|
||||||
if(linesToRemove > 5) {
|
|
||||||
for(int currentLine = 0; currentLine < linesToRemove; currentLine++) {
|
|
||||||
characters += lines[currentLine].length() + 1;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
this.textPane.getDocument().remove(0, characters);
|
this.textPane.getDocument().remove(0, this.textPane.getDocument().getLength());
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
FancyTextObserverWindow.logger.error(e.toString());
|
// This has to work. :-/
|
||||||
FancyTextObserverWindow.logger.error(e.getMessage());
|
}
|
||||||
|
} else {
|
||||||
|
int linesToRemove = (totalLines - MAX_LINES) - 1;
|
||||||
|
if(linesToRemove > 0) {
|
||||||
|
for(int currentLine = 0; currentLine < linesToRemove; currentLine++) {
|
||||||
|
characters += lines[currentLine].length() + 1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.textPane.getDocument().remove(0, characters);
|
||||||
|
} catch (BadLocationException e) {
|
||||||
|
FancyTextObserverWindow.logger.error(e.toString());
|
||||||
|
FancyTextObserverWindow.logger.error(e.getMessage());
|
||||||
|
}
|
||||||
|
// Bonus: Update caret position
|
||||||
|
int length = this.textPane.getDocument().getLength();
|
||||||
|
this.textPane.setCaretPosition(length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ import eu.larkc.csparql.core.engine.CsparqlQueryResultProxy;
|
|||||||
import lu.jpt.csparqlproject.Main;
|
import lu.jpt.csparqlproject.Main;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unused raw text window that uses a textArea instead of a textPane.
|
||||||
|
* Not implemented completely yet.
|
||||||
* Multi-purpose text window to allow for easy viewing of RdfStream quadruples,
|
* Multi-purpose text window to allow for easy viewing of RdfStream quadruples,
|
||||||
* various logging or observing query results.
|
* various logging or observing query results.
|
||||||
*/
|
*/
|
||||||
|
@ -42,7 +42,7 @@ public class RentACarSimulation implements Runnable {
|
|||||||
|
|
||||||
public RentACarSimulation() {
|
public RentACarSimulation() {
|
||||||
this.registerOwnPrefixes();
|
this.registerOwnPrefixes();
|
||||||
int numberOfCars = 1;
|
int numberOfCars = 5;
|
||||||
int numberOfCustomers = 1;
|
int numberOfCustomers = 1;
|
||||||
// Create a car pool and drivers
|
// Create a car pool and drivers
|
||||||
this.carPool = new CarPool(numberOfCars);
|
this.carPool = new CarPool(numberOfCars);
|
||||||
|
Loading…
Reference in New Issue
Block a user