[TASK] Make observer window always scroll horizontally
This commit is contained in:
parent
e22e41d4f3
commit
1879d657c6
|
@ -6,7 +6,6 @@ import org.apache.log4j.PropertyConfigurator;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import eu.larkc.csparql.core.engine.ConsoleFormatter;
|
||||
import eu.larkc.csparql.core.engine.CsparqlEngine;
|
||||
import eu.larkc.csparql.core.engine.CsparqlEngineImpl;
|
||||
import eu.larkc.csparql.core.engine.CsparqlQueryResultProxy;
|
||||
|
@ -55,8 +54,8 @@ public class Main {
|
|||
|
||||
|
||||
// Debugging: Needed to verify which engine is being used
|
||||
//logger.debug("CWD: " + System.getProperty("user.dir"));
|
||||
//logger.debug("Engine from: " + engine.getClass().getProtectionDomain().getCodeSource());
|
||||
logger.debug("CWD: " + System.getProperty("user.dir"));
|
||||
logger.debug("Engine from: " + engine.getClass().getProtectionDomain().getCodeSource());
|
||||
|
||||
// Create and register stream generator at specific URI
|
||||
//RentACarSimulation simulation = new RentACarSimulation();
|
||||
|
@ -72,7 +71,7 @@ public class Main {
|
|||
testGeneratorThread.start();
|
||||
|
||||
// Now build a query to run - interchangeable
|
||||
String query = Main.getSPO();
|
||||
String query = Main.getPatternANOTBCQuery();
|
||||
//String query = RentACarSimulation.getEventUsingBackgroundKnowledge();
|
||||
|
||||
// Create a result proxy by registering the query at the engine
|
||||
|
@ -98,8 +97,7 @@ public class Main {
|
|||
logger.error(e.getStackTrace().toString());
|
||||
}*/
|
||||
|
||||
// Add ConsoleFormatter as observer so it gets notified of every query result
|
||||
resultProxy.addObserver(new ConsoleFormatter());
|
||||
// Add observer to query result proxy
|
||||
resultProxy.addObserver(Main.observerWindow);
|
||||
|
||||
// Let it all run for some time
|
||||
|
@ -122,8 +120,6 @@ public class Main {
|
|||
testGeneratorThread.interrupt();
|
||||
engine.unregisterStream(testStreamGenerator.getIRI());
|
||||
|
||||
// That's it!
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private static String getSPO() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.awt.BorderLayout;
|
|||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
@ -13,8 +14,11 @@ import java.util.Observable;
|
|||
import java.util.Observer;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.text.AttributeSet;
|
||||
|
@ -23,8 +27,6 @@ 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;
|
||||
|
@ -126,10 +128,30 @@ public class TextObserverWindow extends JFrame implements Observer {
|
|||
Container contentPane = this.getContentPane();
|
||||
contentPane.setLayout(new BorderLayout());
|
||||
|
||||
// Get a TextPane ready
|
||||
this.textPane = new JTextPane();
|
||||
// Add a title label for convenience
|
||||
JLabel titleLabel = new JLabel(title);
|
||||
Font labelFont = titleLabel.getFont();
|
||||
titleLabel.setFont(new Font(labelFont.getName(), Font.PLAIN, 18));
|
||||
contentPane.add(titleLabel, BorderLayout.NORTH);
|
||||
|
||||
// Get a TextPane ready - a little hack to make it always scroll horizontally
|
||||
this.textPane = new JTextPane() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public boolean getScrollableTracksViewportWidth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSize(Dimension dimension) {
|
||||
if (dimension.width < getParent().getSize().width) {
|
||||
dimension.width = getParent().getSize().width;
|
||||
}
|
||||
super.setSize(dimension);
|
||||
}
|
||||
};
|
||||
this.textPane.setEnabled(true);
|
||||
this.textPane.setFocusable(false);
|
||||
this.textPane.setEditable(true);
|
||||
this.textPane.setAutoscrolls(true);
|
||||
this.textPane.setMargin(new Insets(5, 5, 5, 5));
|
||||
contentPane.add(this.textPane, BorderLayout.CENTER);
|
||||
|
@ -137,8 +159,13 @@ public class TextObserverWindow extends JFrame implements Observer {
|
|||
// Add a ScrollPane
|
||||
JScrollPane scrollPane = new JScrollPane(this.textPane);
|
||||
scrollPane.setPreferredSize(new Dimension(800, 500));
|
||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
||||
contentPane.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// Bottom Panel contains control elements
|
||||
JPanel bottomPanel = new JPanel();
|
||||
|
||||
// Add a checkbox to toggle autoscroll
|
||||
JCheckBox autoscrollCheckbox = new JCheckBox();
|
||||
autoscrollCheckbox.setText("Automatically scroll to bottom");
|
||||
|
@ -151,8 +178,35 @@ public class TextObserverWindow extends JFrame implements Observer {
|
|||
textObserverWindow.setAutoScrollToBottom(checkBox.isSelected());
|
||||
}
|
||||
});
|
||||
contentPane.add(autoscrollCheckbox, BorderLayout.SOUTH);
|
||||
bottomPanel.add(autoscrollCheckbox);
|
||||
|
||||
// Add buttons to increase/decrease font size
|
||||
JButton increaseFontSizeButton = new JButton("+");
|
||||
increaseFontSizeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Font currentFont = textObserverWindow.textPane.getFont();
|
||||
textObserverWindow.textPane.setFont(
|
||||
new Font(currentFont.getName(), currentFont.getStyle(), currentFont.getSize()+1)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
bottomPanel.add(increaseFontSizeButton);
|
||||
JButton decreaseFontSizeButton = new JButton("-");
|
||||
decreaseFontSizeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Font currentFont = textObserverWindow.textPane.getFont();
|
||||
textObserverWindow.textPane.setFont(
|
||||
new Font(currentFont.getName(), currentFont.getStyle(), currentFont.getSize()-1)
|
||||
);
|
||||
}
|
||||
});
|
||||
bottomPanel.add(decreaseFontSizeButton);
|
||||
|
||||
// Add bottomPanel to contentPane
|
||||
contentPane.add(bottomPanel, BorderLayout.SOUTH);
|
||||
this.setVisible(true);
|
||||
this.pack();
|
||||
}
|
||||
|
@ -248,7 +302,7 @@ public class TextObserverWindow extends JFrame implements Observer {
|
|||
tokenIndex++;
|
||||
}
|
||||
}
|
||||
this.showText("-------------------------------------------------------------------------------- \n", Color.BLACK);
|
||||
this.showText("End of results ----------------------------------------------------------------- \n", Color.BLACK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue