Author: jflesch
Date: 2007-07-23 19:52:57 +0000 (Mon, 23 Jul 2007)
New Revision: 14286
Added:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/AutoRefresh.java
Modified:
trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
Log:
Add an autorefresher to the miniFrost plugin
Modified: trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-07-23 18:56:58 UTC
(rev 14285)
+++ trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-07-23 19:52:57 UTC
(rev 14286)
@@ -7,12 +7,15 @@
import thaw.plugins.miniFrost.MiniFrostPanel;
import thaw.plugins.miniFrost.interfaces.BoardFactory;
+import thaw.plugins.miniFrost.AutoRefresh;
+
public class MiniFrost implements thaw.core.Plugin {
private Core core;
private Hsqldb hsqldb;
private MiniFrostPanel miniFrostPanel;
+ private AutoRefresh autoRefresh;
public final static BoardFactory[] factories =
new BoardFactory[] {
@@ -25,7 +28,8 @@
if (!loadDeps()
|| !initFactories()
- || !loadGUI())
+ || !loadGUI()
+ || !loadAutoRefresh())
return false;
return true;
@@ -80,10 +84,20 @@
}
+ public boolean loadAutoRefresh() {
+ autoRefresh = new AutoRefresh(core.getConfig(),
+ miniFrostPanel.getBoardTree());
+ return true;
+ }
+
public boolean stop() {
+ if (autoRefresh != null)
+ autoRefresh.stop();
+
core.getMainWindow().removeTab(miniFrostPanel.getPanel());
- hsqldb.unregisterChild(this);
+ if (hsqldb != null)
+ hsqldb.unregisterChild(this);
return true;
}
Added: trunk/apps/Thaw/src/thaw/plugins/miniFrost/AutoRefresh.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/AutoRefresh.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/AutoRefresh.java 2007-07-23
19:52:57 UTC (rev 14286)
@@ -0,0 +1,129 @@
+package thaw.plugins.miniFrost;
+
+import java.util.Vector;
+import java.util.Iterator;
+import java.util.Random;
+
+import thaw.plugins.miniFrost.interfaces.Board;
+
+import thaw.core.Logger;
+import thaw.core.Config;
+
+
+public class AutoRefresh implements Runnable {
+
+ public static final int DEFAULT_MAX_BOARDS_REFRESHING = 7;
+ public static final int DEFAULT_INTERVAL = 10; /* s */
+
+ private boolean run;
+
+ private int maxBoardRefreshing;
+ private int interval;
+
+ private Config config;
+ private BoardTree boardTree;
+
+ private Random random;
+
+ public AutoRefresh(Config config, BoardTree boardTree) {
+ this.config = config;
+ this.boardTree = boardTree;
+
+ run = true;
+
+ maxBoardRefreshing = DEFAULT_MAX_BOARDS_REFRESHING;
+ interval = DEFAULT_INTERVAL;
+
+ random = new Random();
+
+ if (config.getValue("miniFrostAutoRefreshMaxBoards") != null)
+ maxBoardRefreshing =
Integer.parseInt(config.getValue("miniFrostAutoRefreshMaxBoards"));
+ if (config.getValue("miniFrostAutoRefreshInterval") != null)
+ interval =
Integer.parseInt(config.getValue("miniFrostAutoRefreshInterval"));
+
+ Thread th = new Thread(this);
+ th.start();
+ }
+
+
+ public boolean canRefreshAnotherOne() {
+ int refreshing = 0;
+
+ for (Iterator it = boardTree.getBoards().iterator();
+ it.hasNext();) {
+ if (((Board)it.next()).isRefreshing())
+ refreshing++;
+
+ if (refreshing >= maxBoardRefreshing)
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean refreshAnotherOne() {
+ int notRefreshing = 0;
+
+ for (Iterator it = boardTree.getBoards().iterator();
+ it.hasNext();) {
+ if (!(((Board)it.next()).isRefreshing()))
+ notRefreshing++;
+ }
+
+ if (notRefreshing == 0)
+ return false;
+
+ int sel = random.nextInt(notRefreshing);
+
+
+ Board board = null;
+
+ int i = 0;
+
+ for (Iterator it = boardTree.getBoards().iterator();
+ it.hasNext() && i <= sel ;) {
+ board = (Board)it.next();
+
+ if (!board.isRefreshing())
+ i++;
+ }
+
+ if (board == null) {
+ Logger.error(this, "Hm, error while selecting the board
to refresh : "+
+ Integer.toString(sel) + " ; "+
+ Integer.toString(notRefreshing) + " ; "+
+
Integer.toString(boardTree.getBoards().size()));
+ return false;
+ }
+
+ board.refresh();
+
+ boardTree.refresh(board);
+
+ return true;
+ }
+
+
+ public void run() {
+ while(run) {
+ try {
+ Thread.sleep(interval * 1000);
+ } catch(InterruptedException e) {
+ Logger.notice(this, "Autorefresher interrupted
?!");
+ }
+
+ if (!run)
+ return;
+
+ synchronized(boardTree.getBoards()) {
+ if (canRefreshAnotherOne())
+ refreshAnotherOne();
+ }
+ }
+ }
+
+ public void stop() {
+ run = false;
+ }
+
+}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java 2007-07-23
18:56:58 UTC (rev 14285)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java 2007-07-23
19:52:57 UTC (rev 14286)
@@ -45,8 +45,8 @@
private MiniFrostPanel mainPanel;
- public final static Color SELECTION_COLOR = new Color(190, 190, 190);
- public final static Color LOADING_COLOR = new Color(230, 230, 230);
+ public final static Color SELECTION_COLOR = new Color(190, 190,
190);
+ public final static Color LOADING_COLOR = new Color(230, 230,
230);
public final static Color LOADING_SELECTION_COLOR = new Color(150, 150,
150);
@@ -157,11 +157,16 @@
boardList = null;
}
+ public Vector getBoardList() {
+ return boardList;
+ }
+
public void setBoardList(Vector l) {
int oldSize = 0;
- if (boardList != null)
+ if (boardList != null) {
oldSize = boardList.size();
+ }
boardList = l;
@@ -198,11 +203,14 @@
}
+ public Vector getBoards() {
+ return model.getBoardList();
+ }
public void refresh() {
- Vector boardList = new Vector();
+ Vector boards = new Vector();
BoardFactory[] factories =
mainPanel.getPluginCore().getFactories();
@@ -213,7 +221,7 @@
if (v != null) {
for (Iterator it = v.iterator();
it.hasNext();) {
- boardList.add(it.next());
+ boards.add(it.next());
}
}
@@ -222,7 +230,7 @@
/* TODO : Sort the vector */
- model.setBoardList(boardList);
+ model.setBoardList(boards);
}
public void refresh(Board board) {
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-23 18:56:58 UTC (rev 14285)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-23 19:52:57 UTC (rev 14286)
@@ -197,7 +197,7 @@
ResultSet set = st.executeQuery();
if (set.next()) {
- Logger.warning(this, "Board already
added");
+ Logger.notice(this, "Board already
added");
return;
}