poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1779866 [1/3] - in /poi/trunk/src: examples/src/org/apache/poi/hssf/usermodel/examples/ examples/src/org/apache/poi/hssf/view/ examples/src/org/apache/poi/ss/examples/html/ java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/usermodel...
Date Sun, 22 Jan 2017 22:01:23 GMT
Author: kiwiwings
Date: Sun Jan 22 22:01:22 2017
New Revision: 1779866

URL: http://svn.apache.org/viewvc?rev=1779866&view=rev
Log:
#59836 - Tracker: Replace primitives with enums
preparation for removing those many HSSFColor subclasses with an enum

Modified:
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/HSSFHtmlHelper.java
    poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
    poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestPaletteRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
    poi/trunk/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java
    poi/trunk/src/testcases/org/apache/poi/hssf/util/TestHSSFColor.java

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java Sun Jan 22 22:01:22 2017
@@ -17,19 +17,22 @@
 
 package org.apache.poi.hssf.usermodel.examples;
 
-import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFDataFormat;
+import org.apache.poi.hssf.usermodel.HSSFFont;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+
 /**
  * Demonstrates many features of the user API at once.  Used in the HOW-TO guide.
- *
- * @author Glen Stampoultzis (glens at apache.org)
- * @author Andrew Oliver (acoliver at apache.org)
  */
 public class BigExample {
     public static void main(String[] args) throws IOException {
@@ -56,17 +59,17 @@ public class BigExample {
         //set font 1 to 12 point type
         f.setFontHeightInPoints((short) 12);
         //make it red
-        f.setColor(HSSFColor.RED.index);
+        f.setColor(HSSFColorPredefined.RED.getIndex());
         // make it bold
         //arial is the default font
-        f.setBoldweight(Font.BOLDWEIGHT_BOLD);
+        f.setBold(true);
 
         //set font 2 to 10 point type
         f2.setFontHeightInPoints((short) 10);
         //make it the color at palette index 0xf (white)
-        f2.setColor(HSSFColor.WHITE.index);
+        f2.setColor(HSSFColorPredefined.WHITE.getIndex());
         //make it bold
-        f2.setBoldweight(Font.BOLDWEIGHT_BOLD);
+        f2.setBold(true);
 
         //set cell stlye
         cs.setFont(f);
@@ -74,11 +77,11 @@ public class BigExample {
         cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
 
         //set a thin border
-        cs2.setBorderBottom(CellStyle.BORDER_THIN);
+        cs2.setBorderBottom(BorderStyle.THIN);
         //fill w fg fill color
-        cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+        cs2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
         // set foreground fill to red
-        cs2.setFillForegroundColor(HSSFColor.RED.index);
+        cs2.setFillForegroundColor(HSSFColorPredefined.RED.getIndex());
 
         // set the font
         cs2.setFont(f2);
@@ -143,7 +146,7 @@ public class BigExample {
 
         // define the third style to be the default
         // except with a thick black border at the bottom
-        cs3.setBorderBottom(CellStyle.BORDER_THICK);
+        cs3.setBorderBottom(BorderStyle.THICK);
 
         //create 50 cells
         for (int cellnum =0; cellnum < 50; cellnum++) {

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java Sun Jan 22 22:01:22 2017
@@ -25,7 +25,7 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.BorderStyle;
 
 /**
@@ -46,13 +46,13 @@ public class Borders {
         // Style the cell with borders all around.
         HSSFCellStyle style = wb.createCellStyle();
         style.setBorderBottom(BorderStyle.THIN);
-        style.setBottomBorderColor(HSSFColor.BLACK.index);
+        style.setBottomBorderColor(HSSFColorPredefined.BLACK.getIndex());
         style.setBorderLeft(BorderStyle.THIN);
-        style.setLeftBorderColor(HSSFColor.GREEN.index);
+        style.setLeftBorderColor(HSSFColorPredefined.GREEN.getIndex());
         style.setBorderRight(BorderStyle.THIN);
-        style.setRightBorderColor(HSSFColor.BLUE.index);
+        style.setRightBorderColor(HSSFColorPredefined.BLUE.getIndex());
         style.setBorderTop(BorderStyle.MEDIUM_DASHED);
-        style.setTopBorderColor(HSSFColor.ORANGE.index);
+        style.setTopBorderColor(HSSFColorPredefined.ORANGE.getIndex());
         cell.setCellStyle(style);
 
         // Write the output to a file

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java Sun Jan 22 22:01:22 2017
@@ -28,7 +28,7 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 
 /**
  * Demonstrates how to work with excel cell comments.
@@ -81,7 +81,7 @@ public class CellComments {
         font.setFontName("Arial");
         font.setFontHeightInPoints((short)10);
         font.setBold(true);
-        font.setColor(HSSFColor.RED.index);
+        font.setColor(HSSFColorPredefined.RED.getIndex());
         string.applyFont(font);
 
         comment2.setString(string);

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java Sun Jan 22 22:01:22 2017
@@ -25,7 +25,7 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.FillPatternType;
 
 /**
@@ -41,7 +41,7 @@ public class FrillsAndFills {
 
         // Aqua background
         HSSFCellStyle style = wb.createCellStyle();
-        style.setFillBackgroundColor(HSSFColor.AQUA.index);
+        style.setFillBackgroundColor(HSSFColorPredefined.AQUA.getIndex());
         style.setFillPattern(FillPatternType.BIG_SPOTS);
         HSSFCell cell = row.createCell(1);
         cell.setCellValue("X");
@@ -49,7 +49,7 @@ public class FrillsAndFills {
 
         // Orange "foreground", foreground being the fill foreground not the font color.
         style = wb.createCellStyle();
-        style.setFillForegroundColor(HSSFColor.ORANGE.index);
+        style.setFillForegroundColor(HSSFColorPredefined.ORANGE.getIndex());
         style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
         cell = row.createCell(2);
         cell.setCellValue("X");

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java Sun Jan 22 22:01:22 2017
@@ -28,13 +28,11 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.hssf.usermodel.HSSFHyperlink;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.Font;
 
 /**
  * Demonstrates how to create hyperlinks.
- *
- * @author Yegor Kozlov (yegor at apach.org)
  */
 public class Hyperlinks {
 
@@ -47,7 +45,7 @@ public class Hyperlinks {
         HSSFCellStyle hlink_style = wb.createCellStyle();
         HSSFFont hlink_font = wb.createFont();
         hlink_font.setUnderline(Font.U_SINGLE);
-        hlink_font.setColor(HSSFColor.BLUE.index);
+        hlink_font.setColor(HSSFColorPredefined.BLUE.getIndex());
         hlink_style.setFont(hlink_font);
 
         HSSFCell cell;

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java Sun Jan 22 22:01:22 2017
@@ -18,6 +18,8 @@
 
 package org.apache.poi.hssf.view;
 
+import static org.apache.poi.hssf.view.SVTableUtils.getAWTColor;
+
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Font;
@@ -25,7 +27,6 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.util.EventObject;
-import java.util.Map;
 
 import javax.swing.AbstractCellEditor;
 import javax.swing.JTable;
@@ -37,7 +38,7 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.hssf.usermodel.HSSFFont;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.FillPatternType;
 
 /**
@@ -47,10 +48,8 @@ import org.apache.poi.ss.usermodel.FillP
  * @author     Jason Height
  */
 public class SVTableCellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener {
-  private static final Color black = getAWTColor(new HSSFColor.BLACK());
-  private static final Color white = getAWTColor(new HSSFColor.WHITE());
-  private Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
-
+  private static final Color black = getAWTColor(HSSFColorPredefined.BLACK);
+  private static final Color white = getAWTColor(HSSFColorPredefined.WHITE);
 
   private HSSFWorkbook wb;
   private JTextField editor;
@@ -67,7 +66,7 @@ public class SVTableCellEditor extends A
    * @return    The cellEditable value
    */
   @Override
-public boolean isCellEditable(java.util.EventObject e) {
+  public boolean isCellEditable(java.util.EventObject e) {
     if (e instanceof MouseEvent) {
       return ((MouseEvent) e).getClickCount() >= 2;
     }
@@ -76,7 +75,7 @@ public boolean isCellEditable(java.util.
 
 
   @Override
-public boolean shouldSelectCell(EventObject anEvent) {
+  public boolean shouldSelectCell(EventObject anEvent) {
     return true;
   }
 
@@ -88,7 +87,7 @@ public boolean shouldSelectCell(EventObj
 
 
   @Override
-public boolean stopCellEditing() {
+  public boolean stopCellEditing() {
     System.out.println("Stop Cell Editing");
     fireEditingStopped();
     return true;
@@ -96,14 +95,14 @@ public boolean stopCellEditing() {
 
 
   @Override
-public void cancelCellEditing() {
+  public void cancelCellEditing() {
     System.out.println("Cancel Cell Editing");
     fireEditingCanceled();
   }
 
 
   @Override
-public void actionPerformed(ActionEvent e) {
+  public void actionPerformed(ActionEvent e) {
     System.out.println("Action performed");
     stopCellEditing();
   }
@@ -115,7 +114,7 @@ public void actionPerformed(ActionEvent
    * @return    The cellEditorValue value
    */
   @Override
-public Object getCellEditorValue() {
+  public Object getCellEditorValue() {
     System.out.println("GetCellEditorValue");
     //JMH Look at when this method is called. Should it return a HSSFCell?
     return editor.getText();
@@ -128,7 +127,7 @@ public Object getCellEditorValue() {
    * @return             The tableCellEditorComponent value
    */
   @Override
-public Component getTableCellEditorComponent(JTable table, Object value,
+  public Component getTableCellEditorComponent(JTable table, Object value,
       boolean isSelected,
       int row,
       int column) {
@@ -142,18 +141,26 @@ public Component getTableCellEditorCompo
 
           int fontstyle = Font.PLAIN;
 
-          if (isbold) fontstyle = Font.BOLD;
-          if (isitalics) fontstyle = fontstyle | Font.ITALIC;
+          if (isbold) {
+            fontstyle = Font.BOLD;
+          }
+          if (isitalics) {
+            fontstyle = fontstyle | Font.ITALIC;
+          }
 
           int fontheight = f.getFontHeightInPoints();
-          if (fontheight == 9) fontheight = 10; //fix for stupid ol Windows
+          if (fontheight == 9) {
+            fontheight = 10; //fix for stupid ol Windows
+          }
 
           Font font = new Font(f.getFontName(),fontstyle,fontheight);
           editor.setFont(font);
 
           if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) {
             editor.setBackground(getAWTColor(style.getFillForegroundColor(), white));
-          } else editor.setBackground(white);
+          } else {
+            editor.setBackground(white);
+          }
 
           editor.setForeground(getAWTColor(f.getColor(), black));
 
@@ -202,18 +209,4 @@ public Component getTableCellEditorCompo
     }
     return editor;
   }
-
-    /** This method retrieves the AWT Color representation from the colour hash table
-     *
-     */
-    private final Color getAWTColor(int index, Color deflt) {
-      HSSFColor clr = colors.get(index);
-      if (clr == null) return deflt;
-      return getAWTColor(clr);
-    }
-
-    private static final Color getAWTColor(HSSFColor clr) {
-      short[] rgb = clr.getTriplet();
-      return new Color(rgb[0],rgb[1],rgb[2]);
-    }
 }

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableUtils.java Sun Jan 22 22:01:22 2017
@@ -18,12 +18,16 @@
 
 package org.apache.poi.hssf.view;
 
-import java.util.*;
-import java.awt.*;
-import javax.swing.border.*;
-
-import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.hssf.util.*;
+import java.awt.Color;
+import java.awt.Font;
+import java.util.Map;
+
+import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
+
+import org.apache.poi.hssf.usermodel.HSSFFont;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 
 /**
  * SVTableCell Editor and Renderer helper functions.
@@ -33,9 +37,9 @@ import org.apache.poi.hssf.util.*;
 public class SVTableUtils {
   private final static Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
   /**  Description of the Field */
-  public final static Color black = getAWTColor(new HSSFColor.BLACK());
+  public final static Color black = getAWTColor(HSSFColorPredefined.BLACK);
   /**  Description of the Field */
-  public final static Color white = getAWTColor(new HSSFColor.WHITE());
+  public final static Color white = getAWTColor(HSSFColorPredefined.WHITE);
   /**  Description of the Field */
   public static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
 
@@ -44,7 +48,7 @@ public class SVTableUtils {
    *  Creates a new font for a specific cell style
    */
   public static Font makeFont(HSSFFont font) {
-    boolean isbold = font.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
+    boolean isbold = font.getBold();
     boolean isitalics = font.getItalic();
     int fontstyle = Font.PLAIN;
     if (isbold) {
@@ -63,31 +67,20 @@ public class SVTableUtils {
     return new Font(font.getFontName(), fontstyle, fontheight);
   }
 
-
-  /**
-   * This method retrieves the AWT Color representation from the colour hash table
+  /** This method retrieves the AWT Color representation from the colour hash table
    *
-   * @param  index  Description of the Parameter
-   * @param  deflt  Description of the Parameter
-   * @return        The aWTColor value
    */
-  public final static Color getAWTColor(int index, Color deflt) {
+  /* package */ static final Color getAWTColor(int index, Color deflt) {
     HSSFColor clr = colors.get(index);
     if (clr == null) {
       return deflt;
     }
-    return getAWTColor(clr);
+    short[] rgb = clr.getTriplet();
+    return new Color(rgb[0],rgb[1],rgb[2]);
   }
 
-
-  /**
-   *  Gets the aWTColor attribute of the SVTableUtils class
-   *
-   * @param  clr  Description of the Parameter
-   * @return      The aWTColor value
-   */
-  public final static Color getAWTColor(HSSFColor clr) {
+  /* package */ static final Color getAWTColor(HSSFColorPredefined clr) {
     short[] rgb = clr.getTriplet();
-    return new Color(rgb[0], rgb[1], rgb[2]);
+    return new Color(rgb[0],rgb[1],rgb[2]);
   }
 }

Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/HSSFHtmlHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/HSSFHtmlHelper.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/HSSFHtmlHelper.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/HSSFHtmlHelper.java Sun Jan 22 22:01:22 2017
@@ -16,24 +16,23 @@
 ==================================================================== */
 package org.apache.poi.ss.examples.html;
 
+import java.util.Formatter;
+
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.hssf.usermodel.HSSFPalette;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.CellStyle;
 
-import java.util.Formatter;
-
 /**
  * Implementation of {@link HtmlHelper} for HSSF files.
- *
- * @author Ken Arnold, Industrious Media LLC
  */
 public class HSSFHtmlHelper implements HtmlHelper {
     private final HSSFWorkbook wb;
     private final HSSFPalette colors;
 
-    private static final HSSFColor HSSF_AUTO = new HSSFColor.AUTOMATIC();
+    private static final HSSFColor HSSF_AUTO = HSSFColorPredefined.AUTOMATIC.getColor();
 
     public HSSFHtmlHelper(HSSFWorkbook wb) {
         this.wb = wb;
@@ -45,7 +44,7 @@ public class HSSFHtmlHelper implements H
     @Override
     public void colorStyles(CellStyle style, Formatter out) {
         HSSFCellStyle cs = (HSSFCellStyle) style;
-        out.format("  /* fill pattern = %d */%n", cs.getFillPattern());
+        out.format("  /* fill pattern = %d */%n", cs.getFillPatternEnum().getCode());
         styleColor(out, "background-color", cs.getFillForegroundColor());
         styleColor(out, "color", cs.getFont(wb).getColor());
         styleColor(out, "border-left-color", cs.getLeftBorderColor());

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java Sun Jan 22 22:01:22 2017
@@ -88,7 +88,7 @@ import org.apache.poi.hssf.record.WriteA
 import org.apache.poi.hssf.record.WriteProtectRecord;
 import org.apache.poi.hssf.record.common.UnicodeString;
 import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
-import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.poifs.crypt.CryptoFunctions;
 import org.apache.poi.poifs.crypt.Decryptor;
 import org.apache.poi.poifs.crypt.EncryptionInfo;
@@ -231,9 +231,10 @@ public final class InternalWorkbook {
      * @return Workbook object
      */
     public static InternalWorkbook createWorkbook(List<Record> recs) {
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log(DEBUG, "Workbook (readfile) created with reclen=",
                     Integer.valueOf(recs.size()));
+        }
         InternalWorkbook retval = new InternalWorkbook();
         List<Record> records = new ArrayList<Record>(recs.size() / 3);
         retval.records.setRecords(records);
@@ -244,54 +245,62 @@ public final class InternalWorkbook {
 
             if (rec.getSid() == EOFRecord.sid) {
                 records.add(rec);
-                if (log.check( POILogger.DEBUG ))
+                if (log.check( POILogger.DEBUG )) {
                     log.log(DEBUG, "found workbook eof record at " + k);
+                }
                 break;
             }
             switch (rec.getSid()) {
 
                 case BoundSheetRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found boundsheet record at " + k);
+                    }
                     retval.boundsheets.add((BoundSheetRecord) rec);
                     retval.records.setBspos( k );
                     break;
 
                 case SSTRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found sst record at " + k);
+                    }
                     retval.sst = ( SSTRecord ) rec;
                     break;
 
                 case FontRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found font record at " + k);
+                    }
                     retval.records.setFontpos( k );
                     retval.numfonts++;
                     break;
 
                 case ExtendedFormatRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found XF record at " + k);
+                    }
                     retval.records.setXfpos( k );
                     retval.numxfs++;
                     break;
 
                 case TabIdRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found tabid record at " + k);
+                    }
                     retval.records.setTabpos( k );
                     break;
 
                 case ProtectRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found protect record at " + k);
+                    }
                     retval.records.setProtpos( k );
                     break;
 
                 case BackupRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found backup record at " + k);
+                    }
                     retval.records.setBackuppos( k );
                     break;
                 case ExternSheetRecord.sid :
@@ -299,57 +308,67 @@ public final class InternalWorkbook {
                 case NameRecord.sid :
                 case SupBookRecord.sid :
                     // LinkTable can start with either of these
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found SupBook record at " + k);
+                    }
                     retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
                     k+=retval.linkTable.getRecordCount() - 1;
                     continue;
                 case FormatRecord.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found format record at " + k);
+                    }
                     retval.formats.add((FormatRecord) rec);
                     retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).getIndexCode() ? retval.maxformatid : ((FormatRecord)rec).getIndexCode();
                     break;
                 case DateWindow1904Record.sid :
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found datewindow1904 record at " + k);
+                    }
                     retval.uses1904datewindowing = ((DateWindow1904Record)rec).getWindowing() == 1;
                     break;
                 case PaletteRecord.sid:
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found palette record at " + k);
+                    }
                     retval.records.setPalettepos( k );
                     break;
                 case WindowOneRecord.sid:
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found WindowOneRecord at " + k);
+                    }
                     retval.windowOne = (WindowOneRecord) rec;
                     break;
                 case WriteAccessRecord.sid:
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found WriteAccess at " + k);
+                    }
                     retval.writeAccess = (WriteAccessRecord) rec;
                     break;
                 case WriteProtectRecord.sid:
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found WriteProtect at " + k);
+                    }
                     retval.writeProtect = (WriteProtectRecord) rec;
                     break;
                 case FileSharingRecord.sid:
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found FileSharing at " + k);
+                    }
                     retval.fileShare = (FileSharingRecord) rec;
                     break;
 
                 case NameCommentRecord.sid:
                     final NameCommentRecord ncr = (NameCommentRecord) rec;
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG, "found NameComment at " + k);
+                    }
                     retval.commentRecords.put(ncr.getNameText(), ncr);
                     break;
                 default:
-                    if (log.check( POILogger.DEBUG ))
+                    if (log.check( POILogger.DEBUG )) {
                         log.log(DEBUG,  "ignoring record (sid=" + rec.getSid() + ") at " + k);
+                    }
                     break;
             }
             records.add(rec);
@@ -376,8 +395,9 @@ public final class InternalWorkbook {
         if (retval.windowOne == null) {
             retval.windowOne = createWindowOne();
         }
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log(DEBUG, "exit create workbook from existing file function");
+        }
         return retval;
     }
 
@@ -389,8 +409,9 @@ public final class InternalWorkbook {
      */
     public static InternalWorkbook createWorkbook()
     {
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log( DEBUG, "creating new workbook from scratch" );
+        }
         InternalWorkbook retval = new InternalWorkbook();
         List<Record> records = new ArrayList<Record>( 30 );
         retval.records.setRecords(records);
@@ -463,8 +484,9 @@ public final class InternalWorkbook {
         records.add(InternalWorkbook.createExtendedSST());
 
         records.add(EOFRecord.instance);
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log( DEBUG, "exit create new workbook from scratch" );
+        }
         return retval;
     }
 
@@ -592,9 +614,10 @@ public final class InternalWorkbook {
      */
 
     public void setSheetBof(int sheetIndex, int pos) {
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log(DEBUG, "setting bof for sheetnum =", Integer.valueOf(sheetIndex),
                 " at pos=", Integer.valueOf(pos));
+        }
         checkSheets(sheetIndex);
         getBoundSheetRec(sheetIndex)
         .setPositionOfBof(pos);
@@ -626,7 +649,9 @@ public final class InternalWorkbook {
         checkSheets(sheetnum);
 
         // YK: Mimic Excel and silently truncate sheet names longer than 31 characters
-        if(sheetname.length() > 31) sheetname = sheetname.substring(0, 31);
+        if(sheetname.length() > 31) {
+            sheetname = sheetname.substring(0, 31);
+        }
 
         BoundSheetRecord sheet = boundsheets.get(sheetnum);
         sheet.setSheetname(sheetname);
@@ -868,8 +893,9 @@ public final class InternalWorkbook {
      */
 
     public int getNumSheets() {
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log(DEBUG, "getNumSheets=", Integer.valueOf(boundsheets.size()));
+        }
         return boundsheets.size();
     }
 
@@ -880,8 +906,9 @@ public final class InternalWorkbook {
      */
 
     public int getNumExFormats() {
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log(DEBUG, "getXF=", Integer.valueOf(numxfs));
+        }
         return numxfs;
     }
 
@@ -1019,8 +1046,9 @@ public final class InternalWorkbook {
      */
 
     public int addSSTString(UnicodeString string) {
-        if (log.check( POILogger.DEBUG ))
-          log.log(DEBUG, "insert to sst string='", string);
+        if (log.check( POILogger.DEBUG )) {
+            log.log(DEBUG, "insert to sst string='", string);
+        }
         if (sst == null) {
             insertSST();
         }
@@ -1038,9 +1066,10 @@ public final class InternalWorkbook {
         }
         UnicodeString retval = sst.getString(str);
 
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log(DEBUG, "Returning SST for index=", Integer.valueOf(str),
                 " String= ", retval);
+        }
         return retval;
     }
 
@@ -1052,8 +1081,9 @@ public final class InternalWorkbook {
      */
 
     public void insertSST() {
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log(DEBUG, "creating new SST via insertSST!");
+        }
         sst = new SSTRecord();
         records.add(records.size() - 1, createExtendedSST());
         records.add(records.size() - 2, sst);
@@ -1096,8 +1126,9 @@ public final class InternalWorkbook {
      */
     public int serialize( int offset, byte[] data )
     {
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log( DEBUG, "Serializing Workbook with offsets" );
+        }
 
         int pos = 0;
 
@@ -1133,8 +1164,9 @@ public final class InternalWorkbook {
             /////  DEBUG END /////
             pos += len;   // rec.length;
         }
-        if (log.check( POILogger.DEBUG ))
+        if (log.check( POILogger.DEBUG )) {
             log.log( DEBUG, "Exiting serialize workbook" );
+        }
         return pos;
     }
 
@@ -1207,13 +1239,15 @@ public final class InternalWorkbook {
         for ( int k = 0; k < records.size(); k++ )
         {
             Record record = records.get( k );
-            if (record instanceof SSTRecord)
+            if (record instanceof SSTRecord) {
                 sst = (SSTRecord)record;
+            }
 
-            if (record.getSid() == ExtSSTRecord.sid && sst != null)
+            if (record.getSid() == ExtSSTRecord.sid && sst != null) {
                 retval += sst.calcExtSSTRecordSize();
-            else
+            } else {
                 retval += record.getRecordSize();
+            }
         }
 
         return retval;
@@ -1250,7 +1284,9 @@ public final class InternalWorkbook {
         try {
             String username = System.getProperty("user.name");
             // Google App engine returns null for user.name, see Bug 53974
-            if(username == null) username = defaultUserName;
+            if(username == null) {
+                username = defaultUserName;
+            }
 
             retval.setUsername(username);
         } catch (AccessControlException e) {
@@ -1799,10 +1835,10 @@ public final class InternalWorkbook {
         retval.setPaletteOptions(( short ) 0);
         retval.setAdtlPaletteOptions(( short ) 0);
         retval.setFillPaletteOptions(( short ) 0x20c0);
-        retval.setTopBorderPaletteIdx(HSSFColor.BLACK.index);
-        retval.setBottomBorderPaletteIdx(HSSFColor.BLACK.index);
-        retval.setLeftBorderPaletteIdx(HSSFColor.BLACK.index);
-        retval.setRightBorderPaletteIdx(HSSFColor.BLACK.index);
+        retval.setTopBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
+        retval.setBottomBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
+        retval.setLeftBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
+        retval.setRightBorderPaletteIdx(HSSFColorPredefined.BLACK.getIndex());
         return retval;
     }
 
@@ -2172,8 +2208,9 @@ public final class InternalWorkbook {
         FormatRecord rec = new FormatRecord(maxformatid, formatString);
 
         int pos = 0;
-        while ( pos < records.size() && records.get( pos ).getSid() != FormatRecord.sid )
+        while ( pos < records.size() && records.get( pos ).getSid() != FormatRecord.sid ) {
             pos++;
+        }
         pos += formats.size();
         formats.add( rec );
         records.add( pos, rec );
@@ -2226,8 +2263,9 @@ public final class InternalWorkbook {
         int matches = 0;
         for (Record record : records) {
             if (record.getSid() == sid) {
-                if (matches++ == pos)
+                if (matches++ == pos) {
                     return record;
+                }
             }
         }
         return null;
@@ -2266,7 +2304,9 @@ public final class InternalWorkbook {
         Record rec = records.get(palettePos);
         if (rec instanceof PaletteRecord) {
           palette = (PaletteRecord) rec;
-        } else throw new RuntimeException("InternalError: Expected PaletteRecord but got a '"+rec+"'");
+        } else {
+            throw new RuntimeException("InternalError: Expected PaletteRecord but got a '"+rec+"'");
+        }
       }
       else
       {
@@ -2316,7 +2356,9 @@ public final class InternalWorkbook {
                     drawingManager = new DrawingManager2(dgg);
                     if(bStore != null){
                         for(EscherRecord bs : bStore.getChildRecords()){
-                            if(bs instanceof EscherBSERecord) escherBSERecords.add((EscherBSERecord)bs);
+                            if(bs instanceof EscherBSERecord) {
+                                escherBSERecords.add((EscherBSERecord)bs);
+                            }
                         }
                     }
                     return drawingManager;
@@ -2344,7 +2386,9 @@ public final class InternalWorkbook {
                 drawingManager = new DrawingManager2(dgg);
                 if(bStore != null){
                     for(EscherRecord bs : bStore.getChildRecords()){
-                        if(bs instanceof EscherBSERecord) escherBSERecords.add((EscherBSERecord)bs);
+                        if(bs instanceof EscherBSERecord) {
+                            escherBSERecords.add((EscherBSERecord)bs);
+                        }
                     }
                 }
             }
@@ -2395,8 +2439,9 @@ public final class InternalWorkbook {
             splitMenuColors.setColor4(0x100000F7);
 
             dggContainer.addChildRecord(dgg);
-            if (bstoreContainer != null)
+            if (bstoreContainer != null) {
                 dggContainer.addChildRecord( bstoreContainer );
+            }
             dggContainer.addChildRecord(opt);
             dggContainer.addChildRecord(splitMenuColors);
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Sun Jan 22 22:01:22 2017
@@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.FontRe
 import org.apache.poi.hssf.record.FormatRecord;
 import org.apache.poi.hssf.record.StyleRecord;
 import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.BorderStyle;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.FillPatternType;
@@ -112,6 +113,7 @@ public final class HSSFCellStyle impleme
     // avoid multi-threading issues when different workbooks are accessed in 
     // multiple threads at the same time
     private static final ThreadLocal<Short> lastDateFormat = new ThreadLocal<Short>() {
+        @Override
         protected Short initialValue() {
             return Short.MIN_VALUE;
         }
@@ -273,6 +275,7 @@ public final class HSSFCellStyle impleme
      * @see #ALIGN_CENTER_SELECTION
      * @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead.
      */
+    @Deprecated
     @Removal(version="3.17")
     @Override
     public void setAlignment(short align)
@@ -303,6 +306,7 @@ public final class HSSFCellStyle impleme
      * @see #ALIGN_CENTER_SELECTION
      * @deprecated POI 3.15 beta 3. Use {@link #getAlignmentEnum()} instead.
      */
+    @Deprecated
     @Override
     public short getAlignment()
     {
@@ -349,6 +353,7 @@ public final class HSSFCellStyle impleme
      * @see VerticalAlignment
      * @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead.
      */
+    @Deprecated
     @Removal(version="3.17")
     @Override
     public void setVerticalAlignment(short align)
@@ -375,6 +380,7 @@ public final class HSSFCellStyle impleme
      * @see VerticalAlignment
      * @deprecated POI 3.15 beta 3. Use {@link #getVerticalAlignmentEnum()} instead.
      */
+    @Deprecated
     @Override
     public short getVerticalAlignment()
     {
@@ -480,6 +486,7 @@ public final class HSSFCellStyle impleme
      * @see #BORDER_SLANTED_DASH_DOT
      * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderLeft(BorderStyle)} instead.
      */
+    @Deprecated
     @Removal(version="3.17")
     @Override
     public void setBorderLeft(short border)
@@ -504,6 +511,7 @@ public final class HSSFCellStyle impleme
      * @return border type
      * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderLeftEnum()}.
      */
+    @Deprecated
     @Override
     public short getBorderLeft()
     {
@@ -539,6 +547,7 @@ public final class HSSFCellStyle impleme
      * @see #BORDER_SLANTED_DASH_DOT
      * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderRight(BorderStyle)} instead.
      */
+    @Deprecated
     @Removal(version="3.17")
     @Override
     public void setBorderRight(short border)
@@ -563,6 +572,7 @@ public final class HSSFCellStyle impleme
      * @return border type
      * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderRightEnum()}.
      */
+    @Deprecated
     @Override
     public short getBorderRight()
     {
@@ -598,6 +608,7 @@ public final class HSSFCellStyle impleme
      * @see #BORDER_SLANTED_DASH_DOT
      * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderTop(BorderStyle)} instead.
      */
+    @Deprecated
     @Removal(version="3.17")
     @Override
     public void setBorderTop(short border)
@@ -622,6 +633,7 @@ public final class HSSFCellStyle impleme
      * @return border type
      * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderTopEnum()}.
      */
+    @Deprecated
     @Override
     public short getBorderTop()
     {
@@ -657,6 +669,7 @@ public final class HSSFCellStyle impleme
      * @see #BORDER_SLANTED_DASH_DOT
      * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderBottom(BorderStyle)} instead.
      */
+    @Deprecated
     @Removal(version="3.17")
     @Override
     public void setBorderBottom(short border)
@@ -681,6 +694,7 @@ public final class HSSFCellStyle impleme
      * @return border type
      * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderBottomEnum()}.
      */
+    @Deprecated
     @Override
     public short getBorderBottom()
     {
@@ -806,6 +820,7 @@ public final class HSSFCellStyle impleme
      * @param fp  fill pattern (set to 1 to fill w/foreground color)
      * @deprecated POI 3.15 beta 3. Use {@link #setFillPattern(FillPatternType)} instead.
      */
+    @Deprecated
     @Removal(version="3.17")
     @Override
     public void setFillPattern(short fp)
@@ -830,6 +845,7 @@ public final class HSSFCellStyle impleme
      * @return fill pattern
      * @deprecated POI 3.15 beta 3. This method will return {@link FillPatternType} in the future. Use {@link #setFillPattern(FillPatternType)} instead. 
      */
+    @Deprecated
     @Override
     public short getFillPattern()
     {
@@ -857,16 +873,20 @@ public final class HSSFCellStyle impleme
      * <p>0x40         0xSOMETHING</p>
      */
     private void checkDefaultBackgroundFills() {
-      if (_format.getFillForeground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index) {
-          //JMH: Why +1, hell why not. I guess it made some sense to someone at the time. Doesnt
-          //to me now.... But experience has shown that when the fore is set to AUTOMATIC then the
-          //background needs to be incremented......
-          if (_format.getFillBackground() != (org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1))
-              setFillBackgroundColor((short)(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1));
-      } else if (_format.getFillBackground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1)
-          //Now if the forground changes to a non-AUTOMATIC color the background resets itself!!!
-          if (_format.getFillForeground() != org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index)
-              setFillBackgroundColor(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index);
+        final short autoIdx = HSSFColorPredefined.AUTOMATIC.getIndex();
+        if (_format.getFillForeground() == autoIdx) {
+            //JMH: Why +1, hell why not. I guess it made some sense to someone at the time. Doesnt
+            //to me now.... But experience has shown that when the fore is set to AUTOMATIC then the
+            //background needs to be incremented......
+            if (_format.getFillBackground() != autoIdx+1) {
+                setFillBackgroundColor((short)(autoIdx+1));
+            }
+        } else if (_format.getFillBackground() == autoIdx+1) {
+            //Now if the forground changes to a non-AUTOMATIC color the background resets itself!!!
+            if (_format.getFillForeground() != autoIdx) {
+                setFillBackgroundColor(autoIdx);
+            }
+        }
     }
 
     /**
@@ -909,13 +929,13 @@ public final class HSSFCellStyle impleme
      * @return fill color
      */
     @Override
-    public short getFillBackgroundColor()
-    {
+    public short getFillBackgroundColor() {
+        final short autoIndex = HSSFColorPredefined.AUTOMATIC.getIndex();
         short result = _format.getFillBackground();
         //JMH: Do this ridiculous conversion, and let HSSFCellStyle
         //internally migrate back and forth
-        if (result == (HSSFColor.AUTOMATIC.index+1)) {
-            return HSSFColor.AUTOMATIC.index;
+        if (result == autoIndex+1) {
+            return autoIndex;
         }
         return result;
     }
@@ -1117,17 +1137,24 @@ public final class HSSFCellStyle impleme
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) return true;
-        if (obj == null) return false;
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
         if (obj instanceof HSSFCellStyle) {
             final HSSFCellStyle other = (HSSFCellStyle) obj;
             if (_format == null) {
-                if (other._format != null)
+                if (other._format != null) {
                     return false;
-            } else if (!_format.equals(other._format))
+                }
+            } else if (!_format.equals(other._format)) {
                 return false;
-            if (_index != other._index)
+            }
+            if (_index != other._index) {
                 return false;
+            }
             return true;
         }
         return false;

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java?rev=1779866&r1=1779865&r2=1779866&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java Sun Jan 22 22:01:22 2017
@@ -21,6 +21,7 @@ import java.util.Locale;
 
 import org.apache.poi.hssf.record.PaletteRecord;
 import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 
 /**
  * Represents a workbook color palette.
@@ -45,16 +46,13 @@ public final class HSSFPalette {
     public HSSFColor getColor(short index)
     {
         //Handle the special AUTOMATIC case
-        if (index == HSSFColor.AUTOMATIC.index) {
-            return HSSFColor.AUTOMATIC.getInstance();
+        if (index == HSSFColorPredefined.AUTOMATIC.getIndex()) {
+            return HSSFColorPredefined.AUTOMATIC.getColor();
         }
         byte[] b = _palette.getColor(index);
-          if (b != null)
-          {
-             return new CustomColor(index, b);
-          }
-        return null;
+        return (b == null) ? null : new CustomColor(index, b);
     }
+
     /**
      * Retrieves the color at a given index
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message