https://bz.apache.org/bugzilla/show_bug.cgi?id=58787

Javen O'Neal <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[patch] Border Drawing      |[patch] Border utility to
                   |utility that does not       |set cell styles around a
                   |create unnecessary styles   |range of cells

--- Comment #22 from Javen O'Neal <[email protected]> ---
Take a look at the following files:

Common SS:
 - src/java/org/apache/poi/ss/util/RegionUtil.java
   - set the same border style or color on an outer edge of a cell region
   - almost the same as attachment 33684 except does not handle ALL, NONE, and
interior edges of a region
 - src/java/org/apache/poi/ss/usermodel/BorderFormatting.java
   - get/set border styles (dot, dash, etc) and colors
   - implementing classes:
      - src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
          bound to a workbook, CFRuleRecord, and BorderFormatting*
      - src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
          bound to a CTBorder
 - src/java/org/apache/poi/ss/util/CellUtil.java
   - constants for the names of border properties to be used as keys in
get/setCellStyleProperties
   - get/setCellStyleProperties, use a Map that is detached from cells or
styles, then when setting cell style properties, search through existing styles
and add a new style only if no identical style exists.

HSSF:
 - src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java
   - a class to handle the bit-stuffing for records used by
HSSFBorderFormatting

HSSF Examples:
 - src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java
   - a cell style attached to (potentially) multiple cells can be modified one
attribute at a time (border line style, border line color)

HWPF:
 - src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
   - create a border object that is detached from other objects (paragraph,
table)
   - specifies border line width, border style (dot, dash, etc), border color,
border space between text and border, etc, presumably for Text Boxes?

XWPF:
 - src/ooxml/java/org/apache/poi/xwpf/usermodel/Borders.java
   - an enum to hold the ~191 border styles for Word documents

Some of these features were written without enums, so it's pretty messy. Going
forward, it's worthwhile to make these methods enum-friendly (and therefore
type safe).

All of the classes listed above operate on a single border format that could be
applied to a single cell, except for RegionUtil.
RegionUtil sets the styles with CellUtil.setCellStyleProperty immediately,
while PropertyTemplate maintains an internal Map to a Sheet, and explicitly
applies the styles to a sheet with applyBorders.

If two regions do not overlap and the style of each region is homogeneous,
RegionUtil may create *slightly* more intermediate styles (the corners) than
PropertyTemplate. If two regions overlap, RegionUtil is likely to create many
more styles than necessary.

Here's what needs done:
1. DrawingBorders example: Use CellRangeAddress("B2:D5") to make it easier to
see what's going on
2. Unit test: add a test case counting up the number of styles that are in a
workbook before and after. Do the same for RegionUtil and demonstrate that
PropertyTemplate creates significantly fewer intermediate styles. Either look
at total number of cell styles (wb.getNumCellStyles) or number of cell styles
in the styles table that are not referenced by any cells.
3. Try to find more descriptive names for PropertyTemplate and Extent.
BorderUtil/BorderPropertyTemplate and
BorderArrangement/BorderRegionEdges/BorderExtent.
4. Try to integrate your PropertyTemplate code into RegionUtil (might be easier
to copy RegionUtil into PropertyTemplate and rename PropertyTemplate to
RegionUtil).
5. My guess is that the inspiration for this class is to build up a template
that you could stamp onto multiple similarly-formatted sheets. This is a more
common usecase for POI because we deal with computer-generated templates, but
it might not be the most common use case (certainly for entry-level
applications). See if you can make this class more approachable to a wider
audience. If not, then maybe it's better to let BorderPropertyTemplate remain a
separate (higher-level) class from RegionUtil, and not plan to replace
RegionUtil.
6. The _propertyTemplate map is stuck/hidden from a user. What if the user
wants to build up a base template, and fork it with two variations? Potential
solution: add a PropertyTemplate(PropertyTemplate other) constructor that would
deep-copy the Map (I think the Java consensus is that copy constructors are
preferred over clone because it's easier to subclass).
7. Create a blocker to this bug: a re-write/deprecation of short borderTypes in
favor of enums. It'd be a shame to have a shiny new class that uses
non-type-safe borderTypes or bloat your class with short and enum variants of
each method
Most of the SS utilities are static (stateless) methods, but I think your
encapsulation of a complex data structure makes sense.

Please look through the classes that I mentioned, especially CellUtil and
RegionUtil to see if there's anything you can leverage.

Thanks for the hard work!

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to