View | Details | Raw Unified | Return to bug 30311
Collapse All | Expand All

(-)C:/Documents and Settings/dq/workspace/poi/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java (-6 / +17 lines)
Lines 113-132 Link Here
113
		if( regions != null)
113
		if( regions != null)
114
		{
114
		{
115
			CFHeaderRecord header = cfAggregate.getHeader();
115
			CFHeaderRecord header = cfAggregate.getHeader();
116
			
117
			if( header==null)
118
			{
119
				header=new CFHeaderRecord();
120
				cfAggregate.setHeader(header);
121
			}
116
			header.setCellRanges(mergeCellRanges(toCellRangeList(regions)));
122
			header.setCellRanges(mergeCellRanges(toCellRangeList(regions)));
117
		}
123
		}
118
	}
124
	}
119
125
120
	/**
126
	/**
121
	 * @return array of <tt>Region</tt>s. never <code>null</code>
127
	 * @return array of <tt>Region</tt>s. never <code>null</code> 
122
	 */
128
	 */
123
	public Region[] getFormattingRegions()
129
	public Region[] getFormattingRegions()
124
	{
130
	{
125
		CFHeaderRecord cfh = cfAggregate.getHeader();
131
		CFHeaderRecord cfh = cfAggregate.getHeader();
126
132
		if( cfh != null)
127
		List cellRanges = cfh.getCellRanges();
133
		{
128
134
			List cellRanges = cfh.getCellRanges();
129
		return toRegionArray(cellRanges);
135
			return toRegionArray(cellRanges);
136
		}
137
		else
138
		{
139
			return new Region[0];
140
		}
130
	}
141
	}
131
142
132
	/**
143
	/**
Lines 153-159 Link Here
153
	 */
164
	 */
154
	public void addRule(HSSFConditionalFormattingRule cfRule)
165
	public void addRule(HSSFConditionalFormattingRule cfRule)
155
	{
166
	{
156
		cfAggregate.getRules().add(cfRule);
167
		cfAggregate.getRules().add(cfRule.getCfRuleRecord());
157
	}
168
	}
158
169
159
	/**
170
	/**
(-)C:/Documents and Settings/dq/workspace/poi/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java (-8 / +14 lines)
Lines 26-32 Link Here
26
26
27
/**
27
/**
28
 * 
28
 * 
29
 * High level representation of Conditional Format  
29
 * High level representation of Conditional Formatting Rule.
30
 * It allows to specify formula based conditions for the Conditional Formatting
31
 * and the formatting settings such as font, border and pattern.
30
 * 
32
 * 
31
 * @author Dmitriy Kumshayev
33
 * @author Dmitriy Kumshayev
32
 */
34
 */
Lines 48-55 Link Here
48
    
50
    
49
    
51
    
50
52
51
	private CFRuleRecord cfRuleRecord;
53
	private final CFRuleRecord cfRuleRecord;
52
	private HSSFWorkbook workbook;
54
	private final HSSFWorkbook workbook;
53
	
55
	
54
	protected HSSFConditionalFormattingRule(HSSFWorkbook workbook)
56
	protected HSSFConditionalFormattingRule(HSSFWorkbook workbook)
55
	{
57
	{
Lines 63-68 Link Here
63
		this.cfRuleRecord = cfRuleRecord;
65
		this.cfRuleRecord = cfRuleRecord;
64
	}
66
	}
65
67
68
	CFRuleRecord getCfRuleRecord()
69
	{
70
		return cfRuleRecord;
71
	}
72
	
66
	/** 
73
	/** 
67
	 *  Keep Font Formatting unchanged for this Conditional Formatting Rule 
74
	 *  Keep Font Formatting unchanged for this Conditional Formatting Rule 
68
	 */
75
	 */
Lines 128-134 Link Here
128
		setFormula1(formula1);
135
		setFormula1(formula1);
129
		
136
		
130
		// Formula 2
137
		// Formula 2
131
		setFormula1(formula2);
138
		setFormula2(formula2);
132
	}
139
	}
133
	
140
	
134
	public void setFormulaCondition(String formula)
141
	public void setFormulaCondition(String formula)
Lines 138-144 Link Here
138
		setFormula1(formula);
145
		setFormula1(formula);
139
	}
146
	}
140
	
147
	
141
	public void setFormula1(String formula)
