Listing of Source server/RCONSOLE_COLORCHOOSER.java
package serverUserWindow2;

import java.util.Hashtable;
import se.entra.phantom.common.Transaction;
import se.entra.phantom.common.NetPhantomConstants;
import se.entra.phantom.server.VirtualPanel;
import se.entra.phantom.server.VirtualCUserWindow;
import se.entra.phantom.server.PhantomCUserWindow;
import se.entra.phantom.server.PhantomObject;
import se.entra.phantom.server.PhantomWorker;
import se.entra.phantom.server.ObjectMessages;
import se.entra.phantom.server.VirtualServerUserWindowAdapter;
import se.entra.phantom.server.VirtualPanelListener;
import se.entra.phantom.server.VirtualComponentListener;
import se.entra.phantom.server.rconsole.AdminColorChanged;

/**
 * This class handles the server part of the user window for color choosing
 * the terminal colors.
 */
public class RCONSOLE_COLORCHOOSER extends VirtualServerUserWindowAdapter implements AdminColorChanged
{
  /**
   * This hash table contains all listeners of color changes.
   */
  private static final Hashtable<AdminColorChanged,AdminColorChanged> table = new Hashtable<AdminColorChanged,AdminColorChanged>();

  ///

  /**
   * Save the user window because we need to call setChanged method in it.
   */
  private VirtualCUserWindow userWindow;

  /**
   * The current color schemes (or null if none).
   */
  private String clientData;

  ///

  /**
   * This method is called whenever the class has been instantiated.
   */
  @Override
  public void create(VirtualPanel panel,VirtualCUserWindow userWindow,PhantomCUserWindow data)
    {
    this.userWindow=userWindow;
    addColorChangeListener(this);
    }

  /**
   * This method is called whenever a panel has been disposed of,
   * in order to remove listeners, etc, in order to free up memory.
   * Normal controls doesn't need to do anything here.
   */
  @Override
  public void dispose()
    {
    removeColorChangeListener(this);
    }

  /**
   * Adds a new listener for color change event.
   */
  private static void addColorChangeListener(AdminColorChanged listener)
    {
    table.put(listener,listener);
    }

  /**
   * Removes a new listener for color change event.
   */
  private static void removeColorChangeListener(AdminColorChanged listener)
    {
    table.remove(listener);
    }

  /**
   * The colors have been changed. The new colors are located
   * in HostSessionManager class.
   */
  @Override
  public void processChangedColors()
    {
    // Cause the change of colors to be reflected through a
    // fireUpdate transaction to client later on.
    userWindow.setChanged();
    }

  /**
   * This method fires the creation data transaction to the client. The
   * first thing must be to call the superclass.
   */
  @Override
  public void fireCreate(Transaction trans)
    {
    //System.out.println("FireCreate");
    //HostSessionManager.appendHostColorTransactionData(trans);
    if ( trans!=null && clientData != null )
      trans.appendString(clientData);
    }

  /**
   * This method is used to fire an update message to the client by
   * a virtual class.
   */
  @Override
  public void fireUpdate(Transaction trans)
    {
    if ( trans!=null && clientData != null )
      trans.appendString(clientData);
    }

  /**
   * This method is called from the VirtualPanel
   * to cause a client transaction to update the panels.
   * The color table has been updated and the user window
   * will keep a fresh copy of it for the <code>getText</code>
   * function.
   */
  @Override
  public void clientUpdated(Transaction trans)
    {
    clientData=trans.readString();
    }

  /**
   * This method is invoked by the server kernel when an event has occured
   * on the client side (such as a push button has been pressed). Every 
   * updateable control (in the VirtualNnnn classes) are set to reflect the 
   * changes made on the client side.
   */
  @Override
  public void issueAction(Transaction trans)
    {
    // Switch the subevent.
    int actionEvent=trans.readShort();

    // Call the application object.
    if (actionEvent == NetPhantomConstants.EVENT_SELECT)
      {
      VirtualPanel panel=userWindow.getPanel();
      PhantomObject o=panel.getApplication().appObject;
      if (o != null)
        {
        PhantomWorker worker=panel.getVirtualSessionManager().getWorker();
        o.callObject(worker,this,userWindow.getId(),ObjectMessages.OBJACT_SELECT,"");
        }
      VirtualPanelListener listen=panel.getListener();
      if ( listen!=null && (listen instanceof VirtualComponentListener) )
        ((VirtualComponentListener)listen).onPropertyChange(panel,userWindow,userWindow.getId(),"UW",this);
      }
    }

  // Basic methods.

  /**
   * Sets the RGB color text.
   * @return
   *   true        for successful operation.
   *   <br>false   for failure.
   */
  @Override
  public boolean setText(String text)
    {
    // Store new instance of string. This text should contain RGB color
    // In string format.
    clientData=text;

    // Update control.
    userWindow.setChanged();
    return true;
    }

  /**
   * Gets the RGB color string.
   * @return
   *   null   for no text support.
   */
  @Override
  public String getText()
    {
    return clientData;
    }

  /**
   * Gets the enabled state of an item.
   * @return
   *   true        item is enabled.
   *   <br>false   item is disabled or failure.
   */
  @Override
  public boolean isEnabled()
    {
    return true;
    }

  /**
   * Gets the visibility state of an item.
   * @return
   *   true        item is visible.
   *   <br>false   item is hidden or failure.
   */
  @Override
  public boolean isVisible()
    {
    return true;
    }
}