Author: jflesch
Date: 2007-08-20 19:22:52 +0000 (Mon, 20 Aug 2007)
New Revision: 14810
Added:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardSelecter.java
Modified:
trunk/apps/Thaw/src/frost/util/XMLTools.java
trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
trunk/apps/Thaw/src/thaw/plugins/Signatures.java
trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java
trunk/apps/Thaw/src/thaw/plugins/index/File.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
Log:
It's now possible to attach boards and files to a frost message
Modified: trunk/apps/Thaw/src/frost/util/XMLTools.java
===================================================================
--- trunk/apps/Thaw/src/frost/util/XMLTools.java 2007-08-20 17:59:04 UTC
(rev 14809)
+++ trunk/apps/Thaw/src/frost/util/XMLTools.java 2007-08-20 19:22:52 UTC
(rev 14810)
@@ -199,6 +199,7 @@
return true;
} catch(final javax.xml.transform.TransformerException e) {
Logger.error(e, "Unable to generate XML because:
"+e.toString());
+ e.printStackTrace();
} catch(java.io.FileNotFoundException e) {
Logger.error(e, "File not found exception ?!");
} catch(final javax.xml.parsers.ParserConfigurationException e) {
Modified: trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-08-20 17:59:04 UTC
(rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-08-20 19:22:52 UTC
(rev 14810)
@@ -142,9 +142,14 @@
if (autoRefresh != null)
autoRefresh.stop();
- core.getMainWindow().removeTab(miniFrostPanel.getPanel());
- configTab.hide();
+ if (miniFrostPanel != null)
+
core.getMainWindow().removeTab(miniFrostPanel.getPanel());
+ else
+ Logger.warning(this, "MiniFrost not started, can't
stop.");
+ if (configTab != null)
+ configTab.hide();
+
if (hsqldb != null)
hsqldb.unregisterChild(this);
Modified: trunk/apps/Thaw/src/thaw/plugins/Signatures.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Signatures.java 2007-08-20 17:59:04 UTC
(rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/Signatures.java 2007-08-20 19:22:52 UTC
(rev 14810)
@@ -53,9 +53,12 @@
/* TODO:
* Missing:
- * - sanity
* - bombe
*/
+
+ /* Can't do:
+ * - sanity : no definitive key
+ */
};
Modified: trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java 2007-08-20 17:59:04 UTC
(rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java 2007-08-20 19:22:52 UTC
(rev 14810)
@@ -198,8 +198,10 @@
protected void printHelp() {
addToConsole("Non-SQL commands:\n");
- addToConsole(" - list_tables : List all the tables\n");
- addToConsole(" - drop_tables : Drop all the known tables\n");
+ addToConsole(" - 'list_tables' : List all the tables\n");
+ addToConsole(" - 'drop_tables' : Drop all the known
tables\n\n");
+ addToConsole("Some useful Hsqldb comments:\n");
+ addToConsole(" - 'checkpoint defrag' : Remove the empty spaces
in the db on the disk\n");
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java 2007-08-20 17:59:04 UTC
(rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java 2007-08-20 19:22:52 UTC
(rev 14810)
@@ -261,9 +261,14 @@
return null;
}
- final FCPClientPut insertion = new FCPClientPut(localPath, 0,
0, null,
- null, 4,
- true, 2, true);
/* getCHKOnly */
+ final FCPClientPut insertion = new FCPClientPut(localPath,
+
FCPClientPut.KEY_TYPE_CHK,
+ 0 /* rev */,
+ null /* name */,
+ null /* private
key */,
+
FCPClientPut.DEFAULT_PRIORITY,
+ true /* global
*/, FCPClientPut.PERSISTENCE_FOREVER,
+ true /*
getCHKOnly */);
this.queueManager = queueManager; /* so the transfer will be
removed when finished */
Added: trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardSelecter.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardSelecter.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardSelecter.java
2007-08-20 19:22:52 UTC (rev 14810)
@@ -0,0 +1,168 @@
+package thaw.plugins.miniFrost;
+
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JScrollPane;
+import java.awt.GridLayout;
+import java.awt.BorderLayout;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+import java.util.Vector;
+import java.util.Iterator;
+
+import thaw.core.I18n;
+import thaw.core.Logger;
+
+import thaw.plugins.miniFrost.interfaces.Board;
+import thaw.plugins.miniFrost.interfaces.BoardFactory;
+
+
+public class BoardSelecter implements ActionListener {
+ private static int DIALOG_SIZE_X = 200;
+ private static int DIALOG_SIZE_Y = 500;
+
+ private MiniFrostPanel mainPanel;
+ private Object parentWindow;
+
+ protected BoardSelecter() {
+
+ }
+
+ /**
+ * @param parentWindow must be a java.awt.Dialog or a java.awt.Frame
+ */
+ protected BoardSelecter(MiniFrostPanel mainPanel,
+ Object parentWindow) {
+ this.mainPanel = mainPanel;
+ this.parentWindow = parentWindow;
+ }
+
+
+ private JButton okButton;
+ private JButton cancelButton;
+
+ private boolean cancelled;
+
+ protected Vector askBoardList() {
+ Vector boards = new Vector();
+ Vector checkBoxes = new Vector();
+
+ JDialog dialog;
+
+ if (parentWindow instanceof java.awt.Frame)
+ dialog = new JDialog((java.awt.Frame)parentWindow,
+
I18n.getMessage("thaw.plugin.miniFrost.boards"));
+ else if (parentWindow instanceof java.awt.Dialog)
+ dialog = new JDialog((java.awt.Dialog)parentWindow,
+
I18n.getMessage("thaw.plugin.miniFrost.boards"));
+ else {
+ Logger.error(this, "Unknow type for the parameter
'parentWindow' : "+parentWindow.getClass().getName());
+ return null;
+ }
+
+
+ dialog.getContentPane().setLayout(new BorderLayout());
+
+ /* boards */
+ BoardFactory[] factories =
mainPanel.getPluginCore().getFactories();
+
+ for (int i = 0 ; i < factories.length ; i++) {
+ /* ignore special boards */
+ if (factories[i] instanceof SpecialBoardFactory)
+ continue;
+
+ Vector v = factories[i].getBoards();
+
+ if (v != null) {
+ boards.addAll(v);
+ }
+ }
+
+ java.util.Collections.sort(boards);
+
+
+ /* checkbox */
+ JPanel checkBoxPanel = new JPanel(new GridLayout(boards.size(),
1));
+
+ for (Iterator it = boards.iterator();
+ it.hasNext();) {
+ JCheckBox box = new
JCheckBox(((Board)it.next()).toString(), false);
+ checkBoxes.add(box);
+ checkBoxPanel.add(box);
+ }
+
+ dialog.getContentPane().add(new JScrollPane(checkBoxPanel),
BorderLayout.CENTER);
+
+
+ /* buttons */
+
+ JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
+ okButton = new JButton(I18n.getMessage("thaw.common.ok"));
+ cancelButton = new
JButton(I18n.getMessage("thaw.common.cancel"));
+ okButton.addActionListener(this);
+ cancelButton.addActionListener(this);
+ buttonPanel.add(okButton);
+ buttonPanel.add(cancelButton);
+
+ dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
+
+ dialog.setSize(DIALOG_SIZE_X,
+ DIALOG_SIZE_Y);
+ dialog.setVisible(true);
+
+ try {
+ synchronized(this) {
+ this.wait();
+ }
+ } catch(InterruptedException e) {
+ /* \_o< */
+ }
+
+ dialog.setVisible(false);
+
+ Vector selected = null;
+
+ if (!cancelled) {
+ selected = new Vector();
+
+ Iterator checkBoxIt = checkBoxes.iterator();
+ Iterator boardsIt = boards.iterator();
+
+ while (checkBoxIt.hasNext() && boardsIt.hasNext()) {
+ JCheckBox box = (JCheckBox)checkBoxIt.next();
+ Board board = (Board)boardsIt.next();
+
+ if (box.isSelected())
+ selected.add(board);
+ }
+ }
+
+ return selected;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ cancelled = !(e.getSource() == okButton);
+
+ synchronized(this) {
+ this.notifyAll();
+ }
+ }
+
+ public static Vector askBoardList(MiniFrostPanel panel, Object
parentWindow) {
+ Vector v = (new BoardSelecter(panel,
parentWindow)).askBoardList();
+
+ if (v == null) {
+ Logger.info(new BoardSelecter(), "Cancelled");
+ return null;
+ }
+
+ return v;
+ }
+
+
+}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java 2007-08-20
17:59:04 UTC (rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/BoardTree.java 2007-08-20
19:22:52 UTC (rev 14810)
@@ -301,11 +301,7 @@
Vector v = factories[i].getBoards();
if (v != null) {
- for (Iterator it = v.iterator();
- it.hasNext();) {
- boards.add(it.next());
- }
-
+ boards.addAll(v);
}
}
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java 2007-08-20
17:59:04 UTC (rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java 2007-08-20
19:22:52 UTC (rev 14810)
@@ -15,28 +15,37 @@
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JFileChooser;
import java.util.Iterator;
import java.util.Vector;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.io.File;
+
+
import thaw.core.I18n;
import thaw.core.Logger;
import thaw.gui.IconBox;
+import thaw.gui.FileChooser;
import thaw.plugins.signatures.Identity;
import thaw.plugins.miniFrost.interfaces.Draft;
+import thaw.plugins.miniFrost.interfaces.Board;
+import thaw.plugins.miniFrost.interfaces.Attachment;
+public class DraftPanel implements ActionListener, MouseListener {
-public class DraftPanel implements ActionListener {
-
private Draft draft;
private JPanel panel;
@@ -54,6 +63,9 @@
private JButton addAttachment;
private JList attachmentList;
+ private JPopupMenu attachmentRightClickMenu;
+ private JMenuItem attachmentRemove;
+
private JDialog dialog;
private final SimpleDateFormat gmtConverter;
@@ -71,10 +83,6 @@
panel = new JPanel(new BorderLayout(5, 5));
- Vector ids = new Vector();
- ids.add(I18n.getMessage("thaw.plugin.miniFrost.anonymous"));
- ids.addAll(Identity.getYourIdentities(mainPanel.getDb()));
-
authorBox = new JComboBox();
authorBox.setEditable(true);
@@ -130,6 +138,9 @@
addAttachment = new JButton(IconBox.attachment);
addAttachment.addActionListener(this);
attachmentList = new JList();
+ attachmentList.setCellRenderer(new AttachmentRenderer());
+ attachmentList.addMouseListener(this);
+
attachmentList.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
southCenterPanel.add(addAttachment, BorderLayout.WEST);
southCenterPanel.add(new JScrollPane(attachmentList),
BorderLayout.CENTER);
@@ -140,6 +151,12 @@
panel.add(northPanel, BorderLayout.NORTH );
panel.add(centerPanel, BorderLayout.CENTER);
panel.add(southPanel, BorderLayout.SOUTH );
+
+
+ attachmentRightClickMenu = new JPopupMenu();
+ attachmentRemove = new
JMenuItem(I18n.getMessage("thaw.common.remove"));
+ attachmentRemove.addActionListener(this);
+ attachmentRightClickMenu.add(attachmentRemove);
}
public DraftPanel(MiniFrostPanel mainPanel, JDialog dialog) {
@@ -149,6 +166,25 @@
}
+ protected class AttachmentRenderer extends DefaultListCellRenderer {
+ public AttachmentRenderer() {
+
+ }
+
+ public java.awt.Component getListCellRendererComponent(final
JList list, Object value,
+ final
int index, final boolean isSelected,
+ final
boolean cellHasFocus) {
+ Attachment att = (Attachment)value;
+
+ value = att.getPrintableType() + " : "+att.toString();
+
+ return super.getListCellRendererComponent(list, value,
+ index,
isSelected,
+ cellHasFocus);
+ }
+ }
+
+
public void setDraft(Draft draft) {
this.draft = draft;
@@ -261,6 +297,60 @@
private JMenuItem addFile = null;
+ private class BoardAdder implements Runnable {
+ public BoardAdder() {
+
+ }
+
+ public void run() {
+ Vector boards = BoardSelecter.askBoardList(mainPanel,
+ ((dialog !=
null) ?
+ dialog :
+
mainPanel.getPluginCore().getCore().getMainWindow().getMainFrame()));
+
+ if (boards == null) {
+ Logger.info(this, "Cancelled");
+ return;
+ }
+
+ for (Iterator it = boards.iterator();
+ it.hasNext();) {
+ draft.addAttachment((Board)it.next());
+ }
+
+ refreshAttachmentList();
+ }
+ }
+
+ private class FileAdder implements Runnable {
+ public FileAdder() {
+
+ }
+
+ public void run() {
+ FileChooser chooser = new FileChooser();
+
chooser.setTitle(I18n.getMessage("thaw.plugin.transferLogs.chooseFile"));
+ chooser.setDirectoryOnly(false);
+ chooser.setDialogType(JFileChooser.OPEN_DIALOG);
+
+ Vector files = chooser.askManyFiles();
+
+ if (files == null) {
+ Logger.info(this, "Cancelled");
+ return;
+ }
+
+ for (Iterator it = files.iterator();
+ it.hasNext(); ) {
+ draft.addAttachment((File)it.next());
+ }
+
+ refreshAttachmentList();
+ }
+ }
+
+
+
public void actionPerformed(ActionEvent e) {
if (e.getSource() == addAttachment) {
@@ -279,16 +369,28 @@
} else if (e.getSource() == addBoard) {
- /* TODO */
+ Logger.info(this, "BoardAdder");
- refreshAttachmentList();
+ (new Thread(new BoardAdder())).start();
return;
} else if (e.getSource() == addFile) {
- /* TODO */
+ Logger.info(this, "FileAdder");
+ (new Thread(new FileAdder())).start();
+
+ return;
+
+ } else if (e.getSource() == attachmentRemove) {
+
+ Object[] selection = attachmentList.getSelectedValues();
+
+ for (int i = 0 ; i < selection.length ; i++) {
+
draft.removeAttachment((Attachment)selection[i]);
+ }
+
refreshAttachmentList();
return;
@@ -343,4 +445,26 @@
else
dialog.setVisible(false);
}
+
+
+ public void mouseClicked(final MouseEvent e) {
+
+ }
+
+ public void mouseEntered(final MouseEvent e) { }
+ public void mouseExited(final MouseEvent e) { }
+
+ public void mousePressed(final MouseEvent e) {
+ showPopupMenu(e);
+ }
+
+ public void mouseReleased(final MouseEvent e) {
+ showPopupMenu(e);
+ }
+
+ protected void showPopupMenu(final MouseEvent e) {
+ if(e.isPopupTrigger()) {
+ attachmentRightClickMenu.show(e.getComponent(),
e.getX(), e.getY());
+ }
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
2007-08-20 17:59:04 UTC (rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
2007-08-20 19:22:52 UTC (rev 14810)
@@ -248,7 +248,7 @@
/* text */
if (!retracted) {
- area = getTextArea(msg.getMessage());
+ area = getTextArea(msg.getMessage().trim());
this.add(area, BorderLayout.CENTER);
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
2007-08-20 17:59:04 UTC (rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKAttachment.java
2007-08-20 19:22:52 UTC (rev 14810)
@@ -3,7 +3,7 @@
import java.util.Vector;
import org.w3c.dom.*;
-
+import thaw.core.Logger;
import thaw.plugins.Hsqldb;
@@ -79,6 +79,21 @@
String[] values = getValues();
for (int i = 0 ; i < properties.length ; i++) {
+ if (properties[i] == null && values[i] == null) {
+ Logger.warning(this, "Null property with null
value ?!");
+ continue;
+ }
+
+ if (values[i] == null) {
+ Logger.notice(this, "Null value for property
'"+properties[i]+"'");
+ values[i] = "";
+ }
+
+ if (properties[i] == null) {
+ Logger.warning(this, "Property name null (value
'"+values[i]+"')");
+ continue;
+ }
+
Element el = doc.createElement(properties[i]);
boolean inCdata = isCDATAException(properties[i]);
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-08-20 17:59:04 UTC (rev 14809)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2007-08-20 19:22:52 UTC (rev 14810)
@@ -14,7 +14,7 @@
public class KSKFileAttachment
- extends KSKAttachment implements Runnable {
+ extends KSKAttachment implements Runnable, java.util.Observer {
private String filename;
private long size;
@@ -54,12 +54,43 @@
public void computeKey(FCPQueueManager queueManager, java.io.File file)
{
- /* TODO */
+ this.queueManager = queueManager;
+
+ FCPClientPut put = new FCPClientPut(file,
+ FCPClientPut.KEY_TYPE_CHK,
+ 0 /* rev */,
+ null /* name */,
+ null /* private key */,
+
FCPClientPut.DEFAULT_PRIORITY,
+ true /* global */,
+
FCPClientPut.PERSISTENCE_UNTIL_DISCONNECT,
+ true /* getCHKOnly */);
+ put.addObserver(this);
+ queueManager.addQueryToTheRunningQueue(put);
}
+ public void update(java.util.Observable o, Object param) {
+ if (o instanceof FCPClientPut) {
+ FCPClientPut put = (FCPClientPut)o;
+ String possibleKey = put.getFileKey();
+
+ if (FreenetURIHelper.isAKey(possibleKey)) {
+ Logger.info(this, "Key computed: "+possibleKey);
+ key = possibleKey;
+ }
+
+ if (put.isFinished())
+ put.deleteObserver(this);
+
+ if (put.isFinished() && put.isSuccessful()) {
+ put.stop(queueManager);
+ queueManager.remove(put);
+ }
+ }
+ }
+
public boolean isReady() {
- /* TODO */
- return true;
+ return !(key == null);
}