0 Replies Latest reply on Nov 30, 2012 11:36 AM by Fab Mars

    How to create a new RichFace skin real quick

    Fab Mars Novice

      I had to do a new skin for RF in the orange tones, but reaaaal quick, so I though "ok the existing ones are nice, let's just shift their hue".

      Pardon me if the code is not OO, that was meant to be reaaaaal reaaal quick. And I'm sharing it in case you'd need something like that. It's Java7 code btw.

      Overall you get a nice orange skin if you hue blueSky.skin.properties by -167°


      import java.awt.Color;
      import java.io.BufferedReader;
      import java.io.BufferedWriter;
      import java.io.IOException;
      import java.io.StringWriter;
      import java.nio.charset.Charset;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.nio.file.Paths;
      import java.nio.file.StandardOpenOption;
      import java.util.regex.Matcher;
      import java.util.regex.Pattern;
       * Outputs a new Richfaces skin based on an existing one and a number of hue-degrees to shift its colors with.
       * Arguments:
       * - reference skin file
       * - output skin file
       * - number of degrees to shift the colors with
      public class SkinShift {
        public static void main(String[] args) throws IOException {
          Path skinInPath = Paths.get(args[0]);
          Path skinOutPath = Paths.get(args[1]);
          float shift = Float.parseFloat(args[2]); //Degrees
          Charset cs = Charset.forName("US-ASCII");
          Pattern pattern = Pattern.compile("=\\s*#");
          StringWriter sw = new StringWriter();
          try( BufferedReader br = Files.newBufferedReader(skinInPath, cs)) {
            String line;
            while((line = br.readLine()) != null) {
              Matcher m = pattern.matcher(line);
              if(!m.find()) {
              else {
                int hit = m.start();
                sw.append(line.substring(0, hit));
                String hexColor = line.substring(hit+1).trim(); //excl = sign
                //parse color after excl #
                int rgb = Integer.parseInt(hexColor.substring(1), 16);
                Color color = new Color(rgb);
                //convert to HSB
                float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
                //shift HSB
                hsb[0] = (hsb[0] * 360.f + shift) / 360.f; //we shift a number of degrees
                //back to rgb, without alpha value
                int shiftedRgb = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
                String newHexColor = Integer.toHexString(shiftedRgb).substring(2).toUpperCase();
            try(BufferedWriter bw = Files.newBufferedWriter(skinOutPath, cs, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {