001    /* steelme theme manager for Java
002     * Copyright (C) 2000 - 2004 T.J. Willis
003     * 
004     * This program is free software; you can redistribute it and/or
005     * modify it under the terms of the GNU General Public License
006     * as published by the Free Software Foundation; either version 2
007     * of the License, or (at your option) any later version.
008     *      
009     * This program is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     * GNU General Public License for more details.
013     *          
014     * You should have received a copy of the GNU General Public License
015     * along with this program; if not, write to the Free Software
016     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
017     *  
018     * $Header: /cvsroot/steelme/steelme/src/net/sourceforge/steelme/BasicLookAndFeelToCSS.java,v 1.2 2004/05/15 16:11:46 tj_willis Exp $
019     */
020    package net.sourceforge.steelme;
021    import javax.swing.text.html.*;
022    import javax.swing.*;
023    import javax.swing.plaf.*;
024    import javax.swing.plaf.metal.*;
025    
026    
027    /**
028     * A pluggable strategy for converting a LookAndFeel to a Cascading
029     * Stylesheet.
030     * @author <a href="mailto:tj_willis@users.sourceforge.net"> T.J. Willis </a>
031     * @version 1.0
032     */
033    public class BasicLookAndFeelToCSS
034        extends LookAndFeelToCSS {
035    
036        /**
037         * Return a StyleSheet that represents the given LookAndFeel.  This
038         * class only supports MetalLookAndFeel types, it will throw an
039         * UnsupportedLookAndFeelException if passed another type.
040         *
041         * @param laf a <code>LookAndFeel</code> value
042         * @return a <code>StyleSheet</code> value
043         * @exception UnsupportedLookAndFeelException if an error occurs
044         */
045        public StyleSheet convert(LookAndFeel laf)
046        throws UnsupportedLookAndFeelException {
047            if( !(laf instanceof MetalLookAndFeel)) {
048                throw new UnsupportedLookAndFeelException("Cannot convert " + laf + " to stylesheet.");
049            }
050            MetalLookAndFeel mlf = (MetalLookAndFeel)laf;
051            StyleSheet s2 = new StyleSheet();
052            FontUIResource fr = mlf.getUserTextFont();
053            String fontName = fr.getName();
054            int fontsize = fr.getSize();
055            String fgcolor = hexString(mlf.getUserTextColor() );
056            String bgcolor = hexString(mlf.getMenuBackground());//WindowBackground());
057    
058    
059            String tableBgColor = hexString(mlf.getWhite());
060            String tableBorderColor = hexString(mlf.getSeparatorForeground());
061            String hrefColor = hexString(mlf.getBlack());
062            String imgBgColor = hexString(mlf.getWhite());
063    
064            String ff = "font-family: " + fontName +";";
065    
066            //s2.addRule("h1 { color: white; font-family: Helvetica }");
067            String rule = "body{ font-family: " + fontName +";";
068            rule += "color: " + fgcolor +";";
069            rule += "background: " + bgcolor +"}";
070    
071            s2.addRule(rule);
072            s2.addRule("img { background: " + imgBgColor + " ; border-color: " + tableBorderColor +"}");
073    
074            s2.addRule("a  { color: " + hrefColor + "}");
075            s2.addRule("hr { color: " + fgcolor +" }");
076            s2.addRule("h1,h2,h3,h4,h5,h6 { font-family: +" + fontName + "}");
077            //s2.addRule("table { background-color: " + bgcolor + "; color: " + fgcolor + "; border-color: " + tableBorderColor + "; + ff }");
078            //s2.addRule("tr { background-color: " + bgcolor + "; color: " + fgcolor + "; border-color: " + tableBorderColor + "; + ff }");
079            //s2.addRule("td { background-color: " + bgcolor + "; color: " + fgcolor + "; border-color: " + tableBorderColor + "; + ff }");
080            s2.addRule("div.box {background-color: " + tableBgColor + ";border-color: " + tableBorderColor + ";");
081            s2.addRule("div.firstletter {border-color: " + tableBorderColor + " }");
082            //      System.out.println("S2---->[");
083            //      dump(s2);
084            //      System.out.println("]<-----S2");
085            return s2;
086    
087    
088        }
089    
090    
091    }