148
	private void setFormula1(String formula)
142
	{
149
	{
143
		// Formula 1
150
		// Formula 1
144
		if( formula != null)
151
		if( formula != null)
Lines 159-165 Link Here
159
		}
166
		}
160
	}
167
	}
161
	
168
	
162
	public void setFormula2(String formula)
169
	private void setFormula2(String formula)
163
	{
170
	{
164
		// Formula 2
171
		// Formula 2
165
		if( formula != null)
172
		if( formula != null)
Lines 243-248 Link Here
243
			return null;
250
			return null;
244
		}
251
		}
245
	}
252
	}
246
	
253
247
	
248
}
254
}
(-)C:/Documents and Settings/dq/workspace/poi/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java (-1 / +121 lines)
Lines 113-119 Link Here
113
    public final static short BORDER_SLANTED_DASH_DOT =  BorderFormatting.BORDER_SLANTED_DASH_DOT;
113
    public final static short BORDER_SLANTED_DASH_DOT =  BorderFormatting.BORDER_SLANTED_DASH_DOT;
114
114
115
    
115
    
116
	private BorderFormatting borderFormatting;
116
	private final BorderFormatting borderFormatting;
117
	
117
	
118
	public HSSFBorderFormatting()
118
	public HSSFBorderFormatting()
119
	{
119
	{
Lines 124-128 Link Here
124
	{
124
	{
125
		return borderFormatting;
125
		return borderFormatting;
126
	}
126
	}
127
128
	public short getBorderBottom()
129
	{
130
		return borderFormatting.getBorderBottom();
131
	}
132
133
	public short getBorderDiagonal()
134
	{
135
		return borderFormatting.getBorderDiagonal();
136
	}
137
138
	public short getBorderLeft()
139
	{
140
		return borderFormatting.getBorderLeft();
141
	}
142
143
	public short getBorderRight()
144
	{
145
		return borderFormatting.getBorderRight();
146
	}
147
148
	public short getBorderTop()
149
	{
150
		return borderFormatting.getBorderTop();
151
	}
152
153
	public short getBottomBorderColor()
154
	{
155
		return borderFormatting.getBottomBorderColor();
156
	}
157
158
	public short getDiagonalBorderColor()
159
	{
160
		return borderFormatting.getDiagonalBorderColor();
161
	}
162
163
	public short getLeftBorderColor()
164
	{
165
		return borderFormatting.getLeftBorderColor();
166
	}
167
168
	public short getRightBorderColor()
169
	{
170
		return borderFormatting.getRightBorderColor();
171
	}
172
173
	public short getTopBorderColor()
174
	{
175
		return borderFormatting.getTopBorderColor();
176
	}
177
178
	public boolean isBackwardDiagonalOn()
179
	{
180
		return borderFormatting.isBackwardDiagonalOn();
181
	}
182
183
	public boolean isForwardDiagonalOn()
184
	{
185
		return borderFormatting.isForwardDiagonalOn();
186
	}
187
188
	public void setBackwardDiagonalOn(boolean on)
189
	{
190
		borderFormatting.setBackwardDiagonalOn(on);
191
	}
192
193
	public void setBorderBottom(short border)
194
	{
195
		borderFormatting.setBorderBottom(border);
196
	}
197
198
	public void setBorderDiagonal(short border)
199
	{
200
		borderFormatting.setBorderDiagonal(border);
201
	}
202
203
	public void setBorderLeft(short border)
204
	{
205
		borderFormatting.setBorderLeft(border);
206
	}
207
208
	public void setBorderRight(short border)
209
	{
210
		borderFormatting.setBorderRight(border);
211
	}
212
213
	public void setBorderTop(short border)
214
	{
215
		borderFormatting.setBorderTop(border);
216
	}
217
218
	public void setBottomBorderColor(short color)
219
	{
220
		borderFormatting.setBottomBorderColor(color);
221
	}
222
223
	public void setDiagonalBorderColor(short color)
224
	{
225
		borderFormatting.setDiagonalBorderColor(color);
226
	}
227
228
	public void setForwardDiagonalOn(boolean on)
229
	{
230
		borderFormatting.setForwardDiagonalOn(on);
231
	}
232
233
	public void setLeftBorderColor(short color)
234
	{
235
		borderFormatting.setLeftBorderColor(color);
236
	}
237
238
	public void setRightBorderColor(short color)
239
	{
240
		borderFormatting.setRightBorderColor(color);
241
	}
242
243
	public void setTopBorderColor(short color)
244
	{
245
		borderFormatting.setTopBorderColor(color);
246
	}
127
    
247
    
128
}
248
}
(-)C:/Documents and Settings/dq/workspace/poi/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (+6 lines)
Lines 167-172 Link Here
167
		return header;
