[sip-comm-dev] [PATCH] Proposition for two wizard page adapters - HEITZ JM


#1

Good evening,

I didn't find an adapter for the WizardPage in SC (please tell me where
it's located if there's one), so I decided to write my owns. Indeed, I
wrote two adapters :
- a basic (trivial) one, just for implementing the methods that do not
always have to perform a particular task - based on a JPanel (one of the
Java most "generic" containers, if I may say so)
- a heavier one, which copes with the page identifiers - you might set
its behavior (I mean, setting if a page identifier getter should block
while the reference is still null).

Feel free to adapt (or correct them, if any mistake) them if you find
them useful.

Jean-Marie HEITZ

BasicWizardPageAdapter.java (1.2 KB)

ExtendedWizardPageAdapter.java (6.41 KB)


#2

Hello Jean-Marie,

Thank you for you patches! I've applied the two concerning AccountID and WizardPage and ACK-ed your effort on http://sip-communicator.org/contributors

There are however a few things that bother me concerning the Adapters (no particular order):

1. The methods pageNext() and pageBack() in the basic adapter should in my opinion remain abstract since no implementation could function properly without them.

2. I don't think that blocking on a getter until someone calls the setter is a good idea as it may lead to very nasty and hard to detect bugs. I'd suggest simply having a single constructor that looks sth like:
     protected ExtendedWizardPageAdapter(Object previousPageID,
                                         Object currentPageID,
                                         Object nextPageID)
you could remove all the other constructors and get rid of all the wait()s and notifications.

3. Accessor methods should have more comments than simply - "Accessor" (you are not going to get away that easily :slight_smile: ). The same goes for your dummy impl methods. For each such method you could copy the comment of the corresponding abstract method and add a note saying that this is a dummy impl.

4. I also have some notes on code styling but it'd be easier if I just applied them before committing your classes.

OK I think that's all for now :slight_smile:

Thanks again for taking the time to contribute!

Emil

HEITZ Jean-Marie wrote:

···

Good evening,

I didn't find an adapter for the WizardPage in SC (please tell me where
it's located if there's one), so I decided to write my owns. Indeed, I
wrote two adapters :
- a basic (trivial) one, just for implementing the methods that do not
always have to perform a particular task - based on a JPanel (one of the
Java most "generic" containers, if I may say so)
- a heavier one, which copes with the page identifiers - you might set
its behavior (I mean, setting if a page identifier getter should block
while the reference is still null).

Feel free to adapt (or correct them, if any mistake) them if you find
them useful.

Jean-Marie HEITZ

------------------------------------------------------------------------

package net.java.sip.communicator.service.gui;
/**
* Code originally written for iax4sc - IAX for Sip Communicator
* Released under GNU LGPL license (gnu.org)
*/
import javax.swing.*;
/**
* This is a trivial adapter for faster implementing the Wizard Page Interface.
* It just implements the methods who might not always perform a specific task.
* It is a JPanel, JPanel being one of the most "generic" GUI container in Java.
* @author JM HEITZ
*
*/
public abstract class BasicWizardPageAdapter
extends JPanel
implements WizardPage
{
    /**
     * Accessor
     * @return the graphical object to display (this, in our case)
     */
    public Object getWizardForm()
    {
    return this;
    }
    /**
     * Does nothing (adapter function)
     */
    public void pageHiding()
    {
    ; }
    /**
     * Does nothing (adapter function)
     */
    public void pageShown()
    {
    ; }
    /**
     * Does nothing (adapter function)
     */
    public void pageShowing()
    {
    ; }
    /**
     * Does nothing (adapter function)
     */
    public void pageNext()
    {
    ; }
    /**
     * Does nothing(adapter function)
     */
    public void pageBack()
    {
    ;
    }
    }

------------------------------------------------------------------------

package net.java.sip.communicator.service.gui;

/**
* Code originally written for iax4sc - IAX for Sip Communicator
* Released under GNU LGPL license (gnu.org)
*/

