You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/05/09 05:09:41 UTC
svn commit: r1742879 - in /poi/trunk/src:
java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/
ooxml/java/org/apache/poi/xssf/usermodel/
testcases/org/apache/poi/ss/usermodel/
Author: onealj
Date: Mon May 9 05:09:41 2016
New Revision: 1742879
URL: http://svn.apache.org/viewvc?rev=1742879&view=rev
Log:
bug 59443: add get/setAddress methods on cell comment class
Modified:
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/Comment.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java?rev=1742879&r1=1742878&r2=1742879&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java Mon May 9 05:09:41 2016
@@ -30,6 +30,7 @@ import org.apache.poi.hssf.record.ObjRec
import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.util.CellAddress;
/**
* Represents a cell comment - a sticky note associated with a cell.
@@ -146,6 +147,7 @@ public class HSSFComment extends HSSFTex
*
* @param visible <code>true</code> if the comment is visible, <code>false</code> otherwise
*/
+ @Override
public void setVisible(boolean visible) {
_note.setFlags(visible ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
setHidden(!visible);
@@ -156,15 +158,34 @@ public class HSSFComment extends HSSFTex
*
* @return <code>true</code> if the comment is visible, <code>false</code> otherwise
*/
+ @Override
public boolean isVisible() {
return _note.getFlags() == NoteRecord.NOTE_VISIBLE;
}
+
+ @Override
+ public CellAddress getAddress() {
+ return new CellAddress(getRow(), getColumn());
+ }
+
+ @Override
+ public void setAddress(CellAddress address) {
+ setRow(address.getRow());
+ setColumn(address.getColumn());
+ }
+
+ @Override
+ public void setAddress(int row, int col) {
+ setRow(row);
+ setColumn(col);
+ }
/**
* Return the row of the cell that contains the comment
*
* @return the 0-based row of the cell that contains the comment
*/
+ @Override
public int getRow() {
return _note.getRow();
}
@@ -174,6 +195,7 @@ public class HSSFComment extends HSSFTex
*
* @param row the 0-based row of the cell that contains the comment
*/
+ @Override
public void setRow(int row) {
_note.setRow(row);
}
@@ -183,6 +205,7 @@ public class HSSFComment extends HSSFTex
*
* @return the 0-based column of the cell that contains the comment
*/
+ @Override
public int getColumn() {
return _note.getColumn();
}
@@ -192,6 +215,7 @@ public class HSSFComment extends HSSFTex
*
* @param col the 0-based column of the cell that contains the comment
*/
+ @Override
public void setColumn(int col) {
_note.setColumn(col);
}
@@ -201,6 +225,7 @@ public class HSSFComment extends HSSFTex
*
* @return the name of the original author of the comment
*/
+ @Override
public String getAuthor() {
return _note.getAuthor();
}
@@ -210,6 +235,7 @@ public class HSSFComment extends HSSFTex
*
* @param author the name of the original author of the comment
*/
+ @Override
public void setAuthor(String author) {
if (_note != null) _note.setAuthor(author);
}
@@ -246,6 +272,7 @@ public class HSSFComment extends HSSFTex
throw new IllegalStateException("Shape type can not be changed in "+this.getClass().getSimpleName());
}
+ @Override
public void afterRemove(HSSFPatriarch patriarch){
super.afterRemove(patriarch);
patriarch.getBoundAggregate().removeTailRecord(getNoteRecord());
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Comment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Comment.java?rev=1742879&r1=1742878&r2=1742879&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Comment.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Comment.java Mon May 9 05:09:41 2016
@@ -17,6 +17,8 @@
package org.apache.poi.ss.usermodel;
+import org.apache.poi.ss.util.CellAddress;
+
public interface Comment {
/**
@@ -32,6 +34,28 @@ public interface Comment {
* @return <code>true</code> if the comment is visible, <code>false</code> otherwise
*/
boolean isVisible();
+
+ /**
+ * Get the address of the cell that this comment is attached to
+ *
+ * @return comment cell address
+ */
+ CellAddress getAddress();
+
+ /**
+ * Set the address of the cell that this comment is attached to
+ *
+ * @param addr
+ */
+ void setAddress(CellAddress addr);
+
+ /**
+ * Set the address of the cell that this comment is attached to
+ *
+ * @param row
+ * @param col
+ */
+ void setAddress(int row, int col);
/**
* Return the row of the cell that contains the comment
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java?rev=1742879&r1=1742878&r2=1742879&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java Mon May 9 05:09:41 2016
@@ -29,6 +29,7 @@ import org.apache.poi.xssf.model.Comment
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+import com.microsoft.schemas.office.excel.CTClientData;
import com.microsoft.schemas.vml.CTShape;
public class XSSFComment implements Comment {
@@ -55,11 +56,9 @@ public class XSSFComment implements Comm
// the same way as we do in setRow()/setColumn()
if(vmlShape != null && vmlShape.sizeOfClientDataArray() > 0) {
CellReference ref = new CellReference(comment.getRef());
- vmlShape.getClientDataArray(0).setRowArray(0,
- new BigInteger(String.valueOf(ref.getRow())));
-
- vmlShape.getClientDataArray(0).setColumnArray(0,
- new BigInteger(String.valueOf(ref.getCol())));
+ CTClientData clientData = vmlShape.getClientDataArray(0);
+ clientData.setRowArray(0, new BigInteger(String.valueOf(ref.getRow())));
+ clientData.setColumnArray(0, new BigInteger(String.valueOf(ref.getCol())));
// There is a very odd xmlbeans bug when changing the row
// arrays which can lead to corrupt pointer
@@ -72,6 +71,7 @@ public class XSSFComment implements Comm
*
* @return Name of the original comment author. Default value is blank.
*/
+ @Override
public String getAuthor() {
return _comments.getAuthor((int) _comment.getAuthorId());
}
@@ -81,6 +81,7 @@ public class XSSFComment implements Comm
*
* @param author the name of the original author of the comment
*/
+ @Override
public void setAuthor(String author) {
_comment.setAuthorId(
_comments.findAuthor(author)
@@ -90,20 +91,23 @@ public class XSSFComment implements Comm
/**
* @return the 0-based column of the cell that the comment is associated with.
*/
+ @Override
public int getColumn() {
- return new CellReference(_comment.getRef()).getCol();
+ return getAddress().getColumn();
}
/**
* @return the 0-based row index of the cell that the comment is associated with.
*/
+ @Override
public int getRow() {
- return new CellReference(_comment.getRef()).getRow();
+ return getAddress().getRow();
}
/**
* @return whether the comment is visible
*/
+ @Override
public boolean isVisible() {
boolean visible = false;
if(_vmlShape != null){
@@ -116,6 +120,7 @@ public class XSSFComment implements Comm
/**
* @param visible whether the comment is visible
*/
+ @Override
public void setVisible(boolean visible) {
if(_vmlShape != null){
String style;
@@ -124,23 +129,28 @@ public class XSSFComment implements Comm
_vmlShape.setStyle(style);
}
}
-
- /**
- * Set the column of the cell that contains the comment
- *
- * @param col the 0-based column of the cell that contains the comment
- */
- public void setColumn(int col) {
+
+ @Override
+ public CellAddress getAddress() {
+ return new CellAddress(_comment.getRef());
+ }
+
+ @Override
+ public void setAddress(int row, int col) {
+ setAddress(new CellAddress(row, col));
+ }
+
+ @Override
+ public void setAddress(CellAddress address) {
CellAddress oldRef = new CellAddress(_comment.getRef());
- CellAddress ref = new CellAddress(getRow(), col);
- _comment.setRef(ref.formatAsString());
+ _comment.setRef(address.formatAsString());
_comments.referenceUpdated(oldRef, _comment);
- if(_vmlShape != null) {
- _vmlShape.getClientDataArray(0).setColumnArray(
- new BigInteger[] { new BigInteger(String.valueOf(col)) }
- );
+ if (_vmlShape != null) {
+ CTClientData clientData = _vmlShape.getClientDataArray(0);
+ clientData.setRowArray(0, new BigInteger(String.valueOf(address.getRow())));
+ clientData.setColumnArray(0, new BigInteger(String.valueOf(address.getColumn())));
// There is a very odd xmlbeans bug when changing the column
// arrays which can lead to corrupt pointer
@@ -150,31 +160,29 @@ public class XSSFComment implements Comm
}
/**
+ * Set the column of the cell that contains the comment
+ *
+ * @param col the 0-based column of the cell that contains the comment
+ */
+ @Override
+ public void setColumn(int col) {
+ setAddress(getRow(), col);
+ }
+
+ /**
* Set the row of the cell that contains the comment
*
* @param row the 0-based row of the cell that contains the comment
*/
+ @Override
public void setRow(int row) {
- CellAddress oldRef = new CellAddress(_comment.getRef());
-
- CellAddress ref = new CellAddress(row, getColumn());
- _comment.setRef(ref.formatAsString());
- _comments.referenceUpdated(oldRef, _comment);
-
- if(_vmlShape != null) {
- _vmlShape.getClientDataArray(0).setRowArray(0,
- new BigInteger(String.valueOf(row)));
-
- // There is a very odd xmlbeans bug when changing the row
- // arrays which can lead to corrupt pointer
- // This call seems to fix them again... See bug #50795
- _vmlShape.getClientDataList().toString();
- }
+ setAddress(row, getColumn());
}
/**
* @return the rich text string of the comment
*/
+ @Override
public XSSFRichTextString getString() {
if(_str == null) {
CTRst rst = _comment.getText();
@@ -188,6 +196,7 @@ public class XSSFComment implements Comm
*
* @param string the XSSFRichTextString used by this object.
*/
+ @Override
public void setString(RichTextString string) {
if(!(string instanceof XSSFRichTextString)){
throw new IllegalArgumentException("Only XSSFRichTextString argument is supported");
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java?rev=1742879&r1=1742878&r2=1742879&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCellComment.java Mon May 9 05:09:41 2016
@@ -378,4 +378,38 @@ public abstract class BaseTestCellCommen
wb.close();
}
}
+
+ @Test
+ public void getAddress() {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sh = wb.createSheet();
+ CreationHelper factory = wb.getCreationHelper();
+ Drawing patriarch = sh.createDrawingPatriarch();
+ Comment comment = patriarch.createCellComment(factory.createClientAnchor());
+
+ assertEquals(CellAddress.A1, comment.getAddress());
+ Cell C2 = sh.createRow(1).createCell(2);
+ C2.setCellComment(comment);
+ assertEquals(new CellAddress("C2"), comment.getAddress());
+ }
+
+ @Test
+ public void setAddress() {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet sh = wb.createSheet();
+ CreationHelper factory = wb.getCreationHelper();
+ Drawing patriarch = sh.createDrawingPatriarch();
+ Comment comment = patriarch.createCellComment(factory.createClientAnchor());
+
+ assertEquals(CellAddress.A1, comment.getAddress());
+ CellAddress C2 = new CellAddress("C2");
+ assertEquals("C2", C2.formatAsString());
+ comment.setAddress(C2);
+ assertEquals(C2, comment.getAddress());
+
+ CellAddress E10 = new CellAddress(9, 4);
+ assertEquals("E10", E10.formatAsString());
+ comment.setAddress(9, 4);
+ assertEquals(E10, comment.getAddress());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org