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

📄 swtwidgethelper.java

📁 A translator that converts Qt Designer UI files into SWT java classes. Use the power of Qt Designer
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* This file is part of ui2swt.
 *
 * $Revision: 1.8 $
 * $Date: 2007/02/18 03:24:19 $
 * $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.swt;

import ui2swt.ClassDefinition;
import ui2swt.Translator;
import ui2swt.UIDefinition;
import ui2swt.Widget;


public class SWTWidgetHelper extends SWTHelper
{
    public static final String SWT_NAME         = "swt.name";
    public static final String SWT_PARENT_VAR   = "swt.parent.var";

    public static final String SWT_STYLE        = "swt.style";
    
    
    //
    //
    //
    
    private static final String UI_NAME_2   = "name.cstring";
    private static final String UI_NAME_3   = "name.cstring";
    private static final String UI_NAME_4   = "name";
    
    private static final String UI_ENABLED  = "enabled.bool";
    
    private static final String UI_GEOMETRY_WIDTH   = "geometry.rect.width";
    private static final String UI_GEOMETRY_HEIGHT  = "geometry.rect.height";

    private static final String UI_TOOL_TIP = "toolTip.string";

    private static final String UI_WINDOW_TITLE_2   = "caption.string";
    private static final String UI_WINDOW_TITLE_3   = "caption.string";
    private static final String UI_WINDOW_TITLE_4   = "windowTitle.string";
    
    private static final String UI_WIDGET_TITLE     = "title.string";
    
    private static final String UI_MIN_SIZE_WIDTH   = "minimumSize.size.width";
    private static final String UI_MIN_SIZE_HEIGHT  = "minimumSize.size.height";
    
    private static final String UI_SIZE_TYPE_HORIZONTAL = "sizePolicy.sizepolicy.hsizetype";
    private static final String UI_SIZE_TYPE_VERTICAL   = "sizePolicy.sizepolicy.vsizetype";
    
    private static final int UI_SIZE_TYPE_FIXED              = 0;
    private static final int UI_SIZE_TYPE_PREFERRED          = 5;
    private static final int UI_SIZE_TYPE_MINIMUM_EXPANDING  = 3;
    private static final int UI_SIZE_TYPE_EXPANDING          = 7;
    
    
    //
    //
    //
    
    public static String getWidgetTitle(
        UIDefinition    iUIDefinition,
        Widget          iWidget )
    {
        return iWidget.getTextProperty(UI_WIDGET_TITLE, "");
    }
    

    //
    //
    //
    
    public static void setAttributeProperties(
        UIDefinition    iUIDefinition,
        Widget          iWidget )
    {
        //
        // Set the name property
        //
        if ( ! iWidget.containsProperty(SWT_NAME) )
        {
            switch (iUIDefinition.getVersion())
            {
                case UIDefinition.VERSION_2:
                    if ( iWidget.containsProperty(UI_NAME_2) )
                    {
                        iWidget.setProperty(SWT_NAME, iWidget.getProperty(UI_NAME_2));
                    }
                    break;
                    
                case UIDefinition.VERSION_3:
                    if ( iWidget.containsProperty(UI_NAME_3) )
                    {
                        iWidget.setProperty(SWT_NAME, iWidget.getProperty(UI_NAME_3));
                    }
                    break;

                case UIDefinition.VERSION_4:
                    if ( iWidget.containsProperty(UI_NAME_4) )
                    {
                        iWidget.setProperty(SWT_NAME, iWidget.getProperty(UI_NAME_4));
                    }
                    break;
            }
        }
    
        
        //
        // Set the var property
        //
        if ( ! iWidget.containsProperty(SWT_VAR) )
        {
            if ( iWidget.getParent() != null )
            {
                if ( iWidget.containsProperty(SWT_NAME) )
                {
                    iWidget.setProperty(
                        SWT_VAR,
                        "this."+iWidget.getProperty(SWT_NAME));
                }
            }
            else if ( iWidget.containsProperty(SWT_PARENT_VAR) )
            {
                if ( iWidget.containsProperty(SWT_NAME) )
                {
                    iWidget.setProperty(
                        SWT_VAR,
                        "this."+iWidget.getProperty(SWT_NAME));
                }
            }
            else
            {
                iWidget.setProperty(SWT_VAR, "this");
            }
        }
        
        
        //
        // Set the parent var property
        //
        if ( ! iWidget.containsProperty(SWT_PARENT_VAR) )
        {
            if ( iWidget.getParent() != null )
            {
                iWidget.setProperty(
                    SWT_PARENT_VAR,
                    iWidget.getParent().getProperty(SWT_VAR));
            }
        }
    }
    
    
    public static void setExpandProperties(
        UIDefinition    iUIDefinition,
        Widget          iWidget )
    {
        if ( ! iWidget.containsProperty(SWT_EXPAND_HORIZONTAL) )
        {
            if ( iWidget.containsProperty(UI_SIZE_TYPE_HORIZONTAL) )
            {
                int sizeType = 
                    iWidget.getIntProperty(
                        UI_SIZE_TYPE_HORIZONTAL,
                        UI_SIZE_TYPE_PREFERRED);
                
                switch (sizeType)
                {
                    case UI_SIZE_TYPE_MINIMUM_EXPANDING:
                    case UI_SIZE_TYPE_EXPANDING:
                        iWidget.setIntProperty(
                            SWT_EXPAND_HORIZONTAL,
                            SWT_EXPAND_YES);
                        break;
                    
                    case UI_SIZE_TYPE_FIXED:
                        iWidget.setIntProperty(
                            SWT_EXPAND_HORIZONTAL,
                            SWT_EXPAND_NO);
                        break;
                        
                    default:
                        break;
                }
            }
        }
        
        if ( ! iWidget.containsProperty(SWT_EXPAND_VERTICAL) )
        {
            if ( iWidget.containsProperty(UI_SIZE_TYPE_VERTICAL) )
            {
                int sizeType = 
                    iWidget.getIntProperty(
                        UI_SIZE_TYPE_VERTICAL,
                        UI_SIZE_TYPE_PREFERRED);
                
                switch (sizeType)
                {
                    case UI_SIZE_TYPE_MINIMUM_EXPANDING:
                    case UI_SIZE_TYPE_EXPANDING:
                        iWidget.setIntProperty(
                            SWT_EXPAND_VERTICAL,
                            SWT_EXPAND_YES);
                        break;
                    
                    case UI_SIZE_TYPE_FIXED:
                        iWidget.setIntProperty(
                            SWT_EXPAND_VERTICAL,
                            SWT_EXPAND_NO);
                        break;
                        
                    default:
                        break;
                }
            }
        }
    }
    
    
    public static void setMinimumSizeProperties(
        UIDefinition    iUIDefinition,
        Widget          iWidget )
    {
        if ( ! iWidget.containsProperty(SWT_MIN_SIZE_HORIZONTAL) )
        {
            int minSize = iWidget.getIntProperty(UI_MIN_SIZE_WIDTH, 0);
            
            if ( minSize > 0 )
            {
                iWidget.setIntProperty(SWT_MIN_SIZE_HORIZONTAL, minSize);
            }
        }

        if ( ! iWidget.containsProperty(SWT_MIN_SIZE_VERTICAL) )
        {
            int minSize = iWidget.getIntProperty(UI_MIN_SIZE_HEIGHT, 0);
            
            if ( minSize > 0 )
            {
                iWidget.setIntProperty(SWT_MIN_SIZE_VERTICAL, minSize);
            }
        }

⌨️ 快捷键说明

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