use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class CheckBox method execute.
@Override
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
Block nextBlock;
XMLRectangle position = new XMLRectangle(-1, -1, -1, -1);
String label = "";
boolean checked = false;
Collection<Block> blocksToDelete = new LinkedList<Block>();
boolean bLastBlock = false;
if (bFirstTime) {
// if position is defined
if (checkBoxDesc.x != -1 && checkBoxDesc.y != -1) {
// defined checkbox
if (checkBoxDesc.width == -1)
checkBoxDesc.width = 1;
if (checkBoxDesc.height == -1)
checkBoxDesc.height = 1;
// if no position is defined and check pattern or uncheck pattern is defined
} else if (!checkPattern.equals("") || !uncheckPattern.equals("")) {
// searching all checkboxes on the screen
bSearch = true;
bFirstTime = false;
// no position and no check/uncheck pattern but label defined
} else if (!Label.equals("")) {
// initialize the position of the checkbox
if (checkBoxDesc.x == -1)
checkBoxDesc.x = 0;
if (checkBoxDesc.y == -1)
checkBoxDesc.y = 0;
if (checkBoxDesc.width == -1)
checkBoxDesc.width = 1;
if (checkBoxDesc.height == -1)
checkBoxDesc.height = 1;
// no position, no check pattern, no label defined
} else {
// use default check and uncheck patterns
checkPattern = "/";
uncheckPattern = "";
// searching all checkboxes on the screen
bSearch = true;
bFirstTime = false;
}
}
if (bSearch) {
nextBlock = blockFactory.getNextBlock(block);
if (block.type.equals("field") && block.length == 1 && (block.getText().equals(checkPattern) || block.getText().equals(uncheckPattern))) {
// test if the next block is a label
if (nextBlock != null && canBlockBeSelected(nextBlock) && nextBlock.type.equals("static")) {
// label found
label = nextBlock.getText();
name = block.name;
position.y = block.line;
position.x = block.column;
checked = block.getText().equals(checkPattern) ? true : false;
blocksToDelete.add(block);
blocksToDelete.add(nextBlock);
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else if (bAdded) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
if (!bAdded || bSearch) {
bFirstTime = false;
if (!bSearch) {
if (blockFactory.getNextBlock(block) == null) {
// case block is the last one : insert block after !
bLastBlock = true;
} else {
// test if the block matches to add the block checkbox just before
if (block.line < checkBoxDesc.y) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
} else if (block.line == checkBoxDesc.y) {
if (block.column < checkBoxDesc.x) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
}
}
Block myCheckBox;
if (bSearch) {
myCheckBox = createCheckBox(label, position, checked);
} else {
myCheckBox = createCheckBox(Label, checkBoxDesc, false);
}
if (bLastBlock) {
blockFactory.insertBlock(myCheckBox, block);
} else {
blockFactory.insertBlock(myCheckBox, blockFactory.getPreviousBlock(block));
}
blockFactory.removeBlocks(blocksToDelete);
bAdded = true;
if (bSearch) {
xrs.newCurrentBlock = myCheckBox;
} else {
xrs.newCurrentBlock = block;
}
xrs.hasMatched = true;
}
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class CheckBox method createCheckBox.
private Block createCheckBox(String label, XMLRectangle zone, boolean bChecked) {
// build the block
Block myCheckBox = new Block();
myCheckBox.name = name;
myCheckBox.type = "checkbox";
myCheckBox.setText(label);
myCheckBox.bRender = true;
myCheckBox.line = zone.y;
myCheckBox.column = zone.x;
myCheckBox.setOptionalAttribute("checked", "" + bChecked);
myCheckBox.setOptionalAttribute("checkingPattern", checkPattern);
myCheckBox.setOptionalAttribute("uncheckingPattern", uncheckPattern);
return myCheckBox;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class DefaultBlockFactory method convertFormattedScreen.
private void convertFormattedScreen() {
int attribute;
Block block;
String text;
for (int i = 0; i < nbItems; i++) {
createFiller(i);
attribute = javelin.getFieldAttribute(i);
if ((attribute & iJavelin.AT_FIELD_PROTECTED) > 0) {
splitProtectedField(i, (attribute & iJavelin.AT_FIELD_PEN_SELECTABLE) != 0);
} else {
block = new Block();
text = javelin.getFieldText(i);
text = formatString(text);
block.setText(rightTrim(text));
block.line = javelin.getFieldLine(i);
block.column = javelin.getFieldColumn(i);
block.attribute = attribute;
block.type = "field";
block.length = javelin.getFieldLength(i);
setBlockName(block);
setupFieldBlock(block, attribute);
setupContinuousFields(block, i);
list.add(block);
fields.put(block.name, block);
}
}
}
Aggregations