use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Slider method execute.
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 startBlock = null;
Block blockTmp = null;
Collection<Block> blocksToDelete = new LinkedList<Block>();
boolean bEndBlockFound = false;
int ratio = 0;
int beginLine = -1;
// search of the start block
if (block.getText().trim().indexOf(startPattern) == 0 && block.length == 1) {
startBlock = block;
blocksToDelete.add(startBlock);
blockTmp = block;
// search of endPattern
while (blockFactory.getSouthBlock(blockTmp) != null && canBlockBeSelected(blockFactory.getSouthBlock(blockTmp)) && blockFactory.getSouthBlock(blockTmp).length == 1 && !bEndBlockFound) {
blockTmp = blockFactory.getSouthBlock(blockTmp);
// check if the block correspond to screenHiddenPattern or screenShowedPattern
if (blockTmp.getText().trim().indexOf(screenShowedPattern) == 0) {
ratio++;
if (beginLine == -1)
beginLine = blockTmp.line;
blocksToDelete.add(blockTmp);
} else if (blockTmp.getText().trim().indexOf(screenHiddenPattern) == 0) {
blocksToDelete.add(blockTmp);
} else if (blockTmp.getText().trim().indexOf(endPattern) == 0) {
blocksToDelete.add(blockTmp);
bEndBlockFound = true;
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
if (!bEndBlockFound) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
Block mySlider = new Block();
mySlider.name = "untitled";
mySlider.type = "slider";
mySlider.setText("");
mySlider.bRender = true;
mySlider.line = startBlock.line;
mySlider.column = startBlock.column;
mySlider.setOptionalAttribute("width", "1");
mySlider.setOptionalAttribute("height", "" + (blockTmp.line - startBlock.line + 1));
mySlider.setOptionalAttribute("ratio", "" + ratio);
mySlider.setOptionalAttribute("begin", "" + beginLine);
blockFactory.insertBlock(mySlider, blockFactory.getPreviousBlock(block));
blockFactory.removeBlocks(blocksToDelete);
xrs.newCurrentBlock = mySlider;
xrs.hasMatched = true;
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class SplitBlock method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
Engine.logBeans.trace("Entering SplitBlock : " + block.getText() + " line :" + block.line + " col :" + block.column);
// create the tokenizer
StringTokenizer st = new StringTokenizer(block.getText(), delimiters, true);
if (st.countTokens() > 0) {
Block curBlock = blockFactory.getPreviousBlock(block);
Block tempBlock;
// variable lastIndex is used to adjust the column attribute of the created blocks
int lastIndex = 0;
if (keepDelimiters) {
while (st.hasMoreTokens()) {
// clones the original blocks in order to get the same attributes
try {
tempBlock = (Block) block.clone();
} catch (CloneNotSupportedException e) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return (xrs);
}
tempBlock.setText(st.nextToken());
// adjust the colum attribute
tempBlock.column = block.column + lastIndex;
// set lastIndex juste before the next token or delimiter
lastIndex += tempBlock.getText().length();
// insert the new sub block
blockFactory.insertBlock(tempBlock, curBlock);
Engine.logBeans.trace("SplitBlock new block: " + tempBlock.getText() + " line :" + tempBlock.line + " col :" + tempBlock.column);
// update the current block
curBlock = tempBlock;
}
} else {
String pattern;
while (st.hasMoreTokens()) {
pattern = st.nextToken();
if (delimiters.indexOf(pattern.charAt(0)) == -1) {
// clones the original blocks in order to get the same attributes
try {
tempBlock = (Block) block.clone();
} catch (CloneNotSupportedException e) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return (xrs);
}
tempBlock.setText(pattern);
// adjust the colum attribute
tempBlock.column = block.column + lastIndex;
// insert the new sub block
blockFactory.insertBlock(tempBlock, curBlock);
Engine.logBeans.trace("SplitBlock new block: " + tempBlock.getText() + " line :" + tempBlock.line + " col :" + tempBlock.column);
// update the current block
curBlock = tempBlock;
}
// set lastIndex juste before the next token or delimiter
lastIndex += pattern.length();
}
}
// once all tokens have been inserted, remove the original block
Engine.logBeans.trace("Exiting SplitBlock : " + block.getText());
if (curBlock != null)
Engine.logBeans.trace("currentBlock : " + curBlock.getText() + " line :" + curBlock.line + " col :" + curBlock.column);
blockFactory.removeBlock(block);
xrs.hasMatched = true;
xrs.newCurrentBlock = curBlock;
return (xrs);
}
Engine.logBeans.trace("Exiting SplitBlock without change : " + block.getText());
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return (xrs);
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class EditField method groupDotedLines.
public void groupDotedLines(Block curBlock, BlockFactory blockFactory) {
char c;
Block nxtBlock;
numberOfLines = 1;
while ((c = curBlock.getText().charAt(0)) == '.') {
nxtBlock = blockFactory.getNextBlock(curBlock);
if (nxtBlock.getText().charAt(0) != c)
break;
if (curBlock.line != nxtBlock.line)
numberOfLines++;
blockFactory.mergeBlocks(curBlock, nxtBlock);
xrs.newCurrentBlock = curBlock;
}
if (numberOfLines != 1)
curBlock.setOptionalAttribute("nblines", (Integer.valueOf(numberOfLines)).toString());
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Menu method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
xrs.newCurrentBlock = block;
boolean menuDetected = false;
Block blk = null;
/*
if ((blk = blockFactory.getBlockByType("field")) == null)
return xrs;
// if more than 3, don't use menus
menuWidth = Math.min(3, (int)Integer.parseInt(blk.getOptionalAttribute("size")));
*/
String str1 = block.getText();
// check with line & column for other 1 char strings
if (isLengthOK(str1) && isLineOK(block.line) && isCharTypeOK(str1)) {
String str;
refColumn = block.column;
refAttrib = block.attribute;
blk = block;
while ((blk = blockFactory.getNextBlock(blk)) != null) {
str = blk.getText();
if (isLengthOK(str) && isLineOK(block.line) && isCharTypeOK(str) && isColumnOK(blk) && isAttributeOK(blk.attribute)) {
menuDetected = true;
blk.setOptionalAttribute("item", ' ' + str + ' ');
// decrease colum because we gonna add a space before
if (refColumn > 0)
blk.column--;
blk.type = "menu";
}
}
if (menuDetected) {
block.setOptionalAttribute("item", ' ' + str1 + ' ');
// decrease colum because we gonna add a space before
if (refColumn > 0)
block.column--;
block.type = "menu";
xrs.newCurrentBlock = block;
xrs.hasMatched = true;
}
}
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Nptui method treatAndAddComponent.
/**
* Treat a NPTUI component, create a block corresponding to it,
* add this block to the block factory,
* remove old blocks corresponding to it from block factory,
* treat window's children components,
* copy window's children blocks in optionnal children,
* etc.
*
* @param component : the NPTUI component to treat
* @param screenWidth : the screen width
* @param dom : the DOM
* @param blockFactory : the block factory
* @param parent : the parent Block, the window to which add the component if it is a window's child, null if no parent window exists.
* @param javelin : the javelin emulator object
*/
private void treatAndAddComponent(ACLNptuiComponent component, int screenWidth, org.w3c.dom.Document dom, BlockFactory blockFactory, Block parent, iJavelin javelin) {
int offset = component.getScreenOffset();
int compLine, compCol;
if (offset % screenWidth != 0) {
compLine = offset / screenWidth;
compCol = offset % screenWidth;
} else {
compLine = (offset / screenWidth) - 1;
compCol = 0;
}
int cursorLine = javelin.getCurrentLine();
int cursorColumn = javelin.getCurrentColumn();
if (blockFactory == null) {
// no parent block defined and no blockFactory
Engine.logBeans.trace("(treatAndAddComponent) no parent block defined and no blockFactory");
return;
}
// look for the object place in blockFactory
Block beginBlock = blockFactory.getFirstBlock();
Block afterBlock = null;
if (beginBlock == null) {
// no block in blockFactory
Engine.logBeans.trace("(treatAndAddComponent) no block in blockFactory");
return;
}
// there is at least one block in blockFactory
if (beginBlock.line == compLine && beginBlock.column >= compCol) {
// the block matching component's line and column is the first block of blockFactory
afterBlock = null;
} else {
while (// while beginBlock is on a line inferior to compLine
beginBlock.line < compLine || (beginBlock.line == compLine && beginBlock.column < compCol)) {
// or beginBlock is on the good line but on a column inferior to compCol
afterBlock = beginBlock;
beginBlock = blockFactory.getNextBlock(beginBlock);
if (beginBlock == null) {
// no block in blockFactory is matching component's line and column
Engine.logBeans.trace("(treatAndAddComponent) no block in blockFactory is matching component's line and column");
return;
}
}
}
if (component instanceof ACLNptuiWindow) {
if (bWindow) {
Engine.logBeans.trace("(treatAndAddComponent) window detected and extraction allowed");
ACLNptuiWindow comp = (ACLNptuiWindow) component;
Block myPanel = new Block();
myPanel.name = "untitled";
myPanel.type = "panel";
myPanel.setText("");
myPanel.bRender = true;
myPanel.line = compLine;
myPanel.column = compCol;
int height = comp.getHeight() - 1;
myPanel.setOptionalAttribute("width", "" + comp.getWidth());
myPanel.setOptionalAttribute("height", "" + height);
myPanel.setOptionalAttribute("shadow", "" + comp.isShadow());
if (comp.getHeader() != null) {
myPanel.setOptionalAttribute("topTitle", "" + comp.getHeader());
myPanel.setOptionalAttribute("topTitleColumn", "" + comp.getHeaderJustification());
} else {
myPanel.setOptionalAttribute("topTitle", "");
myPanel.setOptionalAttribute("topTitleColumn", "");
}
if (comp.getFooter() != null) {
myPanel.setOptionalAttribute("bottomTitle", "" + comp.getFooter());
myPanel.setOptionalAttribute("bottomTitleColumn", "" + comp.getFooterJustification());
} else {
myPanel.setOptionalAttribute("bottomTitle", "");
myPanel.setOptionalAttribute("bottomTitleColumn", "");
}
myPanel.setOptionalAttribute("zOrder", "" + comp.getZOrder());
// comp.isPullDownMenu());
// treat every contained components
ACLNptuiComponent[] childrenComp = comp.getComponents();
for (int i = 0; i < childrenComp.length; i++) {
Engine.logBeans.trace("Treating window child component " + i + " : " + childrenComp[i].getClass());
treatAndAddComponent(childrenComp[i], screenWidth, dom, blockFactory, myPanel, javelin);
}
// remove blocks from the existant window, and copy the content blocks to the new window
removeBlocksFromWindow(blockFactory, afterBlock, compCol, compLine, comp.getWidth() + 2, comp.getHeight(), myPanel, dom);
if (parent == null) {
blockFactory.insertBlock(myPanel, afterBlock);
} else {
// window in another component : impossible
Engine.logBeans.trace("(treatAndAddComponent) window in another component : error, don't add this component");
}
} else {
Engine.logBeans.trace("(treatAndAddComponent) window detected but extraction not allowed");
}
} else if (component instanceof ACLNptuiScrollBar) {
if (bScrollBar) {
Engine.logBeans.trace("(treatAndAddComponent) scrollbar detected and extraction allowed");
ACLNptuiScrollBar comp = (ACLNptuiScrollBar) component;
Block mySlider = new Block();
mySlider.name = "untitled";
mySlider.type = "slider";
mySlider.setText("");
mySlider.line = compLine;
mySlider.column = compCol;
if (comp.isHorizontal()) {
mySlider.setOptionalAttribute("width", "" + comp.getSize());
mySlider.setOptionalAttribute("height", "1");
} else {
mySlider.setOptionalAttribute("width", "1");
mySlider.setOptionalAttribute("height", "" + comp.getSize());
}
mySlider.setOptionalAttribute("shadow", "" + comp.isShadow());
mySlider.setOptionalAttribute("hasArrows", "" + comp.hasArrows());
mySlider.setOptionalAttribute("itemsCount", "" + comp.getItemsCount());
mySlider.setOptionalAttribute("itemsCountBeforeSlider", "" + comp.getItemsCountBeforeSlider());
mySlider.setOptionalAttribute("sliderSize", "" + comp.getSliderSize());
mySlider.setOptionalAttribute("sliderPos", "" + comp.getSliderPosInShaft());
// remove blocks from blockFactory
if (comp.isHorizontal()) {
removeBlocksHorizontaly(blockFactory, afterBlock, compCol, compLine, comp.getSize());
} else {
removeBlocksVerticaly(blockFactory, afterBlock, compCol, compLine, comp.getSize());
}
// add generated blocks
if (parent == null) {
blockFactory.insertBlock(mySlider, afterBlock);
} else {
// scrollbar in window
parent.addOptionalChildren(mySlider);
}
} else {
Engine.logBeans.trace("(treatAndAddComponent) scrollbar detected but extraction not allowed");
}
} else if (component instanceof ACLNptuiSelectionField) {
ACLNptuiSelectionField comp = (ACLNptuiSelectionField) component;
Block myContainer = new Block();
myContainer.name = "untitled";
myContainer.setText("");
myContainer.line = compLine;
myContainer.column = compCol;
myContainer.setOptionalAttribute("shadow", "" + comp.isShadow());
myContainer.setOptionalAttribute("choicesTextSize", "" + comp.getChoiceTextSize());
myContainer.setOptionalAttribute("choicesCols", "" + comp.getChoiceColumns());
myContainer.setOptionalAttribute("choicesRows", "" + comp.getChoiceRows());
if (comp.isAutoEnter())
myContainer.setOptionalAttribute("autoEnter", "" + comp.isAutoEnter());
if (comp.isAutoSelect())
myContainer.setOptionalAttribute("autoSelect", "" + comp.isAutoSelect());
ACLNptuiChoice[] choices = comp.getChoices();
int type = ((ACLNptuiSelectionField) component).getType();
if (type == ACLNptuiSelectionField.TYPE_BUTTONS) {
if (bButton) {
Engine.logBeans.trace("(treatAndAddComponent) buttons detected and extraction allowed");
myContainer.type = "buttonsPanel";
for (int j = 0; j < choices.length; j++) {
ACLNptuiChoice choice = choices[j];
int choiceOffset = choice.getScreenOffset();
Element element = dom.createElement("block");
element.setAttribute("name", "untitled");
element.setAttribute("type", "keyword");
Text textNode = dom.createTextNode(choice.getText());
element.appendChild(textNode);
int choiceLine, choiceColumn;
if (choiceOffset % screenWidth != 0) {
choiceLine = choiceOffset / screenWidth;
choiceColumn = choiceOffset % screenWidth;
} else {
choiceLine = (choiceOffset / screenWidth) - 1;
choiceColumn = 0;
}
element.setAttribute("line", "" + choiceLine);
element.setAttribute("column", "" + choiceColumn);
element.setAttribute("action", "KEY_NPTUI");
element.setAttribute("width", "" + choice.getLength());
element.setAttribute("height", "1");
element.setAttribute("dotransaction", "false");
element.setAttribute("available", "" + choice.isAvailable());
// handle cursor focus
if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
element.setAttribute("hasFocus", "true");
// handle attributes and remove old blocks from block factory
int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
addAttributes(attribute, element);
// add the element to container
myContainer.addOptionalChildren(element);
}
} else {
Engine.logBeans.trace("(treatAndAddComponent) buttons detected but extraction not allowed");
}
} else if (type == ACLNptuiSelectionField.TYPE_CHECK) {
if (bCheckbox) {
Engine.logBeans.trace("(treatAndAddComponent) checkboxes detected and extraction allowed");
myContainer.type = "checkboxesPanel";
for (int j = 0; j < choices.length; j++) {
ACLNptuiChoice choice = choices[j];
int choiceOffset = choice.getScreenOffset();
Element element = dom.createElement("item");
element.setAttribute("name", "untitled");
element.setAttribute("type", "checkbox");
Text textNode = dom.createTextNode(choice.getText());
element.appendChild(textNode);
int choiceLine, choiceColumn;
if (choiceOffset % screenWidth != 0) {
choiceLine = choiceOffset / screenWidth;
choiceColumn = choiceOffset % screenWidth;
} else {
choiceLine = (choiceOffset / screenWidth) - 1;
choiceColumn = 0;
}
element.setAttribute("line", "" + choiceLine);
element.setAttribute("column", "" + choiceColumn);
element.setAttribute("checked", "" + choice.isSelected());
// handle cursor focus
if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
element.setAttribute("hasFocus", "true");
// handle attributes and remove old blocks from block factory
int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
addAttributes(attribute, element);
// add the element to container
myContainer.addOptionalChildren(element);
}
} else {
Engine.logBeans.trace("(treatAndAddComponent) checkboxes detected but extraction not allowed");
}
} else if (type == ACLNptuiSelectionField.TYPE_MENU) {
if (bMenu) {
Engine.logBeans.trace("(treatAndAddComponent) menu detected and extraction allowed");
myContainer.type = "menu";
for (int j = 0; j < choices.length; j++) {
ACLNptuiChoice choice = choices[j];
int choiceOffset = choice.getScreenOffset();
Element element = dom.createElement("item");
element.setAttribute("name", "untitled");
element.setAttribute("type", "menuItem");
element.setAttribute("value", choice.getText());
int choiceLine, choiceColumn;
if (choiceOffset % screenWidth != 0) {
choiceLine = choiceOffset / screenWidth;
choiceColumn = choiceOffset % screenWidth;
} else {
choiceLine = (choiceOffset / screenWidth) - 1;
choiceColumn = 0;
}
element.setAttribute("line", "" + choiceLine);
element.setAttribute("column", "" + choiceColumn);
element.setAttribute("selected", "" + choice.isSelected());
element.setAttribute("available", "" + choice.isAvailable());
element.setAttribute("hilighted", "" + choice.isHilighted());
// handle cursor focus
if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
element.setAttribute("hasFocus", "true");
// handle attributes and remove old blocks from block factory
int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
addAttributes(attribute, element);
// add the element to container
myContainer.addOptionalChildren(element);
}
} else {
Engine.logBeans.trace("(treatAndAddComponent) menu detected but extraction not allowed");
}
} else if (type == ACLNptuiSelectionField.TYPE_RADIO) {
if (bRadio) {
Engine.logBeans.trace("(treatAndAddComponent) radio buttons detected and extraction allowed");
myContainer.type = "radioPanel";
for (int j = 0; j < choices.length; j++) {
ACLNptuiChoice choice = choices[j];
int choiceOffset = choice.getScreenOffset();
Element element = dom.createElement("item");
element.setAttribute("name", "untitled");
element.setAttribute("type", "radio");
element.setAttribute("value", choice.getText());
int choiceLine, choiceColumn;
if (choiceOffset % screenWidth != 0) {
choiceLine = choiceOffset / screenWidth;
choiceColumn = choiceOffset % screenWidth;
} else {
choiceLine = (choiceOffset / screenWidth) - 1;
choiceColumn = 0;
}
element.setAttribute("line", "" + choiceLine);
element.setAttribute("column", "" + choiceColumn);
element.setAttribute("selected", "" + choice.isSelected());
// handle cursor focus
if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
element.setAttribute("hasFocus", "true");
// handle attributes and remove old blocks from block factory
int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
addAttributes(attribute, element);
// add the element to container
myContainer.addOptionalChildren(element);
}
} else {
Engine.logBeans.trace("(treatAndAddComponent) radio buttons detected but extraction not allowed");
}
} else {
// type is unknown or not handled
Engine.logBeans.trace("(treatAndAddComponent) Type is unknown or not handled");
return;
}
// if the children have been added (if the boolean was true)
if (myContainer.hasOptionalChildren()) {
// add generated blocks
if (parent == null) {
blockFactory.insertBlock(myContainer, afterBlock);
} else {
// SelectionField in window
parent.addOptionalChildren(myContainer);
}
}
}
}
Aggregations