Okay here my little CSS solution for wicket, so if u have had my headache, you can use it. Please if you have more powerful regex approach...teach me please. May not be killer but it works just fine for me.

In your CSS File (textfield.css):

.textfieldStyle {
 background: url(${myImage});
}

In your Wicket Code:
PackageResourceReference imageRef = new
PackageResourceReference(MyPanel.class , "image.gif");

CSSSettings css = new CSSSettings(
MyPanel.class,"textfield.css");

String imageRefString =
urlFor
css.addAttribute("myImage ",);
      
//and according to igor

add(new StringHeaderContributor(css.getStyle());



/*

 * CSSSettings.java
 *
 * Created on July 20, 2006, 3:15 AM
 *
 * Wicket lover license :)
 * www.dabarobjects.com
 */

package net.cowblock.wicketx.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.URL;
import java.util.Hashtable;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import wicket.Resource;
import wicket.WicketRuntimeException;

/**
 *
 * @author Aladejebi Ayodeji (dabar)
 */
public class CSSSettings implements Serializable {
    private Map customStyle;
   
    private static final Pattern customAttrRegex = Pattern.compile("[$][{][a-zA-Z]++[-]?+[a-zA-Z]++[}]|[$][{][a-zA-Z]++[}]");
    private static final Pattern innerAttrValue = Pattern.compile("[a-zA-Z]++[-]?+[a-zA-Z]++|[a-zA-Z]++");
    private String css;
    private URL cssPath;
    private Class scope;
    /** Creates a new instance of CSSSettings */
    public CSSSettings(Class cssScope, String cssFileName) {
        customStyle = new Hashtable();
       
        URL path =  cssScope.getResource(cssFileName);
       
        if(path == null)
            throw new WicketRuntimeException("CSS Resource missing");
       
        this.cssPath = path;
       
        this.scope = cssScope;
       
       
    }
    /**
     * You will define this in your CSS File
     * list-style-image: url(${bgimage});
     * and add <strong>bgimage</strong> as attribute, then use urlFor(ResourceReference) to insert value
     */
    public void addAttribute(String attribute, String value){
        this.customStyle.put(attribute,value);
    }
    public void removeAttribute(String attribute){
        this.customStyle.remove(attribute);
    }
    public String getCss(){
        Matcher _attrDefMatch = null;
        Matcher _attrValueMatch = null;
       
        StringBuffer buffer = new StringBuffer();
        try {
           
            BufferedReader read = new BufferedReader(new InputStreamReader( cssPath.openStream()));
            String r ="";
            while((r = read.readLine()) != null){
                _attrDefMatch = customAttrRegex.matcher(r);
               
                while(_attrDefMatch.find()){
                   
                    _attrValueMatch = innerAttrValue.matcher(_attrDefMatch.group());
                   
                    while(_attrValueMatch.find()){
                        //System.out.println(_attrValueMatch.group());
                        String key = _attrValueMatch.group();
                        if(customStyle.containsKey(key.trim()))
                            r = r.replaceAll("[$][{][a-zA-Z]++[-]?+[a-zA-Z]++[}]|[$][{][a-zA-Z]++[}]",
                                    customStyle.get(key.trim()).toString());
                    }
                }
                buffer.append(r);
               
            }
           
           
        } catch (IOException ex) {
            throw new WicketRuntimeException(ex);
        }
      
        return buffer.toString();
    }
    //TODO:
     private Resource getAsResource() {
        return null;
    }
    public static void main(String args[]){
        CSSSettings set = new CSSSettings(CSSSettings.class,"FormX.css");
       
        set.addAttribute("bgimage","web.gif");
        set.addAttribute("line-color","#343444");
       
        System.out.println(set.getCss());
    }

  
   
}


On 7/19/06, Igor Vaynberg < [EMAIL PROTECTED] > wrote:
or you can do add(new StringHeaderContributor(css.getStyle()); instead of using a label

-Igor


On 7/19/06, Ayodeji Aladejebi < [EMAIL PROTECTED]> wrote:
well it doesnt necessarily have to be like that...anything that reduces stress for developers will always fly in dev space. so may things can be worked out...but i believe that more CSS support is needed in wicket. I am making something that looks like this for my project.


CssMap css = CssMap.parseCSS(MyPanel.class, "style.css");

css.add("bg-image",urlFor(imageReference));  // replaces ${bg-image} with image path

add(new Label("styleHead", css.getStyle());


this works fine for me now though still crappy but suits my work for now.




On 7/19/06, Julian Klappenbach < [EMAIL PROTECTED]> wrote:
In general, I doubt that you're going to find much support for that kind of approach.  This is because you'd be hard-coding styles into the component, which make them difficult to "skin" later on without changing code.
 
-jjk


From: [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED] ] On Behalf Of Ayodeji Aladejebi
Sent: Wednesday, July 19, 2006 1:46 AM
To: wicket-user@lists.sourceforge.net
Subject: Re: [Wicket-user] More CSS support in wicket?

Please can one regex expert give me the regex for retrieving name from ${name}?

Thanks and for CSS integration, i dream of this:

@CSS (
 font-family="Verdana",
[EMAIL PROTECTED]("bg.gif,MyPanel.class")}
)
private class MyPanel extends Panel {

}

will generate this header for the panel:

<style type="text/css">
.[panel_id] {
 font-family="Verdana...";
}
</style>

its a dream :)

On 7/19/06, Jean-Baptiste Quenot < [EMAIL PROTECTED]> wrote:
* Eelco Hillenius:
> Did you take a look at what's in wicket.extensions.util.resource? I
> think that package has exactly what you are looking for, e.g.
> PackagedTextTemplate.

I can't find it neither in Wicket's API documentation nor in
Wicket Extensions's.  Do you have a link please?
--
     Jean-Baptiste Quenot
aka  John Banana Qwerty
http://caraldi.com/jbq/

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user



--

"It takes insanity to drive in sanity" - Me

Aladejebi Ayodeji A.,
DabarObjects Solutions
Email: [EMAIL PROTECTED]
Mobile: +234 803 589 1780
Web: www.dabarobjects.com


-------------------------------------------------------------------------

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user





--
"It takes insanity to drive in sanity" - Me

Aladejebi Ayodeji A.,
DabarObjects Solutions
Email: [EMAIL PROTECTED]
Mobile: +234 803 589 1780
Web: www.dabarobjects.com

Community:
www.cowblock.net

-------------------------------------------------------------------------

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user




-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user





--
"It takes insanity to drive in sanity" - Me

Aladejebi Ayodeji A.,
DabarObjects Solutions
Email: [EMAIL PROTECTED]
Mobile: +234 803 589 1780
Web: www.dabarobjects.com

Community:
www.cowblock.net
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to