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

📄 uidefinition.java

📁 A translator that converts Qt Designer UI files into SWT java classes. Use the power of Qt Designer
💻 JAVA
字号:
/* This file is part of ui2swt.
 *
 * $Revision: 1.3 $
 * $Date: 2007/01/14 10:34:54 $
 * $Name:  $
 *
 * Copyright (C) 2006-2007 James Forbes, All Rights Reserved.
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 *  1. The origin of this software must not be misrepresented; you must not
 *     claim that you wrote the original software. If you use this software in
 *     a product, an acknowledgment in the product documentation would be
 *     appreciated but is not required.
 *
 *  2. Altered source versions must be plainly marked as such, and must not be
 *     misrepresented as being the original software.
 *
 *  3. This notice may not be removed or altered from any source distribution.
 */

package ui2swt;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;


public class UIDefinition
{
    public static final int VERSION_2 = 2;
    public static final int VERSION_3 = 3;
    public static final int VERSION_4 = 4;


    //
    //
    //
    
    private static final int DEFAULT_VERSION = VERSION_2;

    private int version;
    private Widget rootWidget;
    private Widget menuBar;
    private List toolBars;
    private List actions;
    private List images;
    
    
    //
    //
    //
    
    public UIDefinition()
    {
        this.version = DEFAULT_VERSION;
    }
    
    
    public int getVersion()
    {
        return this.version;
    }
    
    
    public void setVersion( int iVersion )
    {
        this.version = iVersion;
    }
    
    
    public void setVersion( String iVersionString )
    {
        if ( (iVersionString == null) || (iVersionString.length() == 0) )
        {
            this.version = DEFAULT_VERSION;
        }
        else
        {
            switch (iVersionString.charAt(0))
            {
                case '4':
                    this.version = UIDefinition.VERSION_4;
                    break;

                case '3':
                    this.version = UIDefinition.VERSION_3;
                    break;
                    
                case '2':
                default:
                    this.version = UIDefinition.VERSION_2;
                    break;
            }
        }
    }
    
    
    public Widget getRootWidget()
    {
        return this.rootWidget;
    }
    
    
    public void setRootWidget( Widget iWidget )
    {
        this.rootWidget = iWidget;
    }
    
    
    public Widget getMenuBar()
    {
        return this.menuBar;
    }
    
    
    public void setMenuBar( Widget iMenuBar )
    {
        this.menuBar = iMenuBar;
    }
    
    
    public void addToolBar( Widget iToolBar )
    {
        if ( this.toolBars == null )
        {
            this.toolBars = new LinkedList();
        }
        
        this.toolBars.add(iToolBar);
    }
    
    
    public Widget[] getToolBars()
    {
        if ( this.toolBars == null )
        {
            return new Widget[0];
        }
        else
        {
            Object[] items  = this.toolBars.toArray();
            Widget[] result = new Widget[items.length];
            
            System.arraycopy(items, 0, result, 0, result.length);
            
            return result;
        }
    }
    
    
    public boolean hasToolBars()
    {
        return (this.toolBars != null);
    }
    
    
    public void addAction( Action iAction )
    {
        if ( this.actions == null )
        {
            this.actions = new LinkedList();
        }
        
        this.actions.add(iAction);
    }
    
    
    public Action getAction( String iPropertyName, String iPropertyValue )
    {
        if ( this.actions != null )
        {
            Iterator iterator = this.actions.iterator();
            
            while ( iterator.hasNext() )
            {
                Action action        = (Action)(iterator.next());
                String propertyValue = action.getProperty(iPropertyName);
                
                if ( iPropertyValue.equals(propertyValue) )
                {
                    return action;
                }
            }
        }
        
        return null;
    }
    
    
    public Action[] getActions()
    {
        if ( this.actions == null )
        {
            return new Action[0];
        }
        else
        {
            Object[] items  = this.actions.toArray();
            Action[] result = new Action[items.length];
            
            System.arraycopy(items, 0, result, 0, result.length);
            
            return result;
        }
    }
    
    
    public void addImage( Image iImage )
    {
        if ( this.images == null )
        {
            this.images = new LinkedList();
        }
        
        this.images.add(iImage);
    }
    
    
    public Image getImage( String iPropertyName, String iPropertyValue )
    {
        if ( this.images != null )
        {
            Iterator iterator = this.images.iterator();
            
            while ( iterator.hasNext() )
            {
                Image  image         = (Image)(iterator.next());
                String propertyValue = image.getProperty(iPropertyName);
                
                if ( iPropertyValue.equals(propertyValue) )
                {
                    return image;
                }
            }
        }
        
        return null;
    }
    
    
    public Image[] getImages()
    {
        if ( this.images == null )
        {
            return new Image[0];
        }
        else
        {
            Object[] items  = this.images.toArray();
            Image[]  result = new Image[items.length];
            
            System.arraycopy(items, 0, result, 0, result.length);
            
            return result;
        }
    }
    
    
    //
    //
    //
    
    void dump()
    {
        if ( this.rootWidget != null )
        {
            System.out.println("WIDGETS:");
            this.rootWidget.dump();
        }
        
        if ( this.menuBar != null )
        {
            System.out.println("MENU BAR:");
            this.menuBar.dump();
        }
        
        if ( this.toolBars != null )
        {
            System.out.println("TOOL BARS:");
            
            Iterator iterator = this.toolBars.iterator();
            
            while ( iterator.hasNext() )
            {
                Widget toolBar = (Widget)(iterator.next());
                
                toolBar.dump();
            }
        }
        
        if ( this.actions != null )
        {
            System.out.println("ACTIONS:");
            
            Iterator iterator = this.actions.iterator();
            
            while ( iterator.hasNext() )
            {
                Action action = (Action)(iterator.next());
                
                action.dump();
            }
        }
        
        if ( this.images != null )
        {
            System.out.println("IMAGES:");
            
            Iterator iterator = this.images.iterator();
            
            while ( iterator.hasNext() )
            {
                Image image = (Image)(iterator.next());
                
                image.dump();
            }
        }
    }
}

⌨️ 快捷键说明

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