📄 qgridlayouttranslator.java
字号:
/* This file is part of ui2swt.
*
* $Revision: 1.4 $
* $Date: 2007/01/14 10:35:38 $
* $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 java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;
import ui2swt.ClassDefinition;
import ui2swt.Layout;
import ui2swt.UIDefinition;
import ui2swt.Widget;
public class QGridLayoutTranslator extends AbstractLayoutTranslator
{
private static final String UI_GRID_LAYOUT_ROW = "row";
private static final String UI_GRID_LAYOUT_COLUMN = "column";
//
//
//
public QGridLayoutTranslator()
{
super();
}
protected void setProperties(
UIDefinition iUIDefinition,
Layout iLayout,
Widget iWidget )
{
SWTGridLayoutHelper.setProperties(iUIDefinition, iLayout);
}
protected void generateConstructCode(
UIDefinition iUIDefinition,
Layout iLayout,
Widget iWidget,
ClassDefinition iClassDefinition )
{
SWTLayoutHelper.generateConstructCode(
iUIDefinition,
iLayout,
iWidget,
iClassDefinition);
}
protected void generateSetFieldsCode(
UIDefinition iUIDefinition,
Layout iLayout,
Widget iWidget,
ClassDefinition iClassDefinition )
{
SWTGridLayoutHelper.generateFieldsCode(
iUIDefinition,
iLayout,
iClassDefinition);
}
protected void prepareChildren(
UIDefinition iUIDefinition,
Layout iLayout,
Widget iWidget,
Widget[] iChildren,
ClassDefinition iClassDefinition )
{
//
// Set the row and column properties of the children.
// Sort the children by their row and column property.
// Set the number of rows and column properties of the layout.
//
int numRows = 1;
int numColumns = 1;
SortedSet sortedChildren = new TreeSet(new RowColumnComparator());
for ( int i = 0; i < iChildren.length; i++ )
{
Widget child = iChildren[i];
int row = child.getIntProperty(UI_GRID_LAYOUT_ROW, 0);
int column = child.getIntProperty(UI_GRID_LAYOUT_COLUMN, 0);
child.setIntProperty(SWTGridLayoutHelper.SWT_ROW, row);
child.setIntProperty(SWTGridLayoutHelper.SWT_COLUMN, column);
sortedChildren.add(iChildren[i]);
if ( row >= numRows )
{
numRows = row + 1;
}
if ( column >= numColumns )
{
numColumns = column + 1;
}
}
iLayout.setIntProperty(SWTGridLayoutHelper.SWT_NUM_ROWS, numRows);
iLayout.setIntProperty(SWTGridLayoutHelper.SWT_NUM_COLUMNS, numColumns);
System.arraycopy(sortedChildren.toArray(), 0, iChildren, 0, iChildren.length);
}
protected void layoutChildren(
UIDefinition iUIDefinition,
Layout iLayout,
Widget iWidget,
Widget[] iChildren,
ClassDefinition iClassDefinition )
{
SWTGridLayoutHelper.generateChildrenLayoutData(
iUIDefinition,
iLayout,
iWidget,
iChildren,
iClassDefinition);
}
//
//
//
private class RowColumnComparator implements Comparator
{
public int compare( Object iArg1, Object iArg2 )
{
Widget widget1 = (Widget)(iArg1);
Widget widget2 = (Widget)(iArg2);
int row1 = widget1.getIntProperty(SWTGridLayoutHelper.SWT_ROW, 0);
int row2 = widget2.getIntProperty(SWTGridLayoutHelper.SWT_ROW, 0);
if ( row1 < row2 )
{
return -1;
}
else if ( row1 > row2 )
{
return 1;
}
else
{
int column1 = widget1.getIntProperty(SWTGridLayoutHelper.SWT_COLUMN, 0);
int column2 = widget2.getIntProperty(SWTGridLayoutHelper.SWT_COLUMN, 0);
if ( column1 < column2 )
{
return -1;
}
else if ( column1 > column2 )
{
return 1;
}
else
{
return 0;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -