I've added a radio button on a shape on a spreadsheets programatically with JAVA but I need one more thing.
I would like to anchor the radio button to a specify cell and asign it a true value (1) on this cell qhen the radio button is active or an false value (0).
I've atached 3 images with this funcionality on a spreadsheet on calc UI.
My Java code until now is this:
Code: Select all
// class properties
XComponent xComp;
XSpreadsheetDocument myDoc = null;
XSpreadsheet mySheet = null;
// Add a Radio button on a Spreadsheet's cell with the cellName (for example "A1")
public void addRadio(String name, String label, String cellName) {
XPropertySet props = null;
try {
props = addControl(xComp, name, label, "RadioButton", 1000, 600, cellName);
props.addPropertyChangeListener("State", this);
} catch (Exception e) {
e.printStackTrace();
}
}
// Add a control on a Spreadsheet's cell
private XPropertySet addControl(XComponent doc, String name, String label, String compKind, int width, int height, String cellName) {
XPropertySet modelProps = null;
// create a shape to represent the control's view
XControlShape cShape = createInstanceMSF(XControlShape.class, "com.sun.star.drawing.ControlShape");
Point cellPos = getCellPos(mySheet, cellName);
// position by cellName and size of the shape
cShape.setSize(new Size(width, height));
cShape.setPosition(new Point(cellPos.X+100, cellPos.Y)); [b]// I would like to put the radio button in the middle of the cell[/b]
// adjust the anchor so that the control is tied to the page
XPropertySet shapeProps = UnoRuntime.queryInterface(XPropertySet.class, cShape);
[b] // THIS DOESN'T WORK BECAUSE I'M WORKING WITH A SPREADSHEET NOT A TEXTDOCUMENT
// HOW LINK THE VALUE OF THE RADIO BUTTON TO A CELL? [/b]
// TextContentAnchorType eAnchorType = TextContentAnchorType.AS_CHARACTER;
// shapeProps.setPropertyValue("AnchorType", eAnchorType);
// create the control's model
XControlModel cModel = createInstanceMSF(XControlModel.class, "com.sun.star.form.component." + compKind);
// link model to the shape
cShape.setControl(cModel);
// add the shape to the shapes on the doc's draw page
String[] namesSheets = myDoc.getSheets().getElementNames();
XDrawPage drawPage = getDrawPage(doc, Arrays.asList(namesSheets).indexOf(_nombreHojaCreada));
XShapes formShapes = UnoRuntime.queryInterface(XShapes.class, drawPage);
formShapes.add(cShape);
// set Name and Label properties for the model
modelProps = UnoRuntime.queryInterface(XPropertySet.class, cModel);
modelProps.setPropertyValue("Name", name);
[b] // I WOLUD LIKE TO ASSIGN A PORPERTY 'VALUE' TO THE RADIO BUTTON WHEN IS ACTIVE[/b]
if (label != null) {
modelProps.setPropertyValue("Label", label);
}
return modelProps;
}