Skip to content
Browse files

refactored toolbar

  • Loading branch information...
1 parent d622f5a commit b7bf28f5a5480d7a37742417c54c19ab30cce1f9 @danja committed Mar 11, 2011
View
17 cloc_2011-03-09.txt
@@ -0,0 +1,17 @@
+ 100 files 200 files 300 files 400 files 500 files 505 text files.
+classified 505 files Duplicate file check 505 files (464 known unique) Unique: 100 files Unique: 200 files Unique: 300 files Unique: 400 files 484 unique files.
+Counting: 100 Counting: 200 Counting: 300 Counting: 400 61 files ignored.
+
+http://cloc.sourceforge.net v 1.09 T=10.0 s (42.5 files/s, 10093.9 lines/s)
+-------------------------------------------------------------------------------
+Language files blank comment code scale 3rd gen. equiv
+-------------------------------------------------------------------------------
+HTML 249 9154 3996 69603 x 1.90 = 132245.70
+Java 160 2642 6494 8236 x 1.36 = 11200.96
+CSS 4 86 59 297 x 1.00 = 297.00
+XML 5 59 102 168 x 1.90 = 319.20
+Bourne Shell 6 8 9 24 x 3.81 = 91.44
+Haskell 1 0 0 2 x 2.11 = 4.22
+-------------------------------------------------------------------------------
+SUM: 425 11949 10660 78330 x 1.84 = 144158.52
+-------------------------------------------------------------------------------
View
2 data/sparql-temp.txt
@@ -1,4 +1,4 @@
SELECT DISTINCT * WHERE {
?s ?p ?o
}
-LIMIT 10
+LIMIT 10zxc
View
16 data/temp.txt
@@ -1,13 +1,7 @@
-# Turtle Syntax (autogenerated - leave this line intact)
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
-<http://purl.org/stuff/brian>
- <http://xmlns.com/foaf/0.1/knows>
- <http://purl.org/stuff/andy> .
+SELECT DISTINCT * WHERE {
-<http://purl.org/stuff/carl>
- <http://xmlns.com/foaf/0.1/name>
- "carl" .
-
-<http://purl.org/stuff/andy>
- <http://xmlns.com/foaf/0.1/knows>
- <http://purl.org/stuff/brian> .
+ <http://dbpedia.org/resource/Neptune> a ?object .
+ ?object rdfs:label ?label .
+}
View
3 doc/notes/sparql-to-do_2011-05-05.txt
@@ -1,5 +1,8 @@
HIDE toolbars if not needed (a la gnome bars?)
+spellchecker for RDF terms?
+http://www.javaworld.com/javaworld/jw-02-2001/jw-0216-ternary.html?page=1
+http://jstomp.sourceforge.net/comboBox/search.html
null any previous runner on Run
View
24 src/org/hyperdata/scute/autosave/AutoSave.java
@@ -21,6 +21,7 @@
import org.hyperdata.scute.cards.Card;
import org.hyperdata.scute.cards.CardsPanel;
import org.hyperdata.scute.main.Config;
+import org.hyperdata.scute.main.ScratchPad;
import org.hyperdata.scute.main.Scute;
import org.hyperdata.scute.rdf.ModelContainer;
import org.hyperdata.scute.source.TextContainer;
@@ -40,6 +41,8 @@
/** The text saver. */
private TextSaver textSaver;
+ private TextSaver scratchTextSaver;
+ private TextContainer scratchTextContainer;
/** The model timer. */
private final Timer timer = new Timer();
@@ -87,7 +90,7 @@ public void activityOccurred(EventObject object) {
*/
@Override
public void focusGained(FocusEvent event) {
-
+ // scratchTextSaver - maybe..?
textSaver.save(); // save the old one
reschedule(); // start over
}
@@ -104,6 +107,10 @@ public void reschedule() {
if (textSaver != null) {
textSaver.cancel();
}
+ if (scratchTextSaver != null) {
+ scratchTextSaver.cancel();
+ }
+
timer.purge(); // clean queue
modelSaver = new ModelSaver(workingModelContainer);
@@ -113,6 +120,10 @@ public void reschedule() {
textSaver = new TextSaver(currentTextContainer);
timer.schedule(textSaver, Config.self.getTextSaveDelay());
}
+
+ scratchTextSaver = new TextSaver(scratchTextContainer);
+ timer.schedule(scratchTextSaver, Config.self.getTextSaveDelay());
+
}
/*
@@ -178,6 +189,10 @@ private void finishUp() {
textSaver.cancel();
textSaver.save();
}
+ if (scratchTextSaver != null) {
+ scratchTextSaver.cancel();
+ scratchTextSaver.save();
+ }
Config.self.setSync(true);
Config.self.saveNow();
}
@@ -215,4 +230,11 @@ public void stateChanged(ChangeEvent event) {
}
}
+ /**
+ * @param scratchPad
+ */
+ public void setScratchTextContainer(TextContainer textContainer) {
+ scratchTextContainer = textContainer;
+ }
+
}
View
9 src/org/hyperdata/scute/cards/Card.java
@@ -8,6 +8,7 @@
import javax.swing.JPanel;
+import org.hyperdata.scute.source.EditorPane;
import org.hyperdata.scute.source.TextContainer;
@@ -19,6 +20,7 @@
// this is a bit yucky, will do for now
private TextContainer textContainer = null;
+// private EditorPane editorPane = null;
private boolean textCard = false;
// JPanel's constructors
@@ -64,4 +66,11 @@ public boolean isTextCard() {
return textCard;
}
+// public EditorPane getEditorPane() {
+// return this.editorPane;
+// }
+//
+// public void setEditorPane(EditorPane editorPane) {
+// this.editorPane = editorPane;
+// }
}
View
133 src/org/hyperdata/scute/editortools/EditorToolbar.java
@@ -6,12 +6,18 @@
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.beans.PropertyChangeListener;
+import java.util.HashMap;
+import java.util.Map;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.event.UndoableEditListener;
+import javax.swing.text.Document;
import javax.swing.undo.UndoManager;
import org.jdesktop.swingx.JXErrorPane;
@@ -36,62 +42,127 @@
/** UndoManager that we add edits to. */
public UndoManager undoManager = new UndoManager();
- public EditorToolbar(Frame frame, JEditorPane findPane, EditorPane zoomPane) {
+ private JButton undoButton;
- undoHandler = new UndoHandler(zoomPane);
- zoomPane.getDocument().addUndoableEditListener(undoHandler);
+ private JButton redoButton;
- Action undoAction = zoomPane.getUndoAction();
- JButton undoButton = new JButton(undoAction);
+ private JButton findButton;
+
+ private JButton zoomIn;
+
+ private JButton zoomOut;
+
+ private Frame frame = null;
+
+ private Map<Document, UndoHandler> undoHandlerMap = new HashMap<Document, UndoHandler>();
+
+ private PropertyChangeListener undoActionChangeListener;
+ private PropertyChangeListener redoActionChangeListener;
+
+ public EditorToolbar(Frame frame) {
+ this.frame = frame;
+ init();
+ }
+
+ private void init() {
+ undoButton = new JButton();
undoButton.setIcon(GeneralIcons.undoIcon);
- undoAction.addPropertyChangeListener(new ActionChangedListener(undoButton));
undoButton.setHideActionText(true);
undoButton.setToolTipText("Undo edit");
+ undoActionChangeListener = new ActionChangedListener(undoButton);
add(undoButton);
- Action redoAction = zoomPane.getRedoAction();
- JButton redoButton = new JButton(redoAction);
- redoAction.addPropertyChangeListener(new ActionChangedListener(redoButton));
+ redoButton = new JButton();
redoButton.setIcon(GeneralIcons.redoIcon);
redoButton.setHideActionText(true);
redoButton.setToolTipText("Redo edit");
+ redoActionChangeListener = new ActionChangedListener(redoButton);
add(redoButton);
- Action findAction = new FindAction(frame, findPane);
- JButton findButton = new JButton(findAction);
+ findButton = new JButton();
findButton.setIcon(GeneralIcons.findIcon);
findButton.setHideActionText(true);
findButton.setToolTipText("Find in text..");
add(findButton);
- ZoomAction zoomInAction = new ZoomAction(zoomPane, "+", 1.1);
- JButton zoomIn = new JButton(zoomInAction);
+ zoomIn = new JButton();
zoomIn.setIcon(GeneralIcons.zoomInIcon);
zoomIn.setHideActionText(true);
zoomIn.setToolTipText("Zoom in");
add(zoomIn);
- ZoomAction zoomOutAction = new ZoomAction(zoomPane, "-", 1 / 1.1);
- JButton zoomOut = new JButton(zoomOutAction);
+ zoomOut = new JButton();
zoomOut.setIcon(GeneralIcons.zoomOutIcon);
zoomOut.setHideActionText(true);
zoomOut.setToolTipText("Zoom out");
add(zoomOut);
-
-// JButton exceptionButton = new JButton("X");
-// exceptionButton.addActionListener(new ActionListener(){
-//
-// @Override
-// public void actionPerformed(ActionEvent e) {
-// try {
-// throw new ClassNotFoundException("original message");
-// } catch (Exception exception) {
-//
-// Log.exception(exception);
-// }
-//
-// }});
-//
-// add(exceptionButton);
+ }
+
+ private void refreshButtons() {
+ undoButton.setIcon(GeneralIcons.undoIcon);
+ undoButton.setHideActionText(true);
+ undoButton.setToolTipText("Undo edit");
+
+ redoButton.setIcon(GeneralIcons.redoIcon);
+ redoButton.setHideActionText(true);
+ redoButton.setToolTipText("Redo edit");
+
+ findButton.setIcon(GeneralIcons.findIcon);
+ findButton.setHideActionText(true);
+ findButton.setToolTipText("Find in text..");
+
+ zoomIn.setIcon(GeneralIcons.zoomInIcon);
+ zoomIn.setHideActionText(true);
+ zoomIn.setToolTipText("Zoom in");
+
+ zoomOut.setIcon(GeneralIcons.zoomOutIcon);
+ zoomOut.setHideActionText(true);
+ zoomOut.setToolTipText("Zoom out");
+ }
+
+ /**
+ * @param source
+ */
+ public void setEditorPane(EditorPane targetPane) {
+
+ Document doc = targetPane.getDocument();
+ if (undoHandlerMap.get(doc) == null) {
+ undoHandler = new UndoHandler(targetPane);
+ doc.addUndoableEditListener(undoHandler);
+ }
+
+ Action undoAction = targetPane.getUndoAction();
+ undoButton.setAction(undoAction);
+ undoAction.addPropertyChangeListener(undoActionChangeListener);
+
+ Action redoAction = targetPane.getRedoAction();
+ redoButton.setAction(redoAction);
+ redoAction.addPropertyChangeListener(redoActionChangeListener);
+
+ Action findAction = new FindAction(frame, targetPane);
+ findButton.setAction(findAction);
+
+ ZoomAction zoomInAction = new ZoomAction(targetPane, "+", 1.1);
+ zoomIn.setAction(zoomInAction);
+
+ ZoomAction zoomOutAction = new ZoomAction(targetPane, "-", 1 / 1.1);
+ zoomOut.setAction(zoomOutAction);
+ refreshButtons(); // a pain, but seems necessary
+ }
+
+ public void findOnly() {
+ undoButton.setEnabled(false);
+ redoButton.setEnabled(false);
+ findButton.setEnabled(true);
+ zoomIn.setEnabled(false);
+ zoomOut.setEnabled(false);
+ }
+
+ public void enableAll() {
+ undoButton.setEnabled(true);
+ redoButton.setEnabled(true);
+ findButton.setEnabled(true);
+ zoomIn.setEnabled(true);
+ zoomOut.setEnabled(true);
}
}
View
49 src/org/hyperdata/scute/main/FocusMonitor.java
@@ -0,0 +1,49 @@
+/**
+ *
+ */
+package org.hyperdata.scute.main;
+
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+
+import javax.swing.JEditorPane;
+
+import org.hyperdata.scute.editortools.EditorToolbar;
+import org.hyperdata.scute.source.EditorPane;
+
+/**
+ * @author danny
+ *
+ */
+public class FocusMonitor implements FocusListener {
+
+ private EditorToolbar editorToolbar;
+
+ public void setEditorToolbar(EditorToolbar editorToolbar){
+ this.editorToolbar = editorToolbar;
+ }
+ /* (non-Javadoc)
+ * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
+ */
+ @Override
+ public void focusGained(FocusEvent event) {
+ Object source = event.getSource();
+ if(source instanceof EditorPane){
+ editorToolbar.enableAll();
+ editorToolbar.setEditorPane((EditorPane)source);
+ editorToolbar.setVisible(true);
+ } else {
+ editorToolbar.setVisible(false);
+ }
+ System.out.println("FOCUS="+event.getSource());
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
+ */
+ @Override
+ public void focusLost(FocusEvent e) {
+ // ignore
+ }
+
+}
View
76 src/org/hyperdata/scute/main/Scute.java
@@ -11,12 +11,16 @@
package org.hyperdata.scute.main;
import java.awt.BorderLayout;
-
+import org.jdesktop.swingx.*;
+import org.jdesktop.swingx.MultiSplitLayout.*;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
+import java.util.Arrays;
+import java.util.List;
+
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.TreeSelectionEvent;
@@ -29,6 +33,7 @@
import org.hyperdata.scute.cards.Card;
import org.hyperdata.scute.cards.CardsPanel;
import org.hyperdata.scute.cards.TaskPanel;
+import org.hyperdata.scute.editortools.EditorToolbar;
import org.hyperdata.scute.filemanager.FileExplorerPanel;
import org.hyperdata.scute.graph.GraphPanel;
import org.hyperdata.scute.graphmanager.GraphManagerPanel;
@@ -133,6 +138,10 @@ public static void main(String[] args) {
private ScratchPad scratchPad;
+ private EditorToolbar editorToolbar;
+
+ private FocusMonitor focusMonitor;
+
/**
* Instantiates a new scute.
*/
@@ -162,36 +171,61 @@ public Scute() {
panel = new JPanel(new BorderLayout());
+ focusMonitor = new FocusMonitor();
makeCardsPanel();
- // panel.add(cardsPanel, BorderLayout.CENTER);
+
+ editorToolbar = new EditorToolbar(frame);
+ focusMonitor.setEditorToolbar(editorToolbar);
+
+ cardsPanel.add(editorToolbar, BorderLayout.SOUTH);
scratchPad = new ScratchPad("Text");
+ scratchPad.setFilename(Config.SCRATCH_FILENAME);
+ scratchPad.addFocusListener(focusMonitor);
+ scratchPad.load(); // load saved contents
+
JScrollPane scrollPane = new JScrollPane(scratchPad, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, cardsPanel, scrollPane);
- splitPane.setResizeWeight(1);
- // splitPane.setContinuousLayout(true);
- splitPane.setDividerLocation(.9);
+
+// JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, cardsPanel, scrollPane);
+// splitPane.setResizeWeight(1);
+// splitPane.setDividerLocation(.9);
+
+ List children =
+ Arrays.asList(new Leaf("left"),
+ new Divider(),
+ new Leaf("right"));
+ Split modelRoot = new Split();
+ modelRoot.setChildren(children);
+
+ JXMultiSplitPane multiSplitPane = new JXMultiSplitPane();
+ multiSplitPane.getMultiSplitLayout().setModel(modelRoot);
+ multiSplitPane.add(cardsPanel, "left");
+ multiSplitPane.add(scrollPane, "right");
//
- panel.add(splitPane, BorderLayout.CENTER);
+ panel.add(multiSplitPane, BorderLayout.CENTER);
+ // panel.add(splitPane, BorderLayout.CENTER);
autoSave = new AutoSave();
autoSave.setWorkingModelContainer(this);
autoSave.setWorkingModelContainer(Config.self);
autoSave.setCurrentTextContainer(turtlePanel);
+ autoSave.setScratchTextContainer(scratchPad);
cardsPanel.addChangeListener(autoSave);
- final JPanel controlPanel = new JPanel(); // contains JToolBars
- panel.add(controlPanel, BorderLayout.NORTH);
- controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
+
io = new IO(this, cardsPanel);
fileUI = new FileUI(io);
+ final JPanel controlPanel = new JPanel(); // contains JToolBars
+ panel.add(controlPanel, BorderLayout.NORTH);
+ controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
controlPanel.add(fileUI.getToolBar());
+ controlPanel.add(editorToolbar);
helpUI = new HelpUI(io);
@@ -219,12 +253,12 @@ public Scute() {
}
}
+
+
/**
*
*/
private void setupFrame() {
-
-
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds(FRAME_INSET, FRAME_INSET, screenSize.width - 2
* FRAME_INSET, screenSize.height - 2 * FRAME_INSET);
@@ -315,9 +349,8 @@ private void makeGraphManagerPanel() {
*
*/
private void makeSparqlPanel() {
- sparqlPanel = new SparqlCard(frame);
+ sparqlPanel = new SparqlCard(frame, focusMonitor);
sparqlPanel.setTextCard(true);
-
cardsPanel.add(sparqlPanel, "SPARQL");
}
@@ -360,6 +393,7 @@ private void makeRdfXmlPanel() {
rdfxmlPanel.addUserActivityListener(autoSave);
rdfxmlPanel.loadModel(Models.workingModel);
rdfxmlPanel.setEditorKit(new ScuteEditorKit("XML"));
+ rdfxmlPanel.addFocusListener(focusMonitor);
JPanel statusPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); // left-aligned
statusPanel.setBorder(BorderFactory
@@ -404,6 +438,7 @@ private void makeTurtlePanel() {
turtlePanel.addUserActivityListener(autoSave);
turtlePanel.setEditorKit(new ScuteEditorKit("Turtle"));
turtlePanel.loadModel(Models.workingModel);
+ turtlePanel.addFocusListener(focusMonitor);
cardsPanel.addChangeListener(turtlePanel);
@@ -428,15 +463,22 @@ private void makeTurtlePanel() {
statusPanel.add(validatorButton);
statusPanel.add(validatorPane);
-
+
Card turtleCard = new Card(new BorderLayout());
turtleCard.setTextCard(true);
turtleCard.setTextContainer(turtlePanel);
turtleCard.add(new JScrollPane(turtlePanel), BorderLayout.CENTER);
- turtleCard.add(statusPanel, BorderLayout.SOUTH);
-
+
+// EditorToolbar editorToolbar = turtlePanel.getEditorToolbar();
+// JPanel toolsPanel = new JPanel();
+// toolsPanel.add(editorToolbar);
+// toolsPanel.add(statusPanel);
+// turtleCard.add(toolsPanel, BorderLayout.SOUTH);
+
cardsPanel.add(turtleCard, "Turtle");
}
+
+
/*
View
11 src/org/hyperdata/scute/source/EditorPane.java
@@ -12,6 +12,7 @@
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.UndoManager;
+import org.hyperdata.scute.editortools.EditorToolbar;
import org.hyperdata.scute.editortools.undo.RedoAction;
import org.hyperdata.scute.editortools.undo.UndoAction;
import org.hyperdata.scute.editortools.undo.UndoHandler;
@@ -24,8 +25,7 @@
*
* @author danny
*/
-public abstract class EditorPane extends ScalableEditorPane implements TextContainer,
-ChangeListener {
+public abstract class EditorPane extends ScalableEditorPane implements TextContainer, ChangeListener {
private String filename;
@@ -39,19 +39,24 @@
private UndoAction undoAction = new UndoAction(this);
private RedoAction redoAction = new RedoAction(this);
+ private EditorToolbar editorToolbar;
/**
* @param syntax
*/
public EditorPane(String syntax) {
super.setSyntax(syntax);
- setFont(new Font("monospaced", Font.PLAIN, 12));
+ setFont(new Font("Monospaced", Font.PLAIN, 12));
setPreferredSize(new Dimension(800,600));
addFocusListener(this);
setDragEnabled(true);
getDocument().putProperty("ZOOM_FACTOR", new Double(2.5));
}
+// public void createToolbar(){
+//
+// }
+
/**
* Resets the undo manager.
*/
View
12 src/org/hyperdata/scute/sparql/SparqlContainer.java
@@ -1,6 +1,8 @@
package org.hyperdata.scute.sparql;
import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.sparql.resultset.SPARQLResult;
import org.hyperdata.scute.sparql.endpoints.Endpoint;
@@ -35,4 +37,14 @@
* @param text
*/
public void setQueryString(String text);
+
+ /**
+ * @return
+ */
+ public ResultSet getResultSet();
+
+ /**
+ * @return
+ */
+ // public SPARQLResult getResults();
}
View
23 src/org/hyperdata/scute/sparql/SparqlContainerImpl.java
@@ -6,6 +6,9 @@
import javax.swing.event.EventListenerList;
import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.query.ResultSetFactory;
+import com.hp.hpl.jena.sparql.resultset.SPARQLResult;
import org.hyperdata.scute.sparql.endpoints.Endpoint;
@@ -23,6 +26,7 @@
private EventListenerList listenerList = new EventListenerList();
private SparqlEvent sparqlEvent = null;
+ private ResultSet resultSet;
/* (non-Javadoc)
* @see org.hyperdata.scute.sparql.SparqlContainer#getQueryString()
@@ -78,8 +82,19 @@ public boolean isLocal() {
@Override
public void setResultsText(String resultsString) {
this.resultsString = resultsString;
+ if(isSelect()){
+ resultSet = ResultSetFactory.fromXML(resultsString);
+ }
}
+ /**
+ * @return
+ */
+ private boolean isSelect() {
+ // TODO check what kind of query it is
+ return true;
+ }
+
/* (non-Javadoc)
* @see org.hyperdata.scute.sparql.SparqlContainer#getResultsText()
*/
@@ -115,4 +130,12 @@ public void fireSparqlEvent() {
}
}
}
+
+ /* (non-Javadoc)
+ * @see org.hyperdata.scute.sparql.SparqlContainer#getResults()
+ */
+ @Override
+ public ResultSet getResultSet() {
+ return resultSet;
+ }
}
View
1 src/org/hyperdata/scute/sparql/actions/RunQueryAction.java
@@ -65,7 +65,6 @@ public void actionPerformed(ActionEvent event) {
runRemoteQuery(event);
}else {
stop();
-
}
}
}
View
54 src/org/hyperdata/scute/sparql/panels/SparqlCard.java
@@ -9,6 +9,8 @@
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.EventObject;
@@ -24,6 +26,8 @@
import org.hyperdata.scute.sparql.SparqlContainer;
import org.hyperdata.scute.sparql.SparqlContainerImpl;
import org.hyperdata.scute.sparql.actions.RunQueryAction;
+import org.hyperdata.scute.sparql.popup.PopupListener;
+import org.hyperdata.scute.sparql.popup.SparqlPopupMenu;
import org.hyperdata.scute.swing.status.StatusAction;
import org.hyperdata.scute.swing.status.StatusButton;
import org.hyperdata.scute.swing.status.StatusInfoPane;
@@ -47,13 +51,14 @@
private ScuteEditorKit editorKit;
private SparqlPopupMenu popupMenu;
- public SparqlCard(Frame frame) {
+ public SparqlCard(Frame frame, FocusListener focusListener) {
super(new BorderLayout());
sourcePanel = new SparqlSourcePanel("SPARQL");
editorKit = new ScuteEditorKit("SPARQL"); // ///////////////////////
// editorKit.setSyntax("SPARQL");
sourcePanel.setEditorKit(editorKit);
+ sourcePanel.addFocusListener(focusListener);
sourcePanel.setPreferredSize(new Dimension(300, 300));
popupMenu = new SparqlPopupMenu(sourcePanel);
@@ -64,18 +69,14 @@ public SparqlCard(Frame frame) {
// String text = " <http://dbpedia.org/resource/Category:Neptune> .";
sourcePanel.setText(text);
- resultsPanel = new SparqlResultsPanel();
+ resultsPanel = new SparqlResultsPanel(focusListener);
sparqlContainer.addSparqlListener(resultsPanel);
// passing sourcepanel here a bit messy, but will do for now
SparqlRunToolbar toolbar = new SparqlRunToolbar(sparqlContainer,
sourcePanel, frame);
add(toolbar, BorderLayout.NORTH);
- EditorToolbar editorToolbar = new EditorToolbar(frame,
- resultsPanel.getXmlPane(), sourcePanel);
- toolbar.add(editorToolbar);
-
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
sourcePanel, resultsPanel);
splitPane.setContinuousLayout(true);
@@ -113,50 +114,11 @@ public SparqlCard(Frame frame) {
public static void main(String[] args) {
final JFrame frame = new JFrame();
- SparqlCard sparqlPanel = new SparqlCard(frame);
+ SparqlCard sparqlPanel = new SparqlCard(frame, null);
frame.setSize(800, 600);
frame.add(sparqlPanel);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
// frame.pack();
frame.setVisible(true);
}
-
- // delegate to SparqlContainer
-
- // public String getQueryString() {
- // return sparqlContainer.getQueryString();
- // }
- //
- // public Dataset getDataset() {
- // return sparqlContainer.getDataset();
- // }
- //
- // public boolean isLocal() {
- // return sparqlContainer.isLocal();
- // }
- //
- // public Endpoint getEndpoint() {
- // return sparqlContainer.getEndpoint();
- // }
- //
- // public void setEndpoint(Endpoint endpoint) {
- // sparqlContainer.setEndpoint(endpoint);
- // }
- //
- // public void setResultsText(String resultsString) {
- // sparqlContainer.setResultsText(resultsString);
- // }
- //
- //
- // public String getResultsText() {
- // return sparqlContainer.getResultsText();
- // }
- //
- // public void addSparqlListener(SparqlListener sparqlListener) {
- // sparqlContainer.addSparqlListener(sparqlListener);
- // }
- //
- // public void fireSparqlEvent() {
- // sparqlContainer.fireSparqlEvent();
- // }
}
View
20 src/org/hyperdata/scute/sparql/panels/SparqlHelpersToolbar.java
@@ -1,20 +0,0 @@
-/**
- *
- */
-package org.hyperdata.scute.sparql.panels;
-
-import javax.swing.JComboBox;
-import javax.swing.JPanel;
-
-/**
- * @author danny
- *
- */
-public class SparqlHelpersToolbar extends JPanel {
-
- private JComboBox prefixesBox;
-
- public SparqlHelpersToolbar(){
- prefixesBox = new JComboBox(new Prefixes());
- }
-}
View
99 src/org/hyperdata/scute/sparql/panels/SparqlResultsPanel.java
@@ -4,83 +4,118 @@
package org.hyperdata.scute.sparql.panels;
import java.awt.BorderLayout;
+import java.awt.event.FocusListener;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
+import javax.swing.JTable;
import javax.swing.SwingConstants;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.query.ResultSetFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.sparql.resultset.SPARQLResult;
import org.hyperdata.scute.rdf.RdfUtils;
import org.hyperdata.scute.sparql.SparqlContainer;
import org.hyperdata.scute.sparql.SparqlEvent;
import org.hyperdata.scute.sparql.SparqlListener;
+import org.hyperdata.scute.sparql.table.TableResultsPane;
import org.hyperdata.scute.syntax.ScuteEditorKit;
+import org.hyperdata.scute.system.Log;
+import org.hyperdata.scute.triples.BetterJTable;
/**
* @author danny
- *
+ *
*/
public class SparqlResultsPanel extends JPanel implements SparqlListener {
-
- XMLResultsPanel xmlPanel;
- TableResultsPanel tablePanel;
- HTTPPanel httpPanel;
- public SparqlResultsPanel(){
+ private TextResultsPanel textPanel;
+ private XMLResultsPanel xmlPanel;
+ //private BetterJTable table = new BetterJTable();
+ private TableResultsPane tablePane;
+ private HTTPPanel httpPanel;
+
+ public SparqlResultsPanel(FocusListener focusListener) {
super(new BorderLayout());
+
+ textPanel = new TextResultsPanel();
+ textPanel.addFocusListener(focusListener);
+ textPanel.setEditorKit(new ScuteEditorKit("Turtle")); // for CONSTRUCTed results
- xmlPanel = new XMLResultsPanel ();
+ xmlPanel = new XMLResultsPanel();
+ xmlPanel.addFocusListener(focusListener);
xmlPanel.setEditorKit(new ScuteEditorKit("XML"));
- tablePanel = new TableResultsPanel();
- httpPanel = new HTTPPanel();
+ tablePane = new TableResultsPane();
+ tablePane.addFocusListener(focusListener);
+
+ httpPanel = new HTTPPanel();
+ httpPanel.addFocusListener(focusListener);
+
JTabbedPane tabs = new JTabbedPane(SwingConstants.BOTTOM);
+ tabs.addTab("Text", new JScrollPane(textPanel));
+ tabs.addTab("Table", tablePane); // it has its own scroll
tabs.addTab("XML", new JScrollPane(xmlPanel));
- tabs.addTab("Table", new JScrollPane(tablePanel));
tabs.addTab("HTTP", new JScrollPane(httpPanel));
-
+
add(tabs, BorderLayout.CENTER);
}
-
- public void populate(String resultString){
- try{
- xmlPanel.setText(resultString);
- }catch(Error error){
- System.err.println("SparqlResultsPanel: "+error.getMessage());
+
+ public void populate(String resultString) {
+ try {
+ xmlPanel.setText(resultString);
+ } catch (Error error) {
+ System.err.println("SparqlResultsPanel: " + error.getMessage());
// ignore - probably Interrupted attempt to acquire write lock
}
}
-
- public void populate(SPARQLResult result){
+
+ /**
+ * @param resultSet
+ */
+ private void populate(ResultSet results) {
+ ResultSet resultSet = ResultSetFactory.copyResults(results);
+
+ tablePane.setResults(resultSet);
+ textPanel.setText(ResultSetFormatter.asText(resultSet));
+ xmlPanel.setText("XXX"+ResultSetFormatter.asXMLString(resultSet));
+ }
+
+ public void populate(SPARQLResult result) {
+
String resultString = "...";
- if(result.isBoolean()){
+ if (result.isBoolean()) {
resultString = Boolean.toString(result.getBooleanResult());
+ textPanel.setText(resultString);
}
- if(result.isModel()){
+ if (result.isModel()) {
resultString = RdfUtils.modelToString(result.getModel());
+ textPanel.setText(resultString); // will do for now
}
- if(result.isResultSet()){
-// ResultSetFormatter fmt = new ResultSetFormatter(result.getResultSet(), query) ;
-// fmt.printAll(System.out) ;
- resultString = ResultSetFormatter.asText(result.getResultSet());
+ if (result.isResultSet()) {
+ populate(result.getResultSet());
}
- xmlPanel.setText(resultString);
}
- /* (non-Javadoc)
- * @see org.hyperdata.scute.sparql.SparqlListener#sparqlEvent(org.hyperdata.scute.sparql.SparqlEvent)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.hyperdata.scute.sparql.SparqlListener#sparqlEvent(org.hyperdata.scute
+ * .sparql.SparqlEvent)
*/
@Override
public void sparqlEvent(SparqlEvent sparqlEvent) {
- SparqlContainer sparqlContainer = (SparqlContainer)sparqlEvent.getSource();
-
- // needed for other kinds of results..?
+ SparqlContainer sparqlContainer = (SparqlContainer) sparqlEvent
+ .getSource();
+
populate(sparqlContainer.getResultsText());
-
+ populate(sparqlContainer.getResultSet());
+
}
/**
View
14 src/org/hyperdata/scute/sparql/panels/TableResultsPanel.java
@@ -1,14 +0,0 @@
-/**
- *
- */
-package org.hyperdata.scute.sparql.panels;
-
-import javax.swing.JPanel;
-
-/**
- * @author danny
- *
- */
-public class TableResultsPanel extends JPanel {
-
-}
View
20 src/org/hyperdata/scute/sparql/panels/TextResultsPanel.java
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.hyperdata.scute.sparql.panels;
+
+import javax.swing.JEditorPane;
+import javax.swing.event.ChangeEvent;
+
+import org.hyperdata.scute.source.EditorPane;
+
+/**
+ * @author danny
+ *
+ */
+public class TextResultsPanel extends JEditorPane {
+ public TextResultsPanel(){
+ // super("SPARQL Text Results");
+ super();
+ }
+}
View
2 ...ta/scute/sparql/panels/PopupListener.java → ...ata/scute/sparql/popup/PopupListener.java
@@ -1,7 +1,7 @@
/**
*
*/
-package org.hyperdata.scute.sparql.panels;
+package org.hyperdata.scute.sparql.popup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
View
2 .../scute/sparql/panels/SparqlPopupMenu.java → ...a/scute/sparql/popup/SparqlPopupMenu.java
@@ -1,7 +1,7 @@
/**
*
*/
-package org.hyperdata.scute.sparql.panels;
+package org.hyperdata.scute.sparql.popup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
View
90 src/org/hyperdata/scute/sparql/table/ResultSetTableModel.java
@@ -0,0 +1,90 @@
+/**
+ *
+ */
+package org.hyperdata.scute.sparql.table;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.table.AbstractTableModel;
+
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.query.ResultSetFactory;
+import com.hp.hpl.jena.query.ResultSetRewindable;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+
+
+public class ResultSetTableModel extends AbstractTableModel {
+
+ private ResultSetRewindable resultSet;
+ private List<String> columnNames;
+ private List<QuerySolution> results = new ArrayList<QuerySolution>();
+
+ public ResultSetTableModel(ResultSet resultSetRaw){
+ super();
+ this.resultSet = ResultSetFactory.copyResults(resultSetRaw); // just in case...
+ columnNames = resultSet.getResultVars();
+ while(resultSet.hasNext()){
+ results.add(resultSet.next());
+ }
+ }
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getColumnCount()
+ */
+ @Override
+ public int getColumnCount() {
+ return columnNames.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getColumnName(int)
+ */
+ @Override
+ public String getColumnName(int i) {
+ // System.out.println("NAME="+columnNames.get(i));
+ return columnNames.get(i);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getRowCount()
+ */
+ @Override
+ public int getRowCount() {
+ if(results == null){
+ return 0; // on init
+ }
+ return results.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getValueAt(int, int)
+ */
+ @Override
+ public Object getValueAt(int row, int column) {
+ QuerySolution solution = results.get(row);
+ RDFNode node = solution.get(getColumnName(column));
+ if(node == null){
+ return "";
+ }
+ return node.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#isCellEditable(int, int)
+ */
+ @Override
+ public boolean isCellEditable(int arg0, int arg1) {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
+ */
+// @Override
+// public void setValueAt(Object arg0, int arg1, int arg2) {
+// // TODO Auto-generated method stub
+//
+// }
+
+}
View
43 src/org/hyperdata/scute/sparql/table/TableResultsPane.java
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package org.hyperdata.scute.sparql.table;
+
+import java.awt.BorderLayout;
+import java.awt.event.FocusListener;
+
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.table.TableModel;
+
+import com.hp.hpl.jena.query.ResultSet;
+
+import org.hyperdata.scute.triples.BetterJTable;
+
+
+/**
+ * @author danny
+ *
+ */
+public class TableResultsPane extends JPanel {
+
+ private BetterJTable table;
+
+ public TableResultsPane(){
+ super(new BorderLayout());
+ table = new BetterJTable();
+ table.setDragEnabled(true);
+ add(new JScrollPane(table),BorderLayout.CENTER);
+ }
+
+ public void addFocusListener(FocusListener focusListener){
+ table.addFocusListener(focusListener);
+ }
+
+ public void setResults(ResultSet resultSet){
+ TableModel tableModel = new ResultSetTableModel(resultSet);
+ table.setModel(tableModel);
+table.repaint();
+ }
+}
View
220 src/org/hyperdata/scute/triples/BetterJTable.java
@@ -0,0 +1,220 @@
+/**
+from http://explodingpixels.wordpress.com/2009/05/18/creating-a-better-jtable/
+ *
+ */
+package org.hyperdata.scute.triples;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.*;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableModel;
+
+public class BetterJTable extends JTable {
+
+ private static final Color EVEN_ROW_COLOR = new Color(241, 245, 250);
+ private static final Color TABLE_GRID_COLOR = new Color(0xd9d9d9);
+
+ private static final CellRendererPane CELL_RENDER_PANE = new CellRendererPane();
+
+ public BetterJTable(){
+ super();
+ init();
+ }
+
+// public BetterJTable(TableModel dm) {
+// super(dm);
+// // init();
+// }
+
+ private void init() { // a bit exposed
+ // setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+ setTableHeader(createTableHeader());
+ getTableHeader().setReorderingAllowed(false);
+ setOpaque(false);
+ setGridColor(TABLE_GRID_COLOR);
+ setIntercellSpacing(new Dimension(0, 0));
+ // turn off grid painting as we'll handle this manually in order to
+ // paint
+ // grid lines over the entire viewport.
+ // setShowGrid(false);
+ }
+
+ /**
+ * Creates a JTableHeader that paints the table header background to the
+ * right of the right-most column if neccesasry.
+ */
+ private JTableHeader createTableHeader() {
+ return new JTableHeader(getColumnModel()) {
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ // if this JTableHEader is parented in a JViewport, then paint
+ // the
+ // table header background to the right of the last column if
+ // neccessary. DANNY FIXED
+ if(table == null){
+ return; //on init
+ }
+ Object parent = table.getParent();
+ // JViewport viewport = (JViewport) table.getParent();
+ if (parent != null) {
+ JViewport viewport = (JViewport)parent;
+ if(table.getWidth() < viewport.getWidth()){
+ int x = table.getWidth();
+ int width = viewport.getWidth() - table.getWidth();
+ paintHeader(g, getTable(), x, width);
+ }
+ }
+ }
+ };
+ }
+
+ /**
+ * Paints the given JTable's table default header background at given x for
+ * the given width.
+ */
+ private static void paintHeader(Graphics g, JTable table, int x, int width) {
+ TableCellRenderer renderer = table.getTableHeader()
+ .getDefaultRenderer();
+ Component component = renderer.getTableCellRendererComponent(table, "",
+ false, false, -1, 2);
+
+ component.setBounds(0, 0, width, table.getTableHeader().getHeight());
+
+ ((JComponent) component).setOpaque(false);
+ CELL_RENDER_PANE.paintComponent(g, component, null, x, 0, width, table
+ .getTableHeader().getHeight(), true);
+ }
+
+ @Override
+ public Component prepareRenderer(TableCellRenderer renderer, int row,
+ int column) {
+ Component component = super.prepareRenderer(renderer, row, column);
+ // if the rendere is a JComponent and the given row isn't part of a
+ // selection, make the renderer non-opaque so that striped rows show
+ // through.
+ if (component instanceof JComponent) {
+ ((JComponent) component).setOpaque(getSelectionModel()
+ .isSelectedIndex(row));
+ }
+ return component;
+ }
+
+ // Stripe painting Viewport. //////////////////////////////////////////////
+
+ /**
+ * Creates a JViewport that draws a striped backgroud corresponding to the
+ * row positions of the given JTable.
+ */
+ private static class StripedViewport extends JViewport {
+
+ private final JTable fTable;
+
+ public StripedViewport(JTable table) {
+ fTable = table;
+ setOpaque(false);
+ initListeners();
+ }
+
+ private void initListeners() {
+ // install a listener to cause the whole table to repaint when
+ // a column is resized. we do this because the extended grid
+ // lines may need to be repainted. this could be cleaned up,
+ // but for now, it works fine.
+ PropertyChangeListener listener = createTableColumnWidthListener();
+ for (int i = 0; i < fTable.getColumnModel().getColumnCount(); i++) {
+ fTable.getColumnModel().getColumn(i)
+ .addPropertyChangeListener(listener);
+ }
+ }
+
+ private PropertyChangeListener createTableColumnWidthListener() {
+ return new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ repaint();
+ }
+ };
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ paintStripedBackground(g);
+ paintVerticalGridLines(g);
+ super.paintComponent(g);
+ }
+
+ private void paintStripedBackground(Graphics g) {
+ // get the row index at the top of the clip bounds (the first row
+ // to paint).
+ int rowAtPoint = fTable.rowAtPoint(g.getClipBounds().getLocation());
+ // get the y coordinate of the first row to paint. if there are no
+ // rows in the table, start painting at the top of the supplied
+ // clipping bounds.
+ int topY = rowAtPoint < 0 ? g.getClipBounds().y : fTable
+ .getCellRect(rowAtPoint, 0, true).y;
+
+ // create a counter variable to hold the current row. if there are
+ // no
+ // rows in the table, start the counter at 0.
+ int currentRow = rowAtPoint < 0 ? 0 : rowAtPoint;
+ while (topY < g.getClipBounds().y + g.getClipBounds().height) {
+ int bottomY = topY + fTable.getRowHeight();
+ g.setColor(getRowColor(currentRow));
+ g.fillRect(g.getClipBounds().x, topY, g.getClipBounds().width,
+ bottomY);
+ topY = bottomY;
+ currentRow++;
+ }
+ }
+
+ private Color getRowColor(int row) {
+ return row % 2 == 0 ? EVEN_ROW_COLOR : getBackground();
+ }
+
+ private void paintVerticalGridLines(Graphics g) {
+ // paint the column grid dividers for the non-existent rows.
+ int x = 0;
+ for (int i = 0; i < fTable.getColumnCount(); i++) {
+ TableColumn column = fTable.getColumnModel().getColumn(i);
+ // increase the x position by the width of the current column.
+ x += column.getWidth();
+ g.setColor(TABLE_GRID_COLOR);
+ // draw the grid line (not sure what the -1 is for, but
+ // BasicTableUI
+ // also does it.
+ g.drawLine(x - 1, g.getClipBounds().y, x - 1, getHeight());
+ }
+ }
+ }
+
+ public static JScrollPane createStripedJScrollPane(JTable table) {
+ JScrollPane scrollPane = new JScrollPane(table);
+ scrollPane.setViewport(new StripedViewport(table));
+ scrollPane.getViewport().setView(table);
+ scrollPane.setBorder(BorderFactory.createEmptyBorder());
+ scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER,
+ createCornerComponent(table));
+ return scrollPane;
+ }
+
+ /**
+ * Creates a component that paints the header background for use in a
+ * JScrollPane corner.
+ */
+ private static JComponent createCornerComponent(final JTable table) {
+ return new JComponent() {
+ @Override
+ protected void paintComponent(Graphics g) {
+ paintHeader(g, table, 0, getWidth());
+ }
+ };
+ }
+}

0 comments on commit b7bf28f

Please sign in to comment.
Something went wrong with that request. Please try again.