krysalis-jplugin/src/java/org/krysalis/swingx/icons BasicLabelIconFactory.java,NONE,1.1 DefaultLabelIconFactory.java,NONE,1.1 IconFactory.java,NONE,1.1 JIcon.java,NONE,1.1 LabelIcon.java,NONE,1.1 LabelIconFactory.java,NONE,1.1 StoreEntityLabelIconFactory.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-jplugin/src/java/org/krysalis/swingx/icons
In directory sc8-pr-cvs1:/tmp/cvs-serv24886/src/java/org/krysalis/swingx/icons

Added Files:
	BasicLabelIconFactory.java DefaultLabelIconFactory.java 
	IconFactory.java JIcon.java LabelIcon.java 
	LabelIconFactory.java StoreEntityLabelIconFactory.java 
Log Message:
refactoring swingx.swing.* packages to swingx.*

--- NEW FILE: BasicLabelIconFactory.java ---

/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package   org.krysalis.swingx.icons;

import java.util.HashMap;

import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;

/**
 *@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public class BasicLabelIconFactory extends LabelIconFactory implements Component,


  Configurable{
  private final org.apache.log4j.Category c = org.apache.log4j.Category.getInstance(this.getClass());

  private HashMap mappings = new HashMap();

  public BasicLabelIconFactory () {
  }

  public void configure(Configuration conf) throws ConfigurationException
  {
    Configuration[] mappingsConf = conf.getChildren("icon-mapping");

    for (int i = 0; i < mappingsConf.length; i++) {
      mappings.put(mappingsConf[i].getAttribute("mime-type"),
                   mappingsConf[i].getAttribute("path"));
    }
  }

  public String getIconPathForObject (Object object,
                                      String contentType, int sizeHint) {

    return (String) mappings.get(contentType);

  }
}

--- NEW FILE: DefaultLabelIconFactory.java ---

/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package   org.krysalis.swingx.icons;

import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;

/**
 *@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public class DefaultLabelIconFactory extends LabelIconFactory implements Component, Configurable{
  private final org.apache.log4j.Category c = org.apache.log4j.Category.getInstance(this.getClass());

  private String defaultIconPath = null;

  public DefaultLabelIconFactory () {
  }

  public void configure(Configuration conf) throws ConfigurationException
  {
    defaultIconPath = conf.getChild("icon").getAttribute("path","crystalDefaultSmallDocument.gif");
  }

  public String getIconPathForObject (Object object,
                                      String contentType, int sizeHint) {

    return defaultIconPath;

  }
}

--- NEW FILE: IconFactory.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package   org.krysalis.swingx.icons;




/**
 *@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public interface IconFactory{

  public final static int TINY_SIZE_HINT = 16;
  public final static int SMALL_SIZE_HINT = 24;
  public final static int NORMAL_SIZE_HINT = 32;
  public final static int MEDIUM_SIZE_HINT = 48;
  public final static int BIG_SIZE_HINT = 64;

  public JIcon getIcon (Object enclosedObject, String mimeType, int sizeHint);
}

--- NEW FILE: JIcon.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package  org.krysalis.swingx.icons;

import java.awt.Graphics;

import javax.swing.JComponent;

import org.apache.avalon.framework.component.Component;
import org.krysalis.jplugin.framework.concerns.*;

/**
 *@author     <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public abstract class JIcon extends JComponent
         implements Component {
    private Object enclosedObject;
    private boolean isSelected = false;


    /**
     *  Constructor for the JIcon object
     *
     *@param  enclosedObject  Description of Parameter
     */
    public JIcon(Object enclosedObject) {
        this.enclosedObject = enclosedObject;
    }


    /**
     *  Sets the selected attribute of the JIcon object
     *
     *@param  selected  The new selected value
     */
    public abstract void setSelected(boolean selected);


    /**
     *  Gets the selected attribute of the JIcon object
     *
     *@return    The selected value
     */
    public abstract boolean isSelected();


    /**
     *  Gets the enclosedObject attribute of the JIcon object
     *
     *@return    The enclosedObject value
     */
    public Object getEnclosedObject() {
        return enclosedObject;
    }


    /**
     *  Description of the Method
     *
     *@param  g1  Description of Parameter
     */
    public void paint(Graphics g1) {
        AntiAliasing.antialias(g1);
        super.paint(g1);
    }
}

--- NEW FILE: LabelIcon.java ---

/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package  org.krysalis.swingx.icons;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.event.ChangeEvent;

import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.krysalis.jplugin.framework.services.direction.Director;
import org.krysalis.swingx.resources.ResourceFactory;
import org.krysalis.swingx.ImageUtils;

