[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/

yanas at dev.java.net yanas at dev.java.net
Tue May 29 18:10:07 CEST 2007


User: yanas   
Date: 2007-05-29 16:10:07+0000
Added:
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigFormDescriptor.java

Modified:
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigFormList.java
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigurationFrame.java
   sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigFormListCellRenderer.java

Log:
 a configuration form is now represented in the gui by a ConfigFormDescriptor, which allows to load the ConfigurationForm only when it's added to the container and to use the descriptor for all rendering operations needed after that.

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/
=====================================================================================

File [added]: ConfigFormDescriptor.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigFormDescriptor.java?rev=1.1&content-type=text/vnd.viewcvs-markup
Added lines: 112
----------------
/*
 * 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.impl.gui.main.configforms;

import java.awt.*;

import javax.swing.*;

import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*;

/**
 * The <tt>ConfigFormDescriptor</tt> saves information about the
 * <tt>ConfigurationForm</tt>. When a <tt>ConfigurationForm</tt> is added in the
 * <tt>ConfigurationWindow</tt> we create the corresponding descriptor and load
 * all the data we need in order to show this configuration form.
 * 
 * @author Yana Stamcheva
 */
public class ConfigFormDescriptor
{
    private Logger logger = Logger.getLogger(ConfigFormDescriptor.class);
    
    private ConfigurationForm configForm;
    
    private ImageIcon configFormIcon;
    
    private String configFormTitle;
    
    private Component configFormPanel;
    
    /**
     * Loads the given <tt>ConfigurationForm</tt>.
     * 
     * @param configForm the <tt>ConfigurationForm</tt> to load
     */
    public ConfigFormDescriptor(ConfigurationForm configForm)
    {
        this.configForm = configForm;
        
        byte[] icon = null;
        
        try
        {
            icon = configForm.getIcon();                
            
            configFormTitle = configForm.getTitle();
            
            configFormPanel = ((Component)configForm.getForm());
        }
        catch (Exception e)
        {
            logger.error("Could not load configuration form.", e);
        }
        
        if(icon != null)
            configFormIcon
                = new ImageIcon(ImageLoader.getBytesInImage(icon));
        
        if(!(configFormPanel instanceof Component))
        {
            throw new ClassCastException("ConfigurationFrame :"
            + configForm.getForm().getClass()
            + " is not a class supported by this ui implementation");
        }
    }

    /**
     * Returns the icon of the corresponding <tt>ConfigurationForm</tt>.
     * 
     * @return the icon of the corresponding <tt>ConfigurationForm</tt>
     */
    public ImageIcon getConfigFormIcon()
    {
        return configFormIcon;
    }

    /**
     * Returns the form of the corresponding <tt>ConfigurationForm</tt>.
     * 
     * @return the form of the corresponding <tt>ConfigurationForm</tt>
     */
    public Component getConfigFormPanel()
    {
        return configFormPanel;
    }

    /**
     * Returns the title of the corresponding <tt>ConfigurationForm</tt>.
     * 
     * @return the title of the corresponding <tt>ConfigurationForm</tt>
     */
    public String getConfigFormTitle()
    {
        return configFormTitle;
    }

    /**
     * Returns the corresponding <tt>ConfigurationForm</tt>.
     * 
     * @return the corresponding <tt>ConfigurationForm</tt>
     */
    public ConfigurationForm getConfigForm()
    {
        return configForm;
    }
}

File [changed]: ConfigFormList.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigFormList.java?r1=1.1&r2=1.2
Delta lines:  +16 -5
--------------------
--- ConfigFormList.java	2007-04-26 21:34:29+0000	1.1
+++ ConfigFormList.java	2007-05-29 16:09:59+0000	1.2
@@ -42,7 +42,7 @@
      * Adds a new <tt>ConfigurationForm</tt> to this list. 
      * @param configForm The <tt>ConfigurationForm</tt> to add.
      */
-    public void addConfigForm(ConfigurationForm configForm)
+    public void addConfigForm(ConfigFormDescriptor configForm)
     {
         listModel.addElement(configForm);
     }
@@ -53,17 +53,28 @@
      */
     public void removeConfigForm(ConfigurationForm configForm)
     {
-        listModel.removeElement(configForm);
+        for(int i = 0; i < listModel.getSize(); i ++)
+        {
+            ConfigFormDescriptor descriptor
+                = (ConfigFormDescriptor) listModel.get(i);
+            
+            if(descriptor.getConfigForm().equals(configForm))
+                listModel.removeElement(descriptor);
+        }
     }
 
+    /**
+     * Called when user selects a component in the list of configuration forms.
+     */
     public void valueChanged(ListSelectionEvent e)
     {
         if(!e.getValueIsAdjusting())
         {
-            ConfigurationForm configForm
-                = (ConfigurationForm) this.getSelectedValue();
+            ConfigFormDescriptor configFormDescriptor
+                = (ConfigFormDescriptor) this.getSelectedValue();
             
-            configFrame.showFormContent(configForm);
+            if(configFormDescriptor != null)
+                configFrame.showFormContent(configFormDescriptor);
         }
     }
 }

File [changed]: ConfigurationFrame.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigurationFrame.java?r1=1.26&r2=1.27
Delta lines:  +17 -20
---------------------
--- ConfigurationFrame.java	2007-04-26 21:34:29+0000	1.26
+++ ConfigurationFrame.java	2007-05-29 16:09:59+0000	1.27
@@ -9,16 +9,14 @@
 
 import java.awt.*;
 import java.awt.event.*;
-import java.io.*;
-import java.util.*;
 
-import javax.imageio.*;
 import javax.swing.*;
 
 import net.java.sip.communicator.impl.gui.customcontrols.*;
 import net.java.sip.communicator.impl.gui.i18n.*;
 import net.java.sip.communicator.impl.gui.main.*;
 import net.java.sip.communicator.service.gui.*;
+import net.java.sip.communicator.util.*;
 
 /**
  * The implementation of the <tt>ConfigurationManager</tt> interface.
@@ -29,6 +27,8 @@
     extends SIPCommDialog
     implements  ConfigurationWindow
 {
+    private Logger logger = Logger.getLogger(ConfigurationFrame.class);
+    
     private ConfigFormList configList;
 
     private TitlePanel titlePanel = new TitlePanel();
@@ -102,20 +102,12 @@
      * dialog, otherwise throws a ClassCastException.
      * @see ConfigurationWindow#addConfigurationForm(ConfigurationForm)
      */
-    public void addConfigurationForm(ConfigurationForm configForm) {
-
-        if(configForm.getForm() instanceof Component)
+    public void addConfigurationForm(ConfigurationForm configForm)
         {
-            this.configList.addConfigForm(configForm);
-    
-//            this.recalculateSize();
+        ConfigFormDescriptor descriptor = new ConfigFormDescriptor(configForm);
             
-        }
-        else {
-            throw new ClassCastException("ConfigurationFrame :"
-            + configForm.getForm().getClass()
-            + " is not a class supported by this ui implementation");
-        }
+        if(descriptor != null)
+            configList.addConfigForm(descriptor);
     }
 
     /**
@@ -129,15 +121,21 @@
         this.configList.removeConfigForm(configForm);
     }
 
-    public void showFormContent(ConfigurationForm configForm)
+    /**
+     * Shows on the right the configuration form given by the given
+     * <tt>ConfigFormDescriptor</tt>.
+     * 
+     * @param configFormDescriptor
+     */
+    public void showFormContent(ConfigFormDescriptor configFormDescriptor)
     {
         this.centerPanel.removeAll();
         
-        this.titlePanel.setTitleText(configForm.getTitle());
+        this.titlePanel.setTitleText(configFormDescriptor.getConfigFormTitle());
 
         this.centerPanel.add(titlePanel, BorderLayout.NORTH);
 
-        this.centerPanel.add((Component)configForm.getForm(),
+        this.centerPanel.add(configFormDescriptor.getConfigFormPanel(),
                 BorderLayout.CENTER);
         
         this.centerPanel.revalidate();
@@ -145,7 +143,6 @@
      
     }
     
-    
     /**
      * Calculates the size of the frame depending on the size of the largest
      * contained form.

File [changed]: ConfigFormListCellRenderer.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/gui/main/configforms/ConfigFormListCellRenderer.java?r1=1.1&r2=1.2
Delta lines:  +10 -9
--------------------
--- ConfigFormListCellRenderer.java	2007-04-26 21:34:29+0000	1.1
+++ ConfigFormListCellRenderer.java	2007-05-29 16:09:59+0000	1.2
@@ -12,7 +12,7 @@
 import javax.swing.*;
 
 import net.java.sip.communicator.impl.gui.utils.*;
-import net.java.sip.communicator.service.gui.*;
+import net.java.sip.communicator.util.*;
 
 /**
  * The <tt>ContactListCellRenderer</tt> is the custom cell renderer used in the
@@ -25,6 +25,8 @@
 public class ConfigFormListCellRenderer extends JPanel 
     implements ListCellRenderer
 {
+    private Logger logger = Logger.getLogger(ConfigFormListCellRenderer.class);
+    
     /**
      * The size of the gradient used for painting the selected background of
      * some components.
@@ -84,15 +86,13 @@
     public Component getListCellRendererComponent(JList list, Object value,
             int index, boolean isSelected, boolean cellHasFocus)
     {
-        ConfigurationForm configForm = (ConfigurationForm) value;
-        
-        byte[] configFormIcon = configForm.getIcon();
+        ConfigFormDescriptor cfDescriptor = (ConfigFormDescriptor) value;
         
-        if(configFormIcon != null)            
-            iconLabel.setIcon(new ImageIcon(ImageLoader.getBytesInImage(
-                    configFormIcon)));
+        if(cfDescriptor.getConfigFormIcon() != null)            
+            iconLabel.setIcon(cfDescriptor.getConfigFormIcon());
         
-        textLabel.setText(configForm.getTitle());
+        if(cfDescriptor.getConfigFormTitle() != null)
+            textLabel.setText(cfDescriptor.getConfigFormTitle());
         
         this.isSelected = isSelected;
 
@@ -109,7 +109,8 @@
      * to provide a custom look for this panel. A gradient background is
      * painted when the panel is selected and when the mouse is over it.
      */
-    public void paintComponent(Graphics g) {
+    public void paintComponent(Graphics g)
+    {
         super.paintComponent(g);
 
         Graphics2D g2 = (Graphics2D) g;




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





More information about the commits mailing list