Author: jflesch
Date: 2007-01-01 20:00:29 +0000 (Mon, 01 Jan 2007)
New Revision: 11539
Modified:
trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/plugins/Console.java
trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java
Log:
adding an auto-refresh functionnality for the indexes
Modified: trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2006-12-31 21:13:18 UTC
(rev 11538)
+++ trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2007-01-01 20:00:29 UTC
(rev 11539)
@@ -218,5 +218,19 @@
return Integer.parseInt(split[2]);
}
+
+ public static String getComparablePart(String key) {
+ if (key.startsWith("KSK@"))
+ return key;
+
+ int maxLength = 0;
+
+ if (key.length() <= 70)
+ maxLength = key.length();
+ else
+ maxLength = 70;
+
+ return key.substring(0, maxLength).toLowerCase();
+ }
}
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-12-31 21:13:18 UTC
(rev 11538)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-01-01 20:00:29 UTC
(rev 11539)
@@ -259,3 +259,9 @@
thaw.plugin.index.importIndex=Import index content from a file
thaw.plugin.index.exportIndex=Export index content to a file
+
+thaw.plugin.index.autoRefresher=Auto-refresher
+
+thaw.plugin.index.useAutoRefresh=Use auto-refresh
+thaw.plugin.index.autoRefreshInterval=Auto-refresh interval (in sec):
+thaw.plugin.index.nmbIndexPerRefresh=Number of indexes refreshed for each
interval:
Modified: trunk/apps/Thaw/src/thaw/plugins/Console.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Console.java 2006-12-31 21:13:18 UTC
(rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/Console.java 2007-01-01 20:00:29 UTC
(rev 11539)
@@ -40,10 +40,6 @@
private JScrollPane logAreaScrollPane;
private JButton saveToFile;
- private JPanel configPanel;
- private JLabel sizeLabel;
- private JTextField sizeField;
-
private boolean threadRunning;
private boolean hasChanged;
@@ -76,17 +72,6 @@
core.getMainWindow().addTab(I18n.getMessage("thaw.plugin.console.console"),
consolePanel);
- configPanel = new JPanel();
- configPanel.setLayout(new GridLayout(15, 1));
-
- sizeLabel = new
JLabel(I18n.getMessage("thaw.plugin.console.maxSize"));
- sizeField = new
JTextField(core.getConfig().getValue("consoleMaxLogSize"));
-
- configPanel.add(sizeLabel);
- configPanel.add(sizeField);
-
-
core.getConfigWindow().addTab(I18n.getMessage("thaw.plugin.console.console"),
configPanel);
-
Logger.addLogListener(this);
Thread dispThread = new Thread(this);
@@ -100,11 +85,8 @@
public boolean stop() {
threadRunning = false;
- core.getConfig().setValue("consoleMaxLogSize",
sizeField.getText() );
-
Logger.removeLogListener(this);
- core.getConfigWindow().removeTab(configPanel);
core.getMainWindow().removeTab(consolePanel);
return true;
Modified: trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java 2006-12-31 21:13:18 UTC
(rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java 2007-01-01 20:00:29 UTC
(rev 11539)
@@ -19,7 +19,10 @@
import thaw.plugins.index.IndexManagementHelper;
import thaw.plugins.index.IndexTreeNode;
import thaw.plugins.index.DatabaseManager;
+import thaw.plugins.index.IndexConfigPanel;
+import thaw.plugins.index.AutoRefresh;
+
public class IndexBrowser extends ToolbarModifier implements Plugin,
ChangeListener {
public static final String DEFAULT_INDEX = "USK at
G-ofLp2KlhHBNPezx~GDWDKThJ-QUxJK8c2xiF~-jwE,-55vLnqo3U1H5qmKA1LLADoYGQdk-Y3hSLxyKeUyHNc,AQABAAE/Thaw/2/Thaw.xml";
@@ -30,6 +33,10 @@
private IndexBrowserPanel browserPanel;
private Vector toolbarActions;
+ private IndexConfigPanel configPanel;
+
+ private AutoRefresh autoRefresh = null;
+
public IndexBrowser() {
}
@@ -37,6 +44,7 @@
public boolean run(final Core core) {
this.core = core;
+
if(core.getPluginManager().getPlugin("thaw.plugins.Hsqldb") ==
null) {
Logger.info(this, "Loading Hsqldb plugin");
@@ -48,7 +56,6 @@
}
hsqldb =
(Hsqldb)core.getPluginManager().getPlugin("thaw.plugins.Hsqldb");
-
hsqldb.registerChild(this);
boolean newDb;
@@ -77,10 +84,32 @@
stateChanged(null);
+
+ configPanel = new IndexConfigPanel(core.getConfigWindow(),
core.getConfig());
+ configPanel.addTab();
+
+ autoRefresh = null;
+
+ if (core.getConfig().getValue("indexAutoRefreshActivated") !=
null) {
+ if
(Boolean.valueOf(core.getConfig().getValue("indexAutoRefreshActivated")).booleanValue())
{
+ autoRefresh = new AutoRefresh(hsqldb,
browserPanel, core.getQueueManager(), core.getConfig());
+ }
+ } else {
+ if (AutoRefresh.DEFAULT_ACTIVATED) {
+ autoRefresh = new AutoRefresh(hsqldb,
browserPanel, core.getQueueManager(), core.getConfig());
+ }
+ }
+
+ if (autoRefresh != null)
+ autoRefresh.start();
+
return true;
}
public boolean stop() {
+ if (autoRefresh != null)
+ autoRefresh.stop();
+
core.getMainWindow().getTabbedPane().removeChangeListener(this);
if (browserPanel != null) {
@@ -90,6 +119,8 @@
hsqldb.unregisterChild(this);
+ configPanel.removeTab();
+
return true;
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-12-31 21:13:18 UTC
(rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-01-01 20:00:29 UTC
(rev 11539)
@@ -120,6 +120,19 @@
this.setTransfer();
}
+
+ /**
+ * Index registration allows to have a flat view of the loaded /
displayed indexes
+ */
+ public void register() {
+ indexBrowser.getIndexTree().registerIndex(this);
+ }
+
+ public void unregister() {
+ indexBrowser.getIndexTree().unregisterIndex(this);
+ }
+
+
public static boolean isDumbKey(final String key) {
return ((key == null) || key.equals("") || (key.length() < 20));
}
@@ -628,7 +641,8 @@
return;
}
- loadXML(transfer.getPath());
+ if (changed)
+ loadXML(transfer.getPath());
save();
@@ -1113,10 +1127,10 @@
final Element rootEl = xmlDoc.getDocumentElement();
- loadXMLFromRoot(rootEl);
+ loadXML(rootEl);
}
- public void loadXMLFromRoot(Element rootEl) {
+ public void loadXML(Element rootEl) {
loadHeader(rootEl);
loadLinks(rootEl);
loadFileList(rootEl);
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java
2006-12-31 21:13:18 UTC (rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java
2007-01-01 20:00:29 UTC (rev 11539)
@@ -45,6 +45,7 @@
unknownList = new UnknownIndexList(queueManager, this);
indexTree = new
IndexTree(I18n.getMessage("thaw.plugin.index.indexes"), false, queueManager,
this, config);
+ indexTree.makeFlatList();
leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
indexTree.getPanel(),
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-12-31
21:13:18 UTC (rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2007-01-01
20:00:29 UTC (rev 11539)
@@ -494,6 +494,29 @@
}
+ public void register() {
+ if(children == null)
+ children = loadChildren();
+
+ for(final Iterator it = children.iterator();
+ it.hasNext();) {
+ final IndexTreeNode node =
(IndexTreeNode)((DefaultMutableTreeNode)it.next()).getUserObject();
+ node.register();
+ }
+ }
+
+ public void unregister() {
+ if(children == null)
+ children = loadChildren();
+
+ for(final Iterator it = children.iterator();
+ it.hasNext();) {
+ final IndexTreeNode node =
(IndexTreeNode)((DefaultMutableTreeNode)it.next()).getUserObject();
+ node.unregister();
+ }
+ }
+
+
public boolean isLeaf() {
return false;
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2006-12-31 21:13:18 UTC (rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2007-01-01 20:00:29 UTC (rev 11539)
@@ -139,7 +139,7 @@
if (target == null)
target = indexBrowser.getIndexTree().getRoot();
- if ((name == null) || (name.indexOf("/") >= 0)) {
+ if ((name == null) || (name.indexOf("/") >= 0) ||
name.indexOf("\\") >= 0) {
Logger.error(new IndexManagementHelper(), "invalid
name");
return;
}
@@ -386,6 +386,11 @@
final String name = Index.getNameFromKey(publicKey);
+ if (name == null || name.indexOf("/") >= 0 ||
name.indexOf("\\") >= 0) {
+ Logger.error(new IndexManagementHelper(), "Invalid
index name !\n");
+ return;
+ }
+
IndexCategory parent;
if ((target != null) && (target instanceof IndexCategory))
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-12-31
21:13:18 UTC (rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2007-01-01
20:00:29 UTC (rev 11539)
@@ -12,6 +12,7 @@
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.Vector;
+import java.util.Hashtable;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
@@ -31,6 +32,7 @@
import thaw.core.IconBox;
import thaw.core.Logger;
import thaw.core.MainWindow;
+import thaw.core.FreenetURIHelper;
import thaw.fcp.FCPQueueManager;
import thaw.gui.JDragTree;
import thaw.plugins.Hsqldb;
@@ -92,6 +94,9 @@
private ToolbarModifier toolbarModifier;
private Vector toolbarActions;
+
+ private Hashtable registeredIndexes; /* currently, equals to all the
indexes, but later, will be == to only the displayed indexes */
+
/**
* @param queueManager Not used if selectionOnly is set to true
* @param config Not used if selectionOnly is set to true (used for
lastDestinationDirectory and lastSourceDirectory)
@@ -101,12 +106,12 @@
final IndexBrowserPanel indexBrowser,
final Config config) {
this.queueManager = queueManager;
-
this.selectionOnly = selectionOnly;
panel = new JPanel();
panel.setLayout(new BorderLayout(10, 10));
+ registeredIndexes = new Hashtable();
root = new IndexCategory(queueManager, indexBrowser, -1, null,
rootName);
root.loadChildren();
@@ -302,6 +307,14 @@
}
/**
+ * called by the index browser, you shouldn't have to bother about it
+ */
+ public void makeFlatList() {
+ root.register();
+ }
+
+
+ /**
* Used by IndexBrowserPanel when the visibility changed
*/
public ToolbarModifier getToolbarModifier() {
@@ -455,7 +468,6 @@
if(index.getTreeNode().getParent() != null)
treeModel.nodeChanged(index.getTreeNode().getParent());
}
-
}
}
@@ -548,18 +560,11 @@
public boolean alreadyExistingIndex(final String key) {
- int maxLength = 0;
-
if ((key == null) || (key.length() <= 10))
return false;
- if (key.length() <= 60)
- maxLength = key.length();
- else
- maxLength = 60;
+ String realKey = FreenetURIHelper.getComparablePart(key);
- final String realKey = key.substring(0,
maxLength).toLowerCase();
-
try {
final Connection c =
indexBrowser.getDb().getConnection();
PreparedStatement st;
@@ -603,4 +608,17 @@
treeModel.reload();
}
+
+ public void registerIndex(Index index) {
+
registeredIndexes.put(FreenetURIHelper.getComparablePart(index.getPublicKey()),
+ index);
+ }
+
+ public void unregisterIndex(Index index) {
+
registeredIndexes.remove(FreenetURIHelper.getComparablePart(index.getPublicKey()));
+ }
+
+ public Index getRegisteredIndex(String key) {
+ return
((Index)registeredIndexes.get(FreenetURIHelper.getComparablePart(key)));
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java 2006-12-31
21:13:18 UTC (rev 11538)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java 2007-01-01
20:00:29 UTC (rev 11539)
@@ -68,4 +68,7 @@
public boolean isModifiable();
public boolean hasChanged();
+
+ public void register();
+ public void unregister();
}