ASF Bugzilla – Attachment 21711 Details for
Bug 30311
Conditional formatting not implemented
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Further javadocs and other minor changes (to replace patch 21709)
svn3.diff (text/plain), 6.75 KB, created by
Dmitriy Kumshayev
on 2008-03-25 06:23:18 UTC
(
hide
)
Description:
Further javadocs and other minor changes (to replace patch 21709)
Filename:
MIME Type:
Creator:
Dmitriy Kumshayev
Created:
2008-03-25 06:23:18 UTC
Size:
6.75 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java (revision 640778) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java (working copy) >@@ -27,16 +27,30 @@ > > /** > * HSSFConditionalFormatting class encapsulates all settings of Conditional Formatting. >- * The class is not intended to be used explicitly except cases when there is a need >- * to make a copy HSSFConditionalFormatting settings for some reason. > * >+ * The class can be used >+ * >+ * <UL> >+ * <LI> >+ * to make a copy HSSFConditionalFormatting settings. >+ * </LI> >+ * >+ * > * For example: > * <PRE> > * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index); > * newSheet.addConditionalFormatting(cf); > * </PRE> > * >+ * <LI> >+ * or to modify existing Conditional Formatting settings (formatting regions and/or rules). >+ * </LI> >+ * </UL> >+ * >+ * Use {@link HSSFSheet#getConditionalFormattingAt(int)} to get access to an instance of this class. >+ * <P> > * To create a new Conditional Formatting set use the following approach: >+ * > * <PRE> > * // Create pattern with red background > * HSSFPatternFormatting patternFormatting = new HSSFPatternFormatting(); >@@ -70,23 +84,29 @@ > * > * @author Dmitriy Kumshayev > */ >-public class HSSFConditionalFormatting >+public final class HSSFConditionalFormatting > { >- HSSFSheet sheet; >- CFRecordsAggregate cfAggregate; >+ private final HSSFSheet sheet; >+ private final CFRecordsAggregate cfAggregate; > >- protected HSSFConditionalFormatting(HSSFSheet sheet) >- { >- this.sheet = sheet; >- this.cfAggregate = new CFRecordsAggregate(); >+ HSSFConditionalFormatting(HSSFSheet sheet) { >+ this(sheet, new CFRecordsAggregate()); > } > >- protected HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate) >+ HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate) > { >+ if(sheet == null) { >+ throw new IllegalArgumentException("sheet must not be null"); >+ } >+ if(cfAggregate == null) { >+ throw new IllegalArgumentException("cfAggregate must not be null"); >+ } > this.sheet = sheet; > this.cfAggregate = cfAggregate; > } >- >+ CFRecordsAggregate getCFRecordsAggregate() { >+ return cfAggregate; >+ } > > public void setFormattingRegions(Region[] regions) > { >@@ -97,36 +117,62 @@ > } > } > >+ /** >+ * @return array of <tt>Region</tt>s. never <code>null</code> >+ */ > public Region[] getFormattingRegions() > { > CFHeaderRecord cfh = cfAggregate.getHeader(); > > List cellRanges = cfh.getCellRanges(); > >- if (cellRanges != null) >- { >- return toRegionArray(cellRanges); >- } >- return null; >+ return toRegionArray(cellRanges); > } > >- public void setConditionalFormat(int idx, HSSFConditionalFormattingRule cfRule) >+ /** >+ * set a Conditional Formatting rule at position idx. >+ * Excel allows to create up to 3 Conditional Formatting rules. >+ * This method can be useful to modify existing Conditional Formatting rules. >+ * >+ * @param idx position of the rule. Should be between 0 and 2. >+ * @param cfRule - Conditional Formatting rule >+ */ >+ public void setRule(int idx, HSSFConditionalFormattingRule cfRule) > { > cfAggregate.getRules().set(idx, cfRule); > } > >- public void addConditionalFormat(HSSFConditionalFormattingRule cfRule) >+ /** >+ * add a Conditional Formatting rule. >+ * Excel allows to create up to 3 Conditional Formatting rules. >+ * @param cfRule - Conditional Formatting rule >+ */ >+ public void addRule(HSSFConditionalFormattingRule cfRule) > { > cfAggregate.getRules().add(cfRule); > } >- >- public HSSFConditionalFormattingRule getConditionalFormat(int idx) >+ >+ /** >+ * get a Conditional Formatting rule at position idx. >+ * @param idx >+ * @return a Conditional Formatting rule at position idx. >+ */ >+ public HSSFConditionalFormattingRule getRule(int idx) > { > CFRuleRecord ruleRecord = (CFRuleRecord)cfAggregate.getRules().get(idx); > return new HSSFConditionalFormattingRule(sheet.workbook, ruleRecord); > } > > /** >+ * @return number of Conditional Formatting rules. >+ */ >+ public int getNumbOfRules() >+ { >+ return cfAggregate.getRules().size(); >+ } >+ >+ >+ /** > * Do all possible cell merges between cells of the list so that:<br> > * <li>if a cell range is completely inside of another cell range, it gets removed from the list > * <li>if two cells have a shared border, merge them into one bigger cell range >@@ -237,10 +283,6 @@ > > public String toString() > { >- if(cfAggregate!=null) >- { >- return cfAggregate.toString(); >- } >- return null; >+ return cfAggregate.toString(); > } > } >Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (revision 640697) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (working copy) >@@ -1927,9 +1927,9 @@ > */ > public int addConditionalFormatting( HSSFConditionalFormatting cf ) > { >- HSSFConditionalFormatting cfClone = new HSSFConditionalFormatting(this,cf.cfAggregate.cloneCFAggregate()); >- cfClone.sheet=this; >- return sheet.addConditionalFormatting(cfClone.cfAggregate); >+ CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate(); >+ >+ return sheet.addConditionalFormatting(cfraClone); > } > > /** >@@ -1949,10 +1949,10 @@ > { > for( int i=0; i!= cfRules.length; i++ ) > { >- cf.addConditionalFormat(cfRules[i]); >+ cf.addRule(cfRules[i]); > } > } >- return sheet.addConditionalFormatting(cf.cfAggregate); >+ return sheet.addConditionalFormatting(cf.getCFRecordsAggregate()); > } > > /** >Index: src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java >=================================================================== >--- src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (revision 640697) >+++ src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (working copy) >@@ -44,7 +44,7 @@ > private CFHeaderRecord header; > > // List of CFRuleRecord objects >- private List rules; >+ private final List rules; > > public CFRecordsAggregate() > { >@@ -206,15 +206,12 @@ > { > buffer.append(header.toString()); > } >- if( rules != null ) >+ for(int i=0; i<rules.size(); i++) > { >- for(int i=0; i<rules.size(); i++) >+ CFRuleRecord cfRule = (CFRuleRecord)rules.get(i); >+ if(cfRule!=null) > { >- CFRuleRecord cfRule = (CFRuleRecord)rules.get(i); >- if(cfRule!=null) >- { >- buffer.append(cfRule.toString()); >- } >+ buffer.append(cfRule.toString()); > } > } > buffer.append("[/CF]\n");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 30311
:
21680
|
21681
|
21708
|
21709
| 21711 |
21733
|
21784
|
21789
|
21818