167
		return header;
168
	}
168
	}
169
169
170
	public void setHeader(CFHeaderRecord header)
171
	{
172
		this.header = header;
173
	}
174
170
	/**
175
	/**
171
	 * @return the rules
176
	 * @return the rules
172
	 */
177
	 */
Lines 218-221 Link Here
218
		buffer.append("[/CF]\n");
223
		buffer.append("[/CF]\n");
219
		return buffer.toString();
224
		return buffer.toString();
220
	}
225
	}
226
221
}
227
}
(-)C:/Documents and Settings/dq/workspace/poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java (+87 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.hssf.usermodel;
18
19
import junit.framework.TestCase;
20
21
import org.apache.poi.hssf.util.HSSFColor;
22
import org.apache.poi.hssf.util.Region;
23
24
public class TestHSSFConfditionalFormatting extends TestCase
25
{
26
    public void testLastAndFirstColumns() 
27
    {
28
        HSSFWorkbook workbook = new HSSFWorkbook();
29
        HSSFSheet sheet = workbook.createSheet();
30
        String formula = "7";
31
        
32
        HSSFFontFormatting fontFmt = new HSSFFontFormatting();
33
        fontFmt.setFontStyle(true, false);
34
        
35
        HSSFBorderFormatting bordFmt = new HSSFBorderFormatting();
36
        bordFmt.setBorderBottom(HSSFBorderFormatting.BORDER_THIN);
37
        bordFmt.setBorderTop(HSSFBorderFormatting.BORDER_THICK);
38
        bordFmt.setBorderLeft(HSSFBorderFormatting.BORDER_DASHED);
39
        bordFmt.setBorderRight(HSSFBorderFormatting.BORDER_DOTTED);
40
        
41
        HSSFPatternFormatting patternFmt = new HSSFPatternFormatting();
42
        patternFmt.setFillBackgroundColor(HSSFColor.RED.index);
43
        
44
        HSSFConditionalFormattingRule [] cfRules = new HSSFConditionalFormattingRule[]
45
        {
46
            sheet.createConditionalFormattingRule(formula, fontFmt, bordFmt, patternFmt),
47
            sheet.createConditionalFormattingRule(HSSFConditionalFormattingRule.COMPARISON_OPERATOR_BETWEEN, "1", "2", fontFmt, bordFmt, patternFmt)
48
        };
49
        
50
        short col = 1;
51
        Region [] regions = new Region[]
52
        {
53
        	new Region(1,col,-1,col)
54
        };
55
        
56
        sheet.addConditionalFormatting(regions, cfRules);
57
        sheet.addConditionalFormatting(regions, cfRules);
58
        
59
        // Verification
60
        assertEquals(2, sheet.getNumConditionalFormattings());
61
        sheet.removeConditionalFormatting(1);
62
        assertEquals(1, sheet.getNumConditionalFormattings());
63
        HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(0);
64
        assertNotNull(cf);
65
        
66
        regions = cf.getFormattingRegions();
67
        assertNotNull(regions);
68
        assertEquals(1, regions.length);
69
        Region r = regions[0];
70
        assertEquals((short)1, r.getColumnFrom());
71
        assertEquals((short)1, r.getColumnTo());
72
        assertEquals(1, r.getRowFrom());
73
        assertEquals(-1, r.getRowTo());
74
        
75
        assertEquals(2, cf.getNumbOfRules());
76
77
        HSSFConditionalFormattingRule rule1 = cf.getRule(0);
78
        assertEquals("7",rule1.getFormula1()); 
79
        assertNull(rule1.getFormula2());
80
        
81
        HSSFConditionalFormattingRule rule2 = cf.getRule(1);
82
        assertEquals("2",rule2.getFormula2()); 
83
        assertEquals("1",rule2.getFormula1()); 
84
        
85
    }
86
87
}

Return to bug 30311