📄 widget.java
字号:
/* This file is part of ui2swt.
*
* $Revision: 1.4 $
* $Date: 2007/06/17 04:09:17 $
* $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 Widget extends Item
{
public static final String QT_MAIN_WINDOW = "QMainWindow";
public static final String QT_DIALOG = "QDialog";
public static final String QT_SHELL_LAYOUT = "QShellLayout";
public static final String QT_MENU_BAR = "QMenuBar";
public static final String QT_MENU = "QMenu";
public static final String QT_MENU_ACTION = "QMenuAction";
public static final String QT_MENU_SEPARATOR = "QMenuSeparator";
public static final String QT_TOOL_BAR = "QToolBar";
public static final String QT_TOOL_BAR_ACTION = "QToolBarAction";
public static final String QT_TOOL_BAR_SEPARATOR = "QToolBarSeparator";
public static final String QT_WIDGET = "QWidget";
public static final String QT_FRAME = "QFrame";
public static final String QT_LAYOUT_WIDGET = "QLayoutWidget";
public static final String QT_GROUP_BOX = "QGroupBox";
public static final String QT_BUTTON_GROUP = "QButtonGroup";
public static final String QT_TAB_WIDGET = "QTabWidget";
public static final String QT_LIST_BOX = "QListBox";
public static final String QT_LIST_VIEW = "QListView";
public static final String QT_TABLE = "QTable";
public static final String QT_CHECK_BOX = "QCheckBox";
public static final String QT_COMBO_BOX = "QComboBox";
public static final String QT_LABEL = "QLabel";
public static final String QT_LINE_EDIT = "QLineEdit";
public static final String QT_MULTI_LINE_EDIT = "QMultiLineEdit";
public static final String QT_PROGRESS_BAR = "QProgressBar";
public static final String QT_PUSH_BUTTON = "QPushButton";
public static final String QT_RADIO_BUTTON = "QRadioButton";
public static final String QT_TEXT_BROWSER = "QTextBrowser";
public static final String QT_TEXT_EDIT = "QTextEdit";
public static final String QT_TEXT_VIEW = "QTextView";
public static final String QT_TOOL_BUTTON = "QToolButton";
public static final String QT_SLIDER = "QSlider";
public static final String QT_SPINBOX = "QSpinBox";
public static final String QT_SPACER = "QSpacer";
public static final String QT_LINE = "QLine";
//
//
//
private String className;
private Widget parent;
private List children;
private Layout layout;
//
//
//
public Widget( String iClassName )
{
this.className = iClassName;
this.children = new LinkedList();
}
public Widget( String iClassName, Widget iParent )
{
this(iClassName);
if ( iParent != null )
{
iParent.addChild(this);
}
}
public String getClassName()
{
return this.className;
}
public void setClassName( String iClassName )
{
this.className = iClassName;
}
public Widget getParent()
{
return this.parent;
}
public boolean hasChildren()
{
return !(this.children.isEmpty());
}
public int getNumChildren()
{
return this.children.size();
}
public Widget[] getChildren()
{
Widget[] result = new Widget[this.children.size()];
System.arraycopy(this.children.toArray(), 0, result, 0, result.length);
return result;
}
public void addChild( Widget iChild )
{
this.children.add(iChild);
iChild.parent = this;
}
public Layout getLayout()
{
return this.layout;
}
public void setLayout( Layout iLayout )
{
this.layout = iLayout;
iLayout.parent = this;
}
//
//
//
public boolean containsInheritedProperty( String iName )
{
if ( this.containsProperty(iName) )
{
return true;
}
else if ( this.parent != null )
{
return this.parent.containsInheritedProperty(iName);
}
else
{
return false;
}
}
public String getInheritedProperty( String iName )
{
String property = this.getProperty(iName);
if ( property == null )
{
if ( this.parent != null )
{
return this.parent.getInheritedProperty(iName);
}
else
{
return null;
}
}
else
{
return property;
}
}
public String getInheritedStringProperty( String iName, String iDefaultValue )
{
String value = this.getInheritedProperty(iName);
if ( value == null )
{
return iDefaultValue;
}
else
{
return value;
}
}
public String getInheritedTextProperty( String iName, String iDefaultValue )
{
String value = this.getInheritedProperty(iName);
if ( value == null )
{
return getTextValue(iDefaultValue);
}
else
{
return getTextValue(value);
}
}
public int getInheritedIntProperty( String iName, int iDefaultValue )
{
String value = this.getInheritedProperty(iName);
if ( value == null )
{
return iDefaultValue;
}
else
{
return Integer.parseInt(value);
}
}
public boolean getInheritedBoolProperty( String iName, boolean iDefaultValue )
{
String value = this.getInheritedProperty(iName);
if ( value == null )
{
return iDefaultValue;
}
else
{
return Boolean.valueOf(value).booleanValue();
}
}
//
//
//
void dump()
{
Widget.dump(this, "");
}
static void dump( Widget iWidget, String iIndent )
{
System.out.println(iIndent+"class: "+iWidget.className);
Item.dumpProperties(iWidget, iIndent);
if ( iWidget.layout != null )
{
Layout.dump(iWidget.layout, iIndent+"....");
}
Iterator iChild = iWidget.children.iterator();
while ( iChild.hasNext() )
{
Widget child = (Widget)(iChild.next());
dump(child, iIndent+"....");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -