View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.ui.support;
    14
    15  import java.beans.PropertyChangeListener;
    16  import java.beans.PropertyChangeSupport;
    17  import java.util.HashSet;
    18  import java.util.Set;
    19
    20  import javax.swing.Icon;
    21  import javax.swing.ImageIcon;
    22  import javax.swing.JComponent;
    23
    24  import com.eviware.soapui.model.ModelItem;
    25  import com.eviware.soapui.support.UISupport;
    26  import com.eviware.soapui.ui.desktop.DesktopPanel;
    27
    28  /***
    29   * Default implementation for simple DesktopPanels
    30   *
    31   * @author Ole.Matzura
    32   */
    33
    34  public class DefaultDesktopPanel implements DesktopPanel
    35  {
    36  	private PropertyChangeSupport propertyChangeSupport;
    37  	private String title;
    38  	private JComponent component;
    39  	private Set<ModelItem> depends = new HashSet<ModelItem>();
    40  	private ImageIcon icon;
    41  	private final String description;
    42
    43  	public DefaultDesktopPanel( String title, String description, JComponent component )
    44  	{
    45  		this.title = title;
    46  		this.description = description;
    47  		this.component = component;
    48
    49  		propertyChangeSupport = new PropertyChangeSupport( this );
    50  	}
    51
    52  	public void loadIcon( String path )
    53  	{
    54  		icon = UISupport.createImageIcon( path );
    55  	}
    56
    57  	public String getTitle()
    58  	{
    59  		return title;
    60  	}
    61
    62  	public String getDescription()
    63  	{
    64  		return description;
    65  	}
    66
    67  	public void setTitle( String title )
    68  	{
    69  		String oldTitle = this.title;
    70  		this.title = title;
    71
    72  		propertyChangeSupport.firePropertyChange( TITLE_PROPERTY, oldTitle, title );
    73  	}
    74
    75  	public ModelItem getModelItem()
    76  	{
    77  		return null;
    78  	}
    79
    80  	public boolean onClose( boolean canCancel )
    81  	{
    82  		return true;
    83  	}
    84
    85  	public JComponent getComponent()
    86  	{
    87  		return component;
    88  	}
    89
    90  	public boolean dependsOn(ModelItem modelItem)
    91  	{
    92  		return depends != null && depends.contains( modelItem );
    93  	}
    94
    95  	public void addDependency( ModelItem modelItem )
    96  	{
    97  		depends.add( modelItem );
    98  	}
    99
    100 	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
    101 	{
    102 		propertyChangeSupport.addPropertyChangeListener( propertyName, listener );
    103 	}
    104
    105 	public void addPropertyChangeListener(PropertyChangeListener listener)
    106 	{
    107 		propertyChangeSupport.addPropertyChangeListener( listener );
    108 	}
    109
    110 	public void removePropertyChangeListener(PropertyChangeListener listener)
    111 	{
    112 		propertyChangeSupport.removePropertyChangeListener( listener );
    113 	}
    114
    115 	public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
    116 	{
    117 		propertyChangeSupport.removePropertyChangeListener( propertyName, listener );
    118 	}
    119
    120 	public Icon getIcon()
    121 	{
    122 		return icon;
    123 	}
    124 }