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

📄 swtinthelper.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.6 $
 * $Date: 2007/06/17 04:11:23 $
 * $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.UIDefinition;
import ui2swt.Widget;


public class SWTIntHelper extends SWTHelper
{
    private static final String UI_VALUE        = "value.number";

    private static final String UI_MIN_VALUE_2  = "minValue.number";
    private static final String UI_MIN_VALUE_3  = "minValue.number";
    private static final String UI_MIN_VALUE_4  = "minimum.number";

    private static final String UI_MAX_VALUE_2  = "maxValue.number";
    private static final String UI_MAX_VALUE_3  = "maxValue.number";
    private static final String UI_MAX_VALUE_4  = "maximum.number";

    private static final String UI_LINE_STEP_2  = "lineStep.number";
    private static final String UI_LINE_STEP_3  = "lineStep.number";
    private static final String UI_LINE_STEP_4  = "singleStep.number";
    
    private static final String UI_PAGE_STEP    = "pageStep.number";
    
    private static final String UI_READ_ONLY    = "readOnly.bool";

    
    //
    //
    //
    
    public static boolean isReadOnly(
        UIDefinition    iUIDefinition,
        Widget          iWidget )
    {
        return iWidget.getBoolProperty(UI_READ_ONLY, false);
    }
    
    
    //
    //
    //


    public static void appendReadOnlyStyle(
        UIDefinition    iUIDefinition,
        Widget          iWidget,
        StringBuffer    iStyle )
    {
        if ( SWTIntHelper.isReadOnly(iUIDefinition, iWidget) )
        {
            appendStyleValue(iStyle, "SWT.READ_ONLY");
        }
    }

    
    //
    //
    //
    
    public static void generateSetIntRangeCode(
        UIDefinition    iUIDefinition,
        Widget          iWidget,
        ClassDefinition iClassDefinition )
    {
        String widgetVar = iWidget.getProperty(SWT_VAR);

        switch (iUIDefinition.getVersion())
        {
            case UIDefinition.VERSION_2:
                if ( iWidget.containsProperty(UI_MIN_VALUE_2) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setMinimum",
                            iWidget.getIntProperty(UI_MIN_VALUE_2, 0));
                }
                break;
                
            case UIDefinition.VERSION_3:
                if ( iWidget.containsProperty(UI_MIN_VALUE_3) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setMinimum",
                            iWidget.getIntProperty(UI_MIN_VALUE_3, 0));
                }
                break;
                
            case UIDefinition.VERSION_4:
                if ( iWidget.containsProperty(UI_MIN_VALUE_4) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setMinimum",
                            iWidget.getIntProperty(UI_MIN_VALUE_4, 0));
                }
                break;
        }

        switch (iUIDefinition.getVersion())
        {
            case UIDefinition.VERSION_2:
                if ( iWidget.containsProperty(UI_MAX_VALUE_2) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setMaximum",
                            iWidget.getIntProperty(UI_MAX_VALUE_2, 100));
                }
                break;
                
            case UIDefinition.VERSION_3:
                if ( iWidget.containsProperty(UI_MAX_VALUE_3) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setMaximum",
                            iWidget.getIntProperty(UI_MAX_VALUE_3, 100));
                }
                break;
                
            case UIDefinition.VERSION_4:
                if ( iWidget.containsProperty(UI_MAX_VALUE_4) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setMaximum",
                            iWidget.getIntProperty(UI_MAX_VALUE_4, 100));
                }
                break;
        }

        switch (iUIDefinition.getVersion())
        {
            case UIDefinition.VERSION_2:
                if ( iWidget.containsProperty(UI_LINE_STEP_2) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setIncrement",
                            iWidget.getIntProperty(UI_LINE_STEP_2, 1));
                }
                break;
                
            case UIDefinition.VERSION_3:
                if ( iWidget.containsProperty(UI_LINE_STEP_3) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setIncrement",
                            iWidget.getIntProperty(UI_LINE_STEP_3, 1));
                }
                break;
                
            case UIDefinition.VERSION_4:
                if ( iWidget.containsProperty(UI_LINE_STEP_4) )
                {
                    iClassDefinition.getConstructor()
                        .addMethodCall1(
                            widgetVar,
                            "setIncrement",
                            iWidget.getIntProperty(UI_LINE_STEP_4, 1));
                }
                break;
                
        }

        if ( iWidget.containsProperty(UI_PAGE_STEP) )
        {
            iClassDefinition.getConstructor()
                .addMethodCall1(
                    widgetVar,
                    "setPageIncrement",
                    iWidget.getIntProperty(UI_PAGE_STEP, 10));
        }

        if ( iWidget.containsProperty(UI_VALUE) )
        {
            iClassDefinition.getConstructor()
                .addMethodCall1(
                    widgetVar,
                    "setSelection",
                    iWidget.getIntProperty(UI_VALUE, 1));
        }
    }
}

⌨️ 快捷键说明

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