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

📄 classdefinition.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;
import java.util.SortedSet;
import java.util.TreeSet;


public class ClassDefinition
{
    private List header;
    private String packageName;
    private SortedSet imports;
    private String name;
    private String superName;
    private List constants;
    private List attributes;
    private MethodDefinition constructor;
    private List methods;
    
    
    public ClassDefinition()
    {
        this.header = new LinkedList();
        this.imports = new TreeSet();
        this.constants = new LinkedList();
        this.attributes = new LinkedList();
        this.constructor = new MethodDefinition().setVisibility("public");
        this.methods = new LinkedList();
        this.methods.add(this.constructor);
    }
    
    
    //
    //
    //
    
    public String[] getHeader()
    {
        String[] result = new String[this.header.size()];
        
        System.arraycopy(this.header.toArray(), 0, result, 0, result.length);
        
        return result;
    }
    
    
    public void addHeaderLine( String iLine )
    {
        this.header.add(iLine);
    }
    
    
    public String getPackageName()
    {
        return this.packageName;
    }
    
    
    public ClassDefinition setPackageName( String iPackageName )
    {
        this.packageName = iPackageName;
        
        return this;
    }
    
    
    public String getName()
    {
        return this.name;
    }
    
    
    public ClassDefinition setName( String iName )
    {
        this.name = iName;
        this.constructor.setName(iName);
        
        return this;
    }
    
    
    public String getSuperName()
    {
        return this.superName;
    }
    
    
    public ClassDefinition setSuperName( String iSuperName )
    {
        this.superName = iSuperName;
        
        return this;
    }
    
    
    public String[] getImports()
    {
        String[] result = new String[this.imports.size()];
        
        System.arraycopy(this.imports.toArray(), 0, result, 0, result.length);
        
        return result;
    }
    
    
    public ClassDefinition addImport( String iImport )
    {
        this.imports.add(iImport);
        
        return this;
    }
    
    
    public Object[] getAttributes()
    {
        return this.attributes.toArray();
    }
    
    
    public ClassDefinition addAttribute( String iVisibility, String iType, String iName )
    {
        StringBuffer attribute = new StringBuffer();
        
        attribute.append(iVisibility);
        attribute.append(" ");
        attribute.append(iType);
        attribute.append(" ");
        attribute.append(iName);
        
        this.attributes.add(attribute);
        
        return this;
    }
    
    
    public Object[] getConstants()
    {
        return this.constants.toArray();
    }
    
    
    public ClassDefinition addConstant( String iVisibility, String iType, String iName )
    {
        StringBuffer constant = new StringBuffer();
        
        constant.append(iVisibility);
        constant.append(" static final ");
        constant.append(iType);
        constant.append(" ");
        constant.append(iName);
        
        this.constants.add(constant);
        
        return this;
    }
    
    
    public ClassDefinition addConstant(
            String iVisibility,
            String iType,
            String iName,
            Object iValue )
    {
        StringBuffer constant = new StringBuffer();
        
        constant.append(iVisibility);
        constant.append(" static final ");
        constant.append(iType);
        constant.append(" ");
        constant.append(iName);
        
        if ( iValue != null )
        {
            constant.append(" = ");
            constant.append(iValue);
        }
        
        this.constants.add(constant);
        
        return this;
    }
    
    
    public MethodDefinition[] getMethods()
    {
        MethodDefinition[] result = new MethodDefinition[this.methods.size()];
        
        System.arraycopy(this.methods.toArray(), 0, result, 0, result.length);
        
        return result;
    }
    
    
    public boolean containsMethod( String iMethodName )
    {
        Iterator iterator = this.methods.iterator();
        
        while ( iterator.hasNext() )
        {
            MethodDefinition methodDefinition = (MethodDefinition)(iterator.next());
            
            if ( methodDefinition.getName().equals(iMethodName) )
            {
                return true;
            }
        }
        
        return false;
    }
    
    
    public MethodDefinition addMethod()
    {
        MethodDefinition method = new MethodDefinition();
        
        this.methods.add(method);
        
        return method;
    }
    
    
    public MethodDefinition getConstructor()
    {
        return this.constructor;
    }
}

⌨️ 快捷键说明

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