📄 item.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.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public abstract class Item
{
protected Map properties;
//
//
//
public Item()
{
this.properties = new HashMap();
}
//
//
//
public boolean containsProperty( String iName )
{
return this.properties.containsKey(iName);
}
public String getProperty( String iName )
{
return (String)(this.properties.get(iName));
}
public String getStringProperty( String iName, String iDefaultValue )
{
String value = this.getProperty(iName);
if ( value == null )
{
return iDefaultValue;
}
else
{
return value;
}
}
public String getTextProperty( String iName, String iDefaultValue )
{
String value = this.getProperty(iName);
if ( value == null )
{
return getTextValue(iDefaultValue);
}
else
{
return getTextValue(value);
}
}
public int getIntProperty( String iName, int iDefaultValue )
{
String value = this.getProperty(iName);
if ( value == null )
{
return iDefaultValue;
}
else
{
return Integer.parseInt(value);
}
}
public boolean getBoolProperty( String iName, boolean iDefaultValue )
{
String value = this.getProperty(iName);
if ( value == null )
{
return iDefaultValue;
}
else
{
return Boolean.valueOf(value).booleanValue();
}
}
public int getEnumProperty(
String iName,
String[] iStringValues,
int[] iIntValues,
int iDefaultValue )
{
if ( this.containsProperty(iName) )
{
String value = this.getProperty(iName);
String[] valueSet = value.split("\\|");
for ( int i = 0; i < iStringValues.length; i++ )
{
for ( int j = 0; j < valueSet.length; j++ )
{
if ( iStringValues[i].equals(valueSet[j]) )
{
return iIntValues[i];
}
}
}
}
return iDefaultValue;
}
//
//
//
public void setProperty( String iName, String iValue )
{
this.properties.put(iName, iValue);
}
public void setProperty( String iName, StringBuffer iValue )
{
this.setProperty(iName, iValue.toString());
}
public void setIntProperty( String iName, int iValue )
{
this.setProperty(iName, Integer.toString(iValue));
}
public void setBoolProperty( String iName, boolean iValue )
{
this.setProperty(iName, Boolean.toString(iValue));
}
//
//
//
protected static String getTextValue( String iValue )
{
StringBuffer result = new StringBuffer();
result.append('"');
if ( iValue != null )
{
for ( int i = 0; i < iValue.length(); i++ )
{
char ch = iValue.charAt(i);
switch (ch)
{
case '"':
result.append("\\\"");
break;
case '\\':
result.append("\\");
break;
case '\n':
result.append("\\n");
break;
default:
result.append(ch);
break;
}
}
}
result.append('"');
return result.toString();
}
//
//
//
static void dumpProperties( Item iItem, String iIndent )
{
Set keys = new TreeSet(iItem.properties.keySet());
Iterator iKey = keys.iterator();
while ( iKey.hasNext() )
{
Object key = iKey.next();
Object value = iItem.properties.get(key);
String valueString = ((value == null) ? "" : value.toString());
if ( valueString.length() > 60 )
{
System.out.println(iIndent+" property: "+key+" = "+valueString.substring(0,60)+"...");
}
else
{
System.out.println(iIndent+" property: "+key+" = "+valueString);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -