Fill color in hssf cell - apache-poi

I have been adding background as shown below. All other changes are seen in the excel but cell does not get filled with the color. please help
public static CellStyle getWeeklyHeaderStyle(HSSFWorkbook wb) {
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setWrapText(true);
cellStyle.setAlignment((short) 1);
cellStyle.setVerticalAlignment((short) 1);
cellStyle.setBorderLeft((short) 1);
cellStyle.setBorderRight((short) 1);
cellStyle.setBorderTop((short) 1);
cellStyle.setBorderBottom((short) 1);
getPalette(wb);
cellStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
cellStyle.setFont(getFont(wb));
return cellStyle;
}
public static HSSFPalette getPalette(HSSFWorkbook wb) {
HSSFPalette palette = wb.getCustomPalette();
// replacing the standard red with freebsd.org red
palette.setColorAtIndex(IndexedColors.RED.index, (byte) 204, (byte) 204,
(byte) 255);
return palette;
}

Related

Processing- What could be possible errors of svg file not displayed?

I'm trying to display an svg image with Processing, but it would only show a blank white space. I don't think there is any problem with the code as it works perfectly when I change the shape to ellipse. Do I have to modify any code below to display the svg file, or is there any other possible reasons why it wouldn't show? Thanks in advance!
Table table;
PFont f;
PShape leaf;
color [] c = {color(225, 50, 50), color(225, 100, 0), color(225, 225, 0), color(0, 150, 0), color(0), color(125)};
int i=0;
void setup() {
size(1100, 500);
background(255);
table=loadTable("P3_data.csv", "header");
leaf= loadShape("leaf.svg");
leaf.disableStyle();
}
void draw() {
stroke(255);
strokeWeight(0.1);
for (TableRow row : table.rows()) {
int friend= (row.getInt("Friend"));
int travel= (row.getInt("Travel"));
int selfimprovement= (row.getInt("Self-improvement"));
int club= (row.getInt("Club"));
int schoolwork= (row.getInt("Schoolwork"));
int money= (row.getInt("Money"));
int total= 0;
int [] Daily= {friend, travel, selfimprovement, club, schoolwork, money};
for (int k=0; k<6; k++) {
total +=Daily[k];
}
println (total);
for (int j=0; j<6; j++) {
for (int m=0; m< Daily[j]; m++) {
fill(c[j]);
ellipse((i%120)*10+10, (i/120)*40+10, 3*total, 4*total);
//shape(leaf, (i%120)*10+10, (i/120)*40+10, 3*total, 3*total);
total --;
}
}
if (i>1095) {
break;
}
i++;
}
save("sketch.png");
}
See the documentation of disableStyle()
Shapes are loaded with style information that tells them how to draw (the color, stroke weight, etc.) The disableStyle() method of PShape turns off this information. The enableStyle() method turns it back on.
If you want to display the SVG with its style, the you have to remove the disableStyle call:
leaf = loadShape("leaf.svg");
leaf.disableStyle();
If you want to change the stroke and fill color of the shape generated form the *svg" file, then indeed you have to disable the style:
leaf= loadShape("leaf.svg");
leaf.disableStyle();
In this case the shape is drawn with the current fill and stroke color. This means that all the shape is filled with the same fill color and drawn with the same stroke color:
for (int m=0; m< Daily[j]; m++) {
stroke(0, 0, 255); // blue
fill(255, 0, 0); // red
shape(leaf, (i%120)*10+10, (i/120)*40+10, 3*total, 3*total);
total --;
}

Control image placement on JTextPane

I am able to add ImageIcons to a JTextPane, but when I add them they show up in the center of the JTextPane. I can't find a way to control where they are placed on the JTextPane. Can someone please help me with this?
This method is making the JTextPane:
private void loadTextPanel(JPanel contentPane) {
chatLogPanel = new JPanel();
chatLogPanel.setLayout(null);
EmptyBorder eb = new EmptyBorder(new Insets(10, 10, 10, 10));
DefaultStyledDocument document = new DefaultStyledDocument();
chatLog = new JTextPane(document);
chatLog.setEditorKit(new WrapEditorKit());
chatLog.setBorder(eb);
chatLog.setMargin(new Insets(5, 5, 5, 5));
chatLogScrollPane = new JScrollPane(chatLog);
addComponent(chatLogPanel, chatLogScrollPane, 0, 0, 500, 240);
addComponent(contentPane, chatLogPanel, 0, 40, 500, 240);
}
This is the code I'm using to add a string to the Panel:
private static void appendToChatLog(JTextPane tp, String msg, Color c) {
chatLog.setEditable(true);
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
aset = sc.addAttribute(aset, StyleConstants.Alignment, Integer.valueOf(3));
int len = tp.getDocument().getLength();
tp.setCaretPosition(len);
tp.setCharacterAttributes(aset, false);
tp.replaceSelection(msg);
chatLog.setEditable(false);
}
And this is what I'm currently using to add the image to the JTextPane:
BufferedImage image = generateBufferedImage(message.getImage());
Icon icon = new ImageIcon(image);
StyleContext context = new StyleContext();
StyledDocument document = (StyledDocument) chatLog.getDocument();
Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
JLabel label = new JLabel(icon);
StyleConstants.setComponent(labelStyle, label);
try {
document.insertString(document.getLength(), "Ignored", labelStyle);
} catch (BadLocationException badLocationException) {
badLocationException.printStackTrace();
}
To insert a component to a JTextPane, and display it like a character, use the insertComponent method.
To insert an Icon instead, use the insertIcon method.
Quite intuitive isn't it ;)

ProcessingJS modify stroke-width in SVG

I would like to dynamically set the stroke-width of an SVG curve from within a ProcessingJS sketch.
So far, the only solution that I have found is to use disableStyle() on the SVG shape and then manually set all of the style attributes like Fill(), stroke(), strokeJoin() and strokeWeight(). However, the opacity of the line seems to render differently when executed this way.
Is there some way to access and modify only the stroke-width and leave the other styles unchanged?
Here is the code that I have so far. It seems to work okay, but it would be nice not to have to manually reset all the style attributes that were in the original svg file.
/* #pjs preload="frog_trajs.svg"; */
PShape trajs;
float zoom_factor = 1.0;
float imgW;
float ingH;
float lineWeight = 1.00;
//panning variables
float centerX;
float centerY;
boolean active = false;
PFont f;
void setup()
{
size(900, 600);
frameRate(20);
centerX = width/2;
centerY = height/2;
trajs = loadShape("frog_trajs.svg");
trajs.disableStyle();
imgW = trajs.width;
imgH = trajs.height;
}
void draw()
{
background(255);
//here, the styles are reset, with lineWeight dynamically updated by mouseScrolled()
shapeMode(CENTER);
strokeJoin(ROUND);
strokeWeight(lineWeight);
stroke(#EF25B2,170);
noFill();
shape(trajs,centerX,centerY,imgW,imgH);
}
void mouseScrolled()
{
if(active){
if(mouseScroll > 0)
{
//zoom out;
zoom_factor = 1 - mouseScroll*0.01;
}
else
{
//zoom in;
zoom_factor = 1 - mouseScroll*0.01;
}
lineWeight = lineWeight/zoom_factor;
}
}
void mouseOver(){
active = true;
}
void mouseOut(){
active = false;
}

Change color title UITable static section

I have two UITable static sections in my application with both different headers.
The color of the header must be changed because the custom background.
How can I do this solution like ( link ) in my MonoTouch application?
Because I use static sections, I don't have a UITableViewSource where I can do stuff in.
My solution (thanks to Krumelur)
[Export("tableView:viewForHeaderInSection:")]
UIView GetViewForHeaderInSecion (UITableView tableview, int section)
{
UIView view = new UIView (new RectangleF (0, 0, 300, 0));
view.BackgroundColor = UIColor.Clear;
UILabel label = new UILabel (new RectangleF (15, 5, 300, 25));
label.BackgroundColor = UIColor.Clear;
label.TextColor = UIColor.White;
label.ShadowColor = UIColor.Black;
label.ShadowOffset = new SizeF(0, 1);
label.Font = UIFont.BoldSystemFontOfSize(18);
if (section == 0) {
label.Text = "First section";
} else {
label.Text = "Second section";
}
view.AddSubview(label);
return view;
}
You'll have to export the missing method in your controller. Something like:
[Export("tableView:viewForHeaderInSection:")]
UIView GetViewForHeaderInSection(UITableView tableview, int section
{
// return your UIView with whatever background color here
}
Note that you cannot change the color of the predefined view but have to return an entire view instead.

how to change background color of a static text control (when a button is pushed or in a timer) in mfc?

I know it can be done with OnCtlColor(), but it changes colors when the form is being loaded and the static texts are to be drawn, I want to do it after form is loaded, with a timer maybe, I searched for a solution but I didn't find a clear one, this is what I wrote:
void CTabFive::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CWnd* pWnd = this->GetDlgItem(IDC_Chromosome1);
CDC* dc = pWnd->GetDC();
dc->SetBkColor(RGB(200,0,0));
pWnd->Invalidate();
pWnd->UpdateWindow();
Invalidate();
UpdateWindow();
//flag = true;
}
No timer is needed. Here I have a bool m_coloured member of the class initialized to false, and toggled in the button press. The OnCtlColor will draw in red or in the system colour depending on the value of m_coloured. Works nicely.
HBRUSH Cmfcvs2010Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_LABEL)
{
DWORD d = GetSysColor(COLOR_BTNFACE);
COLORREF normal = RGB(GetRValue(d), GetGValue(d), GetBValue(d));
COLORREF red = RGB(255, 0, 0);
pDC->SetBkColor(m_coloured ? red : normal);
}
return hbr;
}
void Cmfcvs2010Dlg::OnBnClickedButton1()
{
m_coloured = !m_coloured;
Invalidate();
}

Resources