📄 i18n.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/I18n.java,v $// $RCSfile: I18n.java,v $// $Revision: 1.3.2.1 $// $Date: 2004/10/14 18:26:36 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap;import java.util.MissingResourceException;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuItem;/** * Interface for Internationalization support in Openamp. The I18n * implmentation will define where the resources for the given class * are stored. * <P> * <B>Intended Usage: </B> * <P> * There are several possible uses of this interface, outlined below: * * <UL> * <LI><I><B>Simple Usage: </B> </I> <BR> * The simplest case is where you just want to get the possibly * internationalized version of a given string. This would look like * the following: * <P> * <code> * I18n i18n = Environment.getI18n();<br> * String message = i18n.get(this, "message", "Please enter a number: ");<br> * </code> * <P> * There is also similar version of <code>get(...)</code> that takes * a <code>Class</code> instead, and thefore can be used in static * contexts. If the Strings you are looking for pertain to specific * types (i.e. uses) you can you the form of <code>get(...)</code> * that specifies this, as the following example illustrates: * <P> * <code> * I18n i18n = Environment.getI18n();<br> * JButton okButton = new JButton(i18n.get(this, "okButton", i18n.TEXT, "Ok")); * <br> * okButton.setTooltipText(i18n.get(this, "okButton", i18n.TOOLTOP, "Ok"));<br> * </code> * <P> * Again there is a similar version of this method that takes a * <code>Class</code> instead of an object so it can be used in * static contexts. * <P> * Note that in both examples given, the <code>field</code> * parameter to the <code>get(...)</code> methods are the name of * the variable that holds the string returned. For the these methods, * this is a convention rather than a requirement. However, it * suggested that you maintain this convention because doing so makes * it clearer what is going on and because it is most similar to how * the calls are made in the reflective case below. * <P> * Note also that there are several additional <code>get(...)</code> * methods that can be used to make getting paramaterized (as if by * <code>MessageFormat</code>) Strings easier. * * <LI><I><B>Swing Usage: </B> </I> <BR> * If you are setting the text fields on Swing objects, the * <code>set(...)</code> methods of this class can help you. Here is * an example: * <P> * <code> * I18n i18n = Environment.getI18n();<br> * JButton myButton = new JButton();<br> * I18n.set(this, "myButton", myButton);<br> * </code> * <P> * This will get the string information (both tool tip and text) from * the appropriate ResourceBundle and set the button's slots with it. * <P> * Note that in this example the <code>field</code> parameter to the * <code>set(...)</code> method is the name of the field that holds * the object being setup. For these methods this is a convention * rather than a requirement. However, it suggested that you maintain * this convention because doing so makes it clearer what is going on * and because it is most similar to how the calls are made in the * reflective case below. * <LI><I><B>Reflective Calls: </B> </I> <BR> * For the typical uses of this class, there are two calls that can * make things very easy, by doing a bunch of the work for you. In * most implementations if this interface, they will accomplish this * via reflection under-the-hood. Here are some examples: * <P> * <code> * public class MyClass {<BR> * JButton myButton = new JButton();<BR> * public MyClass() {<BR> * Environment.getI18n().set(this, "myButton");<BR> * }<BR> * }<BR> * </code> * <P> * This code will setup the properties of the object held by the * <code>myButton</code> variable, without the programmer having to * do much at all. Here is an example of the other reflective method: * <P> * <code> * public class MyClass {<BR> * JButton myButton = new JButton();<BR> * JLabel myLabel = new JLabel(); * public MyClass() {<BR> * Environment.getI18n().fill(this);<BR> * }<BR> * }<BR> * </code> * <P> * Here we can see that a single call is filling in all of the text * for all of the relevant objects, in this case both * <code>myButton</code> and <code>myLabel</code>. * </UL> * <P> * <SMALL>In case you were wondering, the oft used I18n abreviation * comes from the 18 characters between the 'I' and the 'n' in the * word Internationalization. </SMALL> * * @see com.bbn.openmap.Environment * @see com.bbn.openmap.BasicI18n */public interface I18n { //Types: //////// /** * Primary type for a given field (default if types aren't * applicable). */ public final int TEXT = 1; /** Title for components where that is appropriate. */ public final int TITLE = 2; /** Tooltip for a given field. */ public final int TOOLTIP = 3; /** Mnemonic for a given field. */ public final int MNEMONIC = 4; /** * Get the string associated with the given object/field (Defaults * to TEXT for the type). * * @param requestor object containing the code requesting the * String (typically <code>this</code). * @param field the field the String belongs to. Typically this will * be the variable name refering to the String or the Swing object that * uses the String (like a button or a label). * @param defaultString what to use if the resource can't be found. */ public String get(Object requestor, String field, String defaultString); /** * Get the string associated with the given object/field/type. * * @param requestor object containing the code requesting the * String (typically <code>this</code). * @param field the field the String belongs to. Typically this will * be the variable name refering to the Swing object that uses the String * (like a button or a label). * @param type which specific slot in the Swing object the string * pertains to. One of TEXT, TOOLTIP or MNEMONIC. * @param defaultString what to use if the resource can't be found. */ public String get(Object requestor, String field, int type, String defaultString); /** * Get the string associated with the given class/field (Defaults * to TEXT for the type). * * @param requestor the class of the object containing the code * requesting the String (typically <code>Foo.class</code). * @param field the field the String belongs to. Typically this will * be the variable name refering to the String or the Swing object that * uses the String (like a button or a label). * @param defaultString what to use if the resource can't be found. */ public String get(Class requestor, String field, String defaultString); /** * Get the string associated with the given class/field/type. * * @param requestor the classof the object containing the code * requesting the String (typically <code>Foo.class</code). * @param field the field the String belongs to. Typically this will * be the variable name refering to the Swing object that uses the String * (like a button or a label). * @param type which specific slot in the Swing object the string * pertains to. One of TEXT, TOOLTIP or MNEMONIC. * @param defaultString what to use if the resource can't be found. */ public String get(Class requestor, String field, int type, String defaultString); //Methods making it easier to use MessageFormat: //////////////////////////////////////////////// /** * Method to get a parameterized String, as if by MessageFormat.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -