Search in sources :

Example 1 with ACLNptuiChoice

use of com.eicon.iConnect.acl.ACLNptuiChoice 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);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) Block(com.twinsoft.convertigo.beans.core.Block) ACLNptuiChoice(com.eicon.iConnect.acl.ACLNptuiChoice) Text(org.w3c.dom.Text) ACLNptuiComponent(com.eicon.iConnect.acl.ACLNptuiComponent) ACLNptuiWindow(com.eicon.iConnect.acl.ACLNptuiWindow) ACLNptuiScrollBar(com.eicon.iConnect.acl.ACLNptuiScrollBar) ACLNptuiSelectionField(com.eicon.iConnect.acl.ACLNptuiSelectionField)

Aggregations

ACLNptuiChoice (com.eicon.iConnect.acl.ACLNptuiChoice)1 ACLNptuiComponent (com.eicon.iConnect.acl.ACLNptuiComponent)1 ACLNptuiScrollBar (com.eicon.iConnect.acl.ACLNptuiScrollBar)1 ACLNptuiSelectionField (com.eicon.iConnect.acl.ACLNptuiSelectionField)1 ACLNptuiWindow (com.eicon.iConnect.acl.ACLNptuiWindow)1 Block (com.twinsoft.convertigo.beans.core.Block)1 Element (org.w3c.dom.Element)1 Text (org.w3c.dom.Text)1