poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fannin...@apache.org
Subject svn commit: r1824826 - in /poi/trunk/src: examples/src/org/apache/poi/hssf/view/ examples/src/org/apache/poi/ss/examples/ examples/src/org/apache/poi/ss/examples/html/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/usermodel/ java/org/apache...
Date Tue, 20 Feb 2018 00:25:43 GMT
Author: fanningpj
Date: Tue Feb 20 00:25:43 2018
New Revision: 1824826

URL: http://svn.apache.org/viewvc?rev=1824826&view=rev
Log:
[bug-62018] use ints to index fonts

Modified:
    poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellEditor.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/CellStyleDetails.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
    poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Workbook.java
    poi/trunk/src/java/org/apache/poi/ss/util/CellUtil.java
    poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java

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=1824826&r1=1824825&r2=1824826&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 Tue Feb 20
00:25:43 2018
@@ -40,173 +40,176 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
  * Sheet Viewer Table Cell Editor -- not commented via javadoc as it
  * nearly completely consists of overridden methods.
  *
- * @author     Jason Height
+ * @author Jason Height
  */
 public class SVTableCellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener
{
-  private static final Color black = getAWTColor(HSSFColorPredefined.BLACK);
-  private static final Color white = getAWTColor(HSSFColorPredefined.WHITE);
+    private static final Color black = getAWTColor(HSSFColorPredefined.BLACK);
+    private static final Color white = getAWTColor(HSSFColorPredefined.WHITE);
+    private static final POILogger logger = POILogFactory.getLogger(SVTableCellEditor.class);
+
+    private HSSFWorkbook wb;
+    private JTextField editor;
+
+    public SVTableCellEditor(HSSFWorkbook wb) {
+        this.wb = wb;
+        this.editor = new JTextField();
+    }
+
+
+    /**
+     * Gets the cellEditable attribute of the SVTableCellEditor object
+     *
+     * @return The cellEditable value
+     */
+    @Override
+    public boolean isCellEditable(java.util.EventObject e) {
+        if (e instanceof MouseEvent) {
+            return ((MouseEvent) e).getClickCount() >= 2;
+        }
+        return false;
+    }
+
+
+    @Override
+    public boolean shouldSelectCell(EventObject anEvent) {
+        return true;
+    }
+
+
+    public boolean startCellEditing(EventObject anEvent) {
+        logger.log(POILogger.INFO, "Start Cell Editing");
+        return true;
+    }
+
+
+    @Override
+    public boolean stopCellEditing() {
+        logger.log(POILogger.INFO, "Stop Cell Editing");
+        fireEditingStopped();
+        return true;
+    }
+
+
+    @Override
+    public void cancelCellEditing() {
+        logger.log(POILogger.INFO, "Cancel Cell Editing");
+        fireEditingCanceled();
+    }
+
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        logger.log(POILogger.INFO, "Action performed");
+        stopCellEditing();
+    }
+
+
+    /**
+     * Gets the cellEditorValue attribute of the SVTableCellEditor object
+     *
+     * @return The cellEditorValue value
+     */
+    @Override
+    public Object getCellEditorValue() {
+        logger.log(POILogger.INFO, "GetCellEditorValue");
+        //JMH Look at when this method is called. Should it return a HSSFCell?
+        return editor.getText();
+    }
 
-  private HSSFWorkbook wb;
-  private JTextField editor;
 
-  public SVTableCellEditor(HSSFWorkbook wb) {
-    this.wb = wb;
-    this.editor = new JTextField();
-  }
-
-
-  /**
-   *  Gets the cellEditable attribute of the SVTableCellEditor object
-   *
-   * @return    The cellEditable value
-   */
-  @Override
-  public boolean isCellEditable(java.util.EventObject e) {
-    if (e instanceof MouseEvent) {
-      return ((MouseEvent) e).getClickCount() >= 2;
-    }
-    return false;
-  }
-
-
-  @Override
-  public boolean shouldSelectCell(EventObject anEvent) {
-    return true;
-  }
-
-
-  public boolean startCellEditing(EventObject anEvent) {
-    System.out.println("Start Cell Editing");
-    return true;
-  }
-
-
-  @Override
-  public boolean stopCellEditing() {
-    System.out.println("Stop Cell Editing");
-    fireEditingStopped();
-    return true;
-  }
-
-
-  @Override
-  public void cancelCellEditing() {
-    System.out.println("Cancel Cell Editing");
-    fireEditingCanceled();
-  }
-
-
-  @Override
-  public void actionPerformed(ActionEvent e) {
-    System.out.println("Action performed");
-    stopCellEditing();
-  }
-
-
-  /**
-   *  Gets the cellEditorValue attribute of the SVTableCellEditor object
-   *
-   * @return    The cellEditorValue value
-   */
-  @Override
-  public Object getCellEditorValue() {
-    System.out.println("GetCellEditorValue");
-    //JMH Look at when this method is called. Should it return a HSSFCell?
-    return editor.getText();
-  }
-
-
-  /**
-   *  Gets the tableCellEditorComponent attribute of the SVTableCellEditor object
-   *
-   * @return             The tableCellEditorComponent value
-   */
-  @Override
-  public Component getTableCellEditorComponent(JTable table, Object value,
-      boolean isSelected,
-      int row,
-      int column) {
-    System.out.println("GetTableCellEditorComponent");
-    HSSFCell cell = (HSSFCell) value;
-    if (cell != null) {
-          HSSFCellStyle style = cell.getCellStyle();
-          HSSFFont f = wb.getFontAt(style.getFontIndex());
-          boolean isbold = f.getBold();
-          boolean isitalics = f.getItalic();
-
-          int fontstyle = Font.PLAIN;
-
-          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
-          }
-
-          Font font = new Font(f.getFontName(),fontstyle,fontheight);
-          editor.setFont(font);
-
-          if (style.getFillPattern() == FillPatternType.SOLID_FOREGROUND) {
-            editor.setBackground(getAWTColor(style.getFillForegroundColor(), white));
-          } else {
-            editor.setBackground(white);
-          }
-
-          editor.setForeground(getAWTColor(f.getColor(), black));
-
-
-      //Set the value that is rendered for the cell
-      switch (cell.getCellType()) {
-        case BLANK:
-          editor.setText("");
-          break;
-        case BOOLEAN:
-          if (cell.getBooleanCellValue()) {
-            editor.setText("true");
-          } else {
-            editor.setText("false");
-          }
-          break;
-        case NUMERIC:
-          editor.setText(Double.toString(cell.getNumericCellValue()));
-          break;
-        case STRING:
-          editor.setText(cell.getRichStringCellValue().getString());
-          break;
-        case FORMULA:
-        default:
-          editor.setText("?");
-      }
-      switch (style.getAlignment()) {
-        case LEFT:
-        case JUSTIFY:
-        case FILL:
-          editor.setHorizontalAlignment(SwingConstants.LEFT);
-          break;
-        case CENTER:
-        case CENTER_SELECTION:
-          editor.setHorizontalAlignment(SwingConstants.CENTER);
-          break;
-        case GENERAL:
-        case RIGHT:
-          editor.setHorizontalAlignment(SwingConstants.RIGHT);
-          break;
-        default:
-          editor.setHorizontalAlignment(SwingConstants.LEFT);
-          break;
-      }
+    /**
+     * Gets the tableCellEditorComponent attribute of the SVTableCellEditor object
+     *
+     * @return The tableCellEditorComponent value
+     */
+    @Override
+    public Component getTableCellEditorComponent(JTable table, Object value,
+                                                 boolean isSelected,
+                                                 int row,
+                                                 int column) {
+        logger.log(POILogger.INFO, "GetTableCellEditorComponent");
+        HSSFCell cell = (HSSFCell) value;
+        if (cell != null) {
+            HSSFCellStyle style = cell.getCellStyle();
+            HSSFFont f = wb.getFontAt(style.getFontIntIndex());
+            boolean isbold = f.getBold();
+            boolean isitalics = f.getItalic();
+
+            int fontstyle = Font.PLAIN;
+
+            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
+            }
+
+            Font font = new Font(f.getFontName(), fontstyle, fontheight);
+            editor.setFont(font);
+
+            if (style.getFillPattern() == FillPatternType.SOLID_FOREGROUND) {
+                editor.setBackground(getAWTColor(style.getFillForegroundColor(), white));
+            } else {
+                editor.setBackground(white);
+            }
+
+            editor.setForeground(getAWTColor(f.getColor(), black));
+
+
+            //Set the value that is rendered for the cell
+            switch (cell.getCellType()) {
+                case BLANK:
+                    editor.setText("");
+                    break;
+                case BOOLEAN:
+                    if (cell.getBooleanCellValue()) {
+                        editor.setText("true");
+                    } else {
+                        editor.setText("false");
+                    }
+                    break;
+                case NUMERIC:
+                    editor.setText(Double.toString(cell.getNumericCellValue()));
+                    break;
+                case STRING:
+                    editor.setText(cell.getRichStringCellValue().getString());
+                    break;
+                case FORMULA:
+                default:
+                    editor.setText("?");
+            }
+            switch (style.getAlignment()) {
+                case LEFT:
+                case JUSTIFY:
+                case FILL:
+                    editor.setHorizontalAlignment(SwingConstants.LEFT);
+                    break;
+                case CENTER:
+                case CENTER_SELECTION:
+                    editor.setHorizontalAlignment(SwingConstants.CENTER);
+                    break;
+                case GENERAL:
+                case RIGHT:
+                    editor.setHorizontalAlignment(SwingConstants.RIGHT);
+                    break;
+                default:
+                    editor.setHorizontalAlignment(SwingConstants.LEFT);
+                    break;
+            }
 
+        }
+        return editor;
     }
-    return editor;
-  }
 }

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java Tue Feb 20
00:25:43 2018
@@ -140,7 +140,7 @@ public class SVTableCellRenderer extends
     @Override
     public Component getTableCellRendererComponent(JTable table, Object value,
                           boolean isSelected, boolean hasFocus, int row, int column) {
-	boolean isBorderSet = false;
+	    boolean isBorderSet = false;
 
         //If the JTables default cell renderer has been setup correctly the
         //value will be the HSSFCell that we are trying to render
@@ -148,7 +148,7 @@ public class SVTableCellRenderer extends
 
         if (c != null) {
           HSSFCellStyle s = c.getCellStyle();
-          HSSFFont f = wb.getFontAt(s.getFontIndex());
+          HSSFFont f = wb.getFontAt(s.getFontIntIndex());
           setFont(SVTableUtils.makeFont(f));
 
           if (s.getFillPattern() == FillPatternType.SOLID_FOREGROUND) {

Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/CellStyleDetails.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/CellStyleDetails.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/CellStyleDetails.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/CellStyleDetails.java Tue Feb 20
00:25:43 2018
@@ -63,7 +63,7 @@ public class CellStyleDetails {
                         System.out.print("FG=" + renderColor(style.getFillForegroundColorColor())
+ " ");
                         System.out.print("BG=" + renderColor(style.getFillBackgroundColorColor())
+ " ");
 
-                        Font font = wb.getFontAt(style.getFontIndex());
+                        Font font = wb.getFontAt(style.getFontIntIndex());
                         System.out.print("Font=" + font.getFontName() + " ");
                         System.out.print("FontColor=");
                         if (font instanceof HSSFFont) {

Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java Tue Feb 20 00:25:43
2018
@@ -300,7 +300,7 @@ public class ToHtml {
     }
 
     private void fontStyle(CellStyle style) {
-        Font font = wb.getFontAt(style.getFontIndex());
+        Font font = wb.getFontAt(style.getFontIntIndex());
 
         if (font.getBold()) {
             out.format("  font-weight: bold;%n");

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java Tue Feb 20 00:25:43
2018
@@ -1660,7 +1660,7 @@ public final class ExtendedFormatRecord
     @Override
     public String toString()
     {
-        StringBuffer buffer = new StringBuffer();
+        StringBuilder buffer = new StringBuilder();
 
         buffer.append("[EXTENDEDFORMAT]\n");
         if (getXFType() == XF_STYLE)

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=1824826&r1=1824825&r2=1824826&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 Tue Feb 20 00:25:43
2018
@@ -169,7 +169,7 @@ public final class HSSFCellStyle impleme
      * set the font for this style
      * @param font  a font object created or retrieved from the HSSFWorkbook object
      * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
-     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
+     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(int)
      */
     @Override
     public void setFont(Font font) {
@@ -186,19 +186,31 @@ public final class HSSFCellStyle impleme
      * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
      */
     @Override
+    @Deprecated
     public short getFontIndex()
     {
         return _format.getFontIndex();
     }
 
     /**
+     * gets the index of the font for this style
+     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(int)
+     * @since 4.0.0
+     */
+    @Override
+    public int getFontIntIndex()
+    {
+        return _format.getFontIndex();
+    }
+
+    /**
      * gets the font for this style
      * @param parentWorkbook The HSSFWorkbook that this style belongs to
-     * @see org.apache.poi.hssf.usermodel.HSSFCellStyle#getFontIndex()
-     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
+     * @see org.apache.poi.hssf.usermodel.HSSFCellStyle#getFontIntIndex()
+     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(int)
      */
     public HSSFFont getFont(org.apache.poi.ss.usermodel.Workbook parentWorkbook) {
-        return ((HSSFWorkbook) parentWorkbook).getFontAt(getFontIndex());
+        return ((HSSFWorkbook) parentWorkbook).getFontAt(getFontIntIndex());
     }
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java Tue Feb 20 00:25:43 2018
@@ -25,7 +25,7 @@ import org.apache.poi.ss.usermodel.Font;
  * Represents a Font used in a workbook.
  * 
  * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
- * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
+ * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(int)
  * @see org.apache.poi.hssf.usermodel.HSSFCellStyle#setFont(HSSFFont)
  */
 public final class HSSFFont implements Font {
@@ -46,12 +46,12 @@ public final class HSSFFont implements F
     public final static String FONT_ARIAL = "Arial";
 
 
-    private FontRecord         font;
-    private short              index;
+    private FontRecord font;
+    private int index;
 
     /** Creates a new instance of HSSFFont */
 
-    protected HSSFFont(short index, FontRecord rec)
+    protected HSSFFont(int index, FontRecord rec)
     {
         font       = rec;
         this.index = index;
@@ -85,7 +85,15 @@ public final class HSSFFont implements F
      *  unless you're comparing which one is which)
      */
 
-    public short getIndex()
+    public short getIndex() { return (short)index; }
+
+    /**
+     * get the index within the HSSFWorkbook (sequence within the collection of Font objects)
+     * @return unique index number of the underlying record this Font represents (probably
you don't care
+     *  unless you're comparing which one is which)
+     */
+
+    public int getIndexAsInt()
     {
         return index;
     }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Tue Feb 20 00:25:43
2018
@@ -178,13 +178,13 @@ public final class HSSFWorkbook extends
      * this holds the HSSFFont objects attached to this workbook.
      * We only create these from the low level records as required.
      */
-    private Map<Short,HSSFFont> fonts;
+    private Map<Integer,HSSFFont> fonts;
 
     /**
      * holds whether or not to preserve other nodes in the POIFS.  Used
      * for macros and embedded objects.
      */
-    private boolean   preserveNodes;
+    private boolean preserveNodes;
 
     /**
      * Used to keep track of the data formatter so that all
@@ -1171,13 +1171,13 @@ public final class HSSFWorkbook extends
     public HSSFFont createFont()
     {
         /*FontRecord font =*/ workbook.createNewFont();
-        short fontindex = (short) (getNumberOfFonts() - 1);
+        int fontindex = getNumberOfFontsAsInt() - 1;
 
         if (fontindex > 3)
         {
             fontindex++;   // THERE IS NO FOUR!!
         }
-        if(fontindex == Short.MAX_VALUE){
+        if(fontindex >= Short.MAX_VALUE){
             throw new IllegalArgumentException("Maximum number of fonts was exceeded");
         }
 
@@ -1194,8 +1194,8 @@ public final class HSSFWorkbook extends
                              String name, boolean italic, boolean strikeout,
                              short typeOffset, byte underline)
     {
-        short numberOfFonts = getNumberOfFonts();
-        for (short i=0; i<=numberOfFonts; i++) {
+        int numberOfFonts = getNumberOfFontsAsInt();
+        for (int i = 0; i <= numberOfFonts; i++) {
             // Remember - there is no 4!
             if(i == 4) {
                 continue;
@@ -1218,24 +1218,25 @@ public final class HSSFWorkbook extends
         return null;
     }
 
-    /**
-     * get the number of fonts in the font table
-     * @return number of fonts
-     */
+    @Override
+    @Deprecated
+    public short getNumberOfFonts() {
+        return (short)getNumberOfFontsAsInt();
+    }
 
     @Override
-    public short getNumberOfFonts()
-    {
-        return (short) workbook.getNumberOfFontRecords();
+    public int getNumberOfFontsAsInt() {
+        return workbook.getNumberOfFontRecords();
     }
 
-    /**
-     * Get the font at the given index number
-     * @param idx  index number
-     * @return HSSFFont at the index
-     */
     @Override
+    @Deprecated
     public HSSFFont getFontAt(short idx) {
+        return getFontAt((int)idx);
+    }
+
+    @Override
+    public HSSFFont getFontAt(int idx) {
         if(fonts == null) {
             fonts = new HashMap<>();
         }
@@ -1243,7 +1244,7 @@ public final class HSSFWorkbook extends
         // So we don't confuse users, give them back
         //  the same object every time, but create
         //  them lazily
-        Short sIdx = Short.valueOf(idx);
+        Integer sIdx = Integer.valueOf(idx);
         if(fonts.containsKey(sIdx)) {
             return fonts.get(sIdx);
         }

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/CellStyle.java Tue Feb 20 00:25:43 2018
@@ -49,17 +49,26 @@ public interface CellStyle {
      * set the font for this style
      * @param font  a font object created or retrieved from the Workbook object
      * @see Workbook#createFont()
-     * @see Workbook#getFontAt(short)
+     * @see Workbook#getFontAt(int)
      */
     void setFont(Font font);
 
     /**
      * gets the index of the font for this style
      * @see Workbook#getFontAt(short)
+     * @deprecated use <code>getFontIntIndex()</code> instead
      */
+    @Removal(version = "4.2")
     short getFontIndex();
 
     /**
+     * gets the index of the font for this style
+     * @see Workbook#getFontAt(int)
+     * @since 4.0.0
+     */
+    int getFontIntIndex();
+
+    /**
      * set the cell's using this style to be hidden
      * @param hidden - whether the cell using this style should be hidden
      */

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java Tue Feb 20 00:25:43 2018
@@ -18,6 +18,8 @@
 package org.apache.poi.ss.usermodel;
 
 
+import org.apache.poi.util.Removal;
+
 public interface Font {
 
     /**
@@ -267,9 +269,20 @@ public interface Font {
      * 
      * @return unique index number of the underlying record this Font represents (probably
you don't care
      *  unless you're comparing which one is which)
+     * @deprecated use <code>getIndexAsInt()</code> instead
      */
+    @Removal(version = "4.2")
     public short getIndex();
 
+    /**
+     * get the index within the XSSFWorkbook (sequence within the collection of Font objects)
+     *
+     * @return unique index number of the underlying record this Font represents (probably
you don't care
+     *  unless you're comparing which one is which)
+     * @since 4.0.0
+     */
+    public int getIndexAsInt();
+
     public void setBold(boolean bold);
 
     public boolean getBold();

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Workbook.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Workbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Workbook.java Tue Feb 20 00:25:43 2018
@@ -265,18 +265,39 @@ public interface Workbook extends Closea
      * Get the number of fonts in the font table
      *
      * @return number of fonts
+     * @deprecated use <code>getNumberOfFontsAsInt()</code> instead
      */
+    @Removal(version = "4.2")
     short getNumberOfFonts();
 
     /**
+     * Get the number of fonts in the font table
+     *
+     * @return number of fonts
+     * @since 4.0.0
+     */
+    int getNumberOfFontsAsInt();
+
+    /**
      * Get the font at the given index number
      *
      * @param idx  index number (0-based)
      * @return font at the index
+     * @deprecated use <code>getFontAt(int)</code>
      */
+    @Removal(version = "4.2")
     Font getFontAt(short idx);
 
     /**
+     * Get the font at the given index number
+     *
+     * @param idx  index number (0-based)
+     * @return font at the index
+     * @since 4.0.0
+     */
+    Font getFontAt(int idx);
+
+    /**
      * Create a new Cell style and add it to the workbook's style table
      *
      * @return the new Cell Style object

Modified: poi/trunk/src/java/org/apache/poi/ss/util/CellUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/CellUtil.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/CellUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/CellUtil.java Tue Feb 20 00:25:43 2018
@@ -234,7 +234,7 @@ public final class CellUtil {
     public static void setFont(Cell cell, Font font) {
         // Check if font belongs to workbook
         Workbook wb = cell.getSheet().getWorkbook();
-        final short fontIndex = font.getIndex();
+        final int fontIndex = font.getIndexAsInt();
         if (!wb.getFontAt(fontIndex).equals(font)) {
             throw new IllegalArgumentException("Font does not belong to this workbook");
         }
@@ -408,7 +408,7 @@ public final class CellUtil {
         style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
         style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
         style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
-        style.setFont(workbook.getFontAt(getShort(properties, FONT)));
+        style.setFont(workbook.getFontAt(getInt(properties, FONT)));
         style.setHidden(getBoolean(properties, HIDDEN));
         style.setIndention(getShort(properties, INDENTION));
         style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
@@ -429,8 +429,24 @@ public final class CellUtil {
      */
     private static short getShort(Map<String, Object> properties, String name) {
         Object value = properties.get(name);
-        if (value instanceof Short) {
-            return ((Short) value).shortValue();
+        if (value instanceof Number) {
+            return ((Number) value).shortValue();
+        }
+        return 0;
+    }
+
+    /**
+     * Utility method that returns the named int value form the given map.
+     *
+     * @param properties map of named properties (String -> Object)
+     * @param name property name
+     * @return zero if the property does not exist, or is not a {@link Integer}
+     *         otherwise the property value
+     */
+    private static int getInt(Map<String, Object> properties, String name) {
+        Object value = properties.get(name);
+        if (value instanceof Number) {
+            return ((Number) value).intValue();
         }
         return 0;
     }

Modified: poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/SheetUtil.java Tue Feb 20 00:25:43 2018
@@ -144,7 +144,7 @@ public class SheetUtil {
         if (cellType == CellType.FORMULA)
             cellType = cell.getCachedFormulaResultType();
 
-        Font font = wb.getFontAt(style.getFontIndex());
+        Font font = wb.getFontAt(style.getFontIntIndex());
 
         double width = -1;
         if (cellType == CellType.STRING) {
@@ -266,7 +266,7 @@ public class SheetUtil {
      */
     @Internal
     public static int getDefaultCharWidth(final Workbook wb) {
-        Font defaultFont = wb.getFontAt((short) 0);
+        Font defaultFont = wb.getFontAt( 0);
 
         AttributedString str = new AttributedString(String.valueOf(defaultChar));
         copyAttributes(defaultFont, str, 0, 1);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java Tue Feb 20 00:25:43
2018
@@ -811,28 +811,29 @@ public class SXSSFWorkbook implements Wo
     {
         return _wb.findFont(bold, color, fontHeight, name, italic, strikeout, typeOffset,
underline);
     }
-   
 
-    /**
-     * Get the number of fonts in the font table
-     *
-     * @return number of fonts
-     */
     @Override
-    public short getNumberOfFonts()
+    @Deprecated
+    public short getNumberOfFonts() {
+        return (short)getNumberOfFontsAsInt();
+    }
+
+    @Override
+    public int getNumberOfFontsAsInt()
     {
-        return _wb.getNumberOfFonts();
+        return _wb.getNumberOfFontsAsInt();
     }
 
-    /**
-     * Get the font at the given index number
-     *
-     * @param idx  index number (0-based)
-     * @return font at the index
-     */
     @Override
+    @Deprecated
     public Font getFontAt(short idx)
     {
+        return getFontAt((int)idx);
+    }
+
+    @Override
+    public Font getFontAt(int idx)
+    {
         return _wb.getFontAt(idx);
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Tue Feb 20 00:25:43
2018
@@ -469,11 +469,24 @@ public class XSSFCellStyle implements Ce
      * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short)
      */
     @Override
+    @Deprecated
     public short getFontIndex() {
         return (short) getFontId();
     }
 
     /**
+     * Gets the index of the font for this style
+     *
+     * @return short - font index
+     * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(int)
+     * @since 4.0.0
+     */
+    @Override
+    public int getFontIntIndex() {
+        return getFontId();
+    }
+
+    /**
      * Get whether the cell's using this style are to be hidden
      *
      * @return boolean -  whether the cell using this style is hidden

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java Tue Feb 20 00:25:43
2018
@@ -63,7 +63,7 @@ public class XSSFFont implements Font {
     private IndexedColorMap _indexedColorMap;
     private ThemesTable _themes;
     private CTFont _ctFont;
-    private short _index;
+    private int _index;
 
     /**
      * Create a new XSSFFont
@@ -615,12 +615,14 @@ public class XSSFFont implements Font {
         setFamily(family.getValue());
     }
 
-    /**
-     * get the index within the XSSFWorkbook (sequence within the collection of Font objects)
-     * @return unique index number of the underlying record this Font represents (probably
you don't care
-     *  unless you're comparing which one is which)
-     */
-    public short getIndex()
+    @Override
+    @Deprecated
+    public short getIndex() {
+        return (short)getIndexAsInt();
+    }
+
+    @Override
+    public int getIndexAsInt()
     {
         return _index;
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Tue Feb 20 00:25:43
2018
@@ -925,6 +925,8 @@ public class XSSFWorkbook extends POIXML
 
     /**
      * Finds a font that matches the one with the supplied attributes
+     *
+     * @return the font with the matched attributes or <code>null</code>
      */
     @Override
     public XSSFFont findFont(boolean bold, short color, short fontHeight, String name, boolean
italic, boolean strikeout, short typeOffset, byte underline) {
@@ -972,17 +974,16 @@ public class XSSFWorkbook extends POIXML
         return stylesSource.getStyleAt(idx);
     }
 
-    /**
-     * Get the font at the given index number
-     *
-     * @param idx  index number
-     * @return XSSFFont at the index
-     */
     @Override
     public XSSFFont getFontAt(short idx) {
         return stylesSource.getFontAt(idx);
     }
 
+    @Override
+    public XSSFFont getFontAt(int idx) {
+        return stylesSource.getFontAt(idx);
+    }
+
     /**
      * Get the first named range with the given name.
      *
@@ -1075,13 +1076,13 @@ public class XSSFWorkbook extends POIXML
         return stylesSource.getNumCellStyles();
     }
 
-    /**
-     * Get the number of fonts in the this workbook
-     *
-     * @return number of fonts
-     */
     @Override
     public short getNumberOfFonts() {
+        return (short)getNumberOfFontsAsInt();
+    }
+
+    @Override
+    public int getNumberOfFontsAsInt() {
         return (short)stylesSource.getFonts().size();
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java Tue Feb
20 00:25:43 2018
@@ -1013,19 +1013,19 @@ public abstract class BaseTestBugzillaIs
         Workbook wb = _testDataProvider.createWorkbook();
         int startingFonts = wb instanceof HSSFWorkbook ? 4 : 1;
 
-        assertEquals(startingFonts, wb.getNumberOfFonts());
+        assertEquals(startingFonts, wb.getNumberOfFontsAsInt());
 
         // Get a font, and slightly change it
         Font a = wb.createFont();
-        assertEquals(startingFonts+1, wb.getNumberOfFonts());
+        assertEquals(startingFonts+1, wb.getNumberOfFontsAsInt());
         a.setFontHeightInPoints((short)23);
-        assertEquals(startingFonts+1, wb.getNumberOfFonts());
+        assertEquals(startingFonts+1, wb.getNumberOfFontsAsInt());
 
         // Get two more, unchanged
         /*Font b =*/ wb.createFont();
-        assertEquals(startingFonts+2, wb.getNumberOfFonts());
+        assertEquals(startingFonts+2, wb.getNumberOfFontsAsInt());
         /*Font c =*/ wb.createFont();
-        assertEquals(startingFonts+3, wb.getNumberOfFonts());
+        assertEquals(startingFonts+3, wb.getNumberOfFontsAsInt());
         
         wb.close();
     }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Tue Feb 20 00:25:43
2018
@@ -276,7 +276,7 @@ public abstract class BaseTestCell {
         cs = c.getCellStyle();
 
         assertNotNull("Formula Cell Style", cs);
-        assertEquals("Font Index Matches", f.getIndex(), cs.getFontIndex());
+        assertEquals("Font Index Matches", f.getIndexAsInt(), cs.getFontIndex());
         assertEquals("Top Border", BorderStyle.THIN, cs.getBorderTop());
         assertEquals("Left Border", BorderStyle.THIN, cs.getBorderLeft());
         assertEquals("Right Border", BorderStyle.THIN, cs.getBorderRight());

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java?rev=1824826&r1=1824825&r2=1824826&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFont.java Tue Feb 20 00:25:43
2018
@@ -58,7 +58,7 @@ public abstract class BaseTestFont {
     @Test
     public final void testGetNumberOfFonts() throws IOException {
         Workbook wb = _testDataProvider.createWorkbook();
-        int num0 = wb.getNumberOfFonts();
+        int num0 = wb.getNumberOfFontsAsInt();
 
         Font f1=wb.createFont();
         f1.setBold(true);



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


Mime
View raw message