[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/, /sip-communicator/src/net/java/sip/communicator/plugin...

yanas at dev.java.net yanas at dev.java.net
Thu Apr 26 23:39:01 CEST 2007


User: yanas   
Date: 2007-04-26 21:39:01+0000
Added:
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/pluginIcon.png
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/active.png
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/stopping.png
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/starting.png
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/desactivated.png
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/installed.png
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/PluginTableModel.java
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/ManageButtonsPanel.java
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/TitlePanel.java
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/PluginListCellRenderer.java
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/pluginmanager.manifest.mf
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/PluginManagerConfigForm.java
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources.properties
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/PluginManagerActivator.java
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/NewBundleDialog.java
   sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/Resources.java

Log:
 plugin manager bundle added

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/
==========================================================================================

File [added]: pluginIcon.png
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/pluginIcon.png?rev=1.1&content-type=text/vnd.viewcvs-markup
File [added]: active.png
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/active.png?rev=1.1&content-type=text/vnd.viewcvs-markup
File [added]: stopping.png
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/stopping.png?rev=1.1&content-type=text/vnd.viewcvs-markup
File [added]: starting.png
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/starting.png?rev=1.1&content-type=text/vnd.viewcvs-markup
File [added]: desactivated.png
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/desactivated.png?rev=1.1&content-type=text/vnd.viewcvs-markup
File [added]: installed.png
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources/installed.png?rev=1.1&content-type=text/vnd.viewcvs-markup
Directory: /sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/
================================================================================

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

import javax.swing.table.*;

import org.osgi.framework.*;

/**
 * The <tt>TableModel</tt> of the table containing all plug-ins.
 * 
 * @author Yana Stamcheva
 */
public class PluginTableModel extends AbstractTableModel
{
    private BundleContext bundleContext = PluginManagerActivator.bundleContext;
    
    private boolean showSystemBundles;
    
    private Object showSystemBundlesSync = new Object();
    
    /**
     * Returns the count of table rows.
     * @return int the count of table rows
     */
    public int getRowCount()
    {
        boolean showSystem;
        synchronized (showSystemBundlesSync)
        {
            showSystem = showSystemBundles;
        }
        
        if(bundleContext.getBundles() == null)
            return 0;
        else
        {
            if(showSystem)
                return bundleContext.getBundles().length;
            else
            {
                int bundlesSize = 0;
                
                Bundle[] bundles
                    = PluginManagerActivator.bundleContext.getBundles();
             
                for (int i = 0; i < bundles.length; i ++)
                {
                    Bundle bundle = bundles[i];
                    
                    Object sysBundleProp
                        = bundle.getHeaders().get("System-Bundle");
                
                    if(sysBundleProp == null || !sysBundleProp.equals("yes"))
                        bundlesSize++;
                }
                return bundlesSize;
            }
        }
    }

    /**
     * Returns TRUE if the given <tt>Bundle</tt> is contained in this table,
     * FALSE - otherwise.
     * @param bundle the <tt>Bundle</tt> to search for
     * @return TRUE if the given <tt>Bundle</tt> is contained in this table,
     * FALSE - otherwise.
     */
    public boolean contains(Bundle bundle)
    {
        boolean showSystem;
        synchronized (showSystemBundlesSync)
        {
            showSystem = showSystemBundles;
        }
        
        Bundle[] bundles
            = PluginManagerActivator.bundleContext.getBundles();
     
        for (int i = 0; i < bundles.length; i ++)
        {
            Bundle b = bundles[i];
            
            if(b.equals(bundle))
            {
                if(showSystem)
                    return true;
                else
                {
                    Object sysBundleProp
                        = bundle.getHeaders().get("System-Bundle");
            
                    if(sysBundleProp == null || !sysBundleProp.equals("yes"))
                        return true;
                    else
                        return false;
                }
            }            
        }
        
        return false;        
    }
    
    /**
     * Returns the count of table columns.
     * @return int the count of table columns
     */
    public int getColumnCount()
    {
        return 1;
    }

    /**
     * Returns FALSE for all cells in this table.
     */
    public boolean isCellEditable(int row, int column)
    {
        return false;
    }

    /**
     * Returns the value in the cell given by row and column.
     */
    public Object getValueAt(int row, int column)
    {
        boolean showSystem;
        synchronized (showSystemBundlesSync)
        {
            showSystem = showSystemBundles;
        }
        
        Bundle[] bundles
            = PluginManagerActivator.bundleContext.getBundles();
        
        if(showSystem)
            return bundles[row];
        else
        {
            int bundleCounter = 0;
            
            for(int i = 0; i < bundles.length; i++)   
            {   
                if(bundleCounter == row)   
                    return bundles[i];   
                    
                Object sysBundleProp
                    = bundles[i+1].getHeaders().get("System-Bundle");
        
                if(sysBundleProp == null || !sysBundleProp.equals("yes"))
                    bundleCounter++;
            }
        }
        
        return null;
    }

    /**
     * Updates the table content.
     */
    public void update()
    {
        fireTableDataChanged();
    }
    
    /**
     * Returns TRUE if system bundles are show, FALSE - otherwise.
     * @return TRUE if system bundles are show, FALSE - otherwise
     */
    public boolean isShowSystemBundles()
    {
        boolean showSystem;
        
        synchronized (showSystemBundlesSync)
        {
            showSystem = showSystemBundles;
        }
        
        return showSystem;
    }

    /**
     * Sets the <tt>showSystemBundles</tt> property.
     * @param showSystemBundles indicates if system bundles will be shown or not
     */
    public void setShowSystemBundles(boolean showSystemBundles)
    {
        synchronized (showSystemBundlesSync)
        {
            this.showSystemBundles = showSystemBundles;
        }
    }
}

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

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

import net.java.sip.communicator.service.gui.*;

import org.osgi.framework.*;

/**
 * The panel containing all buttons for the <tt>PluginManagerConfigForm</tt>.
 * 
 * @author Yana Stamcheva
 */
public class ManageButtonsPanel
    extends JPanel
    implements ActionListener
{
    private JButton desactivateButton = new JButton(
            Resources.getString("desactivate"));
    
    private JButton activateButton = new JButton(
            Resources.getString("activate"));
    
    private JButton uninstallButton = new JButton(
            Resources.getString("uninstall"));
    
    private JButton updateButton = new JButton(
            Resources.getString("update"));
    
    private JButton newButton = new JButton(Resources.getString("new"));
    
    private JCheckBox showSysBundlesCheckBox = new JCheckBox(
            Resources.getString("showSystemBundles"));
    
    private JPanel buttonsPanel = new JPanel(new GridLayout(0, 1, 8, 8));
    
    private JTable pluginTable;
    
    public ManageButtonsPanel(JTable pluginTable)
    {
        this.pluginTable = pluginTable;
        
        this.setLayout(new BorderLayout());
    
        this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
        
        //Obtains previously saved value for the showSystemBundles check box.
        String showSystemBundlesProp = PluginManagerActivator
            .getConfigurationService().getString(
            "net.java.sip.communicator.plugin.pluginManager.showSystemBundles");
        
        if(showSystemBundlesProp != null)
        {
            boolean isShowSystemBundles
                = new Boolean(showSystemBundlesProp).booleanValue();
            
            this.showSysBundlesCheckBox.setSelected(isShowSystemBundles);
            
            ((PluginTableModel)pluginTable.getModel())
                .setShowSystemBundles(isShowSystemBundles);
        }
        
        this.showSysBundlesCheckBox
            .addChangeListener(new ShowSystemBundlesChangeListener());
        
        this.buttonsPanel.add(newButton);
        this.buttonsPanel.add(activateButton);
        this.buttonsPanel.add(desactivateButton);
        this.buttonsPanel.add(uninstallButton);
        this.buttonsPanel.add(updateButton);
        this.buttonsPanel.add(showSysBundlesCheckBox);
        
        this.add(buttonsPanel, BorderLayout.NORTH);
        
        this.newButton.addActionListener(this);
        this.activateButton.addActionListener(this);
        this.desactivateButton.addActionListener(this);
        this.uninstallButton.addActionListener(this);
        this.updateButton.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e)
    {
        JButton sourceButton = (JButton) e.getSource();
        
        if(sourceButton.equals(newButton))
        {
            NewBundleDialog dialog = new NewBundleDialog();
            
            dialog.pack();
            dialog.setLocation(
                    Toolkit.getDefaultToolkit().getScreenSize().width/2
                        - dialog.getWidth()/2,
                    Toolkit.getDefaultToolkit().getScreenSize().height/2
                        - dialog.getHeight()/2
                    );
            
            dialog.setVisible(true);
        }
        else if(sourceButton.equals(activateButton))
        {
            int[] selectedRows = pluginTable.getSelectedRows();
            
            for (int i = 0; i < selectedRows.length; i++)
            {
                try
                {
                    ((Bundle)pluginTable.getModel()
                            .getValueAt(selectedRows[i], 0)).start();
                }
                catch (BundleException ex)
                {
                    PluginManagerActivator.getUIService().getPopupDialog()
                        .showMessagePopupDialog(ex.getMessage(), "Error",
                            PopupDialog.ERROR_MESSAGE);
                }
            }
        }
        else if(sourceButton.equals(desactivateButton))
        {
            int[] selectedRows = pluginTable.getSelectedRows();
            
            for (int i = 0; i < selectedRows.length; i++)
            {
                try
                {
                    ((Bundle)pluginTable.getModel()
                            .getValueAt(selectedRows[i], 0)).stop();
                }
                catch (BundleException ex)
                {
                    PluginManagerActivator.getUIService().getPopupDialog()
                        .showMessagePopupDialog(ex.getMessage(), "Error",
                        PopupDialog.ERROR_MESSAGE);
                }
            }
        }
        else if(sourceButton.equals(uninstallButton))
        {
            int[] selectedRows = pluginTable.getSelectedRows();

            for (int i = selectedRows.length - 1; i >= 0; i--)
            {
                try
                {
                    ((Bundle)pluginTable.getModel()
                            .getValueAt(selectedRows[i], 0)).uninstall();
                }
                catch (BundleException ex)
                {
                    PluginManagerActivator.getUIService().getPopupDialog()
                        .showMessagePopupDialog(ex.getMessage(), "Error",
                        PopupDialog.ERROR_MESSAGE);
                }
            }
        }
        else if(sourceButton.equals(updateButton))
        {
            int[] selectedRows = pluginTable.getSelectedRows();
            
            for (int i = 0; i < selectedRows.length; i++)
            {
                try
                {
                    ((Bundle)pluginTable.getModel()
                            .getValueAt(selectedRows[i], 0)).update();
                }
                catch (BundleException ex)
                {
                    PluginManagerActivator.getUIService().getPopupDialog()
                    .showMessagePopupDialog(ex.getMessage(), "Error",
                        PopupDialog.ERROR_MESSAGE);
                }
            }
        }
    }
    
    /**
     * Enable or disable the activate button.
     * 
     * @param enable TRUE - to enable the activate button, FALSE - to disable it
     */
    public void enableActivateButton(boolean enable)
    {
        this.activateButton.setEnabled(enable);
    }
    
    /**
     * Enable or disable the desactivate button.
     * 
     * @param enable TRUE - to enable the desactivate button, FALSE - to
     * disable it
     */
    public void enableDesactivateButton(boolean enable)
    {
        this.desactivateButton.setEnabled(enable);
    }
    
    /**
     * Enable or disable the uninstall button.
     * 
     * @param enable TRUE - to enable the uninstall button, FALSE - to
     * disable it
     */
    public void enableUninstallButton(boolean enable)
    {
        this.uninstallButton.setEnabled(enable);
    }
    
    /**
     * Adds all system bundles to the bundles list when the check box is
     * selected and removes them when user deselect it.
     */
    private class ShowSystemBundlesChangeListener implements ChangeListener
    {
        public void stateChanged(ChangeEvent e)
        {
            //Save the current value of the showSystemBundles check box.
            PluginManagerActivator.getConfigurationService().setProperty(
                "net.java.sip.communicator.plugin.pluginManager.showSystemBundles",
                new Boolean(showSysBundlesCheckBox.isSelected()));
                        
            PluginTableModel tableModel
                = (PluginTableModel)pluginTable.getModel();
            
            tableModel.setShowSystemBundles(showSysBundlesCheckBox.isSelected());
            
            tableModel.update();
        }
    }
    
    /**
     * Returns the current value of the "showSystemBundles" check box.
     * @return TRUE if the the "showSystemBundles" check box is selected,
     * FALSE - otherwise.
     */
    public boolean isShowSystemBundles()
    {
        return showSysBundlesCheckBox.isSelected();
    }
}

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

import java.awt.*;

import javax.swing.*;

/**
 * The <tt>TitlePanel</tt> is a decorated panel, that could be used for a
 * header or a title area. This panel is used for example in the
 * <tt>ConfigurationFrame</tt>.
 * 
 * @author Yana Stamcheva
 */
public class TitlePanel extends JPanel
{
    /**
     * A color between blue and gray used to paint some borders.
     */
    public static final Color BLUE_GRAY_BORDER_COLOR = new Color(142, 160, 188);

    /**
     * The size of the gradient used for painting the background.
     */
    private static final int GRADIENT_SIZE = 10;

    /**
     * The start color used to paint a gradient mouse over background.
     */
    private static final Color MOVER_START_COLOR = new Color(230,
            230, 230);

    /**
     * The end color used to paint a gradient mouse over background.
     */
    private static final Color MOVER_END_COLOR = new Color(255,
            255, 255);

    private JLabel titleLabel = new JLabel();

    /**
     * Creates an instance of <tt>TitlePanel</tt>.
     */
    public TitlePanel() {

        super(new FlowLayout(FlowLayout.CENTER));

        this.setPreferredSize(new Dimension(0, 30));

        this.titleLabel.setFont(this.getFont().deriveFont(Font.BOLD, 14));
    }

    /**
     * Creates an instance of <tt>TitlePanel</tt> by specifying the title
     * String.
     * 
     * @param title A String title.
     */
    public TitlePanel(String title) {

        super(new FlowLayout(FlowLayout.CENTER));

        this.titleLabel.setFont(this.getFont().deriveFont(Font.BOLD, 14));

        this.titleLabel.setText(title);

        this.add(titleLabel);
    }

    /**
     * Overrides the <code>paintComponent</code> method of <tt>JPanel</tt>
     * to paint a gradient background of this panel.
     */
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;

        GradientPaint p = new GradientPaint(this.getWidth() / 2, 0,
                MOVER_START_COLOR, this.getWidth() / 2,
                GRADIENT_SIZE,
                MOVER_END_COLOR);

        GradientPaint p1 = new GradientPaint(this.getWidth() / 2, this
                .getHeight()
                - GRADIENT_SIZE,
                MOVER_END_COLOR, this.getWidth() / 2,
                this.getHeight(), MOVER_START_COLOR);

        g2.setPaint(p);
        g2.fillRect(0, 0, this.getWidth(), GRADIENT_SIZE);

        g2.setColor(MOVER_END_COLOR);
        g2.fillRect(0, GRADIENT_SIZE, this.getWidth(),
                this.getHeight() - GRADIENT_SIZE);

        g2.setPaint(p1);
        g2.fillRect(0, this.getHeight() - GRADIENT_SIZE
                - 1, this.getWidth(), this.getHeight() - 1);

        g2.setColor(BLUE_GRAY_BORDER_COLOR);
        g2.drawRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, 5, 5);
    }

    /**
     * Sets the title String.
     * @param title The title String.
     */
    public void setTitleText(String title) {
        this.titleLabel.setText(title);

        this.add(titleLabel);
    }
}

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

import java.awt.*;

import javax.swing.*;
import javax.swing.table.*;

import org.osgi.framework.*;

/**
 * The <tt>ContactListCellRenderer</tt> is the custom cell renderer used in the
 * SIP-Communicator's <tt>ContactList</tt>. It extends JPanel instead of JLabel,
 * which allows adding different buttons and icons to the contact cell.
 * The cell border and background are repainted. 
 * 
 * @author Yana Stamcheva
 */
public class PluginListCellRenderer extends JPanel 
    implements TableCellRenderer
{
    /**
     * The start color used to paint a gradient selected background.
     */
    private static final Color SELECTED_END_COLOR
        = new Color(240, 240, 240);

    /**
     * The end color used to paint a gradient selected background.
     */
    private static final Color SELECTED_START_COLOR
        = new Color(209, 212, 225);
    
    private JPanel mainPanel = new JPanel(new BorderLayout());
    
    private JPanel nameVersionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    
    private JLabel nameLabel = new JLabel();
    
    private JLabel versionLabel = new JLabel();
    
    private JLabel descriptionLabel = new JLabel();
    
    private JLabel stateLabel = new JLabel();
    
    private JLabel iconLabel = new JLabel();
    
    private JLabel systemLabel
        = new JLabel("( " + Resources.getString("system") + " )");
    
    private boolean isSelected = false;
    
    private String direction;    
    
    /**
     * Initialize the panel containing the node.
     */
    public PluginListCellRenderer()
    {
        super(new BorderLayout(8, 8));

        this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        
        this.setBackground(Color.WHITE);
        
        this.setOpaque(true);
        
        this.mainPanel.setOpaque(false);
        this.nameVersionPanel.setOpaque(false);
                
        this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        
        this.nameLabel.setIconTextGap(2);
        
        this.nameLabel.setFont(this.getFont().deriveFont(Font.BOLD));
        this.systemLabel.setFont(this.getFont().deriveFont(Font.BOLD));
        
        this.nameVersionPanel.add(nameLabel);
        this.nameVersionPanel.add(versionLabel);
        
        this.mainPanel.add(nameVersionPanel, BorderLayout.NORTH);
        this.mainPanel.add(descriptionLabel, BorderLayout.CENTER);
        
        this.add(iconLabel, BorderLayout.WEST);
        
        this.add(mainPanel, BorderLayout.CENTER);
        this.add(stateLabel, BorderLayout.WEST);
    }

    /**
     * Implements the <tt>ListCellRenderer</tt> method.
     * 
     * Returns this panel that has been configured to display the meta contact
     * and meta contact group cells.
     */
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex)
    {   
        Bundle bundle = (Bundle) value;
        
        Object bundleName
            = bundle.getHeaders().get(Constants.BUNDLE_NAME);
        Object bundleVersion
            = bundle.getHeaders().get(Constants.BUNDLE_VERSION);
        Object bundleDescription
            = bundle.getHeaders().get(Constants.BUNDLE_DESCRIPTION);
        Object bundleIconPath = bundle.getHeaders().get("Bundle-Icon-Path");
        Icon stateIcon = getStateIcon(bundle.getState());
        
        if(bundleName != null)
            this.nameLabel.setText(bundleName.toString());
        else
            this.nameLabel.setText("unknown");
        
        if(bundleVersion != null)
            this.versionLabel.setText(bundleVersion.toString());
        else
            this.versionLabel.setText("");
        
        if(bundleDescription != null)
            this.descriptionLabel.setText(bundleDescription.toString());
        else
            this.descriptionLabel.setText("");
            
        if(stateIcon != null)
            this.stateLabel.setIcon(stateIcon);
        
        Object sysBundleProp
            = bundle.getHeaders().get("System-Bundle");
        
        this.nameVersionPanel.remove(systemLabel);
        
        if(sysBundleProp != null && sysBundleProp.equals("yes"))
            this.nameVersionPanel.add(systemLabel);
        
        this.isSelected = isSelected;

        return this;
    }
    
    private ImageIcon getStateIcon(int state)
    {
        switch (state)
        {
            case Bundle.INSTALLED:
                return Resources.getImage("installedStateIcon");
            case Bundle.RESOLVED:
                return Resources.getImage("desactivatedStateIcon");
            case Bundle.STARTING:
                return Resources.getImage("startingStateIcon");
            case Bundle.ACTIVE:
                return Resources.getImage("activeStateIcon");
            case Bundle.STOPPING:
                return Resources.getImage("stoppingStateIcon");
        }
        return null;
    }
        
    /**
     * Paint a background for all groups and a round blue border and background
     * when a cell is selected. 
     */
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

        if (this.isSelected)
        {
            GradientPaint p = new GradientPaint(this.getWidth()/2, 0,
                    SELECTED_START_COLOR,
                    this.getWidth()/2,
                    this.getHeight(),
                    SELECTED_END_COLOR);

            g2.setPaint(p);            
            g2.fillRoundRect(1, 1, this.getWidth(), this.getHeight() - 1, 7, 7);
        }
        
        g2.setColor(SELECTED_START_COLOR);
        g2.drawLine(0, this.getHeight() - 1,
                this.getWidth(), this.getHeight() - 1);
    }
}

File [added]: pluginmanager.manifest.mf
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/pluginmanager.manifest.mf?rev=1.1&content-type=text/vnd.viewcvs-markup
Added lines: 25
---------------
Bundle-Activator: net.java.sip.communicator.plugin.pluginmanager.PluginManagerActivator
Bundle-Name: Plugin Manager plugin
Bundle-Description: Manage all SIP Communicator plugins.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: org.osgi.framework,
 net.java.sip.communicator.util,
 net.java.sip.communicator.service.gui,
 net.java.sip.communicator.service.gui.event,
 net.java.sip.communicator.service.configuration,
 javax.swing,
 javax.swing.event,
 javax.swing.table,
 javax.swing.text,
 javax.swing.text.html,
 javax.accessibility,
 javax.swing.plaf,
 javax.swing.plaf.metal,
 javax.swing.plaf.basic,
 javax.imageio,
 javax.swing.filechooser,
 javax.swing.tree,
 javax.swing.undo,
 javax.swing.border

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

import java.awt.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

import net.java.sip.communicator.service.gui.*;

import org.osgi.framework.*;

/**
 * The <tt>ConfigurationForm</tt> that would be added in the user interface
 * configuration window. It contains a list of all installed plug-ins. Allows
 * installing new plugins and manage the existing once.
 * 
 * @author Yana Stamcheva
 */
