📄 multilanguagename.java
字号:
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Christopher Kohlhaas |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by the |
| Free Software Foundation. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.entities;
import java.util.*;
/** Some entities (especially dynamic-types and attributes)
can have multiple names to allow easier reuse of created schemas or
support for multi-language-environments.
@see MultiLanguageNamed
*/
public class MultiLanguageName implements java.io.Serializable {
// Don't forget to increase the serialVersionUID when you change the fields
private static final long serialVersionUID = 1;
private boolean readOnly;
TreeMap mapLocales = new TreeMap();
public MultiLanguageName(String language,String translation) {
setName(language,translation);
}
public MultiLanguageName(String[][] data) {
for (int i=0;i<data.length;i++)
setName(data[i][0],data[i][1]);
}
public MultiLanguageName() {
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public boolean isReadOnly() {
return this.readOnly;
}
public String getName(String language) {
String result = (String)mapLocales.get(language);
if (result == null) {
result = (String)mapLocales.get("en");
}
if (result == null) {
Iterator it = mapLocales.values().iterator();
if (it.hasNext())
result = (String) it.next();
}
if (result == null) {
result = "";
}
return result;
}
public void setName(String language,String translation) {
checkWritable();
if (translation != null && !translation.trim().equals("")) {
mapLocales.put(language,translation);
} else {
mapLocales.remove(language);
}
}
private void checkWritable() {
if ( isReadOnly() )
throw new ReadOnlyException("Can't modify this multilanguage name.");
}
public void setTo(MultiLanguageName newName) {
checkWritable();
mapLocales = (TreeMap) newName.mapLocales.clone();
}
public Collection getAvailableLanguages() {
return mapLocales.keySet();
}
public Object clone() {
MultiLanguageName newName= new MultiLanguageName();
newName.mapLocales.putAll(mapLocales);
return newName;
}
public String toString() {
return getName("en");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -