From 33d513ec03ff00520475eb2f42bdbf3d0d6e4d66 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Wed, 12 Oct 2016 16:23:00 +0200 Subject: [PATCH] [TASK] Make it possible to enable/disable window activity. --- .../gui/FancyTextObserverWindow.java | 34 ++++++++++++++----- .../util/WindowLoggingRdfStream.java | 7 ++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java b/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java index c09e2e1..d8056de 100644 --- a/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java +++ b/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java @@ -54,6 +54,7 @@ public class FancyTextObserverWindow extends JFrame implements Observer { private volatile boolean autoScrollToBottom = true; private volatile boolean usePrefixManager = true; private volatile boolean clearInsteadOfEleminatingLines = true; + private volatile boolean updateThisWindow = true; /** * Constructor @@ -90,6 +91,14 @@ public class FancyTextObserverWindow extends JFrame implements Observer { this.usePrefixManager = usePrefixManager; } + /** + * Set whether this window is currently being updated with data + * @param updateThisWindow + */ + public void setUpdateThisWindow(boolean updateThisWindow) { + this.updateThisWindow = updateThisWindow; + } + /** * Show the given text in the window * @param text @@ -196,20 +205,19 @@ public class FancyTextObserverWindow extends JFrame implements Observer { // 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"); - autoscrollCheckbox.setEnabled(true); - autoscrollCheckbox.setSelected(true); - autoscrollCheckbox.addActionListener(new ActionListener() { + // Add a checkbox to toggle updating this window + JCheckBox updateWindowCheckbox = new JCheckBox(); + updateWindowCheckbox.setText("Update this window"); + updateWindowCheckbox.setEnabled(true); + updateWindowCheckbox.setSelected(true); + updateWindowCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox checkBox = (JCheckBox) e.getSource(); - textObserverWindow.setAutoScrollToBottom(checkBox.isSelected()); + textObserverWindow.setUpdateThisWindow(checkBox.isSelected()); } }); - // TODO: Fix the feature first! - //bottomPanel.add(autoscrollCheckbox); + bottomPanel.add(updateWindowCheckbox); // Add a checkbox to toggle uri shortening using PrefixManager JCheckBox usePrefixManagerCheckbox = new JCheckBox(); @@ -265,6 +273,10 @@ public class FancyTextObserverWindow extends JFrame implements Observer { * @param color to display the text in */ private void appendToTextPane(String text, boolean addLinebreak, Color color) { + if(this.updateThisWindow == false) { + // Don't update then window + return; + } final FancyTextObserverWindow me = this; EventQueue.invokeLater(() -> { me.actuallyAppendTextToTextPane(text, addLinebreak, color); @@ -349,6 +361,10 @@ public class FancyTextObserverWindow extends JFrame implements Observer { */ @Override public void update(Observable observable, Object argument) { + if(this.updateThisWindow == false) { + // Don't update the window + return; + } try { if(observable instanceof CsparqlQueryResultProxy) { CsparqlQueryResultProxy result = (CsparqlQueryResultProxy) observable; diff --git a/src/main/java/lu/jpt/csparqlproject/util/WindowLoggingRdfStream.java b/src/main/java/lu/jpt/csparqlproject/util/WindowLoggingRdfStream.java index 2e2ea66..33b8bd3 100644 --- a/src/main/java/lu/jpt/csparqlproject/util/WindowLoggingRdfStream.java +++ b/src/main/java/lu/jpt/csparqlproject/util/WindowLoggingRdfStream.java @@ -1,6 +1,7 @@ package lu.jpt.csparqlproject.util; import eu.larkc.csparql.cep.api.RdfQuadruple; +import lu.jpt.csparqlproject.gui.FancyTextObserverWindow; import lu.jpt.csparqlproject.gui.RawTextObserverWindow; /** @@ -9,7 +10,8 @@ import lu.jpt.csparqlproject.gui.RawTextObserverWindow; */ public class WindowLoggingRdfStream extends LoggableRdfStream { - private RawTextObserverWindow observerWindow; + //private RawTextObserverWindow observerWindow; + private FancyTextObserverWindow observerWindow; public WindowLoggingRdfStream(String iri) { super(iri); @@ -17,7 +19,8 @@ public class WindowLoggingRdfStream extends LoggableRdfStream { final WindowLoggingRdfStream me = this; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { - me.observerWindow = new RawTextObserverWindow("[RdfStream] "+iri); + //me.observerWindow = new RawTextObserverWindow("[RdfStream] "+iri); + me.observerWindow = new FancyTextObserverWindow("[RdfStream] "+iri); } }); }