Color from string for settings etc

This is code to parse a string to color
used 2 of the popular html formats
see code at [url src=http://sel2in.com/pages/prog/java/awt/String_Color_Parser.html]http://sel2in.com/pages/prog/java/awt/String_Color_Parser.html
http://sel2in.com/pages/prog/java/awt/String_Color_Parser.html
Copyright 2008
Contact [email protected] http://sel2in.com
// sel2in.img.dogspa.ImgAdd
package sel2in.awt;
import java.awt.color.*;
import tgk.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import static sel2in.img.dogspa.Consts.*;
* Parse a string representing a color (RGB with optional alpha) quite like it is in html.
* @author [email protected] http://sel2in.com Copyright 2008
public class ColorSetHelper
     public static boolean error = false;
     * Try to parse string as a color else return default passed in.
     * @param s String that should be in format
     * A.  #RRGGBB like #3117A1 or
     * #RRGGBBAA #3117A111 where AA is the alpha component. Each part is 0-255 inclusize or throws an error.
     * B. Another format is rgb(r1, g1, b1) like rgb(45,32, 201)
     * or rgba(45,32, 201, 33) where a is alpha 0 means transparent and 255 means opaque
     * Can also use percentages 0% to 100% :-
     * rgb(r1%, g1%, b1%) like rgb(100%,80%, 90%, 50%) values have to be 0% to 100% inclusive decimels are allowed
     * @param defClr Default Color
     public static Color parseColor(String s, Color defClr){
     public static Color parseHashHexa(String s, Color defClr){
          return c;
     * Testing expects one string value
          rgba(255,7,4,5)
     public static void main(String args[]) {
          ColorSetHelper ap = new ColorSetHelper();
          Color c = ap.parseColor(args[0], Color.white);
          u.sl(c + "\ngetAlpha " + c.getAlpha());
}what did to you think ?

no that did not have rgb(100,1,323,100) and rgba(100,1,323,100) type of decleration that my client was used to in html
last param in rgba is alpha
yeah i cut when i edited the post wanted to copy to my page (actually needed to copy the source but anyway)
i wanted to copy it to my web page [http://sel2in.com/pages/prog/java/awt/String_Color_Parser.html|http://sel2in.com/pages/prog/java/awt/String_Color_Parser.html]
Copyright 2008
Contact [email protected] http://sel2in.com
// sel2in.img.dogspa.ImgAdd
package sel2in.awt;
import java.awt.color.*;
import tgk.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import static sel2in.img.dogspa.Consts.*;
* Parse a string representing a color (RGB with optional alpha) quite like it is in html.
* @author [email protected] http://sel2in.com Copyright 2008
public class ColorSetHelper
     * Indicates if last call resulted in error - as the functions dont throw and error and instead return the default
     * This variable is rest at start of every function call. not thread safe.
     public static boolean error = false;
     * Try to parse string as a color else return default passed in.
     * @param s String that should be in format
     * A.  #RRGGBB like #3117A1 or
     * #RRGGBBAA #3117A111 where AA is the alpha component. Each part is 0-255 inclusize or throws an error.
     * B. Another format is rgb(r1, g1, b1) like rgb(45,32, 201)
     * or rgba(45,32, 201, 33) where a is alpha 0 means transparent and 255 means opaque
     * Can also use percentages 0% to 100% :-
     * rgb(r1%, g1%, b1%) like rgb(100%,80%, 90%, 50%) values have to be 0% to 100% inclusive decimels are allowed
     * @param defClr Default Color
     public static Color parseColor(String s, Color defClr){
          error = false;
          if(s==null || s.length() < 3)return null;
          if(s.charAt(0) == '#'){
               return parseHashHexa(s, defClr);
          StringTokenizer st = new StringTokenizer(s, " ,()");
          //rgba(1,4,2,4)
          String typ = "rgb";
          //boolean alpha = false;//not used works well with both
          if(st.hasMoreTokens()) typ = st.nextToken();
          //if(typ.endsWith("a"))alpha = true;
          int r = 0, g = 0, b = 0 , a = 255;
          Color c = defClr;
          try{
               if(st.hasMoreTokens()){
                    s = st.nextToken();
                    if(s.endsWith("%")){///**/""
                         s = s.substring(0, s.length() -1);
                         r = (int)(Integer.parseInt(s) * 255 / 100);
                    }else{
                         r = Integer.parseInt(s);
                    if(st.hasMoreTokens()){
                         s = st.nextToken();
                         if(s.endsWith("%")){
                              s = s.substring(0, s.length() -1);
                              g = (int)(Integer.parseInt(s) * 255 / 100);
                         }else{
                              g = Integer.parseInt(s);
                         if(st.hasMoreTokens()){
                              s = st.nextToken();
                              if(s.endsWith("%")){
                                   s = s.substring(0, s.length() -1);
                                   b = (int)(Integer.parseInt(s) * 255 / 100);
                              }else{
                                   b = Integer.parseInt(s);
                              if(st.hasMoreTokens()){
                                   s = st.nextToken();
                                   if(s.endsWith("%")){
                                        s = s.substring(0, s.length() -1);
                                        a = (int)(Integer.parseInt(s) * 255 / 100);
                                   }else{
                                        a = Integer.parseInt(s);
          }catch(Throwable e){
               u.sl(e, e);
               error = true;
          try{
               c = new Color(r, g, b, a);
          }catch(Throwable e){
               error = true;
               u.sl(e, e);
          return c;
     public static Color parseHashHexa(String s, Color defClr){
          error = false;
          int r = 0, g = 0, b = 0 , a = 255;
          Color c = defClr;
          try{
               r = Integer.parseInt(s.substring(1,3), 16);
               g = Integer.parseInt(s.substring(3,5), 16);
               b = Integer.parseInt(s.substring(5,7), 16);
               if(s.length() > 7)a = Integer.parseInt(s.substring(7, 9), 16);
          }catch(Throwable e){
               error = true;
               u.sl(e, e);
          }finally{
               try{
                    c = new Color(r, g, b, a);
               }catch(Throwable e){
                    error = true;
                    u.sl(e, e);
          return c;
     * Testing expects one string value
          rgba(255,7,4,5)
     public static void main(String args[]) {
          ColorSetHelper ap = new ColorSetHelper();
          Color c = ap.parseColor(args[0], Color.white);
          u.sl(c + "\ngetAlpha " + c.getAlpha());
}

Similar Messages

  • Converting Color to string eg "#FFFFFFF" etc

    It's possible to convert a string representation to a color by using the Color.decode() method - if I have a color how do I get the string representation?
    Thanks
    Phil

    I don't see anything built into the Color class, but it is pretty easy, I think:    public static String colorString(Color color) {
            return "#" +
                    Integer.toString(color.getRed(), 16) +
                    Integer.toString(color.getGreen(), 16) +
                    Integer.toString(color.getBlue(), 16);
        }Is that what you wanted?
    -- Scott

  • What is the Scan from string pattern for "match everything" ?

    Hello,
    Using Scan from string for a while, I know that %s only matches string up to a whitespace. And I also thought %[^] would match everything including whitespaces. But it turned out that it would stop at the closing square brace.
    So, what is the real scan pattern for match everything including whitespaces ?

    What do you want the Scan From String to end on?  Or are you just grabbing the rest of the string?  If that is your scenario, then just use the "remaining string" output.  It might help if you give a full example of a normal input string and EVERYTHING you want as an output.

  • How do I find images in LR 2.4 (imported from CS4 Bridge) that have color labels already assigned In CS4 Bridge? I have set both Bridge and LR color labels text to match (eg Green for green, etc).

    How do you find images in LR 2.4 that have been imported from CS4 Bridge and have been assigned a color label in Bridge?  I have set both LR 2.4 and my CS4 Bridge to match the text for each color to be the same (eg. Green for green, etc), and the filter search in LR 2.4 shows that a label has been assigned, but I am unable to identify and locate the specific images in LR 2.4 that have had a color label assigned from CS4 Bridge.  I have tried to search via attribute, metadata, text, etc...Is it necessary to re-assign color labels all over again, image by image, in LR 2.4, or is there a way to automatically have the color labels assigned in CS4 Bridge be assigned and searchable to the images after they have been imported into the LR 2.4 catalogue from the Bridge program?

    JohnM.
    I closed both programs and re-imported photos and re-tried the action of having LR  read the XMP metadata from the CS4 files, and it seems to work now just fine...don't know why now and not before, but thanks much. Is there a way to have LR do this automatically upon import of images from CS4?  I tried to do this with an import metadata preset, but no luck.  It seems as if I can only do this once the images have already been imported into LR, and then to have to have LR read the metadata from the CS4 Bridge files.  thanks gain.

  • [svn] 3519: Fix typo in error string for situations where there are advanced messaging configuration settings from LCDS used in the configuration files but no AdvancedMessagingSupport service .

    Revision: 3519
    Author: [email protected]
    Date: 2008-10-08 04:17:40 -0700 (Wed, 08 Oct 2008)
    Log Message:
    Fix typo in error string for situations where there are advanced messaging configuration settings from LCDS used in the configuration files but no AdvancedMessagingSupport service. The error string said that there was no flex.messaging.services.AdvancedMessagingService registered but it is the flex.messaging.services.AdvancedMessagingSupport service that needs to be registered.
    Add configuration test that starts the server with a destination that has the reliable property set which is an advanced messaging feature but there is no AdvancedMessagingSupport service registered.
    Modified Paths:
    blazeds/trunk/modules/common/src/flex/messaging/errors.properties
    Added Paths:
    blazeds/trunk/qa/apps/qa-regress/testsuites/config/tests/messagingService/ReliableDestina tionWithNoAdvancedMessagingSupport/
    blazeds/trunk/qa/apps/qa-regress/testsuites/config/tests/messagingService/ReliableDestina tionWithNoAdvancedMessagingSupport/error.txt
    blazeds/trunk/qa/apps/qa-regress/testsuites/config/tests/messagingService/ReliableDestina tionWithNoAdvancedMessagingSupport/services-config.xml

    Hi,
    Unfortunately I already tried all kinds of re-installs (the full list is in my original message). The only one remaining is the reinstall of Windows 8 itself, which I would really like to avoid.
    What I find really strange is the time it takes for the above error message to appear. It's like one hour or even more (never measured exactly, I left the computer running).
    What kind of a timeout is that? I would expect that, if ports are really used by some other application, I get the message in less than a minute (seconds, actually). To me this looks like the emulator itself for some reason believes there's a problem with
    some port while in reality there isn't.
    I'll eventually contact Microsoft Support, thanks for the suggestion.

  • Adobe Master Collection 5.5,  method of extracting all the presets, settings, etc. from every progra

    Is there an automatic method of extracting all the presets, settings, etc. from every program in the Adobe Master Collection 5.5? 
    I am about to regenerate my Operating System Partitions  from scratch & do not want to go through setting up each & every program in the master collection by hand.

    Adobe does have some pages documenting where it keeps preference et. al. files.  For example, this one for Photoshop CS5:
    http://helpx.adobe.com/photoshop/kb/preference-file-functions-names-locations.html
    I do know that overlaying the contents of the Adobe Photoshop CS5 Settings folder does restore most of the preferences.  The Color Settings are in a file called Color Settings.csf in another folder (depending on OS).  What I don't know is whether there are paths in those files that will differ depending on how you reinstall your system.
    You'll want to reinstall all your plug-ins again, much the same as when you reinstall Photoshop.  But you can make a copy of your Plug-ins subfolders from your 32 and 64 bit Photoshop installation areas just for good measure, to make sure you don't forget some of them.
    As for other programs in the suite...  You'll have to look for that info separately.
    -Noel

  • My ipod was connecting to my home wi-fi just fine until I uploaded new music from my Itunes on my laptop. Now my ipod and my iphone will not connect to my wireless network. I've tried resetting the network settings etc... Nothing seems to work. Help!

    My ipod (version 6.1.3) was connectiong to my home wi-fi just fine until I uploaded new music from my itunes via my laptop. Now my ipod and my iphone will not connect to my wireless network. I've uplugged my wireless network and reset my network settings etc... nothing seems to work. Please help!

    Does the iOS devices connect to other networks?
    Does the iOS devices see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on the router
    - Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar
    Since both iPhone and iPod stopped connecting I suspect a problem with your network.

  • I am getting a "not delivered" when I try to send a photo from my Ipad or iPhone via iMessage. I can receive photos in iMessage and I can send and receive photos other than with iMessage. I have tried restoring factory settings etc but no luck.

    I am getting a "not delivered" when I try to send a photo from my Ipad or iPhone via iMessage. I can receive photos in iMessage and I can send and receive photos other than with iMessage. I have tried restoring factory settings etc but no luck. Is anyone else having this problem please?

    I've been having this problem too, but here's the catch: originally it was only with my dad, and only sometimes.  Now it's dad and husband, every time!  Pix go through, via imessage, to everyone else, and they go through to dad/husband if I "send as text" after it fails. 
    And the other annoying thing- the blue bar will run all the way, and it will say "delivered".  So I close out of imessage. When I reopen it again, the "delivered" has changed to "not delivered" with the red exclamation point.  I just googled "imessage not sending photos" and founds TONS of people with the same problem, but no solutions.  (I have rebooted phone, reset network settings, with no luck.  I even had to backup/delete/restore my whole phone the other day for a different reason, and hoped that would fix it, but now it won't send to my dad OR my husband (who is on not just the same carrier, but the same family plan as me)

  • Encode/Decode a String containing Chinese etc. characters to/from unicode

    Hi, I am working to encode a multilingual String (English, chinese, japanese, Latin etc) as unicode. The encoded string is used as follows
    1)decoded by the User Interface for display purpose. The user interface is a web UI and
    2)read by user. So it should be human readable when it contains only English and special characters.
    Thus having a string that contains letters from English, Japanese, CHinese etc, we want the Japanese/Chinese characters to be encoded by the hex values such as &#31169; be encoded as %E7%A7%81.
    However, it is preferable that other special characters like ! ? , space etc not be encoded and left as such.
    The encoding of characters is achievable by using Java.net.URLEncoder but it also replaces all special characters including space character, which becomes a pain for the reader.
    Unfortunately URLEncoder.java does not have any API to configure which characters to encode. Any suggestions how I can proceed, or what encoder i can use?
    Thanks in advance!
    Regards

    I have to say that I disagree that "%E7%A7%81" is "human-readable". On the contrary, I would say that "&#31169;" is human-readable; even though I don't understand it myself, there are a lot of humans who do.
    But let's say that "human-readable" wasn't the right term. Maybe you just wanted a representation of an arbitrary Unicode string in ASCII characters only. In which case I would recommend Base-64 encoding. It does make everything unreadable, though, whereas your requirements appear to be to only make languages other than English be unreadable. So if you don't like that you are going to have to write your own encoder.
    Note also that your original premise:
    Hi, I am working to encode a multilingual String (English, chinese, japanese, Latin etc) as unicode.is misguided, since all data in Java Strings is already Unicode characters.

  • I have paid and downloaded LION and want to update my IMAC, can i just run install and it keep photos settings etc from Snow Leopard or is a full reinstall with wiped hard drive, anyone have any experience of this and do i need to run a backup beforehand?

    I have paid and downloaded LION and want to update my IMAC, can i just run install and it keep photos settings etc from Snow Leopard or is a full reinstall with wiped hard drive, anyone have any experience of this and do i need to run a backup beforehand?

    Always backup your important data before upgrading to a new Mac OS X.
    Lion doesn't erase the drive but better to be safe than sorry.
    And run Disk Utility  (Applications/Utilities). Verify and if necessary repair the startup disk before upgrading.
    Using Disk Utility to verify or repair disks
    Before upgrading read here >  Lion upgrade questions and answers:  Apple Support Communities
    And here >  What applications are not compatible with Mac OS X 10.7 "Lion"? What upgrade or substitute options are available for common incompatible applications? @ EveryMac.com

  • Getting Color object from String

    hi
    i need to get a Color object from a string provided at runtime.ie for the string "RED" i need to get a object of Color.RED.I have already tried to use decode() from Color class but it throws numberformat exception,can someone guide me.

    Color.decode(String) will decode octal and hexidecimal representations of colors e.g.
    Color poo = Color.decode("0x215DB8"); // hex description of color
    works.
    If you want to use RED, BLUE ... read them at run into a String or whatever and then test this String to get what color the user wanted e.g.
    read from text file at run time that button colour should be ORANGE.
    In your code, put
    String colourStr; // read what colour the user specified into this var
    Color their_color = null;
    if(colour.equals("ORANGE"))
    their_color = new Color(Color.orange);
    else if(colour.equals("BLACK"))
    // you can guess what goes here.. and so on.
    It often nice to make them specify the hex value of the colour because there are more of these than the predefined colours (shock horror).
    Anyway,
    seeya, Edd.

  • I have 3 computers...Window PC, PowerBook G3 (old) and MacBook Pro. I use firefox for all of them and have for quite some time. Is there a way for them all to use the same toolbar? Each of them have differnet bookmark/ settings etc.,

    I have 3 computers...Window PC, PowerBook G3 (old) and MacBook Pro. I use firefox for all of them and have for quite some time. Is there a way for them all to use the same toolbar? Each of them have differnet bookmark/ settings etc.,

    Open Media Encoder and add your Sequences:
    File > Add Premiere Pro Sequence
    Navigate to your Premiere Project and select it in the list.
    You can then select multiple Sequences from the Project (Ctrl+Click)
    and load them all at once into Media Encoder and apply
    the same encoding preset to all Sequences at the same time.

  • How can I change the background of a running webpage on my own. Example Facebook I want to change its backround color from white to black just in my view not for all

    How can I change the background of a running webpage on my own. Example Facebook I want to change its background color from white to black just in my view, not for all. Cause I really hate some site with white background because as I read for an hour it aches my eyes but not on those with darker background color.

    You can use the NoSquint extension to set font sizes (text/page zoom) and text colors on web pages.
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • I have two iCloud accounts, my original one that I used for iTunes years ago which has all my content, apps etc and a mobile me one which I got when I set mobile me up which has all my settings etc, this is causing problems, can I merge them?

    As I said I have two iCloud accounts, both do different things, i.e. my original iTunes account has all my app's and music etc, and then also the account which was set up for me when I set up a 'mobile me' account has all my calendars, contacts, settings etc, how can I merge these or even easily set my settings etc to go to my older iTunes account, I have tried to set up family sharing and all I can share is my calendars not my apps because they are with another iTunes account.
    I am also a little concerned that my fire vault has just set its self up using the mobile me account, if I was to get rid of an account I imagine this would be the easiest one to ditch then what would happen to all my encrypted data?
    Many thanks for your help.
    NIK

    I am logged into the same things on both my iPhone and my MacBook Pro, except for mail. I use a gmail IMAP account and everything there already works on both machines. The iCloud account on my iPhone uses one Apple ID and the one on the Mac uses the second Apple ID.

  • When I try to print from my iPad I see a message "searching for printer" and then "no printer found.".  I have a printer application loaded and it finds my wireless printer.   How do I get the iPad to do the same so I can print from emails, the web, etc?

    When I try to print from my iPad I see a message "searching for printer" and then "no printer found.".  I have a printer application loaded and it finds my wireless printer.   How do I get the iPad to do the same so I can print from emails, the web, etc?  Thanks

    sandrafromsilver spring wrote:
    When I try to print from my iPad I see a message "searching for printer" and then "no printer found.".  I have a printer application loaded and it finds my wireless printer.   How do I get the iPad to do the same so I can print from emails, the web, etc?  Thanks
    Go to the following link:
    http://jaxov.com/2010/11/how-to-enable-airprint-service-on-mac-os-x-10-6-5/

Maybe you are looking for

  • Newbie trying to create an Animated GIF

    I'm a newbie working with FW-CS3 on a Vista environment. I have two images (equal size) from which I want to create an animated gif, whereby they rotate intermittently in an endless loop (i.e. image A displays and then fades into image B, which after

  • Windows borked my external drive's partition map

    I have two partitions on my 1 TB external drive, a ~750 GB HFS+ partition full of huge files (games, iTunes, etc.) and a 150 GB NTFS partition for Steam games (derp TF2 derp). The hard drive was originally in GPT, but now is in MBR due to Windows bei

  • Refresh ALV View when action triggered using button

    Hello Friends, I am getting few records for one year by calling function module from wdoinit method (sy-datum - 360) as default records. I want to also give selection screen if user wants to limit to "Last 30 Days" or "Last 60 Days". (this they can s

  • Error"This order cannot be processed"is appearing  while saving in QA32

    Hi Experts, When I am going for Qa32 transaction after UD code selection I did stock posting, while saving QA32 transaction one error is occuring "Order cannnot be processed". For material inspn type 13 is active. in the last financial year that is t

  • No luck with SCT

    I tried overstock and J Crew and didn't get any pop ups. I even made sure my pop up blocker was off and that I'm opted in for offers. Is it because I was in using my phone? Wasn't sure if that matters or not.