/**
 *@author     <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public class LabelIcon extends JIcon implements Component,
        Composable, Initializable {
    ImageIcon normalJIcon;
    ImageIcon selectedJIcon;
    JButton mainButton = new JButton();
    private boolean isSelected = false;
    private ResourceFactory resourceFactory;
    private Director director;


    /**
     *  Constructor for the LabelIcon object
     *
     *@param  enclosedObject  Description of Parameter
     */
    public LabelIcon(Object enclosedObject) {
        super(enclosedObject);
    }


    /**
     *  Sets the text attribute of the LabelIcon object
     *
     *@param  text  The new text value
     */
    public void setText(String text) {
        mainButton.setText(text);
    }


    /**
     *  Sets the selected attribute of the LabelIcon object
     *
     *@param  selected  The new selected value
     */
    public void setSelected(boolean selected) {
        isSelected = selected;
        if (isSelected) {
            mainButton.setIcon(selectedJIcon);
        } else {
            mainButton.setIcon(normalJIcon);
        }
        repaint();
    }


    /**
     *  Sets the icon attribute of the LabelIcon object
     *
     *@param  icon  The new icon value
     */
    public void setIcon(ImageIcon icon) {
        normalJIcon = icon;
        selectedJIcon = ImageUtils.getDisabledImageIcon(icon);
        mainButton.setIcon(icon);
    }


    /**
     *  Gets the selected attribute of the LabelIcon object
     *
     *@return    The selected value
     */
    public boolean isSelected() {
        return isSelected;
    }


    /**
     *  Description of the Method
     *
     *@param  cm                      Description of Parameter
     *@exception  ComponentException  Description of Exception
     */
    public void compose(ComponentManager cm) throws ComponentException {
        resourceFactory = (ResourceFactory) cm.lookup("ResourceFactory");
        director = (Director) cm.lookup("Director");
    }


    /**
     *  Description of the Method
     */
    public void initialize() {
        this.setLayout(new BorderLayout());
        this.add(mainButton, BorderLayout.CENTER);
        mainButton.setFocusPainted(false);
        mainButton.setBorderPainted(false);
        mainButton.setHorizontalTextPosition(JLabel.CENTER);
        mainButton.setHorizontalAlignment(JLabel.CENTER);
        mainButton.setVerticalTextPosition(JLabel.BOTTOM);
        mainButton.setVerticalAlignment(JLabel.BOTTOM);
        String entityString = super.getEnclosedObject().toString();
        mainButton.setToolTipText(entityString);
        mainButton.setFont(new Font("SansSerif", Font.BOLD, 10));
        if (entityString.length() > 25) {
            entityString = entityString.substring(0, 22) + "...";
        }
        mainButton.setText(entityString);
        mainButton.addActionListener(
            new java.awt.event.ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    this_actionPerformed(e);
                }
            }
                );
    }


    /**
     *  Description of the Method
     *
     *@param  e  Description of Parameter
     */
    void this_actionPerformed(ActionEvent e) {
        director.fireEvent(new ChangeEvent(this.getEnclosedObject()));
    }
}

--- NEW FILE: LabelIconFactory.java ---

/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package   org.krysalis.swingx.icons;

import java.util.HashMap;

import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.krysalis.swingx.resources.ResourceFactory;

/**
 *@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public abstract class LabelIconFactory
implements IconFactory, Component, Composable {
  private final org.apache.log4j.Category c = org.apache.log4j.Category.getInstance(this.getClass());
  private ResourceFactory resourceFactory;
  private static final HashMap icons = new HashMap();
  public final static int TINY_SIZE_HINT = 16;
  public final static int SMALL_SIZE_HINT = 24;
  public final static int NORMAL_SIZE_HINT = 32;
  public final static int MEDIUM_SIZE_HINT = 48;
  public final static int BIG_SIZE_HINT = 64;

  public void compose (ComponentManager cm) throws ComponentException {
    resourceFactory = (ResourceFactory)cm.lookup("ResourceFactory");
  }

  public abstract String getIconPathForObject(Object object, String mimeType,
                                              int sizeHint);

  public JIcon getIcon (Object object, String mimeType,
                        int sizeHint) {

    String iconPath = getIconPathForObject(object, mimeType, sizeHint);

    if(iconPath==null)
    {return null;}

    LabelIcon entityLabel = new LabelIcon(object);
    entityLabel.setIcon(resourceFactory.getImageIcon(iconPath));
    entityLabel.setText(object.toString());

    return  entityLabel;
  }

}

--- NEW FILE: StoreEntityLabelIconFactory.java ---

/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Software       *
 * License version 1.1_01, a copy of which has been included  with this      *
 * distribution in the LICENSE file.                                         *
 *****************************************************************************/
package   org.krysalis.swingx.icons;

import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.krysalis.jplugin.framework.storage.StoreEntity;

/**
 *@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
 *@created    June 20, 2001
 *@version    1.0
 */
public class StoreEntityLabelIconFactory extends LabelIconFactory implements Component, Configurable{
  private final org.apache.log4j.Category c = org.apache.log4j.Category.getInstance(this.getClass());

  private String folderIconPath = null;

  public StoreEntityLabelIconFactory () {
  }

  public void configure(Configuration conf) throws ConfigurationException
  {
    folderIconPath = conf.getChild("icon").getAttribute("path");
  }


  public String getIconPathForObject (Object object,
                                      String contentType, int sizeHint) {
    if (object instanceof StoreEntity) {
      StoreEntity storeEntity = (StoreEntity)object;
      if (storeEntity.getAllowsChildren()) {
        return folderIconPath;
      }
    }
    return null;
  }
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.