Author: jflesch
Date: 2006-12-04 22:33:12 +0000 (Mon, 04 Dec 2006)
New Revision: 11229
Added:
trunk/apps/Thaw/src/thaw/core/GUIHelper.java
Modified:
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
trunk/apps/Thaw/src/thaw/plugins/fetchPlugin/FetchPanel.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
Log:
Add option 'right click -> paste' to some dialogs
Added: trunk/apps/Thaw/src/thaw/core/GUIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/GUIHelper.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/core/GUIHelper.java 2006-12-04 22:33:12 UTC
(rev 11229)
@@ -0,0 +1,58 @@
+package thaw.core;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractButton;
+import javax.swing.text.JTextComponent;
+
+public class GUIHelper {
+
+ public GUIHelper() {
+
+ }
+
+ public static class PasteHelper implements ActionListener {
+ JTextComponent txtComp;
+
+ public PasteHelper(AbstractButton src, JTextComponent txtComp) {
+ if (src != null)
+ src.addActionListener(this);
+ this.txtComp = txtComp;
+ }
+
+ public void actionPerformed(ActionEvent evt) {
+ pasteToComponent(txtComp);
+ }
+ }
+
+ public static void pasteToComponent(JTextComponent txtComp) {
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ Clipboard cp = tk.getSystemClipboard();
+
+ String result;
+ Transferable contents = cp.getContents(null);
+
+ boolean hasTransferableText = ((contents != null) &&
+
contents.isDataFlavorSupported(DataFlavor.stringFlavor));
+
+ try {
+ if ( hasTransferableText ) {
+ result =
(String)contents.getTransferData(DataFlavor.stringFlavor);
+ txtComp.setText(txtComp.getText() + result);
+ } else {
+ Logger.notice(new GUIHelper(), "Nothing to get
from clipboard");
+ }
+ } catch(java.awt.datatransfer.UnsupportedFlavorException e) {
+ Logger.error(new GUIHelper(), "Error while pasting:
UnsupportedFlavorException: "+e.toString());
+ } catch(java.io.IOException e) {
+ Logger.error(new GUIHelper(), "Error while pasting:
IOException: "+e.toString());
+ }
+ }
+
+}
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-12-04 16:49:10 UTC
(rev 11228)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-12-04 22:33:12 UTC
(rev 11229)
@@ -69,6 +69,8 @@
thaw.common.search=Search
+thaw.common.paste=Paste
+
## Errors
thaw.error.idAlreadyUsed=Unable to connect. Our Id is already used by another
client connected to the node.
Modified: trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java 2006-12-04 16:49:10 UTC
(rev 11228)
+++ trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java 2006-12-04 22:33:12 UTC
(rev 11229)
@@ -85,7 +85,7 @@
panelAdded = split;
}
- split.setSize(MainWindow.DEFAULT_SIZE_X - 150,
MainWindow.DEFAULT_SIZE_Y - 150); /* needed to avoid size = 0at the begining */
+ split.setSize(MainWindow.DEFAULT_SIZE_X - 150,
MainWindow.DEFAULT_SIZE_Y - 175); /* needed to avoid size = 0at the begining */
split.setResizeWeight(0.5);
setMainWindow(core.getMainWindow());
Modified: trunk/apps/Thaw/src/thaw/plugins/fetchPlugin/FetchPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/fetchPlugin/FetchPanel.java
2006-12-04 16:49:10 UTC (rev 11228)
+++ trunk/apps/Thaw/src/thaw/plugins/fetchPlugin/FetchPanel.java
2006-12-04 22:33:12 UTC (rev 11229)
@@ -17,6 +17,12 @@
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
+import javax.swing.JPopupMenu;
+import javax.swing.JMenuItem;
+
+import java.awt.event.MouseListener;
+import java.awt.event.MouseEvent;
+
import java.io.File;
import java.util.Vector;
import java.util.Iterator;
@@ -24,7 +30,7 @@
import thaw.core.*;
import thaw.plugins.FetchPlugin;
-public class FetchPanel implements java.awt.event.ActionListener {
+public class FetchPanel implements java.awt.event.ActionListener,
MouseListener {
private JPanel mainPanel = null;
private JPanel centeredPart = null; /* (below is the validation button)
*/
@@ -53,6 +59,8 @@
private String[] queues = null;
private JComboBox queueSelecter = null;
+ private JPopupMenu rightClickMenu;
+
private Core core;
private FetchPlugin fetchPlugin;
@@ -88,8 +96,10 @@
this.loadListButton.addActionListener(this);
this.pasteButton = new
JButton(I18n.getMessage("thaw.plugin.fetch.pasteFromClipboard"));
- this.pasteButton.addActionListener(this);
+ new GUIHelper.PasteHelper(pasteButton, fileList);
+ fileList.addMouseListener(this);
+
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,2));
buttonPanel.add(this.pasteButton);
@@ -159,6 +169,12 @@
this.destinationButton = new
JButton(I18n.getMessage("thaw.plugin.fetch.chooseDestination"));
this.destinationButton.addActionListener(this);
+ rightClickMenu = new JPopupMenu();
+ JMenuItem item = new
JMenuItem(I18n.getMessage("thaw.common.paste"));
+ new GUIHelper.PasteHelper(item, fileList);
+ rightClickMenu.add(item);
+
+ /*** Putting things together ***/
this.dstChoosePanel.add(this.destinationLabel);
this.dstChoosePanel.add(this.destinationField);
this.dstChoosePanel.add(this.destinationButton);
@@ -243,28 +259,6 @@
}
- if(e.getSource() == this.pasteButton) {
- Toolkit tk = Toolkit.getDefaultToolkit();
- Clipboard cp = tk.getSystemClipboard();
-
- try {
- String result;
- Transferable contents = cp.getContents(null);
-
- boolean hasTransferableText = ((contents !=
null) &&
-
contents.isDataFlavorSupported(DataFlavor.stringFlavor));
-
- if ( hasTransferableText ) {
- result =
(String)contents.getTransferData(DataFlavor.stringFlavor);
-
this.fileList.setText(this.fileList.getText() + "\n" + result);
- } else {
- Logger.info(this, "Nothing to get from
clipboard");
- }
- } catch(Exception exception) {
- Logger.notice(this, "Exception while pasting:
"+exception.toString());
- }
- }
-
if(e.getSource() == this.loadListButton) {
FileChooser fileChooser = new FileChooser();
File toParse = null;
@@ -299,5 +293,25 @@
this.fileList.setText(result);
}
}
+
+
+
+ public void mouseClicked(MouseEvent e) { }
+ public void mouseEntered(MouseEvent e) { }
+ public void mouseExited(MouseEvent e) { }
+ public void mousePressed(MouseEvent e) {
+ this.showPopupMenu(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ this.showPopupMenu(e);
+ }
+
+ protected void showPopupMenu(MouseEvent e) {
+ if(e.isPopupTrigger()) {
+ rightClickMenu.show(e.getComponent(), e.getX(),
e.getY());
+ }
+ }
+
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2006-12-04 16:49:10 UTC (rev 11228)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2006-12-04 22:33:12 UTC (rev 11229)
@@ -19,6 +19,8 @@
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JLabel;
+import javax.swing.JPopupMenu;
+import javax.swing.JMenuItem;
import java.util.Vector;
import java.util.Iterator;
@@ -27,6 +29,9 @@
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseEvent;
+
import thaw.core.FileChooser;
import thaw.core.Config;
import thaw.core.I18n;
@@ -149,58 +154,18 @@
}
- public static class IndexAdder extends BasicIndexAction {
- public IndexAdder(Hsqldb db, FCPQueueManager queueManager,
UnknownIndexList indexList, IndexTree tree, AbstractButton actionSource) {
- super(db, queueManager, indexList, tree, actionSource);
- }
- public void setTarget(IndexTreeNode node) {
- super.setTarget(node);
- getActionSource().setEnabled(node == null || node
instanceof IndexCategory);
- }
-
- public void actionPerformed(ActionEvent e) {
- String key =
askAName(I18n.getMessage("thaw.plugin.index.indexKey"), "USK@");
-
- addIndex(getDb(), getQueueManager(),
getUnknownIndexList(), getTree(), (IndexCategory)getTarget(), key);
- }
- }
-
-
- /**
- * Can be use directly
- */
- public static void addIndex(Hsqldb db, FCPQueueManager queueManager,
UnknownIndexList indexList, IndexTree tree, IndexCategory target, String
publicKey) {
- publicKey = FreenetURIHelper.cleanURI(publicKey);
-
- if (publicKey == null)
- return;
-
- String name = Index.getNameFromKey(publicKey);
-
- if (name == null)
- return;
-
- if (target == null)
- target = tree.getRoot();
-
- Index index = new Index(db, queueManager, indexList, -2,
target, name, name, publicKey, null, 0, null);
-
- if (tree.addToIndexCategory(target, index)) {
- index.create();
- index.updateFromFreenet(-1);
- }
-
- indexList.removeLink(index);
- }
-
-
-
- public static class KeyAsker implements ActionListener {
+ public static class KeyAsker implements ActionListener, MouseListener {
private JButton okButton;
private JButton cancelButton;
private int formState;
+ private JTextField publicKeyField = null;
+ private JTextField privateKeyField = null;
+
+ private JPopupMenu popupMenuA;
+ private JPopupMenu popupMenuB;
+
public KeyAsker() {
}
@@ -215,8 +180,8 @@
}
public String[] askKeysBis(boolean askPrivateKey,
- String defaultPublicKey,
- String defaultPrivateKey) {
+ String defaultPublicKey,
+ String defaultPrivateKey) {
formState = 0;
if (defaultPublicKey == null)
@@ -229,8 +194,8 @@
frame.getContentPane().setLayout(new BorderLayout());
- JTextField publicKeyField = new
JTextField(defaultPublicKey);
- JTextField privateKeyField = new
JTextField(defaultPrivateKey);
+ publicKeyField = new JTextField(defaultPublicKey);
+ privateKeyField = new JTextField(defaultPrivateKey);
JPanel subPanelA = new JPanel(); /* left => labels */
JPanel subPanelB = new JPanel(); /* right => textfield
*/
@@ -241,9 +206,20 @@
subPanelA.add(new
JLabel(I18n.getMessage("thaw.plugin.index.indexKey")+ " "), BorderLayout.WEST);
subPanelB.add(publicKeyField, BorderLayout.CENTER);
+ popupMenuA = new JPopupMenu();
+ JMenuItem item = new
JMenuItem(I18n.getMessage("thaw.common.paste"));
+ popupMenuA.add(item);
+ new thaw.core.GUIHelper.PasteHelper(item,
publicKeyField);
+ publicKeyField.addMouseListener(this);
+
if (askPrivateKey) {
subPanelA.add(new
JLabel(I18n.getMessage("thaw.plugin.index.indexPrivateKey")+" "),
BorderLayout.WEST);
subPanelB.add(privateKeyField,
BorderLayout.CENTER);
+ popupMenuB = new JPopupMenu();
+ item = new
JMenuItem(I18n.getMessage("thaw.common.paste"));
+ popupMenuB.add(item);
+ new thaw.core.GUIHelper.PasteHelper(item,
privateKeyField);
+ privateKeyField.addMouseListener(this);
}
frame.getContentPane().add(subPanelA,
BorderLayout.WEST);
@@ -266,6 +242,9 @@
frame.setSize(700, 100);
frame.setVisible(true);
+ /* TODO: DO IT BETTER YOU ?^{"(*? */
+ /* VVVVVVVVVVV */
+
while(formState == 0) {
try {
Thread.sleep(500);
@@ -305,6 +284,28 @@
formState = 2;
}
}
+
+ public void mouseClicked(MouseEvent e) { }
+ public void mouseEntered(MouseEvent e) { }
+ public void mouseExited(MouseEvent e) { }
+
+ public void mousePressed(MouseEvent e) {
+ this.showPopupMenu(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ this.showPopupMenu(e);
+ }
+
+ protected void showPopupMenu(MouseEvent e) {
+ if(e.isPopupTrigger()) {
+ if (e.getComponent() == publicKeyField)
+ popupMenuA.show(e.getComponent(),
e.getX(), e.getY());
+ if (e.getComponent() == privateKeyField)
+ popupMenuB.show(e.getComponent(),
e.getX(), e.getY());
+ }
+ }
+
}
public static class IndexKeyModifier extends BasicIndexAction
implements Runnable {
@@ -373,6 +374,11 @@
}
+ public static void addIndex(Hsqldb db, FCPQueueManager queueManager,
UnknownIndexList uIndexList, IndexTree tree, IndexCategory target, String
publicKey) {
+ reuseIndex(db, queueManager, uIndexList, tree, target,
publicKey, null);
+ }
+
+
/**
* Can be use directly
* @param privateKey Can be null
@@ -716,12 +722,14 @@
- public static class KeyAdder extends BasicIndexAction implements
Runnable {
+ public static class KeyAdder extends BasicIndexAction implements
Runnable, MouseListener {
private JButton cancelButton = null;
private JButton okButton = null;
private JTextArea textArea = null;
private JFrame frame = null;
+ private JPopupMenu popupMenu = null;
+
public KeyAdder(Hsqldb db, AbstractButton actionSource) {
super(db, null, null, null, actionSource);
}
@@ -744,6 +752,12 @@
cancelButton = new
JButton(I18n.getMessage("thaw.common.cancel"));
okButton = new
JButton(I18n.getMessage("thaw.common.ok"));
+ popupMenu = new JPopupMenu();
+ JMenuItem item = new
JMenuItem(I18n.getMessage("thaw.common.paste"));
+ popupMenu.add(item);
+ textArea.addMouseListener(this);
+ new thaw.core.GUIHelper.PasteHelper(item, textArea);
+
cancelButton.addActionListener(this);
okButton.addActionListener(this);
@@ -792,6 +806,25 @@
frame.setVisible(false);
}
}
+
+ public void mouseClicked(MouseEvent e) { }
+ public void mouseEntered(MouseEvent e) { }
+ public void mouseExited(MouseEvent e) { }
+
+ public void mousePressed(MouseEvent e) {
+ this.showPopupMenu(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ this.showPopupMenu(e);
+ }
+
+ protected void showPopupMenu(MouseEvent e) {
+ if(e.isPopupTrigger()) {
+ popupMenu.show(e.getComponent(), e.getX(),
e.getY());
+ }
+ }
+
}
/**