You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Steve Tarlton <st...@gmail.com> on 2009/07/10 08:56:19 UTC

A packaged resource that has a variable image based on component value

I know this is probably very simple to do, but I haven't been able to get my
head wrapped around it. I want to create a component within the column of a
table that has 6 different images associated to it. Each image is tied to a
number as the component is actually an integer representing a state. I
believe I would simply create a packaged resource vary the image it selects
based on the value of the component. I figured maybe someone here on the
list might give me a nudge in the right direction.

BTW: The inmethod datagrid ROCKS!

Re: A packaged resource that has a variable image based on component value

Posted by satar <st...@gmail.com>.
This is what I ended up with to include a solution for my colored circle
images in case someone else finds the need for such a solution. I am
assuming it was a reasonable way to go:

...
    /*
     * Checkbox column for the color blind
     */
    if (colorblind) {
      columns.add(new CheckBoxColumn("checkBox"));
    }

    /*
     * Check Item State column
     */
    columns
        .add(new PropertyColumn(new ResourceModel("state"), "state",
"state") {
          private static final long serialVersionUID = 1L;

          @Override
          public String getCellCssClass(IModel rowModel, int rowNum) {
            return "state";
          }

          @Override
          public boolean isEscapeMarkup() {
            return false;
          }

          @Override
          protected IConverter getConverter(final Class<?> varType) {
            return new IConverter() {
              // serialVersionUID.
              private static final long serialVersionUID = 1L;

              public Object convertToObject(String value,
                  java.util.Locale locale) {
                // TODO Auto-generated method stub
                return null;
              }

              public String convertToString(Object value,
                  java.util.Locale locale) {

                String color = "white";

                switch ((Integer) value) {
                case 0:
                  color = "black";
                  break;
                case 1:
                  color = "gray";
                  break;
                case 2:
                  color = "red";
                  break;
                case 3:
                  color = "yellow";
                  break;
                case 4:
                  color = "blue";
                  break;
                case 5:
                  color = "green";
                }

                if (!colorblind) {
                  return "[lt]img src=\"images/".concat(color).concat(
                      "-circle.png\"").concat(" alt=\"").concat(
                      value.toString()).concat("\[gt]");
                } else {
                  return value.toString();
                }
              }

            };
          }
        }.setInitialSize(3).setSizeUnit(SizeUnit.EM).setResizable(false)
            .setReorderable(true).setHeaderTooltipModel(
                new Model("State of the check item")));
...

where [lt]=<
and [gt]=>
Not sure how to address this problem when replying...

I stored all my image files under webapp/images. I am a beginner with Wicket
but this seemed to work fine for me and I can see it coming up for someone
else so figured I would share my outcome. 
-- 
View this message in context: http://www.nabble.com/A-packaged-resource-that-has-a-variable-image-based-on-component--value-tp24422634p24434326.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A packaged resource that has a variable image based on component value

Posted by satar <st...@gmail.com>.
Seems to have chopped of my return line, which was:

                    return "(less than)font style=\"background-color: " +
color + "\"(greater than)" + value + "(less than)/font(greater than)";

(less than) = <
(greater than) = >

Hope it works this time


satar wrote:
> 
> So I decided that I am not experienced enough yet with Wicket or using
> inmethod DataGrid to try to do images but would like to at least change
> the background color based on an integer value. This is what I did but
> still think it is somewhat lame and probably there is a much better
> approach:
> 
> For my column that contains an Integer in its model I did the following:
> 
>           @Override
>           public boolean isEscapeMarkup() {
>             return false;
>           }
>           
>           @Override
>           protected IConverter getConverter(final Class<?> varType) {
>               return new IConverter() {
>                   //serialVersionUID.
>                   private static final long serialVersionUID = 1L;
> 
>                   public Object convertToObject(String value,
>                       java.util.Locale locale) {
>                     // TODO Auto-generated method stub
>                     return null;
>                   }
> 
>                   public String convertToString(Object value,
>                       java.util.Locale locale) {
>                     
>                     String color = "white";
>                     
>                     switch ((Integer) value) {
>                     case 0 : color = "gray";
>                     case 1 : color = "black";
>                     case 2 : color = "red";
>                     case 3 : color = "yellow";
>                     case 4 : color = "blue";
>                     case 5 : color = "green";
>                     }
>                     return "" + value + "";
>                   }
> 
>               };
>           } 
> 
> 

-- 
View this message in context: http://www.nabble.com/A-packaged-resource-that-has-a-variable-image-based-on-component--value-tp24422634p24424855.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A packaged resource that has a variable image based on component value

Posted by satar <st...@gmail.com>.
So I decided that I am not experienced enough yet with Wicket or using
inmethod DataGrid to try to do images but would like to at least change the
background color based on an integer value. This is what I did but still
think it is somewhat lame and probably there is a much better approach:

For my column that contains an Integer in its model I did the following:

          @Override
          public boolean isEscapeMarkup() {
            return false;
          }
          
          @Override
          protected IConverter getConverter(final Class<?> varType) {
              return new IConverter() {
                  //serialVersionUID.
                  private static final long serialVersionUID = 1L;

                  public Object convertToObject(String value,
                      java.util.Locale locale) {
                    // TODO Auto-generated method stub
                    return null;
                  }

                  public String convertToString(Object value,
                      java.util.Locale locale) {
                    
                    String color = "white";
                    
                    switch ((Integer) value) {
                    case 0 : color = "gray";
                    case 1 : color = "black";
                    case 2 : color = "red";
                    case 3 : color = "yellow";
                    case 4 : color = "blue";
                    case 5 : color = "green";
                    }
                    return "" + value + "";
                  }

              };
          } 

-- 
View this message in context: http://www.nabble.com/A-packaged-resource-that-has-a-variable-image-based-on-component--value-tp24422634p24424827.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A packaged resource that has a variable image based on component value

Posted by satar <st...@gmail.com>.
Okay, I will see if I can figure out how to do that. Currently, I am
@Override-ing the getCellCssClass and seeing if I can vary the css resource
depending on the corresponding columns value as that is the only idea I had
currently on how I could possibly do this.
-- 
View this message in context: http://www.nabble.com/A-packaged-resource-that-has-a-variable-image-based-on-component--value-tp24422634p24423005.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A packaged resource that has a variable image based on component value

Posted by Eelco Hillenius <ee...@gmail.com>.
I would vary the packaged resource rather than having a resource vary
what it points to. That way, you can let browsers cache the image, and
you could potentially move it out of a packaged resource to a static
image some day if you'd want it e.g. to get maximum performance.

Eelco

On Thu, Jul 9, 2009 at 11:56 PM, Steve Tarlton<st...@gmail.com> wrote:
> I know this is probably very simple to do, but I haven't been able to get my
> head wrapped around it. I want to create a component within the column of a
> table that has 6 different images associated to it. Each image is tied to a
> number as the component is actually an integer representing a state. I
> believe I would simply create a packaged resource vary the image it selects
> based on the value of the component. I figured maybe someone here on the
> list might give me a nudge in the right direction.
>
> BTW: The inmethod datagrid ROCKS!
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org