Converting string to color
I have a String str = "red" . how do i convert this to Color.red .
Hmm... I see two possibilities..
1. You make a Hashtable with entries like this:
hash.put ("red", Color.red);
hash.put ("blue", Color.blue);
//etc. etc.2. You take a look what reflect can do.. ;-)
(java.lang.reflect)
I'd suggest the thing with the hashtable; it's easier and faster. :)
CUL8er,
Nick.
Similar Messages
-
Converting Strings to Color Objects
Greetings All -
I'm in my first Java class (I was a C programmer in the 80s!) and am a little stumped on an assigment. Your help will be much appreciated.
I have to read color strings out of an HTML file and put them in a HashMap (a small applet assignment). I've been unable to find an elegant method for converting from a string to a color object.
Please let me know if I'm stuck with a big nested if or am I overlooking something?
Thank you -
GargoyleThis will handle #rrggbb strings, and also the dozen or so colors defined by name (red, cyan, etc) in the static fields of java.awt.Color:
static Color stringToColor (String s)
try {
return Color.decode(s);
} catch (Exception e) {}
try {
return (Color) Color.class.getField(s).get(null);
} catch (Exception e) {}
System.out.println("bad color string: " + s);
return null;
} -
How can i open the "Convert to Indexed Color" dialog with custom presets?
Hi,
I need to automatically open the "Convert to Indexed Colors" dialog in Photoshop. Before and after that i have some scripts running so its not possible to open the dialog manually. Also i want to set some custom presets (like number of colors etc.).
Found something similar to what i want for the Color Range selection (opens the dialog with the presets you put in):
function colorrange(enabled, withDialog, fuzziness) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putInteger(app.charIDToTypeID('Fzns'),fuzziness);
var desc2 = new ActionDescriptor();
desc2.putDouble(app.charIDToTypeID('Lmnc'), 31.22);
desc2.putDouble(app.stringIDToTypeID("a"), 0.86);
desc2.putDouble(app.stringIDToTypeID("b"), 0.31);
desc1.putObject(app.charIDToTypeID('Mnm '), app.charIDToTypeID('LbCl'), desc2);
var desc3 = new ActionDescriptor();
desc3.putDouble(app.charIDToTypeID('Lmnc'), 95.34);
desc3.putDouble(app.stringIDToTypeID("a"), 54.59);
desc3.putDouble(app.stringIDToTypeID("b"), 49.85);
desc1.putObject(app.charIDToTypeID('Mxm '), app.charIDToTypeID('LbCl'), desc3);
desc1.putInteger(app.stringIDToTypeID("colorModel"), 0);
var desc4 = new ActionDescriptor();
var desc4 = executeAction(app.stringIDToTypeID('colorRange'), desc1, dialogMode);
How can i achieve the same for the indexed color conversion dialog? Apart from doing a lot of guessing regarding the stringIDs.
Is there some kind of "lookup table" for char and string IDs?
Thank you guys in advance! This forum has been a great help many times.Ok never mind i got it, stupid me.
Recorded it with Script Listener and changed the "DialogMode" parameter of the executeAction function from "DialogModes.No" to "DialogModes.All".
var idCnvM = charIDToTypeID( "CnvM" );
var desc249 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var desc250 = new ActionDescriptor();
var idPlt = charIDToTypeID( "Plt " );
var idClrP = charIDToTypeID( "ClrP" );
var idSele = charIDToTypeID( "Sele" );
desc250.putEnumerated( idPlt, idClrP, idSele );
var idClrs = charIDToTypeID( "Clrs" );
desc250.putInteger( idClrs, 4 );
var idFrcC = charIDToTypeID( "FrcC" );
var idFrcC = charIDToTypeID( "FrcC" );
var idNone = charIDToTypeID( "None" );
desc250.putEnumerated( idFrcC, idFrcC, idNone );
var idTrns = charIDToTypeID( "Trns" );
desc250.putBoolean( idTrns, false );
var idDthr = charIDToTypeID( "Dthr" );
var idDthr = charIDToTypeID( "Dthr" );
var idDfsn = charIDToTypeID( "Dfsn" );
desc250.putEnumerated( idDthr, idDthr, idDfsn );
var idDthA = charIDToTypeID( "DthA" );
desc250.putInteger( idDthA, 75 );
var idIndC = charIDToTypeID( "IndC" );
desc249.putObject( idT, idIndC, desc250 );
executeAction( idCnvM, desc249, DialogModes.ALL ); //Change from NO to ALL -
Question on converting #FFFFFF to Color
Yea, I'm new at this but am having fun!. I have written an applet to replace and applet that I downloaded a few months ago. I need to set the colors of the foreground and background from <PARAM> tags in html. My question is how can I convert #FFFFFF that will be in the param tag to a Color object for setForeground() and setBackgroud()? I'm using a swing Applet.
Test this little program that convert any hexadecimal color to an RGB color :
import java.awt.*;
public class ColorConverter {
public static void main(String[] args) {
getColorFromHtml(0xffffff);
getColorFromHtml(0xff0000);
getColorFromHtml(0x00ff00);
getColorFromHtml(0x0000ff);
public static Color getColorFromHtml(int htmlColor) {
int red = htmlColor>>16;
int green = (htmlColor>>8)&0x00ff;
int blue = htmlColor&0x0000ff;
System.out.println("red :" +red+" green : "+green+" blue : "+blue);
return(new Color(red, green, blue));
}------ unformatted version -----
import java.awt.*;
public class ColorConverter {
public static void main(String[] args) {
getColorFromHtml(0xffffff);
getColorFromHtml(0xff0000);
getColorFromHtml(0x00ff00);
getColorFromHtml(0x0000ff);
public static Color getColorFromHtml(int htmlColor) {
int red = htmlColor>>16;
int green = (htmlColor>>8)&0x00ff;
int blue = htmlColor&0x0000ff;
System.out.println("red :" red" green : "+green+" blue : "+blue);
return(new Color(red, green, blue));
Before that you have to convert the string #FFFFFF to an int :
String s = "#FFFFFF";
s = s.substring(1);
int hexColor = Integer.parseInt(s, 16);
Color rgb = getColorFromHtml(hexColor);
Denis -
Not able to convert string attribute to number and date please help me out
not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out
Hi,
You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
regards,
Nick -
How can I convert a pages color document to a PDF Black and White doc.
How can I convert a pages color document to a PDF Black and White doc. Or, covert the color to B&W in a new doc?
> How can I convert a pages color document to a PDF Black and White doc. Or, covert the color to B&W in a new doc?
The general idea is that you colour correct photographs once, archive, and convert with or without colour changes. The archived photograph is unchanged - or we would be colour correcting the same photographs again and again and again.
If you have a photograph with a corrected exposure, you can open the photograph in the Apple ColorSync Utility, apply a colour space conversion to a grayscale appearance using the preinstalled ICC profile, save the photograph under another name, and place that in your pagination.
If you have a paginated document with corrected exposures, and any such non-scalable bitmap or scalable spline graphics as you have chosen to add, you can render the pagination as a whole to PDF through the same ICC profile, carrying out the same colour space conversion on any and all objects.
Caveat: If you intend the pagination for certain processes, in particular offset lithography, then you are probably expected not to render the type to grayscale, but rather to render it to single ink solid black. No software can determine what printing process you intend, you have to understand a bit about printing, and how to set up general colour space conversions in software. Ask your prepress provider, and if the answer is not prompt and proficient, pick another provider.
/hh -
Convert String to Date and Format the Date Expression in SSRS
Hi,
I have a parameter used to select a month and year string that looks like: jun-2013
I can convert it to a date, but what I want to do is, when a user selects a particular month-year (let's say "jun-2013")
I populate one text box with the date the user selected , and (the challenge Im having is) I want to populate a text box next to the first text box with the month-year 2 months ahead. So if the user selects
jun-2013 textbox A will show jun-2013
and textbox B will show aug-2013..
I have tried:
=Format(Format(CDate(Parameters!month.Value ),
"MM-YYYY" )+ 2 ) -- But this gives an error
This returns the month in number format like "8" for august...
=Format(Format(CDate(Parameters!month.Value ),
"MM" )+ 2 )
What is the proper syntax to give me the result in this format = "aug-2013" ???
Thanks in advance.
MC
M CollierYou can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
In your case, the code would be something like:
var sDate = "2013-01-10";
// Convert string to date
var oDate = util.scand("yyyy-mm-dd", sDate);
// Convert date to new string
var sDate2 = util.printd("mm/dd/yyyy", oDate);
// Set a field value
getField("date2").value = sDate2;
The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started. -
Convert String variable value to an Object referece type
Hi all,
I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
Let's think that there is a string variable name like,
String name="HelloWorld";
and there is a class name same to the variable value.
class HelloWorld
I am passing this string variable value to a method which is going to make a object of helloworld;
new convertobj().convert("HelloWorld");
class convertobj{
public void convert(String name){
// in hert it is going to create the object of HelloWorld;
// HelloWorld hello=new HelloWorld(); just like this.
now i want to do this from the name variable value.( name na=new name()) like wise.
please let me know if there any possible way to do that.
I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
thanx.Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
John -
Converting from indexed color to grayscale no longer works in CS4
I have a number of files to convert from indexed colors to grayscale. Did some but clicked "don't show me again" box on the Discard Colors warning. Now I can't make the conversion. Everything looks fine, but when I close file, then reopen, it's reverted to indexed colors - restarting Photoshop or the computer doesn't help.
I'd appreciate any help....Thanks, GrantGrant,
All your contact information is posted to the web. These forums are crawled by bots harvesting info.
I don't think you want additional junk mail, unsolicited phone call scams, and possible attempts to crack your website, do you?
People here recommend not to post contact info. Perhaps a forum moderator can remove your personal info, but you might be able to edit your post yourself.
GIF only uses indexed color mode, So if you want your files to NOT be in the Indexed Color mode you need to save them as another file format like .png or .jpg -
How to convert string to an integer in SQL Server 2008
Hi All,
How to convert string to an integer in sql server,
Input : string str="1,2,3,5"
Output would be : 1,2,3,5
Thanks in advance.
Regards,
SunilNo, you cannot convert to INT and get 1,2,3 BUT you can get
1
2
3
Is it ok?
CREATE FUNCTION [dbo].[SplitString]
@str VARCHAR(MAX)
RETURNS @ret TABLE (token VARCHAR(MAX))
AS
BEGIN
DECLARE @x XML
SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
INSERT INTO @ret
SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
FROM @x.nodes('//t') x(i)
RETURN
END
----Usage
SELECT * FROM SplitString ('1,2,3')
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How to convert String (dd-MMM-yyyy) to oracle.jbo.domain.Date
Hi
Could you please tell how do I convert String of date in format dd-MM-yyyy to ADF date? Please show me some sample.
Thankshttp://javaalmanac.com/egs/java.text/FormatDateDef.html
Once you have a java.util.Date you can convert it to oracle.jbo.domain.Date. (see http://www.fifkredit.com/bc4jdoc/rt/oracle/jbo/domain/Date.html) -
Convert from spot color to custom CMYK value in Applescript
I thought this would be very simple and it's not apparently. I am trying to convert a spot color into a custom CMYK value. Basically:
tell application "Adobe Illustrator"
set theList to every path item of current document
repeat with k from 1 to count of theList
if fill color of item k of theList = {name:"Dark Green"} then
set fill color of item k of theList to {cyan:0.0, magenta:100.0, yellow:0.0, black:0.0}
end if
end repeat
end tell
But this script obviously doesn't work. From what I can tell, the fill color simply returns the tint of the item, not the name of it. I can't find anything that returns the name of a spot color so I can set the correct corresponding color. In the above example, I made the color obviously changed so I could visually see the result.
Any advice would be greatly appreciated! I'm a first time poster here.
Thanks!tell application "Adobe Illustrator"
tell current document
set theList to every path item
set sw to every swatch
repeat with i from 1 to count of sw
set swname to name of item i of sw
if swname = "Dark Green" then
set swco to color of item i of sw
repeat with k from (count of theList) to 1 by -1
set co to fill color of item k of theList
if swco = co then
set fill color of item k of theList to {cyan:0.0, magenta:100.0, yellow:0.0, black:0.0}
end if
end repeat
end if
end repeat
end tell
end tell -
Facing problem in converting string to date using getOANLSServices()
I am trying to set a value for date field in my vo and trying to insert into the table.
In controller I am getting the String which has a date:
ex: String date="01-NOV-2007";
while setting into the row I need to convert into Date but it is returning null.
The below code I used
to convert into date :
Date dt = new Date(getOADBTransaction().getOANLSServices().stringToDate(date));
But this dt is returning a null value is there any solution please advise me.
Regards!
SmarajeetSmarajeet ,
See this thread, in one of my replies i have mentioned how to convert string to java.sql.date.You can use the same for oracle.jbo.domain.Date.
urgent!How to set the default selected date for an OAMessageDateFieldBean
--Mukul -
Converting String To XML Format and send as attachment
Hi
My requirement is to convert String into XML Format and that XML File i have to send as an attachment
can any one one give solution for this Problem.
Thank you
Venkatesh.Khi,
i m filling the itab first and converting to xml
itab contaning these data
GS_PERSON-CUST_ID = '3'.
GS_PERSON-FIRSTNAME = 'Bill'.
GS_PERSON-LASTNAME = 'Gates'.
APPEND GS_PERSON TO GT_PERSON.
GS_PERSON-CUST_ID = '4'.
GS_PERSON-FIRSTNAME = 'Frodo'.
GS_PERSON-LASTNAME = 'Baggins'.
APPEND GS_PERSON TO GT_PERSON.
after conversion data is coming like that
#<?xml version="1.0" encoding="utf-16"?>
<CUSTOMERS>
<item>
<customer_id>0003</customer_id>
<first_name>Bill</first_name>
<last_name>Gates</last_name>
</item>
<item>
<customer_id>0004</customer_id>
<first_name>Frodo</first_name>
<last_name>Baggins</last_name>
</item>
</CUSTOMERS>
but errors are 1) # is coming at the first
2)for 'encoding="utf-16"?>', it is not coming perfectly, some other data (iso-8859-1) should come here
can anybody plz solve it.
regards,
viki -
Converting string to XML format
Hi All,
I have a requirement to convert string to xml format and download it. Atpresent, I have a string which is a collection of xml tags. I want to convert this string to xml format like <VALUE004>20387899.437</VALUE004>
<VALUE005>20387899.437</VALUE005>
<VALUE006>20387899.437</VALUE006>
Is there any function module for this.Chk this thread.
Re: Regd: File Conversion to XML format
Maybe you are looking for
-
How to change the language of itunes on my iPhone4
I recently bought an iPhone 4 and the itunes language is set to korean or something and I can't seem to find any way of changing it to english. Can someone help me with that?
-
How big a deal is the shared memory for video editing
Hi, It looks like the portable Mac I have been waiting for has been released. The one thing that I am wondering about is the shared video? memory. How big a deal is it? It looks like it should not be an issue with iMovie. How about FCE? With the Macb
-
I've suddenly lost the ability to run a slideshow
For some reason, I lost the ability to run a slide show when in the event view. It worked moments ago. I created a show, selected music saved and now it wont work for that event or any other.
-
How to insert address into email link in Acrobat V10.
Can't find this option on the upgraded version of Acrobat. I asked this question before and did not receive an answer. Prior question: http://forums.adobe.com/message/4766511#4766511
-
JSF Page Creation wizard title configuration uses old values!
I just noticed that if you don't explicit change the value of the page's title in the JSF Page Creation Wizard, the page created will get the title from the last page where you changed the title. Tested in JDev 10.1.3.1Production and JDev 10.1.3.1 Pr