Author: jflesch
Date: 2008-02-17 20:39:29 +0000 (Sun, 17 Feb 2008)
New Revision: 18024
Added:
trunk/apps/Thaw/src/thaw/plugins/signatures/IdentityTable.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListTable.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustTab.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentityList.java
Modified:
trunk/apps/Thaw/src/thaw/fcp/FCPMetaTransferQuery.java
trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListUploader.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
Log:
WoT : Add a tab to browser users trust lists
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPMetaTransferQuery.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPMetaTransferQuery.java 2008-02-17
18:35:20 UTC (rev 18023)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPMetaTransferQuery.java 2008-02-17
20:39:29 UTC (rev 18024)
@@ -4,6 +4,7 @@
import java.util.Observable;
import java.util.Observer;
import java.util.Hashtable;
+import java.util.Vector;
import thaw.core.Logger;
@@ -33,7 +34,9 @@
}
private void add(String id, FCPTransferQuery query) {
- idToQuery.put(id, query);
+ synchronized(idToQuery) {
+ idToQuery.put(id, query);
+ }
}
/***
@@ -83,7 +86,9 @@
}
private void remove(String id) {
- idToQuery.remove(id);
+ synchronized(idToQuery) {
+ idToQuery.remove(id);
+ }
}
/**
@@ -112,11 +117,16 @@
public void stopAll() {
- for (Iterator it = idToQuery.values().iterator(); it.hasNext()
; ) {
-
+ Vector queries = new Vector();
+
+ synchronized(idToQuery) {
+ for (Iterator it = idToQuery.values().iterator();
it.hasNext() ; )
+ queries.add(it.next());
+ }
+
+ for (Iterator it = queries.iterator(); it.hasNext() ; ) {
FCPTransferQuery query = (FCPTransferQuery)it.next();
stop(query);
-
}
}
@@ -128,8 +138,12 @@
String targetId;
if (msg != null && (targetId = msg.getValue(idField))
!= null) {
- Observer obs =
(Observer)(idToQuery.get(targetId));
+ Observer obs;
+ synchronized(idToQuery) {
+ obs =
(Observer)(idToQuery.get(targetId));
+ }
+
if (obs != null) {
/* we redirect only to the target
FCPTransferQuery */
obs.update(o, param);
Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2008-02-17
18:35:20 UTC (rev 18023)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2008-02-17
20:39:29 UTC (rev 18024)
@@ -726,6 +726,12 @@
thaw.plugin.wot.usedIdentity=Identit?? utilis??e pour publier la liste de
confiances
thaw.plugin.wot.usedIdentity.none=[Ne pas publier la liste de confiance]
thaw.plugin.wot.numberOfRefresh=Nombre de liste de confiances ?? rafraichir
simultan??ment
+thaw.plugin.wot.score=Score
+thaw.plugin.wot.yourTrustList=Votre liste de confiances:
+thaw.plugin.wot.itsTrustList=Liste de confiance de l'utilisateur:
+thaw.plugin.wot.itsTrustLevel=Niveau de confiance de l'utilisateur
+thaw.plugin.wot.yourTrustLevel=Votre niveau de confiance
+thaw.plugin.wot.wotTrustLevel=Niveau de confiance calcul?? par le WoT
## node configurator
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2008-02-17 18:35:20 UTC
(rev 18023)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2008-02-17 20:39:29 UTC
(rev 18024)
@@ -733,6 +733,12 @@
thaw.plugin.wot.usedIdentity=Identity used to publish your trust list
thaw.plugin.wot.usedIdentity.none=[Don't publish the trust list]
thaw.plugin.wot.numberOfRefresh=Number of trust list to refresh simultaneously
+thaw.plugin.wot.score=Score
+thaw.plugin.wot.yourTrustList=Your trust list:
+thaw.plugin.wot.itsTrustList=User's trust list:
+thaw.plugin.wot.itsTrustLevel=User's trust level
+thaw.plugin.wot.yourTrustLevel=Your trust level
+thaw.plugin.wot.wotTrustLevel=Computed trust level
##?Node configurator
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2008-02-17 18:35:20 UTC
(rev 18023)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2008-02-17 20:39:29 UTC
(rev 18024)
@@ -726,6 +726,12 @@
thaw.plugin.wot.usedIdentity=Identit\u00e9 utilis\u00e9e pour publier la liste
de confiances
thaw.plugin.wot.usedIdentity.none=[Ne pas publier la liste de confiance]
thaw.plugin.wot.numberOfRefresh=Nombre de liste de confiances \u00e0
rafraichir simultan\u00e9ment
+thaw.plugin.wot.score=Score
+thaw.plugin.wot.yourTrustList=Votre liste de confiances:
+thaw.plugin.wot.itsTrustList=Liste de confiance de l'utilisateur:
+thaw.plugin.wot.itsTrustLevel=Niveau de confiance de l'utilisateur
+thaw.plugin.wot.yourTrustLevel=Votre niveau de confiance
+thaw.plugin.wot.wotTrustLevel=Niveau de confiance calcul\u00e9 par le WoT
## node configurator
Modified: trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java 2008-02-17 18:35:20 UTC
(rev 18023)
+++ trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java 2008-02-17 20:39:29 UTC
(rev 18024)
@@ -20,6 +20,7 @@
private Signatures sigs;
private WebOfTrustConfigTab configTab = null;
+ private WebOfTrustTab wotTab = null;
private int used = 0;
@@ -172,10 +173,23 @@
thaw.gui.IconBox.minTrust,
configTab.getPanel());
+ configTab.addAsObserver();
+
if (core.getConfig().getValue("wotActivated") == null
- ||
Boolean.valueOf(core.getConfig().getValue("wotActivated")).booleanValue())
+ ||
Boolean.valueOf(core.getConfig().getValue("wotActivated")).booleanValue()) {
initThread();
+
+ wotTab = new WebOfTrustTab(db,
core.getConfig());
+
core.getMainWindow().addTab(I18n.getMessage("thaw.plugin.wot"),
+
thaw.gui.IconBox.trust,
+ wotTab.getPanel());
+
+ core.getMainWindow().getMainFrame().validate();
+
+ wotTab.loadState();
+ }
+
return true;
}
@@ -255,6 +269,7 @@
used--;
if (configTab != null) {
+ configTab.deleteAsObserver();
core.getConfigWindow().removeTab(configTab.getPanel());
configTab = null;
}
@@ -263,6 +278,11 @@
unloadDeps(core);
}
+ if (wotTab != null) {
+ core.getMainWindow().removeTab(wotTab.getPanel());
+ wotTab = null;
+ }
+
stopThread();
}
Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2008-02-17 18:35:20 UTC (rev 18023)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -86,8 +86,7 @@
public QueueWatcher queueWatcher;
public QueuePanel(final Core core, final QueueWatcher queueWatcher,
- final DetailPanel detailPanel,
- boolean isForInsertionQueue) {
+ final DetailPanel detailPanel, boolean
isForInsertionQueue) {
this.queueWatcher = queueWatcher;
Added: trunk/apps/Thaw/src/thaw/plugins/signatures/IdentityTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/IdentityTable.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/IdentityTable.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -0,0 +1,179 @@
+package thaw.plugins.signatures;
+
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.Observable;
+import java.util.Vector;
+
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.TableModelEvent;
+import thaw.core.Config;
+import thaw.core.I18n;
+import thaw.gui.Table;
+
+public class IdentityTable extends Observable implements MouseListener {
+ private static final long serialVersionUID = -6972180330110075151L;
+
+ private thaw.gui.Table table;
+
+ private IdentityModel model;
+ private IdentityRenderer renderer;
+
+ public IdentityTable(Config config, String prefix, boolean showDup) {
+ model = new IdentityModel(showDup);
+ table = new Table(config, prefix, model);
+ table.setDefaultRenderer(table.getColumnClass(0), renderer =
new IdentityRenderer(model));
+ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ table.addMouseListener(this);
+ }
+
+ public void setModel(IdentityModel model) {
+ this.model = model;
+ table.setModel(model);
+ renderer.setModel(model);
+ }
+
+ public static class IdentityModel extends
javax.swing.table.AbstractTableModel {
+ private static final long serialVersionUID =
-7614528570324908651L;
+
+ public static String[] columnNames = {
+ I18n.getMessage("thaw.plugin.signature.nickname"),
+ I18n.getMessage("thaw.plugin.signature.trustLevel"),
+ I18n.getMessage("thaw.plugin.signature.isDup")
+ };
+
+ private Vector identities;
+
+ private boolean showDup;
+
+ public IdentityModel(boolean showDup) {
+ this.showDup = showDup;
+ }
+
+ public void setIdentities(Vector i) {
+ identities = i;
+
+ final TableModelEvent event = new TableModelEvent(this);
+ fireTableChanged(event);
+ }
+
+ public Vector getIdentities() {
+ return identities;
+ }
+
+ public int getRowCount() {
+ if (identities == null)
+ return 0;
+
+ return identities.size();
+ }
+
+ public int getColumnCount() {
+ if (showDup)
+ return columnNames.length;
+ return columnNames.length-1;
+ }
+
+ public String getColumnName(final int column) {
+ return columnNames[column];
+ }
+
+ public Object getValueAt(int row, int column) {
+ if (identities == null)
+ return null;
+
+ if (column == 0)
+ return
((Identity)identities.get(row)).toString();
+
+ if (column == 1)
+ return
((Identity)identities.get(row)).getTrustLevelStr();
+
+ return null;
+ }
+
+ public Identity getIdentity(int line) {
+ return (Identity)identities.get(line);
+ }
+ }
+
+
+
+ public static class IdentityRenderer extends
thaw.gui.Table.DefaultRenderer {
+ private static final long serialVersionUID =
5405210731032136559L;
+ private IdentityModel model;
+
+ public IdentityRenderer(IdentityModel model) {
+ super();
+ setModel(model);
+ }
+
+ public void setModel(IdentityModel model) {
+ this.model = model;
+ }
+
+ public java.awt.Component getTableCellRendererComponent(final
JTable table, Object value,
+ final
boolean isSelected, final boolean hasFocus,
+ final
int row, final int column) {
+
+ if (value instanceof String
+ && "X".equals(value)) {
+ value = thaw.gui.IconBox.minClose;
+ }
+
+ java.awt.Component c =
super.getTableCellRendererComponent(table, value,
+
isSelected, hasFocus,
+
row, column);
+ Identity i = model.getIdentity(row);
+
+ c.setForeground(i.getTrustLevelColor());
+
+ return c;
+ }
+
+ }
+
+ public void setIdentities(Vector ids) {
+ model.setIdentities(ids);
+ }
+
+ public thaw.gui.Table getTable() {
+ return table;
+ }
+
+ public Identity getIdentity(int row) {
+ return model.getIdentity(row);
+ }
+
+ public Vector getIdentities() {
+ return model.getIdentities();
+ }
+
+
+ public void mouseClicked(MouseEvent arg0) {
+ setChanged();
+ notifyObservers(model.getIdentity(table.getSelectedRow()));
+ }
+
+
+
+ public void mouseEntered(MouseEvent arg0) {
+ }
+
+
+
+ public void mouseExited(MouseEvent arg0) {
+ }
+
+
+
+ public void mousePressed(MouseEvent arg0) {
+ }
+
+
+
+ public void mouseReleased(MouseEvent arg0) {
+ }
+
+
+}
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2008-02-17 18:35:20 UTC (rev 18023)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -8,9 +8,7 @@
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
-import javax.swing.JTable;
import javax.swing.ListSelectionModel;
-import javax.swing.event.TableModelEvent;
import javax.swing.JComboBox;
import java.awt.BorderLayout;
@@ -33,8 +31,6 @@
import thaw.gui.IconBox;
import thaw.gui.FileChooser;
-import thaw.gui.Table;
-
import java.util.Observer;
import java.util.Observable;
@@ -379,106 +375,10 @@
/********************* OTHER IDENTITIES
**********************************/
- protected class IdentityModel extends
javax.swing.table.AbstractTableModel {
- private static final long serialVersionUID =
-7614528570324908651L;
-
- public String[] columnNames = {
- I18n.getMessage("thaw.plugin.signature.nickname"),
- I18n.getMessage("thaw.plugin.signature.trustLevel"),
- I18n.getMessage("thaw.plugin.signature.isDup")
- };
-
- private Vector identities;
-
- public IdentityModel() {
-
- }
-
- public void setIdentities(Vector i) {
- identities = i;
-
- final TableModelEvent event = new TableModelEvent(this);
- fireTableChanged(event);
- }
-
- public Vector getIdentities() {
- return identities;
- }
-
- public int getRowCount() {
- if (identities == null)
- return 0;
-
- return identities.size();
- }
-
- public int getColumnCount() {
- return columnNames.length;
- }
-
- public String getColumnName(final int column) {
- return columnNames[column];
- }
-
- public Object getValueAt(int row, int column) {
- if (identities == null)
- return null;
-
- if (column == 0)
- return
((Identity)identities.get(row)).toString();
-
- if (column == 1)
- return
((Identity)identities.get(row)).getTrustLevelStr();
-
- if (column == 2)
- return ((Identity)identities.get(row)).isDup() ?
- "X" : "";
-
- return null;
- }
-
- public Identity getIdentity(int line) {
- return (Identity)identities.get(line);
- }
- }
-
-
- protected class OtherIdentitiesRenderer extends
thaw.gui.Table.DefaultRenderer {
- private static final long serialVersionUID =
5405210731032136559L;
- private IdentityModel model;
-
- public OtherIdentitiesRenderer(IdentityModel model) {
- super();
- this.model = model;
- }
-
- public java.awt.Component getTableCellRendererComponent(final
JTable table, Object value,
- final
boolean isSelected, final boolean hasFocus,
- final
int row, final int column) {
-
- if (value instanceof String
- && "X".equals(value)) {
- value = thaw.gui.IconBox.minClose;
- }
-
- java.awt.Component c =
super.getTableCellRendererComponent(table, value,
-
isSelected, hasFocus,
-
row, column);
- Identity i = model.getIdentity(row);
-
- c.setForeground(i.getTrustLevelColor());
-
- return c;
- }
-
- }
-
-
protected class OtherIdentitiesPanel implements ActionListener,
TrustListParser.TrustListContainer {
private JDialog dialog;
- private IdentityModel model;
- private Table table;
+ private IdentityTable table;
private JButton close;
@@ -497,16 +397,11 @@
dialog.getContentPane().add(label, BorderLayout.NORTH);
- model = new IdentityModel();
+ table = new IdentityTable(config,
"other_identities_table", true);
- OtherIdentitiesRenderer renderer = new
OtherIdentitiesRenderer(model);
+ dialog.getContentPane().add(new
JScrollPane(table.getTable()),
+
BorderLayout.CENTER);
- table = new Table(config, "other_identities_table",
model);
- table.setDefaultRenderer(table.getColumnClass(0),
renderer);
-
- dialog.getContentPane().add(new JScrollPane(table),
- BorderLayout.CENTER);
-
JPanel eastPanel = new JPanel(new BorderLayout());
JPanel buttonsPanel = new JPanel(new
GridLayout(Identity.trustLevelInt.length +4, 1));
@@ -564,7 +459,7 @@
}
public void updateList() {
- model.setIdentities(Identity.getOtherIdentities(db));
+ table.setIdentities(Identity.getOtherIdentities(db));
}
public void actionPerformed(ActionEvent e) {
@@ -583,7 +478,7 @@
File file = chooser.askOneFile();
-
TrustListParser.exportTrustList(model.getIdentities(), file);
+
TrustListParser.exportTrustList(table.getIdentities(), file);
return;
@@ -603,7 +498,7 @@
return;
}
- int[] rows = table.getSelectedRows();
+ int[] rows = table.getTable().getSelectedRows();
for (int i = 0 ; i < rows.length ; i++) {
int row = rows[i];
@@ -611,7 +506,7 @@
if (row < 0)
continue;
- Identity target = model.getIdentity(row);
+ Identity target = table.getIdentity(row);
if (target == null)
continue;
Added: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListTable.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListTable.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -0,0 +1,120 @@
+package thaw.plugins.webOfTrust;
+
+import java.util.Observable;
+import java.util.Observer;
+import java.util.Vector;
+
+import javax.swing.event.TableModelEvent;
+
+import thaw.core.Config;
+import thaw.core.I18n;
+import thaw.gui.Table;
+import thaw.plugins.Hsqldb;
+import thaw.plugins.signatures.Identity;
+import thaw.plugins.signatures.IdentityTable;
+
+public class TrustListTable extends Observable implements Observer {
+ private Hsqldb db;
+
+ private IdentityTable table;
+ private TrustListModel model;
+
+ public TrustListTable(Hsqldb db, Config config) {
+ this.db = db;
+
+ model = new TrustListModel();
+
+ table = new IdentityTable(config, "wotIdList_", false);
+ table.setModel(model);
+ table.addObserver(this);
+
+ refresh(null);
+ }
+
+ public static class TrustListModel extends IdentityTable.IdentityModel {
+ private static final long serialVersionUID =
2742525676359889703L;
+
+ private Vector trustLinks = null;
+
+ public TrustListModel() {
+ super(false);
+ }
+ public static String[] columnNames = {
+ I18n.getMessage("thaw.plugin.signature.nickname"),
+ I18n.getMessage("thaw.plugin.wot.itsTrustLevel"),
+ I18n.getMessage("thaw.plugin.wot.yourTrustLevel"),
+ I18n.getMessage("thaw.plugin.wot.wotTrustLevel")
+ };
+
+ public void setIdentities(Vector i) {
+ trustLinks = i;
+
+ final TableModelEvent event = new TableModelEvent(this);
+ fireTableChanged(event);
+ }
+
+ public Vector getIdentities() {
+ return null;
+ }
+
+ public int getRowCount() {
+ if (trustLinks == null)
+ return 0;
+
+ return trustLinks.size();
+ }
+
+ public int getColumnCount() {
+ return columnNames.length;
+ }
+
+ public String getColumnName(final int column) {
+ return columnNames[column];
+ }
+
+ public Object getValueAt(int row, int column) {
+ if (trustLinks == null)
+ return null;
+
+ if (column == 0)
+ return
((WotIdentity.TrustLink)trustLinks.get(row)).getDestination().toString();
+
+ if (column == 1)
+ return
Identity.getTrustLevelStr(((WotIdentity.TrustLink)trustLinks.get(row)).getLinkTrustLevel());
+
+ if (column == 2)
+ return
((WotIdentity.TrustLink)trustLinks.get(row)).getDestination().getUserTrustLevelStr();
+
+ if (column == 3)
+ return
((WotIdentity.TrustLink)trustLinks.get(row)).getDestination().getTrustLevelStr();
+
+
+ return null;
+ }
+
+ public Identity getIdentity(int row) {
+ return
((WotIdentity.TrustLink)trustLinks.get(row)).getDestinationAsSeenByTheSource();
+ }
+
+ }
+
+ public void refresh(Identity src) {
+ Vector ids;
+
+ if (src != null)
+ ids = WotIdentity.getTrustList(db, src);
+ else
+ ids = new Vector();
+
+ model.setIdentities(ids);
+ }
+
+ public Table getTable() {
+ return table.getTable();
+ }
+
+ public void update(Observable arg0, Object arg1) {
+ setChanged();
+ notifyObservers(arg1);
+ }
+}
Modified: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListUploader.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListUploader.java
2008-02-17 18:35:20 UTC (rev 18023)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListUploader.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -264,7 +264,7 @@
"trustList", FreenetURIHelper.convertSSKtoUSK(privateKey)+"/", /* the
convertion fonction forget the '/' */
2, /* priority */
false, /* global */
-
FCPClientPut.PERSISTENCE_FOREVER); /* persistence */
+
FCPClientPut.PERSISTENCE_UNTIL_DISCONNECT); /* persistence */
upload.addObserver(this);
queueManager.addQueryToTheRunningQueue(upload);
Modified: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java
2008-02-17 18:35:20 UTC (rev 18023)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -16,9 +16,10 @@
import thaw.core.I18n;
import thaw.core.Logger;
import thaw.plugins.Hsqldb;
+import thaw.plugins.Signatures;
import thaw.plugins.signatures.Identity;
-public class WebOfTrustConfigTab implements Observer, ActionListener {
+public class WebOfTrustConfigTab implements Observer, ActionListener,
Signatures.SignaturesObserver {
private thaw.core.ConfigWindow configWindow;
private Config config;
private Hsqldb db;
@@ -58,9 +59,18 @@
readActivated();
activated.addActionListener(this);
+ }
+
+ public void addAsObserver() {
configWindow.addObserver(this);
+ Signatures.addObserver(this);
}
+ public void deleteAsObserver() {
+ configWindow.deleteObserver(this);
+ Signatures.deleteObserver(this);
+ }
+
private void resetContentOfIdentitySelector() {
Vector identities = Identity.getYourIdentities(db);
@@ -142,4 +152,18 @@
public void actionPerformed(ActionEvent e) {
readActivated();
}
+
+ public void identityUpdated(Identity i) {
+ // TODO Raccord de m??thode auto-g??n??r??
+
+ }
+
+ public void privateIdentityAdded(Identity i) {
+ reloadSettings();
+ }
+
+ public void publicIdentityAdded(Identity i) {
+ // TODO Raccord de m??thode auto-g??n??r??
+
+ }
}
Added: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustTab.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustTab.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -0,0 +1,93 @@
+package thaw.plugins.webOfTrust;
+
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import java.util.Observable;
+import java.util.Observer;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+
+import thaw.core.Config;
+import thaw.core.I18n;
+import thaw.plugins.Hsqldb;
+import thaw.plugins.Signatures;
+import thaw.plugins.signatures.Identity;
+
+
+public class WebOfTrustTab implements Signatures.SignaturesObserver, Observer {
+
+ private Config config;
+
+ private JSplitPane mainSplit;
+ private JPanel rightPanel;
+ private JPanel itsTrustListPanel;
+
+ private WotIdentityList idList;
+ private TrustListTable trustListTable;
+
+ public WebOfTrustTab(Hsqldb db, Config config) {
+ this.config = config;
+
+ JPanel leftPanel;
+
+ leftPanel = new JPanel(new BorderLayout(5,5));
+ rightPanel = new JPanel(new GridLayout(1, 1));
+ itsTrustListPanel = new JPanel(new BorderLayout(5,5));
+
+ idList = new WotIdentityList(db, config);
+ trustListTable = new TrustListTable(db, config);
+
+ leftPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.wot.yourTrustList")), BorderLayout.NORTH);
+ leftPanel.add(new JScrollPane(idList.getList()),
BorderLayout.CENTER);
+ itsTrustListPanel.add(new
JLabel(I18n.getMessage("thaw.plugin.wot.itsTrustList")), BorderLayout.NORTH);
+ itsTrustListPanel.add(new
JScrollPane(trustListTable.getTable()), BorderLayout.CENTER);
+
+ rightPanel.add(itsTrustListPanel);
+
+ mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
+
leftPanel, rightPanel);
+
+ idList.addObserver(this);
+ }
+
+ public void loadState() {
+ Signatures.addObserver(this);
+
+ mainSplit.setResizeWeight(0.5);
+
+ String val;
+
+ if ((val = config.getValue("wotMainSplitPosition")) != null)
+ mainSplit.setDividerLocation(Integer.parseInt(val));
+ else
+ mainSplit.setDividerLocation(350);
+ }
+
+ public JSplitPane getPanel() {
+ return mainSplit;
+ }
+
+ public void saveState() {
+ Signatures.deleteObserver(this);
+
+ config.setValue("wotMainSplitPosition",
+
Integer.toString(mainSplit.getDividerLocation()));
+ }
+
+ public void refresh() {
+ idList.refresh();
+ }
+
+ public void identityUpdated(Identity i) { refresh(); }
+ public void privateIdentityAdded(Identity i) { refresh(); }
+ public void publicIdentityAdded(Identity i) { refresh(); }
+
+ public void update(Observable o, Object param) {
+ if (o == idList) {
+ trustListTable.refresh((Identity)param);
+ }
+ }
+}
Modified: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
2008-02-17 18:35:20 UTC (rev 18023)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -7,6 +7,7 @@
import java.io.File;
import java.sql.*;
+import java.util.Vector;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -36,6 +37,10 @@
return super.getTrustLevel();
}
+ public String getUserTrustLevelStr() {
+ return super.getTrustLevelStr();
+ }
+
/**
* @return true if lastUpdate in the db is == NULL
*/
@@ -315,4 +320,131 @@
return null;
}
+
+ /**
+ * Just a container
+ * @author jflesch
+ */
+ public static class TrustLink {
+ private WotIdentity src;
+ private WotIdentity dst;
+ private Identity destinationAsSeenByTheSource;
+
+ public TrustLink(Hsqldb db, WotIdentity src, WotIdentity dst,
int linkTrustLevel) {
+ this.src = src;
+ this.dst = dst;
+ destinationAsSeenByTheSource = new Identity(db,
dst.getId(),
+
dst.getNick(), dst.getPublicKey(),
+
dst.getPrivateKey(), dst.isDup(),
+
linkTrustLevel);
+ }
+
+ public WotIdentity getSource() {
+ return src;
+ }
+
+ public WotIdentity getDestination() {
+ return dst;
+ }
+
+ public int getLinkTrustLevel() {
+ return destinationAsSeenByTheSource.getTrustLevel();
+ }
+
+ public Identity getDestinationAsSeenByTheSource() {
+ return destinationAsSeenByTheSource;
+ }
+ }
+
+ /**
+ * @param db
+ * @param idSrc
+ * @return a vector of TrustLink
+ */
+ public static Vector getTrustList(Hsqldb db, Identity idSrc) {
+ Vector v = new Vector();
+
+ WotIdentity src = new WotIdentity(idSrc);
+
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("SELECT signatures.id AS id, "+
+
" signatures.nickname AS nickname, "+
+
" signatures.publicKey AS publicKey, "+
+
" signatures.privateKey AS privateKey, "+
+
" signatures.isDup AS isDup, "+
+
" signatures.trustLevel AS yourTrustLevel, "+
+
" wotTrustLists.trustLevel AS linkTrustLevel "+
+
"FROM wotTrustLists INNER JOIN signatures ON wotTrustLists.destination =
signatures.id "+
+
"WHERE source = ?");
+ st.setInt(1, idSrc.getId());
+
+ ResultSet set = st.executeQuery();
+
+ while(set.next()) {
+ WotIdentity dst = new WotIdentity(new
Identity(db,
+
set.getInt("id"),
+
set.getString("nickName"),
+
set.getString("publicKey"),
+
set.getString("privateKey"),
+
set.getBoolean("isDup"),
+
set.getInt("yourTrustLevel")));
+ int linkTrustLevel =
set.getInt("linkTrustLevel");
+
+ TrustLink l = new TrustLink(db, src,
dst, linkTrustLevel);
+
+ v.add(l);
+ }
+
+ st.close();
+ }
+ } catch(SQLException e) {
+ Logger.error(new WotIdentity(), "Error while getting
trust list : "+e.toString());
+ e.printStackTrace();
+ }
+
+ return v;
+ }
+
+ /**
+ * Returns only the identities with a trust > 0
+ */
+ public static Vector getOtherIdentities(Hsqldb db) {
+ Vector v = new Vector();
+
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("SELECT id, "+
+
" nickname, publicKey, "+
+
" privateKey, isDup, trustLevel "+
+
"FROM signatures WHERE privateKey IS NULL AND
trustLevel >= 0");
+ ResultSet set = st.executeQuery();
+
+ /* TODO : Optimize if possible */
+
+ while(set.next()) {
+ WotIdentity wi = new WotIdentity(new
Identity(db,
+
set.getInt("id"),
+
set.getString("nickName"),
+
set.getString("publicKey"),
+
set.getString("privateKey"),
+
set.getBoolean("isDup"),
+
set.getInt("trustLevel")));
+ if (wi.getTrustLevel() > 0 &&
wi.getTrustLevel() != Identity.trustLevelInt[0])
+ v.add(wi);
+ }
+
+ st.close();
+ }
+ } catch(SQLException e) {
+ Logger.error(new WotIdentity(), "Error while gettings
identities used in the WoT : "+e.toString());
+ e.printStackTrace();
+ }
+
+ return v;
+ }
}
Added: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentityList.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentityList.java
(rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentityList.java
2008-02-17 20:39:29 UTC (rev 18024)
@@ -0,0 +1,39 @@
+package thaw.plugins.webOfTrust;
+
+import java.util.Observable;
+import java.util.Observer;
+import java.util.Vector;
+
+import thaw.core.Config;
+import thaw.gui.Table;
+import thaw.plugins.Hsqldb;
+import thaw.plugins.signatures.IdentityTable;
+
+public class WotIdentityList extends Observable implements Observer {
+ private Hsqldb db;
+
+ private IdentityTable table;
+
+ public WotIdentityList(Hsqldb db, Config config) {
+ this.db = db;
+
+ table = new IdentityTable(config, "wotIdList_", false);
+ table.addObserver(this);
+
+ refresh();
+ }
+
+ public void refresh() {
+ Vector ids = WotIdentity.getOtherIdentities(db);
+ table.setIdentities(ids);
+ }
+
+ public Table getList() {
+ return table.getTable();
+ }
+
+ public void update(Observable arg0, Object arg1) {
+ setChanged();
+ notifyObservers(arg1);
+ }
+}