
 // ####### IconAdapter Class #######
 //
 // DESCRIPTION:
 // ShowUIDefaults class utilizes two classes that are found in Dr.Jamf's Listing class
 // included with this distribution. The following classes
 //    - IconAdapter class
 //    - BorderAdaper class
 // must be available to ShowUIDefaults so that the Border and Icon interface objects
 // render correctly within the javax.swing.JTable cells.
 //
 // see http://www.woven_media.com/ for more info.

 // --------------------------------------------------
 // IconAdapter
 // Author: Dr. Lazlo Jamf (Sun Forum:DrLazloJamf)
 // --------------------------------------------------

/**
 * IconAdapter class handles this instance's painting of <code>javax.swing.ImageIcon</code>
 * and <code>javax.swing.Icon interface</object> objects.
 *
 * @param icon <code>javax.swing.Icon interface</code> object for this instance.
 * @param key  <code>java.lang.String</code> of this instance's
 *             <code>javax.swing.UIDefaults</code> key attribute.
 * @author     Dr. Lazlo Jamf <Sun Java Developer's Forum user: DrLazloJamf>
 */
class IconAdapter implements Icon {
    private Icon icon;
    private Component component;

    public IconAdapter(Icon icon, String key) {
        this.icon = icon;
        try {
            int dotIndex = key.lastIndexOf('.');
            if (dotIndex != -1) {
                String classname = "javax.swing.J" + key.substring(0, dotIndex);
                component = (Component) Class.forName(classname).newInstance();
            }
        } catch (Exception e) {
        }
    }

    public int getIconWidth() {
        return icon.getIconWidth();
    }

    public int getIconHeight() {
        return icon.getIconHeight();
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        try {
            if (component != null)
                c = component;
            icon.paintIcon(c, g, x, y);
        } catch(Exception e) {
        }
    }
} // End IconAdapter


// ####### BorderAdapter Class #######

/**
 * <code>BorderAdapter</code> class handles this instance's displaying of
 * <code>javax.swing.border.Border</code> objects.
 *
 * @param icon <code>javax.swing.Border interface</code> instance.
 * @param key  <code>java.lang.String</code> of this instance's
 *             <code>javax.swing.UIDefaults</code> key attribute.
 * @author     Dr. Lazlo Jamf <Sun Java Developer's Forum user: DrLazloJamf>
 */
class BorderAdapter implements Border
{
    private Border border;
    private Component component;

     /**
      * Class constructor sets an instance of the <code>javax.swing.Border</code> interface
      * and a <code>java.lang.String</code> containing the qualified javax.swing.JComponent
      * class name.
      *
      * @param icon <code>javax.swing.Border interface</code> instance.
      * @param key  <code>java.lang.String</code> containing qualified <code>javax.swing.JComponent</code>
      *             class name.
      * @see        <code>javax.swing.Border interface</code>
      */
    public BorderAdapter(Border border, String key)
    {
        this.border = border;
        try
        {
            int dotIndex = key.lastIndexOf('.');
            if (dotIndex != -1)
            {
                String classname = "javax.swing.J" + key.substring(0, dotIndex);
                component = (Component) Class.forName(classname).newInstance();
            }
        }
        catch (Exception e)
        {
        }
    }

    /**
     * Returns the <code>boolean</code> value of the border#isBorderOpaque method.
     *
     * @return <code>boolean</code> value for this instance's border#isBorderOpaque method.
     */
    public boolean isBorderOpaque()
    {
        return border.isBorderOpaque();
    }

    /**
     * Accessor for border's <code>java.awt.Insets</code>.
     *
     * @return <code>java.awt.Insets</code> of this border's insets.
     */
    public Insets getBorderInsets(Component c)
    {
        try
        {
            if (component != null)
            {
                c = component;
            }
            return border.getBorderInsets(c);
        } catch(Exception e)
        {
            return new Insets(0,0,0,0);
        }
    }

    /**
     * Paints border at this x, y location.
     *
     * @param c <code>java.awt.Component</code> reference to the component to paint.
     * @param g <code>java.awt.Graphics</code> object.
     * @param x <code>int</code> value of the x axis coordinate.
     * @param y <code>int</code> value of the y axis coordinate.
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
    {
        try
        {
            if (component != null)
            {
                c = component;
            }
            border.paintBorder(c, g, x, y, width, height);
        }
        catch(Exception e)
        {
        }
    }
} // End class

