⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elementparser4.java

📁 A translator that converts Qt Designer UI files into SWT java classes. Use the power of Qt Designer
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }
    }

    
    //
    //
    //
    
    private Layout parseLayout(
        XMLElement  iElement,
        String      iClassName,
        Widget      iParent )
    {
        Layout layout = new Layout(iClassName, iParent);
        
        ElementParserHelper.parseAttributeProperties(iElement, layout);

        Enumeration childEnum = iElement.enumerateChildren();

        while ( childEnum.hasMoreElements() )
        {
            XMLElement childElement = (XMLElement)(childEnum.nextElement());
            String     childName    = childElement.getName();
            
            if ( "property".equals(childName) )
            {
                ElementParserHelper.parseProperty(childElement, layout);
            }
            else if ( "attribute".equals(childName) )
            {
                ElementParserHelper.parseProperty(childElement, layout);
            }
            else if ( "item".equals(childElement.getName()) )
            {
                this.parseLayoutItem(childElement, iParent);
            }
            else
            {
                System.err.println("WARNING: Unknown element: "+childName);
            }
        }
        
        return layout;
    }

    
    private void parseLayoutItem(
        XMLElement  iElement,
        Widget      iParent )
    {
        Enumeration childEnum = iElement.enumerateChildren();

        while ( childEnum.hasMoreElements() )
        {
            XMLElement childElement = (XMLElement)(childEnum.nextElement());
            String     childName    = childElement.getName();
            
            if ( "widget".equals(childName) )
            {
                String className = childElement.getStringAttribute("class");
                Widget widget    = null;
                
                if ( "Line".equals(className) )
                {
                    widget = this.parseWidget(childElement, Widget.QT_LINE, iParent);
                }
                else
                {
                    widget = this.parseWidget(childElement, className, iParent);
                }
                
                ElementParserHelper.parseAttributeProperties(iElement, widget);
            }
            else if ( "layout".equals(childName) )
            {
                String className    = childElement.getStringAttribute("class");
                Widget layoutWidget = new Widget(Widget.QT_LAYOUT_WIDGET, iParent);
                
                ElementParserHelper.parseAttributeProperties(iElement, layoutWidget);
                this.parseLayout(childElement, className, layoutWidget);
            }
            else if ( "spacer".equals(childName) )
            {
                Widget widget = this.parseWidget(childElement, Widget.QT_SPACER, iParent);

                ElementParserHelper.parseAttributeProperties(iElement, widget);
            }
            else
            {
                System.err.println("WARNING: Unknown element: "+childName);
            }
        }
    }
    
    
    //
    //
    //

    private Widget parseMenuBar( XMLElement iElement )
    {
        return parseMenu(iElement, Widget.QT_MENU_BAR, null);
    }
    

    private Widget parseMenu(
        XMLElement  iElement,
        String      iClassName,
        Widget      iParent )
    {
        Widget menu     = new Widget(iClassName, iParent);
        Map    childMap = new HashMap();

        ElementParserHelper.parseAttributeProperties(iElement, menu);
        
        Enumeration childEnum = iElement.enumerateChildren();

        while ( childEnum.hasMoreElements() )
        {
            XMLElement  childElement = (XMLElement)(childEnum.nextElement());
            String      childName    = childElement.getName();
            
            if ( "property".equals(childName) )
            {
                ElementParserHelper.parseProperty(childElement, menu);
            }
            else if ( "widget".equals(childName) )
            {
                String className = childElement.getStringAttribute("class");
                String name      = childElement.getStringAttribute("name");
                
                if ( "QMenu".equals(className) )
                {
                    Widget child = this.parseMenu(childElement, Widget.QT_MENU, null);
                    
                    childMap.put(name, child);
                }
                else
                {
                    System.err.println("WARNING: Unknown menu child class: "+className);
                }
            }
            else if ( "addaction".equals(childName) )
            {
                String name = childElement.getStringAttribute("name");
                
                if ( "separator".equals(name) )
                {
                    new Widget(Widget.QT_MENU_SEPARATOR, menu);
                }
                else
                {
                    Widget child = (Widget)(childMap.get(name));
                    
                    if ( child != null )
                    {
                        menu.addChild(child);
                    }
                    else
                    {
                        child = new Widget(Widget.QT_MENU_ACTION, menu);
                        child.setProperty("name", name);
                    }
                }
            }
            else
            {
                System.err.println("WARNING: Unknown menubar element: "+childName);
            }
        }
        
        return menu;
    }
    
    
    //
    //
    //

    private Widget parseToolBar( XMLElement iElement )
    {
        Widget toolBar = new Widget(Widget.QT_TOOL_BAR);

        ElementParserHelper.parseAttributeProperties(iElement, toolBar);
        
        Enumeration childEnum = iElement.enumerateChildren();

        while ( childEnum.hasMoreElements() )
        {
            XMLElement  childElement = (XMLElement)(childEnum.nextElement());
            String      childName    = childElement.getName();
            
            if ( "property".equals(childName) )
            {
                ElementParserHelper.parseProperty(childElement, toolBar);
            }
            else if ( "addaction".equals(childName) )
            {
                Widget child;
                String name = childElement.getStringAttribute("name");
                
                if ( "separator".equals(name) )
                {
                    child = new Widget(Widget.QT_TOOL_BAR_SEPARATOR, toolBar);
                }
                else
                {
                    child = new Widget(Widget.QT_TOOL_BAR_ACTION, toolBar);
                }

                ElementParserHelper.parseAttributeProperties(childElement, child);
            }
        }
        
        return toolBar;
    }
    
    
    //
    //
    //
    
    private Action parseAction( XMLElement iElement )
    {
        Action action = new Action();

        ElementParserHelper.parseAttributeProperties(iElement, action);

        Enumeration childEnum = iElement.enumerateChildren();

        while ( childEnum.hasMoreElements() )
        {
            XMLElement childElement = (XMLElement)(childEnum.nextElement());
            String     childName    = childElement.getName();
            
            if ( "property".equals(childName) )
            {
                ElementParserHelper.parseProperty(childElement, action);
            }
        }
        
        return action;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -