From: Mailing l. f. S. c. m. <jtc...@li...> - 2011-12-01 16:37:59
|
Revision: 3308 http://jtcfrost.svn.sourceforge.net/jtcfrost/?rev=3308&view=rev Author: artur8ur Date: 2011-12-01 16:37:49 +0000 (Thu, 01 Dec 2011) Log Message: ----------- Allow to save comments for an identity. 1st commit. Allows basic functionality. Modified Paths: -------------- trunk/frost-wot/source/frost/identities/FrostIdentities.java trunk/frost-wot/source/frost/identities/Identity.java trunk/frost-wot/source/frost/messaging/frost/gui/MessagePanel.java trunk/frost-wot/source/frost/messaging/frost/gui/messagetreetable/MessageTreeTable.java Added Paths: ----------- trunk/frost-wot/source/frost/gui/SetIdentityCommentDialog.java Added: trunk/frost-wot/source/frost/gui/SetIdentityCommentDialog.java =================================================================== --- trunk/frost-wot/source/frost/gui/SetIdentityCommentDialog.java (rev 0) +++ trunk/frost-wot/source/frost/gui/SetIdentityCommentDialog.java 2011-12-01 16:37:49 UTC (rev 3308) @@ -0,0 +1,171 @@ +/* + FcpPersistentRequest.java / Frost + Copyright (C) 2011 Frost Project <jtcfrost.sourceforge.net> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package frost.gui; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.WindowConstants; + +import frost.identities.Identity; +import frost.util.DateFun; +import frost.util.gui.textpane.AntialiasedTextArea; +import frost.util.gui.translation.Language; + +/** + * @author Jan Gerritsen + * + */ +@SuppressWarnings("serial") +public class SetIdentityCommentDialog extends javax.swing.JFrame { + + protected Language language = null; + + private Identity identity; + + private JButton okButton; + private JButton cancelButton; + + private AntialiasedTextArea commentTextArea; + + public SetIdentityCommentDialog(Identity identity) { + this.language = Language.getInstance(); + this.identity = identity; + + initialize(); + } + + /** + * Component initialization + */ + private void initialize() { + setTitle(language.getString("SetIdentityCommentDialog.title")); + + // Set window size + Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); + + int width, height; + + if( screenSize.width > 800 ) { + width = 650; + } else { + width = (int) (screenSize.width * 0.90); + } + + if( screenSize.height > 650 ) { + height = 500; + } else { + height = (int) (screenSize.height * 0.85); + } + + setSize(width, height); + this.setResizable(true); + + // OK Button + okButton = new JButton(language.getString("Common.ok")); + okButton.addActionListener( new java.awt.event.ActionListener() { + public void actionPerformed(final ActionEvent e) { + identity.setComment(commentTextArea.getText()); + dispose(); + } + }); + + // Cancel Button + cancelButton = new JButton(language.getString("Common.cancel")); + cancelButton.addActionListener( new java.awt.event.ActionListener() { + public void actionPerformed(final ActionEvent e) { + dispose(); + } + }); + + // Button row + final JPanel buttonsPanel = new JPanel(new BorderLayout()); + buttonsPanel.setLayout( new BoxLayout( buttonsPanel, BoxLayout.X_AXIS )); + buttonsPanel.add( Box.createHorizontalGlue() ); + buttonsPanel.add( cancelButton ); + buttonsPanel.add(Box.createRigidArea(new Dimension(10,3))); + buttonsPanel.add( okButton ); + buttonsPanel.setBorder(BorderFactory.createEmptyBorder(10,0,0,0)); + + // Header row + final JPanel headerPanel = new JPanel(new GridBagLayout()); + final GridBagConstraints constraints = new GridBagConstraints(); + final Insets insets = new Insets(3, 3, 3, 3); + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.NORTHWEST; + constraints.weighty = 0.0; + constraints.weightx = 1.0; + constraints.insets = insets; + constraints.gridwidth = 1; + constraints.gridy = 0; + + // uniqeName + headerPanel.add(new JLabel("Name: " + identity.getUniqueName()), constraints); + + constraints.gridy++; + + // labelLastSeenTimestamp + headerPanel.add(new JLabel( + "Last seen: " + + DateFun.FORMAT_DATE_VISIBLE.print(identity.getLastSeenTimestamp()) + + " " + + DateFun.FORMAT_TIME_VISIBLE.print(identity.getLastSeenTimestamp()) + ), constraints); + + constraints.gridy++; + + // ReceivedMessageCount + headerPanel.add(new JLabel("Received messages: " + identity.getReceivedMessageCount()), constraints); + + constraints.gridy++; + + // Comment + headerPanel.add(new JLabel("Comment:"), constraints); + commentTextArea = new AntialiasedTextArea(); + commentTextArea.setText(identity.getComment()); + final JScrollPane commentScrollPane = new JScrollPane(commentTextArea); + commentScrollPane.setWheelScrollingEnabled(true); + commentScrollPane.setMinimumSize(new Dimension(100, 50)); + + + // main panel + final JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.add( headerPanel, BorderLayout.NORTH); + mainPanel.add( commentScrollPane, BorderLayout.CENTER ); + mainPanel.add( buttonsPanel, BorderLayout.SOUTH ); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5,7,7,7)); + + this.getContentPane().setLayout(new BorderLayout()); + this.getContentPane().add(mainPanel, null); + + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + } + +} Modified: trunk/frost-wot/source/frost/identities/FrostIdentities.java =================================================================== --- trunk/frost-wot/source/frost/identities/FrostIdentities.java 2011-03-13 10:47:19 UTC (rev 3307) +++ trunk/frost-wot/source/frost/identities/FrostIdentities.java 2011-12-01 16:37:49 UTC (rev 3308) @@ -42,11 +42,13 @@ private final Object lockObject = new Object(); - Language language = Language.getInstance(); + private Language language = Language.getInstance(); + + private IdentitiesStorage identitiesStorage = IdentitiesStorage.inst(); public void initialize() throws StorageException { - localIdentities = IdentitiesStorage.inst().loadLocalIdentities(); + localIdentities = identitiesStorage.loadLocalIdentities(); // check if there is at least one identity in database, otherwise create one if ( localIdentities.size() == 0 ) { @@ -59,7 +61,7 @@ } // load all identities - identities = IdentitiesStorage.inst().loadIdentities(); + identities = identitiesStorage.loadIdentities(); // remove all own identities from identities for(final LocalIdentity li : localIdentities.values() ) { @@ -186,18 +188,18 @@ } if( useLock ) { - if( !IdentitiesStorage.inst().beginExclusiveThreadTransaction() ) { + if( !identitiesStorage.beginExclusiveThreadTransaction() ) { return false; } } try { - if( !IdentitiesStorage.inst().insertIdentity(id) ) { + if( !identitiesStorage.insertIdentity(id) ) { return false; } identities.put(key, id); } finally { if( useLock ) { - IdentitiesStorage.inst().endThreadTransaction(); + identitiesStorage.endThreadTransaction(); } } return true; @@ -210,16 +212,16 @@ if (localIdentities.containsKey(li.getUniqueName())) { return false; } - if( !IdentitiesStorage.inst().beginExclusiveThreadTransaction() ) { + if( !identitiesStorage.beginExclusiveThreadTransaction() ) { return false; } try { - if( !IdentitiesStorage.inst().insertLocalIdentity(li) ) { + if( !identitiesStorage.insertLocalIdentity(li) ) { return false; } localIdentities.put(li.getUniqueName(), li); } finally { - IdentitiesStorage.inst().endThreadTransaction(); + identitiesStorage.endThreadTransaction(); } return true; } @@ -228,7 +230,7 @@ if( li == null ) { return false; } - if( !IdentitiesStorage.inst().beginExclusiveThreadTransaction() ) { + if( !identitiesStorage.beginExclusiveThreadTransaction() ) { return false; } final boolean removed; @@ -237,9 +239,9 @@ return false; } localIdentities.remove(li.getUniqueName()); - removed = IdentitiesStorage.inst().removeLocalIdentity(li); + removed = identitiesStorage.removeLocalIdentity(li); } finally { - IdentitiesStorage.inst().endThreadTransaction(); + identitiesStorage.endThreadTransaction(); } return removed; } @@ -251,15 +253,15 @@ if (!identities.containsKey(li.getUniqueName())) { return false; } - if( !IdentitiesStorage.inst().beginExclusiveThreadTransaction() ) { + if( !identitiesStorage.beginExclusiveThreadTransaction() ) { return false; } final boolean removed; try { identities.remove(li.getUniqueName()); - removed = IdentitiesStorage.inst().removeIdentity(li); + removed = identitiesStorage.removeIdentity(li); } finally { - IdentitiesStorage.inst().endThreadTransaction(); + identitiesStorage.endThreadTransaction(); } return removed; @@ -321,7 +323,7 @@ // TODO: merge the imported identities with the existing identities (WOT), use a mergeIdentities method public int importIdentities(final List<Identity> importedIdentities) { // for now we import new identities, and take over the trust state if our identity state is CHECK - if( !IdentitiesStorage.inst().beginExclusiveThreadTransaction() ) { + if( !identitiesStorage.beginExclusiveThreadTransaction() ) { return 0; } int importedCount = 0; @@ -345,7 +347,7 @@ } } } finally { - IdentitiesStorage.inst().endThreadTransaction(); + identitiesStorage.endThreadTransaction(); } return importedCount; } Modified: trunk/frost-wot/source/frost/identities/Identity.java =================================================================== --- trunk/frost-wot/source/frost/identities/Identity.java 2011-03-13 10:47:19 UTC (rev 3307) +++ trunk/frost-wot/source/frost/identities/Identity.java 2011-12-01 16:37:49 UTC (rev 3308) @@ -49,6 +49,7 @@ private String uniqueName; private long lastSeenTimestamp = -1; private int receivedMessageCount = 0; + private String comment = ""; private int state = CHECK; private transient String stateString = CHECK_STRING; @@ -81,11 +82,12 @@ /** * Only used for migration. */ - public Identity(final String uname, final String pubkey, final long lseen, final int s) { + public Identity(final String uname, final String pubkey, final long lseen, final int state, final String comment) { uniqueName = uname; publicKey = pubkey; lastSeenTimestamp = lseen; - state = s; + this.state = state; + this.comment = comment; updateStateString(); uniqueName = Mixed.makeFilename(uniqueName); @@ -99,6 +101,7 @@ publicKey = li.getPublicKey(); lastSeenTimestamp = li.getLastSeenTimestamp(); receivedMessageCount = li.getReceivedMessageCount(); + comment = li.getComment(); updateStateString(); } @@ -212,6 +215,7 @@ return el; } + @Deprecated public Element getXMLElement_old(final Document doc) { final Element el = doc.createElement("MyIdentity"); @@ -315,6 +319,15 @@ public int getState() { return state; } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + updateIdentitiesStorage(); + } @Override public String toString() { Modified: trunk/frost-wot/source/frost/messaging/frost/gui/MessagePanel.java =================================================================== --- trunk/frost-wot/source/frost/messaging/frost/gui/MessagePanel.java 2011-03-13 10:47:19 UTC (rev 3307) +++ trunk/frost-wot/source/frost/messaging/frost/gui/MessagePanel.java 2011-12-01 16:37:49 UTC (rev 3308) @@ -31,6 +31,7 @@ import javax.swing.tree.*; import frost.*; +import frost.gui.SetIdentityCommentDialog; import frost.identities.*; import frost.messaging.frost.*; import frost.messaging.frost.boards.*; @@ -230,6 +231,7 @@ private final JMenuItem setCheckItem = new JMenuItem(); private final JMenuItem setGoodItem = new JMenuItem(); private final JMenuItem setObserveItem = new JMenuItem(); + private final JMenuItem setCommentItem = new JMenuItem(); private final JMenuItem deleteItem = new JMenuItem(); private final JMenuItem undeleteItem = new JMenuItem(); @@ -281,6 +283,8 @@ setTrustState_actionPerformed(IdentityState.CHECK); } else if (e.getSource() == setObserveItem) { setTrustState_actionPerformed(IdentityState.OBSERVE); + } else if (e.getSource() == setCommentItem) { + setComment_actionPerformed(); } } @@ -296,6 +300,7 @@ setBadItem.addActionListener(this); setCheckItem.addActionListener(this); setObserveItem.addActionListener(this); + setCommentItem.addActionListener(this); deleteItem.addActionListener(this); undeleteItem.addActionListener(this); showItem.addActionListener(this); @@ -319,6 +324,7 @@ setBadItem.setText(language.getString("MessagePane.messageTable.popupmenu.setToBad")); setCheckItem.setText(language.getString("MessagePane.messageTable.popupmenu.setToCheck")); setObserveItem.setText(language.getString("MessagePane.messageTable.popupmenu.setToObserve")); + setCommentItem.setText(language.getString("MessagePane.messageTable.popupmenu.setComment")); deleteItem.setText(language.getString("MessagePane.messageTable.popupmenu.deleteMessage")); undeleteItem.setText(language.getString("MessagePane.messageTable.popupmenu.undeleteMessage")); showItem.setText(language.getString("MessagePane.messageTable.popupmenu.showMessage")); @@ -352,6 +358,8 @@ add(setObserveItem); add(setCheckItem); add(setBadItem); + addSeparator(); + add(setCommentItem); deleteItem.setEnabled(true); undeleteItem.setEnabled(true); @@ -361,6 +369,8 @@ setCheckItem.setEnabled(true); setBadItem.setEnabled(true); + setCommentItem.setEnabled(true); + super.show(invoker, x, y); return; } @@ -397,6 +407,9 @@ setCheckItem.setEnabled(false); setBadItem.setEnabled(false); + add(setCommentItem); + setCommentItem.setEnabled(false); + if (messageTable.getSelectedRow() > -1 && selectedMessage != null) { if( identities.isMySelf(selectedMessage.getFromName()) ) { // keep all off @@ -404,18 +417,22 @@ setObserveItem.setEnabled(true); setCheckItem.setEnabled(true); setBadItem.setEnabled(true); + setCommentItem.setEnabled(true); } else if (selectedMessage.isMessageStatusCHECK()) { setObserveItem.setEnabled(true); setGoodItem.setEnabled(true); setBadItem.setEnabled(true); + setCommentItem.setEnabled(true); } else if (selectedMessage.isMessageStatusBAD()) { setObserveItem.setEnabled(true); setGoodItem.setEnabled(true); setCheckItem.setEnabled(true); + setCommentItem.setEnabled(true); } else if (selectedMessage.isMessageStatusOBSERVE()) { setGoodItem.setEnabled(true); setCheckItem.setEnabled(true); setBadItem.setEnabled(true); + setCommentItem.setEnabled(true); } else if (selectedMessage.isMessageStatusOLD()) { // keep all buttons disabled } else if (selectedMessage.isMessageStatusTAMPERED()) { @@ -1071,8 +1088,6 @@ return; } - // set all selected messages unread - final int[] rows = messageTable.getSelectedRows(); boolean idChanged = false; for(final FrostMessageObject targetMessage : selectedMessages ) { final Identity id = getSelectedMessageFromIdentity(targetMessage); @@ -1096,7 +1111,7 @@ // any id changed, gui update needed? if( idChanged ) { updateTableAfterChangeOfIdentityState(); - if( rows.length == 1 ) { + if( messageTable.getSelectedRows().length == 1 ) { // keep msg selected, change toolbar buttons setGoodButton.setEnabled( !(idState == IdentityState.GOOD) ); setCheckButton.setEnabled( !(idState == IdentityState.CHECK) ); @@ -1105,7 +1120,24 @@ } } } + + + public void setComment_actionPerformed() { + final List<FrostMessageObject> selectedMessages = getSelectedMessages(); + if( selectedMessages.size() == 0 ) { + return; + } + + for(final FrostMessageObject targetMessage : selectedMessages ) { + final Identity identity = getSelectedMessageFromIdentity(targetMessage); + if( identity == null ) { + continue; + } + ( new SetIdentityCommentDialog(identity) ).setVisible(true); + } + } + private void toggleShowOnly_actionPerformed(final ActionEvent e) { if (e.getSource() == toggleShowUnreadOnly) { Modified: trunk/frost-wot/source/frost/messaging/frost/gui/messagetreetable/MessageTreeTable.java =================================================================== --- trunk/frost-wot/source/frost/messaging/frost/gui/messagetreetable/MessageTreeTable.java 2011-03-13 10:47:19 UTC (rev 3307) +++ trunk/frost-wot/source/frost/messaging/frost/gui/messagetreetable/MessageTreeTable.java 2011-12-01 16:37:49 UTC (rev 3308) @@ -954,6 +954,7 @@ sb.append(" "); sb.append(DateFun.FORMAT_TIME_VISIBLE.print(id.getLastSeenTimestamp())); sb.append("<br>Received messages: ").append(id.getReceivedMessageCount()); + sb.append("<br>Comment: <br>").append(id.getComment().replace("\n", "<br/>")); sb.append("</html>"); setToolTipText(sb.toString()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |