Adds javadoc.

cusax-fix
George Politis 17 years ago
parent 536b0578a4
commit 12cf740eab

@ -16,19 +16,20 @@
import net.java.sip.communicator.service.protocol.*;
/**
* A special {@link JMenu} that holds the menu items for controlling the
* Off-the-Record functionality for a specific contact.
*
* @author George Politis
* @author Lubomir Marinov
*/
@SuppressWarnings("serial")
class OtrContactMenu
extends JMenu
implements ActionListener,
PopupMenuListener,
ScOtrEngineListener,
ScOtrKeyManagerListener
implements ActionListener, PopupMenuListener, ScOtrEngineListener,
ScOtrKeyManagerListener
{
private static final String ACTION_COMMAND_AUTHENTICATE_BUDDY
= "AUTHENTICATE_BUDDY";
private static final String ACTION_COMMAND_AUTHENTICATE_BUDDY =
"AUTHENTICATE_BUDDY";
private static final String ACTION_COMMAND_CB_AUTO = "CB_AUTO";
@ -53,10 +54,21 @@ class OtrContactMenu
*/
private final boolean inMacOSXScreenMenuBar;
/**
* We keep this variable so we can determine if the policy has changed
* or not in in {@link OtrContactMenu#setOtrPolicy(OtrPolicy)}.
*/
private OtrPolicy otrPolicy;
private SessionStatus sessionStatus;
/**
* The OtrContactMenu contructor.
*
* @param contact the Contact this menu referes to.
* @param inMacOSXScreenMenuBar a {@link boolean} that indicates whether the
* menu is displayed in a Mac OS X sreen menubar or not.
*/
public OtrContactMenu(Contact contact, boolean inMacOSXScreenMenuBar)
{
this.contact = contact;
@ -73,7 +85,7 @@ public OtrContactMenu(Contact contact, boolean inMacOSXScreenMenuBar)
OtrActivator.scOtrEngine.addListener(this);
OtrActivator.scOtrKeyManager.addListener(this);
setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
}
@ -100,16 +112,13 @@ else if (ACTION_COMMAND_REFRESH_OTR.equals(actionCommand))
else if (ACTION_COMMAND_AUTHENTICATE_BUDDY.equals(actionCommand))
{
// Launch auth buddy dialog.
OtrBuddyAuthenticationDialog authenticateBuddyDialog
= new OtrBuddyAuthenticationDialog(contact);
Dimension screenSize
= Toolkit.getDefaultToolkit().getScreenSize();
authenticateBuddyDialog.setLocation(
screenSize.width / 2
- authenticateBuddyDialog.getWidth() / 2,
screenSize.height / 2
- authenticateBuddyDialog.getHeight() / 2);
OtrBuddyAuthenticationDialog authenticateBuddyDialog =
new OtrBuddyAuthenticationDialog(contact);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
authenticateBuddyDialog.setLocation(screenSize.width / 2
- authenticateBuddyDialog.getWidth() / 2, screenSize.height / 2
- authenticateBuddyDialog.getHeight() / 2);
authenticateBuddyDialog.setVisible(true);
}
@ -153,8 +162,7 @@ public void contactPolicyChanged(Contact contact)
{
// Update the corresponding to the contact menu.
if (contact.equals(OtrContactMenu.this.contact))
setOtrPolicy(
OtrActivator.scOtrEngine.getContactPolicy(contact));
setOtrPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
}
/*
@ -164,8 +172,7 @@ public void contactPolicyChanged(Contact contact)
public void contactVerificationStatusChanged(Contact contact)
{
if (contact.equals(OtrContactMenu.this.contact))
setSessionStatus(
OtrActivator.scOtrEngine.getSessionStatus(contact));
setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
}
/**
@ -180,19 +187,13 @@ void dispose()
OtrActivator.scOtrKeyManager.removeListener(this);
}
private SessionStatus getSessionStatus()
{
return sessionStatus;
}
/*
* Implements ScOtrEngineListener#globalPolicyChanged().
*/
public void globalPolicyChanged()
{
setOtrPolicy(
OtrActivator.scOtrEngine
.getContactPolicy(OtrContactMenu.this.contact));
setOtrPolicy(OtrActivator.scOtrEngine
.getContactPolicy(OtrContactMenu.this.contact));
}
/*
@ -219,6 +220,10 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e)
rebuildMenu();
}
/**
* Rebuilds own menuitems according to {@link OtrContactMenu#sessionStatus}
* and the {@link OtrPolicy} for {@link OtrContactMenu#contact}.
*/
private void rebuildMenu()
{
this.removeAll();
@ -238,7 +243,7 @@ private void rebuildMenu()
startOtr.setActionCommand(ACTION_COMMAND_START_OTR);
startOtr.addActionListener(this);
switch (getSessionStatus())
switch (this.sessionStatus)
{
case ENCRYPTED:
JMenuItem refreshOtr = new JMenuItem();
@ -312,10 +317,16 @@ private void rebuildMenu()
public void sessionStatusChanged(Contact contact)
{
if (contact.equals(OtrContactMenu.this.contact))
setSessionStatus(
OtrActivator.scOtrEngine.getSessionStatus(contact));
setSessionStatus(OtrActivator.scOtrEngine.getSessionStatus(contact));
}
/**
* Sets the {@link OtrContactMenu#sessionStatus} value, updates the menu
* icon and, if necessary, rebuilds the menuitems to match the passed in
* sessionStatus.
*
* @param sessionStatus the {@link SessionStatus}.
*/
private void setSessionStatus(SessionStatus sessionStatus)
{
if (sessionStatus != this.sessionStatus)
@ -328,6 +339,12 @@ private void setSessionStatus(SessionStatus sessionStatus)
}
}
/**
* Sets the {@link OtrContactMenu#otrPolicy} and, if necessary, rebuilds the
* menuitems to match the passed in otrPolicy.
*
* @param otrPolicy
*/
private void setOtrPolicy(OtrPolicy otrPolicy)
{
if (!otrPolicy.equals(this.otrPolicy))
@ -339,17 +356,20 @@ private void setOtrPolicy(OtrPolicy otrPolicy)
}
}
/**
* Updates the menu icon based on {@link OtrContactMenu#sessionStatus}
* value.
*/
private void updateIcon()
{
String imageID;
switch (getSessionStatus())
switch (sessionStatus)
{
case ENCRYPTED:
imageID
= OtrActivator.scOtrKeyManager.isVerified(contact)
? "plugin.otr.ENCRYPTED_ICON_16x16"
: "plugin.otr.ENCRYPTED_UNVERIFIED_ICON_16x16";
imageID =
OtrActivator.scOtrKeyManager.isVerified(contact) ? "plugin.otr.ENCRYPTED_ICON_16x16"
: "plugin.otr.ENCRYPTED_UNVERIFIED_ICON_16x16";
break;
case FINISHED:

@ -23,8 +23,7 @@
*/
public class OtrMetaContactMenu
extends AbstractPluginComponent
implements ActionListener,
PopupMenuListener
implements ActionListener, PopupMenuListener
{
/**
@ -56,8 +55,8 @@ public OtrMetaContactMenu(Container container)
{
super(container);
inMacOSXScreenMenuBar
= Container.CONTAINER_CHAT_MENU_BAR.equals(container)
inMacOSXScreenMenuBar =
Container.CONTAINER_CHAT_MENU_BAR.equals(container)
&& OtrActivator.uiService.useMacOSXScreenMenuBar();
}
@ -71,13 +70,19 @@ public void actionPerformed(ActionEvent e)
OtrActivator.scOtrEngine.launchHelp();
}
/**
* Creates an {@link OtrContactMenu} for each {@link Contact} contained in
* the <tt>metaContact</tt>.
*
* @param metaContact The {@link MetaContact} this
* {@link OtrMetaContactMenu} refers to.
*/
private void createOtrContactMenus(MetaContact metaContact)
{
JMenu menu = getMenu();
// Remove any existing OtrContactMenu items.
for (int itemIndex = 0, itemCount = menu.getItemCount();
itemIndex < itemCount;)
for (int itemIndex = 0, itemCount = menu.getItemCount(); itemIndex < itemCount;)
{
JMenuItem menuItem = menu.getItem(itemIndex);
@ -99,19 +104,16 @@ private void createOtrContactMenus(MetaContact metaContact)
int itemIndex = 0;
while (contacts.hasNext())
{
menu.insert(
new OtrContactMenu(
contacts.next(),
inMacOSXScreenMenuBar),
itemIndex);
menu.insert(new OtrContactMenu(contacts.next(),
inMacOSXScreenMenuBar), itemIndex);
itemIndex++;
}
}
}
/*
* Implements PluginComponent#getComponent(). Returns the JMenu which is
* the component of this plug-in creating it first if it doesn't exist.
* Implements PluginComponent#getComponent(). Returns the JMenu which is the
* component of this plug-in creating it first if it doesn't exist.
*/
public Component getComponent()
{
@ -132,12 +134,11 @@ private JMenu getMenu()
menu.setText(getName());
if (Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU
.equals(getContainer()))
.equals(getContainer()))
{
Icon icon
= OtrActivator
.resourceService
.getImage("plugin.otr.MENU_ITEM_ICON_16x16");
Icon icon =
OtrActivator.resourceService
.getImage("plugin.otr.MENU_ITEM_ICON_16x16");
if (icon != null)
menu.setIcon(icon);
@ -154,10 +155,8 @@ private JMenu getMenu()
*/
public String getName()
{
return
OtrActivator
.resourceService
.getI18NString("plugin.otr.menu.TITLE");
return OtrActivator.resourceService
.getI18NString("plugin.otr.menu.TITLE");
}
/*
@ -191,17 +190,18 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e)
menu.addSeparator();
whatsThis = new JMenuItem();
whatsThis.setIcon(
OtrActivator.resourceService
.getImage("plugin.otr.HELP_ICON_15x15"));
whatsThis.setText(
OtrActivator.resourceService
.getI18NString("plugin.otr.menu.WHATS_THIS"));
whatsThis.setIcon(OtrActivator.resourceService
.getImage("plugin.otr.HELP_ICON_15x15"));
whatsThis.setText(OtrActivator.resourceService
.getI18NString("plugin.otr.menu.WHATS_THIS"));
whatsThis.addActionListener(this);
menu.add(whatsThis);
}
}
/*
* Implements PluginComponent#setCurrentContact(MetaContact).
*/
public void setCurrentContact(MetaContact metaContact)
{
if (this.currentContact != metaContact)

@ -9,6 +9,7 @@
import net.java.sip.communicator.service.protocol.event.*;
/**
* The Off-the-Record {@link TransformLayer} implementation.
*
* @author George Politis
*
@ -16,10 +17,12 @@
public class OtrTransformLayer
implements TransformLayer
{
public OtrTransformLayer()
{
}
/*
*
* @see
* net.java.sip.communicator.service.protocol.TransformLayer#messageDelivered
* (net.java.sip.communicator.service.protocol.event.MessageDeliveredEvent)
*/
public MessageDeliveredEvent messageDelivered(MessageDeliveredEvent evt)
{
if (OtrActivator.scOtrEngine.isMessageUIDInjected(evt
@ -31,12 +34,27 @@ public MessageDeliveredEvent messageDelivered(MessageDeliveredEvent evt)
return evt;
}
/*
* (non-Javadoc)
*
* @seenet.java.sip.communicator.service.protocol.TransformLayer#
* messageDeliveryFailed
* (net.java.sip.communicator.service.protocol.event.MessageDeliveryFailedEvent
* )
*/
public MessageDeliveryFailedEvent messageDeliveryFailed(
MessageDeliveryFailedEvent evt)
{
return evt;
}
/*
* (non-Javadoc)
*
* @seenet.java.sip.communicator.service.protocol.TransformLayer#
* messageDeliveryPending
* (net.java.sip.communicator.service.protocol.event.MessageDeliveredEvent)
*/
public MessageDeliveredEvent messageDeliveryPending(
MessageDeliveredEvent evt)
{
@ -73,6 +91,13 @@ public MessageDeliveredEvent messageDeliveryPending(
return processedEvent;
}
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.protocol.TransformLayer#messageReceived
* (net.java.sip.communicator.service.protocol.event.MessageReceivedEvent)
*/
public MessageReceivedEvent messageReceived(MessageReceivedEvent evt)
{
// Process the incoming message.

@ -1,6 +1,6 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.otr;
@ -10,41 +10,125 @@
import net.java.sip.communicator.service.protocol.*;
/**
* This interface must be implemented by classes that provide the Off-the-Record
* functionality.
*
* @author George Politis
*
*
*/
public interface ScOtrEngine
{
// Proxy methods OtrEngine.
/**
* Transforms an outgoing message.
*
* @param contact the destination {@link Contact}.
* @param content the original message content.
* @return the transformed message content.
*/
public abstract String transformSending(Contact contact, String content);
/**
* Transforms an incoming message.
*
* @param contact the source {@link Contact}.
* @param content the original message content.
* @return the transformed message content.
*/
public abstract String transformReceiving(Contact contact, String content);
/**
* Starts the Off-the-Record session for the given {@link Contact}, if it's
* not already started.
*
* @param contact the {@link Contact} with whom we want to start an OTR
* session.
*/
public abstract void startSession(Contact contact);
/**
* Ends the Off-the-Record session for the given {@link Contact}, if it is
* not already started.
*
* @param contact the {@link Contact} with whom we want to end the OTR
* session.
*/
public abstract void endSession(Contact contact);
/**
* Refreshes the Off-the-Record session for the given {@link Contact}. If
* the session does not exist, a new session is established.
*
* @param contact the {@link Contact} with whom we want to refresh the OTR
* session.
*/
public abstract void refreshSession(Contact contact);
/**
* Gets the {@link SessionStatus} for the given {@link Contact}.
*
* @param contact the {@link Contact} whose {@link SessionStatus} we are
* interested in.
* @return the {@link SessionStatus}.
*/
public abstract SessionStatus getSessionStatus(Contact contact);
// New Methods (Misc)
/**
* Gets weather the passed in messageUID is injected by the engine or not.
* If it is injected, it shouldn't be re-transformed.
*/
public abstract boolean isMessageUIDInjected(String messageUID);
/**
* Registers an {@link ScOtrEngineListener}.
*
* @param listener the {@link ScOtrEngineListener} to register.
*/
public abstract void addListener(ScOtrEngineListener listener);
/**
* Unregisters an {@link ScOtrEngineListener}.
*
* @param listener the {@link ScOtrEngineListener} to unregister.
*/
public abstract void removeListener(ScOtrEngineListener listener);
// New Methods (Policy management)
/**
* Gets the global {@link OtrPolicy}.
*/
public abstract OtrPolicy getGlobalPolicy();
/**
* Gets a {@link Contact} specific policy.
*
* @param contact the {@link Contact} whose policy we want.
* @return The {@link Contact} specific OTR policy. If the specified
* {@link Contact} has no policy, the global policy is returned.
*/
public abstract OtrPolicy getContactPolicy(Contact contact);
/**
* Sets the global policy.
*
* @param policy
*/
public abstract void setGlobalPolicy(OtrPolicy policy);
/**
* Sets the contact specific policy
*
* @param contact the {@link Contact} whose policy we want to set
* @param policy the {@link OtrPolicy}
*/
public abstract void setContactPolicy(Contact contact, OtrPolicy policy);
/**
* Launches the help page.
*/
public abstract void launchHelp();
}

Loading…
Cancel
Save