Instantiate CustomColor with android.Color or awt.Color at runtime
hi
i have a swing program that i am refactoring and turning part of it into a library
since i also want to use these classes in android( dalvik vm )
i have a CustomColor class that was using the awt Color class
reduced version:
class CustomColor {
private java.awt.Color myColor;
public CustomColor(java.awt.Color myColor){
this.myColor = myColor;
}now i want this CustomColor to adopt to the vm it is running in
android uses a different Color object
so i want the CustomColor class to detect at runtime which vm it is running in
class CustomColor {
private Object myColor;
public CustomColor(Object myColor){
if(android){
this.myColor =android.myColor;
} else {
this.myColor = awt.myColor;
}i wonder if there is not a better solution to this problem ?
a design pattern ?
thanks for any hints
sc*3
thanks for your answer
my current solution is wrapping each Color class:
class AwtColorWrapper implements ColorInterface{
private awt.Color color;
public Object getColor(){
return color;
}and
class AndroidColorWrapper implements ColorInterface{
private android.Color color;
public Object getColor(){
return color;
}
Similar Messages
-
Display of text of different rows with different color - JTable
Hi all !
I have struck in a problem. I have to display the different rows with different color in the JTable. I have created an arraylist in the model class, which stores color of all the rows. Now in renderer class, I am just picking up color from the arraylist, taking rowIndex as index for arraylist. I used to set foreground color for each row in the renderer class. The problem is that it is not showing all the rows properly, sometimes it show all the rows correctly, but as i resize the window/panel, it starts behaving abnormally, some text is painted properly, but other aren't.
Does anybody have any solution regarding this problem.
One thing i want to mention is that in getTableCellRendererComponent() method, i used to retrive the color everytime, and setting the foreground color of the text. Is this a right approach or some other technique have to be followed.
here is code of renderer class ---
import java.awt.*;
import javax.swing.*;
* Renderer to plot stage record table.
public class ExStageCellRenderer extends javax.swing.table.DefaultTableCellRenderer
Color curColor;
* returns component to be painted, overridding this method from
* DefaultCellRenderer
* @param table
* table whose component has to be plotted
* @param value
* value of that particular cell
* @param isSelected
* is Cell selected
* @param hasFocus
* has the cell got focus
* @param row
* row of the cell
* @param column
* column of the cell
* @return painted component
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
int column)
Component component = super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
ExStageDataModel model = (ExStageDataModel)table.getModel ();
if (curColor instanceof Color) {
curColor = model.getColor(row);
} else {
// If color unknown, use table's foreground color
curColor = table.getForeground();
String tooltip = "";
StringBuffer stringBuffer = new StringBuffer ();
for (int i = 0; i < table.getColumnCount (); i++)
Object Value = table.getValueAt (row, i);
if (Value == null) continue;
stringBuffer.append (Value.toString () + " ");
tooltip += stringBuffer.toString ();
tooltip = tooltip.trim ();
((JComponent) component).setToolTipText (tooltip);
if (column == 1)
this.setHorizontalAlignment (SwingConstants.CENTER);
else if (column == 0 || column == 4 || column == 5)
this.setHorizontalAlignment (SwingConstants.LEFT);
else
this.setHorizontalAlignment (SwingConstants.RIGHT);
// LOOK!! should turn tip off if there is none !!
component.setForeground (this.curColor);
//System.out.println("render : " + component.getBounds ());
//component.validate ();
component.update (component.getGraphics ());
return component;
Waiting for reply....
Code snookerHmm, why are you doing the curColor instanceof? What does this accomplish? I don't see any reason to ask what it was before; all you should be interested in here is what you want it to be now.
All you should have to do is say:
this.setForeground(model.getColor(row));I also don't see why you're doing the update() -- JTable is going to do that for you at the appropriate time, you have no idea if now is the right time to do it or not. In fact it probably isn't, you're probably updating the previously-drawn cell with your new color and alignment, which may be the strange behavior you're seeing.
Also, I don't see why you're doing the super. All that's going to do is return "this", so why not just use "this"?
Well, without knowing your larger code or exactly what you're trying to accomplish, maybe I'm just missing something.
I've just recently been working on a program where I had some similar requirements -- different foreground and background colors and alignment -- and I found it much cleaner to create a class to hold all this data, and then create a default renderer for that class. Then I made some constructors for this "attribute" class that let me set whatever I need, like
public CellAttrib(String s,Color c,int alignment,Border border)
this.s=s;
this.c=c;
this.border=border;
// with suitable defaults ...
pubic CellAtrtrib(String s)
this.s=s;
this.c=Color.BLACK;
this.border=null;
}Then the renderer just queried the cell-attributes class, as in:
setForeground(value.getColor());
setHorizontalAlignment(value.getAlignment());
setBorder(value.getBorder); -
I have an ipad2 and my question is about the calendar. I set up multiple calendars with different colors. Some of the events show up in filled color. Others only show with a colored dot in front of the event. I can't figure out why some show up one way and others show up differently? Any thoughts?
On mine the ones that show on a coloured background are all-day events, the ones with dots and just timed events.
-
Not able to color different rows with different colors in a column of table
Hi,
I am trying to to display different rows with different colors in a column of the table based on some decode condition.
I have gone through the following threads :
Can we colour the rows in the column of a table
Changing Color of a value in a column
This is what i have done :
1.Added the following code to custom.xss(changed the name to Custom.xss as suggested in one of the above threads) --- in path ---- jdev\myhtml\OA_HTML\cabo\styles
<style selector=".1">
<includeStyle name="DefaultFontFamily"/>
<property name="font-size">11pt</property>
<property name="font-weight">Bolder</property>
<property name="color">#008000</property>
<property name="text-indent">3px</property>
</style>
<style selector=".2">
<includeStyle name="DefaultFontFamily"/>
<property name="font-size">11pt</property>
<property name="font-weight">Bolder</property>
<property name="color">#FFFF00</property>
<property name="text-indent">3px</property>
</style>
2. Sql query of the VO is :
select comments,role ,decode(role,'REQUESTER','1','2') Colorattr from xxat_sars_action_history where request_id = :1 and event_name = :2 and action_code <> 'PENDING'
order by sequence_num desc
3. Coded the following in the process request of the controller:
OATableBean table = (OATableBean)webBean.findIndexedChildRecursive("CommentsTB");
OAMessageStyledTextBean roleBN = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("role");
OADataBoundValueViewObject cssjob = new OADataBoundValueViewObject(roleBN,"Colorattr");
roleBN.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, cssjob);
where 1 and 2 form the colors ( i have even tried with 'Red' and 'Yellow'...as it was not working replaced with 1 and 2)
4.The query returns data fine with corresponding 1 and 2 values.
But different colors are not getting reflecting on to the UI.
I am testing this on my local jdev.
Please do let me know if i am missing something.
Thanks ,
Sushma.Any Clues please.....
Thanks,
Sushma. -
my iCal calendar that I created with the color green keeps changing to purple. no matter how many times I change it to green, it turns it back to purple. Of course this only happens with iCloud and not "from my Mac". Any ideas on how to correct this? This seems like a trivial error, but it's super annoying.
I called Apple and they said that they know about this problem. It's a problem with iCloud which their Engineers know about. (there was a new iCloud release, hence...) No ETA for a fix yet. I asked that this be escalated so Engineering doesn't put it at the bottom of their fix list. I talked to a Senior Advisor and mentioned to them to have QA check their regression tests as this has happened before to me (the problem just didn't take this long to resolve). I like to use green too for important stuff, so I've resorted to creating a new calendar using the normal calendar green for events going forward. They could have picked another color besides green to have this problem with and I wouldn't have been so upset. ;-)
-
How to plot with multi colors in a single XY graph?
Hi,
I'm making hesteresis measurements. In this case, I collect data while sweeping voltage first from 0 to 2V, and then back from 2V to 0V, and the data are plotted in a single XY graph. In the XY graph, I want forward sweep plot of one color while the reverse sweep with another color so I can easily make comparisons. And I want to see the data real time. I tried to wire "plot color" in "property node", but this will change the color globally and can not be applied to a section of data. Can anyone advise me how to do this? Thanks!
Guanglei
Solved!
Go to Solution.Hi Graham,
Thank you very much for the reply, I really appreciate it.
However I don't quite understand your descripton. Yes I do spit my data in two arrays, one for forward sweep, and the other for reverse sweep. I can plot with different colors in XY graph by appending several XY graphs into one, but by doing this I can not see the data real time. I quickly made a vi to demonstrate my problem, hope this will give you a better understanding. Thanks.
Guanglei
Attachments:
demo_GL.vi 108 KB -
Hi All,
I need to create a 5/5 matrix in SSRS report. The data will be :
Col_Side Col_Header Col_data
1 1 1
1 1 1
1 2 1
1 5 1
1 5 1
1 5 1
2 3 1
2 5 1
3 1 2
3 1 2
3 1 2
4 2 1
4 4 1
5 1 1
5 1 1
5 5 1
So, the matrix column will be Col_Header and matrix row will be Col_Side and count(Col_data) will be on the data.
Finally, it will create a 5 by 5 matrix with Count(Col_data) as its data for each combinations. If there is no combination (for ex: in the above data we do not have no combination of (1,3) , (1,4) , (2,1) etc..) then the matrix will be filling that corresponding
cell with zero.
Here I need to fill the cells with some colors based on some criteria.
I need to fill (5,3), (5,4), (5,5) combination with "Red" color. Like this , I need to give different colors in each of the cells. Here, (5,5) combination will be having 1 in its cell. (5,4) and (5,3) will be having zero in its corresponding
cells. I 'm trying to fill all the 3 cells with "Red" color. But, I am able to fill only (5,5) with "Red" color. Since the other 2 cells (5,3) and (5,4), has zero in their cells, it will not fill the cells with "Red" color.
How can I fill those two cells (5,3) and (5,4) with red color?
I know this is very vague. I have no option to give the picture here..
Please suggestHi Julie,
According to your description, there is a 5/5 matrix with three fields: Col_Side, Col_Header, Col_data. You drag Col_Side field to Rows, Col_Header to Columns and Col_data to Data, then filling blank cells with zero using expression. Now you want to fill
(5,3), (5,4), (5,5) cells with red color using expression, but it has no effect on cells (5,3) and (5,4).
According to my test, the expression has on effect on cells (5,3) and (5,4) since there is no corresponding data and the cells are blank. As a workaround, we can insert data for cells (5,3) and (5,4) in dataset, then use expression by following steps:
In the dataset, insert two sets of data (5,3,0), (5,4,0).
Right-click the cell of data, click Text Box Properties.
Click Fill in left pane, click (fx) button, then type the expression like below, then click OK.
=iif(Fields!Col_Side.Value=5 and Fields!Col_Header.Value >=3 ,"red","white" )
The following screenshot is for your reference:
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu -
My illustrator CS6 crashes when i try to open an AI file with RGB color mode
My illustrator CS6 crashes when i try to open an AI file with RGB color mode. I worked on this file yesterday and changed it to RGB mode. Today i tried to open the file again but illustrator won't open it and crashes. It does work when i want to open a file with CMYK color mode.
Anyone know how to fix this ?Have you tried trashing the prefs?
-
White with vertical colored lines on Equium A60
Hi
I am new to this but really need your help. My laptop is about 18 months old and has always worked fine. Last week I plugged a broadband modem into it through an Ethernet cable and set up broadband. A couple of minutes after doing this when I looked at the screen again, it had gone all white with vertical colored lines down it. I have rebooted the machine etc and that is all I ever get now. As soon as I switch on, it just goes straight to white with these vertical colored lines.
I have tried connecting an external monitor to it and that works fine. The laptop is a Toshiba Equium A60. I am worried that the screen has blown, is it possible for a surge or something like that to come down the Ethernet cable and blow the screen?
Thanks
AdrianDisplay functionality has nothing to do with Ethernet cable. Test with external monitor is very good and on this way you can see if maybe graphic card is responsible for that.
According to your description I believe that display is the problem. Of course, just intensive display test can give more answers. -
Saving a pdf with seperate colors
Hello guys,
I'm new in here, so i hope my thread is on the right place. If not, please correct it.
I need to know, if it is possible to save a .pdf file (with some printing documents on it: with CMYK colors and PANTONE colors) with seperate colors.
I tried my best but i didn't find something. Google and other websites didn't help me.
I have the Adobe Acrobat Vers. 8
It's no problem to have a look at the seperat colors, but i don't know how to safe it, that the costumer can have a look at those seperat colors too.
So i need a .pdf file with x-sites (for every color a site)
Maybe you can help me.
Thanks in advance and sorry for my bad english
regards
philWhat program are you using to create the original file? You should have options from there when you make it a pdf to print to plates (as .ps for distilling, or as .pdf), or change the color mode to "separations" instead of "composite" under the color options, or something similar. The details depend on what program you're using to create the file.
-
Hi
I have a problem with color prints from photoshop elements 12. The pictures are too light and with strange colors. I have a Canon pixma mg615I0 printer and use mac os X yosemite. The pictures are taken with a coanon eos 550d in the color space sRGB. I have followed adobes recommendations and have tried both letting the printer respektive photoshop manage the colors. But nothing works. I see that there are different opinions about which is best to do so I tried both. I have the latest printer driver installed. Can anyone help me with this?Do the following:
Print a test page from the printer. Perhaps the print head needs cleaning via its maintenance facility.
Let the printer manage colors, not PSE
Calibrate the monitor -
ALV to EXCEL along with the color
Hello,
Is it possible to download an ALV report output to an EXCEL along with the color in the ALV report.I made an ALV report with some rows having red color depending on a bussiness logic. When user downloads the ALV report to excel from standard ALV layout they cannot get the colors in the excel. Is there a way to do this or any sunstitute?
Thanks,
Giri.Hi Giridhar,
Have a look at this code
Download a report to excel with format (border, color cell, etc)
Try this program...it may help you to change the font ..etc.
Code:
REPORT ZSIRI NO STANDARD PAGE HEADING.
this report demonstrates how to send some ABAP data to an
EXCEL sheet using OLE automation.
INCLUDE OLE2INCL.
handles for OLE objects
DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object
H_MAPL TYPE OLE2_OBJECT, " list of workbooks
H_MAP TYPE OLE2_OBJECT, " workbook
H_ZL TYPE OLE2_OBJECT, " cell
H_F TYPE OLE2_OBJECT. " font
TABLES: SPFLI.
DATA H TYPE I.
table of flights
DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
*& Event START-OF-SELECTION
START-OF-SELECTION.
read flights
SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
display header
ULINE (61).
WRITE: / SY-VLINE NO-GAP,
(3) 'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(4) 'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(8) 'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
ULINE /(61).
display flights
LOOP AT IT_SPFLI.
WRITE: / SY-VLINE NO-GAP,
IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
ENDLOOP.
ULINE /(61).
tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
TEXT = TEXT-007
EXCEPTIONS
OTHERS = 1.
start Excel
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
PERFORM ERR_HDL.
SET PROPERTY OF H_EXCEL 'Visible' = 1.
CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
PERFORM ERR_HDL.
tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
TEXT = TEXT-008
EXCEPTIONS
OTHERS = 1.
get list of workbooks, initially empty
CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
PERFORM ERR_HDL.
add a new workbook
CALL METHOD OF H_MAPL 'Add' = H_MAP.
PERFORM ERR_HDL.
tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
TEXT = TEXT-009
EXCEPTIONS
OTHERS = 1.
output column headings to active Excel sheet
PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
PERFORM FILL_CELL USING 1 3 1 'Von'(003).
PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
LOOP AT IT_SPFLI.
copy flights to active EXCEL sheet
H = SY-TABIX + 1.
PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
ENDLOOP.
changes by Kishore - start
CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
PERFORM ERR_HDL.
add a new workbook
CALL METHOD OF H_MAPL 'Add' = H_MAP EXPORTING #1 = 2.
PERFORM ERR_HDL.
tell user what is going on
SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
TEXT = TEXT-009
EXCEPTIONS
OTHERS = 1.
output column headings to active Excel sheet
PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
PERFORM FILL_CELL USING 1 3 1 'Von'(003).
PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
LOOP AT IT_SPFLI.
copy flights to active EXCEL sheet
H = SY-TABIX + 1.
PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
ENDLOOP.
changes by Kishore - end
disconnect from Excel
CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'C:\SKV.XLS'.
FREE OBJECT H_EXCEL.
PERFORM ERR_HDL.
FORM FILL_CELL *
sets cell at coordinates i,j to value val boldtype bold *
FORM FILL_CELL USING I J BOLD VAL.
CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
PERFORM ERR_HDL.
SET PROPERTY OF H_ZL 'Value' = VAL .
PERFORM ERR_HDL.
GET PROPERTY OF H_ZL 'Font' = H_F.
PERFORM ERR_HDL.
SET PROPERTY OF H_F 'Bold' = BOLD .
PERFORM ERR_HDL.
ENDFORM.
*& Form ERR_HDL
outputs OLE error if any *
--> p1 text
<-- p2 text
FORM ERR_HDL.
IF SY-SUBRC <> 0.
WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
STOP.
ENDIF.
ENDFORM. " ERR_HDL
Have a look this Link
http://www.sap-img.com/abap/download-to-excel-with-format-border-color-cell-etc.htm
Regards,
Santosh -
How to add the text box with background color in Acrobat 9 Pro ? (Urgent)
I have previously used the Callout tool to add the comments in a PDF file, but the comments were difficult to read as some of them were mixed with the pictures just shown below. Therefore , I hope that there's a tool that can create the box with background color, but I cannot find such tool. What should I do ? Hope to get the answer ASAP, as it's very urgent !
P.S. The picture below is represent the problem: the comment are difficult to read.In the properties of the callout comment you can change the fill color.
-
How to paste text in Adobe Muse with same color where i copied this text?
How to paste text in Adobe Muse with same color where i copied this text?
Copy&paste is a function of your browser, not the forum software. Ctrl+V will work just fine.
Mylenium -
XY Graph overlay multi plot with different colors
Hi,
I want to do a cyclic X-Y plot in a for loop and plot the graph for each cycle in different colors.
I want a plot like XYgraph2 but with different colors and probably even without that tracing line. How do i modify my diagram?
Thank you for your time and efforts.
SUCHIT
Suchit Shah
Graduate Student
Electrical & Computer Engineering,
Northeastern University,
BOSTON
MA 02115
Certified LabVIEW Associate Developer
Solved!
Go to Solution.
Attachments:
block dia.JPG 45 KB
front dia.JPG 122 KBHi all! This is my first post
My name is Francesco and I'm programming a keithley for measure some FET
using labview 8.6. I plot my output data on a XY graph but I have several curves,
one for each value of Vgs. Looking in your forum I've found the code
MultiplePlots.vi (21 kb) posted by Darin.K about a month ago that use Multiple
plots and it is perfect for my goal because with this I can plot every curve with a
different color. The only problem is that I like to plot my data in real time.
The code, however, use a Loop with N=50, accumulates the values on the edge
and plot at the end of the Loop the entire line.
My question is if someone can explain me how to modify the code to plot the line
point by point, so in real time and not at the end o the loop because I need to see
the current values during the measurement and not only at the end.
I think that I need to move the XYgraph inside the loop. I try but without lucky.
Can anyone help me?
thanks and sorry for my very bad english.
Francesco
Maybe you are looking for
-
Yesterday I had installed Adobe Creative Cloud. There is no Adobe Bridge App in the Adobe Application Manager?
-
HT1414 how to transfer outlook 2010 contacts to iphone 4
I am having trouble transfering Outlook contacts from Outlook 2010 to iphone 4 that I just reset to the factory settings (no contact info). I have several contacts folders in outlook, each one associated with a different email account. When I go to
-
Update for Insert Flash Video command
I looked at DW for the very first time, having recently upgraded all my hardware and software. I now have the full Master Collection - very exciting. Opened DW with great trepidation after a lifetime with my beloved GoLive and was confronted with the
-
DW v8 Won't Let Me "Put" Files
I have just upgraded from an earlier version of Dreamweaver to v8, along with switching from Windows PC to Mac OSX. In my previous version, I had no trouble clicking the 'up-down' arrows to 'put' files onto my remote server via ftp. I have set up the
-
iunes get opened in my pc which has xp but i cant open any page in my itunes everything is blank... any ideas???