Reverting method name change. Taking a risk on breaking binary compatibility for method HSSFSheet. getDefaultColWidth() (follow-on from r696075 / bug 45805)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@696084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-09-16 21:56:36 +00:00
parent fface3d680
commit 63755a491e
7 changed files with 44 additions and 50 deletions

View File

@ -103,7 +103,7 @@ public class SViewerPanel extends JPanel {
TableColumnModel columns = sheetView.getColumnModel();
for (int i=0; i< columns.getColumnCount(); i++) {
TableColumn column = columns.getColumn(i);
int width = sheet.getColWidth(i);
int width = sheet.getColumnWidth(i);
//256 is because the width is in 256ths of a character
column.setPreferredWidth(width/256*magicCharFactor);
}

View File

@ -134,7 +134,7 @@ public class HSSF
c = r.createCell(cellnum + 1,
HSSFCell.CELL_TYPE_STRING);
c.setCellValue(new HSSFRichTextString("TEST"));
s.setColWidth(cellnum + 1, (int)(50 * 8 / 0.05));
s.setColumnWidth(cellnum + 1, (int)(50 * 8 / 0.05));
if ((rownum % 2) == 0)
{
c.setCellStyle(cs2);

View File

@ -160,9 +160,9 @@ public class HSSFPicture
return anchor;
}
private float getColumnWidthInPixels(short column){
private float getColumnWidthInPixels(int column){
int cw = patriarch.sheet.getColWidth(column);
int cw = patriarch.sheet.getColumnWidth(column);
float px = getPixelWidth(column);
return cw/px;
@ -178,10 +178,10 @@ public class HSSFPicture
return height/PX_ROW;
}
private float getPixelWidth(short column){
private float getPixelWidth(int column){
int def = patriarch.sheet.getDefaultColWidth()*256;
int cw = patriarch.sheet.getColWidth(column);
int def = patriarch.sheet.getDefaultColumnWidth()*256;
int cw = patriarch.sheet.getColumnWidth(column);
return cw == def ? PX_DEFAULT : PX_MODIFIED;
}

View File

@ -404,30 +404,24 @@ public final class HSSFSheet {
}
/**
* @deprecated (Sep 2008) use {@link #setColWidth(int, int)}
* @deprecated (Sep 2008) use {@link #setColumnWidth(int, int)}
*/
public void setColumnWidth(short columnIndex, short width) {
setColWidth(columnIndex & 0xFFFF, width & 0xFFFF);
setColumnWidth(columnIndex & 0xFFFF, width & 0xFFFF);
}
/**
* @deprecated (Sep 2008) use {@link #getColWidth(int)}
* @deprecated (Sep 2008) use {@link #getColumnWidth(int)}
*/
public short getColumnWidth(short columnIndex) {
return (short)getColWidth(columnIndex & 0xFFFF);
return (short)getColumnWidth(columnIndex & 0xFFFF);
}
/**
* @deprecated (Sep 2008) use {@link #getDefaultColWidth()}
*/
public short getDefaultColumnWidth() {
return (short) getDefaultColWidth();
}
/**
* @deprecated (Sep 2008) use {@link #setDefaultColWidth(int)}
* @deprecated (Sep 2008) use {@link #setDefaultColumnWidth(int)}
*/
public void setDefaultColumnWidth(short width) {
setDefaultColWidth(width & 0xFFFF);
setDefaultColumnWidth(width & 0xFFFF);
}
/**
@ -453,7 +447,7 @@ public final class HSSFSheet {
* @param columnIndex - the column to set (0-based)
* @param width - the width in units of 1/256th of a character width
*/
public void setColWidth(int columnIndex, int width) {
public void setColumnWidth(int columnIndex, int width) {
sheet.setColumnWidth(columnIndex, width);
}
@ -462,7 +456,7 @@ public final class HSSFSheet {
* @param columnIndex - the column to set (0-based)
* @return width - the width in units of 1/256th of a character width
*/
public int getColWidth(int columnIndex) {
public int getColumnWidth(int columnIndex) {
return sheet.getColumnWidth(columnIndex);
}
@ -471,7 +465,7 @@ public final class HSSFSheet {
* characters
* @return default column width
*/
public int getDefaultColWidth() {
public int getDefaultColumnWidth() {
return sheet.getDefaultColumnWidth();
}
/**
@ -479,7 +473,7 @@ public final class HSSFSheet {
* characters
* @param width default column width
*/
public void setDefaultColWidth(int width) {
public void setDefaultColumnWidth(int width) {
sheet.setDefaultColumnWidth(width);
}

View File

@ -218,7 +218,7 @@ public final class TestBugs extends TestCase {
}
}
sheet.setDefaultColWidth(18) ;
sheet.setDefaultColumnWidth(18) ;
writeTestOutputFileForViewing(wb, "test22568");
}

View File

@ -268,11 +268,11 @@ public final class TestDataValidation extends TestCase {
for (int i = 0; i < 6; i++) {
row.createCell(i).setCellStyle(_style_4);
if (i == 2 || i == 3 || i == 4) {
sheet.setColWidth(i, 3500);
sheet.setColumnWidth(i, 3500);
} else if (i == 5) {
sheet.setColWidth(i, 10000);
sheet.setColumnWidth(i, 10000);
} else {
sheet.setColWidth(i, 8000);
sheet.setColumnWidth(i, 8000);
}
}
HSSFCell cell = row.getCell(0);

View File

@ -681,8 +681,8 @@ public final class TestHSSFSheet extends TestCase {
// autoSize the first column and check its size before the merged region (1,0,1,1) is set:
// it has to be based on the 2nd row width
sheet.autoSizeColumn((short)0);
assertTrue("Column autosized with only one row: wrong width", sheet.getColWidth(0) >= minWithRow1And2);
assertTrue("Column autosized with only one row: wrong width", sheet.getColWidth(0) <= maxWithRow1And2);
assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) >= minWithRow1And2);
assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) <= maxWithRow1And2);
//create a region over the 2nd row and auto size the first column
sheet.addMergedRegion(new CellRangeAddress(1,1,0,1));
@ -692,16 +692,16 @@ public final class TestHSSFSheet extends TestCase {
// check that the autoSized column width has ignored the 2nd row
// because it is included in a merged region (Excel like behavior)
HSSFSheet sheet2 = wb2.getSheet(sheetName);
assertTrue(sheet2.getColWidth(0) >= minWithRow1Only);
assertTrue(sheet2.getColWidth(0) <= maxWithRow1Only);
assertTrue(sheet2.getColumnWidth(0) >= minWithRow1Only);
assertTrue(sheet2.getColumnWidth(0) <= maxWithRow1Only);
// remove the 2nd row merged region and check that the 2nd row value is used to the autoSizeColumn width
sheet2.removeMergedRegion(1);
sheet2.autoSizeColumn((short)0);
HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
HSSFSheet sheet3 = wb3.getSheet(sheetName);
assertTrue(sheet3.getColWidth(0) >= minWithRow1And2);
assertTrue(sheet3.getColWidth(0) <= maxWithRow1And2);
assertTrue(sheet3.getColumnWidth(0) >= minWithRow1And2);
assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2);
}
/**
@ -785,16 +785,16 @@ public final class TestHSSFSheet extends TestCase {
HSSFSheet sh = wb.getSheetAt(0);
for (char i = 'A'; i <= 'S'; i++) {
int idx = i - 'A';
int w = sh.getColWidth(idx);
int w = sh.getColumnWidth(idx);
assertEquals(ref[idx], w);
}
//the second sheet doesn't have overridden column widths
sh = wb.getSheetAt(1);
int def_width = sh.getDefaultColWidth();
int def_width = sh.getDefaultColumnWidth();
for (char i = 'A'; i <= 'S'; i++) {
int idx = i - 'A';
int w = sh.getColWidth(idx);
int w = sh.getColumnWidth(idx);
//getDefaultColumnWidth returns width measured in characters
//getColumnWidth returns width measured in 1/256th units
assertEquals(def_width*256, w);
@ -803,35 +803,35 @@ public final class TestHSSFSheet extends TestCase {
//test new workbook
wb = new HSSFWorkbook();
sh = wb.createSheet();
sh.setDefaultColWidth(10);
assertEquals(10, sh.getDefaultColWidth());
assertEquals(256*10, sh.getColWidth(0));
assertEquals(256*10, sh.getColWidth(1));
assertEquals(256*10, sh.getColWidth(2));
sh.setDefaultColumnWidth(10);
assertEquals(10, sh.getDefaultColumnWidth());
assertEquals(256*10, sh.getColumnWidth(0));
assertEquals(256*10, sh.getColumnWidth(1));
assertEquals(256*10, sh.getColumnWidth(2));
for (char i = 'D'; i <= 'F'; i++) {
short w = (256*12);
sh.setColWidth(i, w);
assertEquals(w, sh.getColWidth(i));
sh.setColumnWidth(i, w);
assertEquals(w, sh.getColumnWidth(i));
}
//serialize and read again
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sh = wb.getSheetAt(0);
assertEquals(10, sh.getDefaultColWidth());
assertEquals(10, sh.getDefaultColumnWidth());
//columns A-C have default width
assertEquals(256*10, sh.getColWidth(0));
assertEquals(256*10, sh.getColWidth(1));
assertEquals(256*10, sh.getColWidth(2));
assertEquals(256*10, sh.getColumnWidth(0));
assertEquals(256*10, sh.getColumnWidth(1));
assertEquals(256*10, sh.getColumnWidth(2));
//columns D-F have custom width
for (char i = 'D'; i <= 'F'; i++) {
short w = (256*12);
assertEquals(w, sh.getColWidth(i));
assertEquals(w, sh.getColumnWidth(i));
}
// check for 16-bit signed/unsigned error:
sh.setColWidth(0, 40000);
assertEquals(40000, sh.getColWidth(0));
sh.setColumnWidth(0, 40000);
assertEquals(40000, sh.getColumnWidth(0));
}
/**