/**
* A heavier adapter than the basic adapter for Wizard Page Interface.
* It provides accessors for setting the page identifiers, as well as some
* tools for blocking a thread using an identifier getter while it's null,
* if its behavior is set to do so. * Be VERY attentive when you use this class, since it uses synchronization * (conditionnal variable) technique to block while a page identifier is null * (not default behavior) - synchronization problems may be hard to identify.
* @author JM HEITZ
*
*/
public abstract class ExtendedWizardPageAdapter
extends BasicWizardPageAdapter
implements WizardPage {
    /**
     * Current Page Blocker
     */
    private boolean curBlock=true;
    /**
     * Next Page Blocker
     */
    private boolean nextBlock=true;
    /**
     * Previous Page Blocker
     */
    private boolean prevBlock=true;
    /**
     * Current Page Identifier Mutex
     */
    private Boolean curLock=new Boolean(false);
    /**
     * Current Page Identifier
     */ private Object currentIdentifier=null; /**
     * Next Page Identifier Mutex
     */
    private Boolean nextLock=new Boolean(false);
    /**
     * Next Page Identifier
     */
    private Object nextIdentifier=null;
    /**
     * Previous Page Identifier Mutex
     */
    private Boolean prevLock=new Boolean(false);
    /**
     * Previous Page Identifier
     */
    private Object prevIdentifier=null;
    /**
     * Constructor
     * This constructor is here because it may be hard to known in advance
     * all the page identifiers.
     * @param cur Current Identifier
     * @param block blocking behavior
     */
    protected ExtendedWizardPageAdapter(Object cur,boolean block) {
        this(null,cur,null,block); }
    /**
     * Constructor
     * This constructor is here because it may be hard to known in advance
     * all the page identifiers.
     * @param cur Current Identifier
     */
    protected ExtendedWizardPageAdapter(Object cur) {
        this(null,cur,null,false); }
    /**
     * Constructor
     * @param prev previous page identifier
     * @param cur current page identifier
     * @param next next page identifier
     * @param block blocking behavior
     */
    protected ExtendedWizardPageAdapter(Object prev,Object cur,Object next,
            boolean block) {
        this.prevIdentifier=prev;
        this.currentIdentifier=cur;
        this.nextIdentifier=next;
        this.curBlock=block;
        this.prevBlock=block;
        this.nextBlock=block;
    }
    /**
     * Accessor
     * @param o next page identifier
     */
    public void setNextPageIdentifier(Object o) {
        synchronized(nextLock) {
            this.nextIdentifier=o;
            nextLock.notifyAll();
        }
    }
    /**
     * Accessor
     * @param o previous page identifier
     */
    public void setPrevPageIdentifier(Object o) {
        synchronized(prevLock) {
            this.prevIdentifier=o;
            prevLock.notifyAll();
        }
    }
    /**
     * Accessor
     * @param o current page identifier
     */
    public void setCurPageIdentifier(Object o) {
        synchronized(curLock) {
            this.currentIdentifier=o;
            curLock.notifyAll();
        }
    }
    /**
     * Accessor
     * @return current page identifier
     */
    public Object getIdentifier() {
        synchronized(curLock) {
            while(curBlock && currentIdentifier==null) { try {
                    curLock.wait();
                }
                catch(InterruptedException e) {
                    ;
                }
            }
            return currentIdentifier;
        }
    }
    /**
     * Accessor
     * @return next page identifier
     */
    public Object getNextPageIdentifier()
    {
        synchronized(nextLock)
        {
            while(nextBlock && nextIdentifier==null)
            {
                try
                {
                    nextLock.wait();
                }
                catch(InterruptedException e)
                {
                    ;
                }
            } return nextIdentifier;
        }
    }
    /**
     * Accessor
     * @return previous bage identifier
     */
    public Object getBackPageIdentifier()
    {
        synchronized(prevLock)
        {
            while(prevBlock && prevIdentifier==null)
            {
                try
                {
                    prevLock.wait();
                }
                catch(InterruptedException e)
                {
                    ;
                }
            } return prevIdentifier;
        }
    }

    /**
     * Accessor
     * @param block set if the adapter should block or not
     */
    public void setBehavior(boolean block)
    {
        setCurBlock(block);
        setNextBlock(block);
        setPrevBlock(block);
    }
    /**
     * Accessor
     * @param block set if the adapter should block or not
     */
    public void setCurBlock(boolean block)
    {
        synchronized(curLock)
        {
            curBlock=block;
            curLock.notifyAll();
        }
    }
    /**
     * Accessor
     * @param block set if the adapter should block or not
     */
    public void setNextBlock(boolean block)
    {
        synchronized(nextLock)
        {
            nextBlock=block;
            nextLock.notifyAll();
        }
    }
    /**
     * Accessor
     * @param block set if the adapter should block or not
     */
    public void setPrevBlock(boolean block)
    {
        synchronized(prevLock)
        {
            prevBlock=block;
            prevLock.notifyAll();
        }
    }
    /**
     * Accessor
     * @return the blocking policy
     */
    public boolean getCurBlock()
    {
        synchronized(curLock)
        {
            return curBlock;
        }
    }
    /**
     * Accessor
     * @return the blocking policy
     */
    public boolean getNextBlock()
    {
        synchronized(nextLock)
        {
            return nextBlock;
        }
    }
    /**
     * Accessor
     * @return the blocking policy
     */
    public boolean getPrevBlock()
    {
        synchronized(prevLock)
        {
            return prevBlock;
        }
    }
}

------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net