public class PluginManagerConfigForm
    extends JPanel
    implements ConfigurationForm
{ 
    private JScrollPane pluginListScrollPane = new JScrollPane();
    
    private JTable pluginTable = new JTable();
    
    private PluginTableModel tableModel = new PluginTableModel();
    
    private ManageButtonsPanel buttonsPanel;
    
    public PluginManagerConfigForm()
    {
        super(new BorderLayout());
        
        pluginTable.setModel(tableModel);
        
        TableColumn col = pluginTable.getColumnModel().getColumn(0);
        col.setCellRenderer(new PluginListCellRenderer());
        
        PluginListSelectionListener selectionListener
            = new PluginListSelectionListener();
        
        pluginTable.getSelectionModel()
            .addListSelectionListener(selectionListener);
        pluginTable.getColumnModel().getSelectionModel()
            .addListSelectionListener(selectionListener);
        
        pluginTable.setRowHeight(48);
        
        pluginTable.setBorder(
                BorderFactory.createEmptyBorder(8, 8, 8, 8));
        
        pluginTable.setTableHeader(null);
        
        buttonsPanel = new ManageButtonsPanel(pluginTable);
        
        this.add(pluginListScrollPane, BorderLayout.CENTER);
        
        this.add(buttonsPanel, BorderLayout.EAST);
        
        
        pluginListScrollPane.getViewport().add(pluginTable);
        
        pluginListScrollPane.setHorizontalScrollBarPolicy(
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

        pluginListScrollPane.getVerticalScrollBar().setUnitIncrement(30);
                
        PluginManagerActivator.bundleContext
            .addBundleListener(new PluginListBundleListener());
    }
    
    /**
     * Listens for events triggered when a selection is made in the plugin list.
     */
    private class PluginListSelectionListener implements ListSelectionListener
    {
        public void valueChanged(ListSelectionEvent e)
        {
            int selectedRow = pluginTable.getSelectedRow();
            
            if(selectedRow == -1)
                return;
            
            Bundle selectedBundle
                = (Bundle) pluginTable.getValueAt(selectedRow, 0);
            
            Object sysBundleProp
                = selectedBundle.getHeaders().get("System-Bundle");
            
            if(sysBundleProp != null && sysBundleProp.equals("yes"))
                buttonsPanel.enableUninstallButton(false);
            else
                buttonsPanel.enableUninstallButton(true);
            
            if(selectedBundle.getState() == Bundle.ACTIVE)
            {   
                if(sysBundleProp != null && sysBundleProp.equals("yes"))
                    buttonsPanel.enableDesactivateButton(false);
                else
                    buttonsPanel.enableDesactivateButton(true);
                
                buttonsPanel.enableActivateButton(false);
            }
            else
            {  
                buttonsPanel.enableActivateButton(true);
                buttonsPanel.enableDesactivateButton(false);
            }
        }
    }
    
    /**
     * Listens for <tt>BundleEvents</tt> triggered by the bundle context.
     */
    private class PluginListBundleListener implements BundleListener
    {
        public void bundleChanged(BundleEvent event)
        {   
            tableModel.update();
     
            if(event.getType() == BundleEvent.INSTALLED)
            {
                pluginTable.scrollRectToVisible(new Rectangle(
                            0, pluginTable.getHeight(),
                            1, pluginTable.getHeight()));
            }
        }
    }
    
    /**
     * Implements the <tt>ConfigurationForm.getTitle()</tt> method. Returns the
     * title of this configuration form.
     */
    public String getTitle()
    {
        return Resources.getString("plugins");
    }

    /**
     * Implements the <tt>ConfigurationForm.getIcon()</tt> method. Returns the
     * icon of this configuration form.
     */
    public byte[] getIcon()
    {
        return Resources.getImageInBytes("pluginIcon");
    }

    /**
     * Implements the <tt>ConfigurationForm.getForm()</tt> method. Returns the
     * component corresponding to this configuration form.
     */
    public Object getForm()
    {
        return this;
    }
    
}

File [added]: resources.properties
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/plugin/pluginmanager/resources.properties?rev=1.1&content-type=text/vnd.viewcvs-markup
Added lines: 17
---------------
activate=Activate
desactivate=Desactivate
install=Install
uninstall=Uninstall
update=Update
new=New
plugins=Plug-ins
cancel=Cancel
url=URL
showSystemBundles=Show system bundles
system=System
installedStateIcon=net/java/sip/communicator/plugin/pluginmanager/resources/installed.png
desactivatedStateIcon=net/java/sip/communicator/plugin/pluginmanager/resources/desactivated.png
startingStateIcon=net/java/sip/communicator/plugin/pluginmanager/resources/starting.png
stoppingStateIcon=net/java/sip/communicator/plugin/pluginmanager/resources/stopping.png
activeStateIcon=net/java/sip/communicator/plugin/pluginmanager/resources/active.png
pluginIcon=net/java/sip/communicator/plugin/pluginmanager/resources/pluginIcon.png

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

import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.gui.*;

import org.osgi.framework.*;

/**
 * The <tt>BundleActivator</tt> of the PluginManager plugin.
 * 
 * @author Yana Stamcheva
 */
public class PluginManagerActivator implements BundleActivator
{
    public static BundleContext bundleContext;
    
    private static UIService uiService;
    
    private static ConfigurationService configService;
   
    /**
     * Starts this bundle and adds the <tt>PluginManagerConfigForm</tt> contained
     * in it to the configuration window obtained from the <tt>UIService</tt>.
     */
    public void start(BundleContext bc) throws Exception
    {
        bundleContext = bc;
        
        ServiceReference uiServiceRef
            = bc.getServiceReference(UIService.class.getName());
        
        uiService = (UIService) bc.getService(uiServiceRef);        
        
        ConfigurationWindow configWindow = uiService.getConfigurationWindow();
        
        if(configWindow != null)
        {
            PluginManagerConfigForm pluginManager
                        = new PluginManagerConfigForm();
                    
            configWindow.addConfigurationForm(pluginManager);
        }
    }

    /**
     * Stops this bundles.
     */
    public void stop(BundleContext arg0) throws Exception
    {   
    }
    
    /**
     * Returns the <tt>UIService</tt> obtained from the bundle context.
     * @return the <tt>UIService</tt> obtained from the bundle context
     */
    public static UIService getUIService()
    {
        return uiService;
    }
    

    /**
     * Returns the <tt>ConfigurationService</tt> obtained from the bundle
     * context.
     * @return the <tt>ConfigurationService</tt> obtained from the bundle
     * context
     */
    public static ConfigurationService getConfigurationService() {
        if(configService == null) {
            ServiceReference configReference = bundleContext
                .getServiceReference(ConfigurationService.class.getName());

            configService = (ConfigurationService) bundleContext
                .getService(configReference);
        }

        return configService;
    }
}

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

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import net.java.sip.communicator.service.gui.*;

import org.osgi.framework.*;

public class NewBundleDialog
    extends JDialog
    implements ActionListener
{
    private JButton installButton = new JButton(Resources.getString("install"));
    
    private JButton cancelButton = new JButton(Resources.getString("cancel"));
    
    private JTextField bundlePathField = new JTextField();
    
    private JLabel bundlePathLabel = new JLabel(Resources.getString("url") + ": ");
    
    private JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    
    private JPanel dataPanel = new JPanel(new BorderLayout(5, 5));
    
    private JPanel mainPanel = new JPanel(new BorderLayout());
    
    public NewBundleDialog ()
    {
        this.mainPanel.setPreferredSize(new Dimension(450, 150));
        
        this.getContentPane().add(mainPanel);
        
        this.mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
        this.mainPanel.add(dataPanel, BorderLayout.NORTH);
        
        this.mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
        
        this.buttonsPanel.add(installButton);
        this.buttonsPanel.add(cancelButton);
        
        this.installButton.addActionListener(this);
        this.cancelButton.addActionListener(this);
     
        this.dataPanel.add(bundlePathLabel, BorderLayout.WEST);
        
        this.dataPanel.add(bundlePathField, BorderLayout.CENTER);
        
    }

    public void actionPerformed (ActionEvent e)
    {
        JButton sourceButton = (JButton) e.getSource();
        
        if (sourceButton.equals(installButton))
        {
            if (bundlePathField.getText().length() > 0)
            {
                try
                {
                    PluginManagerActivator.bundleContext
                        .installBundle(bundlePathField.getText(), null);                    
                }
                catch (BundleException ex)
                {
                    PluginManagerActivator.getUIService().getPopupDialog()
                        .showMessagePopupDialog(ex.getMessage(), "Error",
                        PopupDialog.ERROR_MESSAGE);
                }
                finally
                {
                    dispose();
                }
            }
        }
        
        dispose();
    }
}

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

import java.awt.image.*;
import java.io.*;
import java.util.*;

import javax.imageio.*;
import javax.swing.*;

import net.java.sip.communicator.util.*;
/**
 * The Messages class manages the access to the internationalization
 * properties files.
 * @author Yana Stamcheva
 */
public class Resources {

    private static Logger log = Logger.getLogger(Resources.class);

    private static final String BUNDLE_NAME
        = "net.java.sip.communicator.plugin.pluginmanager.resources";

    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
            .getBundle(BUNDLE_NAME);

    /**
     * Returns an internationalized string corresponding to the given key.
     * @param key The key of the string.
     * @return An internationalized string corresponding to the given key.
     */
    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);

        } catch (MissingResourceException e) {

            return '!' + key + '!';
        }
    }

    /**
     * Loads an image from a given image identifier.
     * @param imageID The identifier of the image.
     * @return The image for the given identifier.
     */
    public static ImageIcon getImage(String imageID) {
        BufferedImage image = null;

        String path = Resources.getString(imageID);
        try {
            image = ImageIO.read(Resources.class.getClassLoader()
                    .getResourceAsStream(path));

        } catch (IOException e) {
            log.error("Failed to load image:" + path, e);
        }

        return new ImageIcon(image);
    }
    
    /**
     * Loads an image from a given image identifier.
     * @param imageID The identifier of the image.
     * @return The image for the given identifier.
     */
    public static byte[] getImageInBytes(String imageID) {
        byte[] image = new byte[100000];

        String path = Resources.getString(imageID);
        try {
            Resources.class.getClassLoader()
                    .getResourceAsStream(path).read(image);

        } catch (IOException e) {
            log.error("Failed to load image:" + path, e);
        }

        return image;
    }
}




---------------------------------------------------------------------
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