📄 componentfactory.java
字号:
RotateButton xbutton = new RotateButton(); String xresource; int xitems = 0; while ( 1 == 1 ) { // generate a prefix for the resource name String xprefix = id + ".rotatebutton" + xitems; // locate icon ImageIcon xicon = null; xresource = null; try { xresource = bundle.getString( xprefix + ".icon" ); } catch ( MissingResourceException xex ) { } if ( xresource != null ) { try { Image ximage = AWTUtilities.getImageResource( xresource ); xicon = new ImageIcon( ximage ); } catch ( IOException ex ) { } } // locate command String xcommand = null; try { xcommand = bundle.getString( xprefix + ".command" ); } catch ( MissingResourceException xex ) { } // locate text String xtext = null; try { xtext = bundle.getString( xprefix + ".text" ); } catch ( MissingResourceException xex ) { } // locate tip String xtip = null; try { xtip = bundle.getString( xprefix + ".tip" ); } catch ( MissingResourceException xex ) { } // setBorderPainted( boolean ) // setContentAreaFilled(boolean) // locate disabled icon // setDisableSelectedIcon( Icon ) // setPressedIcon( Icon ) // setRolloverIcon( Icon ) // setRolloverSelectedIcon( Icon ) // locate selected icon // add a rotation if valid if ( xicon == null || xcommand == null ) { // no rotation, must be the end of the botton items break; } else { // locate component controls setComponent( bundle, xprefix, xbutton ); // add the rotation xbutton.addIcon( xicon, xcommand, xtext, xtip ); } // next item please xitems++; } // setup the controls if ( alistener != null ) { xbutton.addActionListener( alistener ); } xbutton.addFocusListener( flistener ); // rotate the button just to be sure xbutton.rotate( 0 ); return xbutton; } /** * Produce a JLabel using the given resource bundle. * <p> * The label is produced with the attributes found in the resource bundle. If no * attributes are found for the label, then the label is returned void of any * useful attributes. * <p> * Attributes are found using the following resource ids: * <pre> * [id].label.text - text of the label * [id].label.tip - tip text of the label * [id].label.foreground - foreground color of the label * [id].label.background - background color of the label * [id].label.font - font of the label * </pre> * * @param bundle resource bundle used in obtaining resource strings * @param id prefix of all resource ids * @return a label with all found attributes, possibly none * @see JLabel */ public static JLabel getLabel( FormatResourceBundle bundle, String id ) { String xprefix = id + ".label"; JLabel xlabel = new JLabel(); String xresource = null; // locate text try { xresource = bundle.getString( xprefix + ".text" ); } catch ( MissingResourceException xex ) { } if ( xresource != null ) { xlabel.setText( xresource ); } // setDisabledIcon(Icon disabledIcon) // setIcon(Icon icon) // setIconTextGap(int iconTextGap) // locate component controls setComponent( bundle, xprefix, xlabel ); return xlabel; } /** * Produce a JTextField using the given resource bundle, and attaching the given listeners. * <p> * The textfield is produced with the attributes found in the resource bundle. If no * attributes are found for the textfield, then the textfield is returned void of any * useful attributes. * <p> * Attributes are found using the following resource ids: * <pre> * [id].field.columns - number of columns in preffered width * [id].field.tip - tip text of the textfield * [id].field.foreground - foreground color of the textfield * [id].field.background - background color of the textfield * [id].field.font - font of the textfield * </pre> * * @param bundle resource bundle used in obtaining resource strings * @param id prefix of all resource ids * @param flistener focus listener to attach, or null * @return a textfield with all found attributes, possibly none * @see JTextField */ public static JTextField getTextField( FormatResourceBundle bundle, String id, FocusListener flistener ) { String xprefix = id + ".field"; JTextField xfield = new JTextField(); String xresource = null; // locate columns xresource = null; try { xresource = bundle.getString( xprefix + ".columns" ); } catch ( MissingResourceException xex ) { } if ( xresource != null ) { try { int xcolumns = Integer.parseInt( xresource ); xfield.setColumns( xcolumns ); } catch ( Exception ex ) { } } // setCaret(Caret c) // setCaretColor(Color c) // setSelectedTextColor(Color c) // setSelectionColor(Color c) // setText(String t) // locate component controls setComponent( bundle, xprefix, xfield ); // setup the controls xfield.addFocusListener( flistener ); return xfield; } /** * Produce a JPasswordField using the given resource bundle, and attaching the given listeners. * <p> * The password field is produced with the attributes found in the resource bundle. If no * attributes are found for the password field, then the password field is returned void * of any useful attributes. * <p> * Attributes are found using the following resource ids: * <pre> * [id].field.tip - tip text of the password field * [id].field.foreground - foreground color of the password field * [id].field.background - background color of the password field * [id].field.font - font of the password field * </pre> * * @param bundle resource bundle used in obtaining resource strings * @param id prefix of all resource ids * @param flistener focus listener to attach, or null * @return a password field with all found attributes, possibly none * @see JPasswordField */ public static JPasswordField getPasswordField( FormatResourceBundle bundle, String id, FocusListener flistener ) { String xprefix = id + ".passfld"; JPasswordField xpass = new JPasswordField(); String xresource = null; // setCaret(Caret c) // setCaretColor(Color c) // setSelectedTextColor(Color c) // setSelectionColor(Color c) // setText(String t) // locate component controls setComponent( bundle, xprefix, xpass ); // setup the controls xpass.addFocusListener( flistener ); return xpass; } /** * Produce a JMenu with menuitems using the given resource bundle, * and attaching the given listeners. * <p> * The menu is produced with the attributes found in the resource bundle. Separators * and MenuItems are added in succession from sequences resource ids. If no * attributes are found for the menu, then the menu is returned void of any * useful attributes. * <p> * Attributes are found using the same resource ids as getMenu() and getMenuItem(). * However, MenuItem resource ids are a sequence of: * <pre> * [id].menuitem[#].[attribute] * </pre> * By supplying these appropriately, the contents and order of a menuitems can be changed * by only modifying the resource bundle. * <p> * A separator can also be specified for a menuitem by supplying the following id: * <pre> * [id].menuitem[#].separator * </pre> * * @param bundle resource bundle used in obtaining resource strings * @param id prefix of all resource ids * @param alistener action listener to attach, or null * @return a menu with all found attributes, possibly none * @see #getMenu() * @see #getMenuItem() */ public static JMenu getMenuAndItems( FormatResourceBundle bundle, String id, ActionListener alistener ) { JMenu xmenu = getMenu( bundle, id ); int xitems = 0; while ( 1 == 1 ) { // generate a prefix for the resource name String xprefix = id + ".menuitem" + xitems; // look for a separator String xresource = null; try { xresource = bundle.getString( xprefix + ".separator" ); } catch ( MissingResourceException xex ) { } if ( xresource != null ) { xmenu.addSeparator(); } // get the menuitem from the resources JMenuItem xitem = getMenuItemByPrefix( bundle, xprefix, alistener ); // and add to menu if valid if ( ( xitem.getText() == null || xitem.getText().length() == 0 ) && xitem.getIcon() == null ) { // no menu item must be the end of the menu break; } else { xmenu.add( xitem ); } // next item please xitems++; } return xmenu; } /** * Produce a JMenu using the given resource bundle, and attaching the given listeners. * <p> * The menu is produced with the attributes found in the resource bundle. If no * attributes are found for the menu, then the menu is returned void of any * useful attributes. * <p> * Attributes are found using the following resource ids: * <pre> * [id].menu.icon - image resource name of the menu * [id].menu.text - text of the menu * </pre> * * @param bundle resource bundle used in obtaining resource strings * @param id prefix of all resource ids * @return a menu with all found attributes, possibly none * @see JMenu */ public static JMenu getMenu( FormatResourceBundle bundle, String id ) { String xprefix = id + ".menu"; JMenu xmenu = new JMenu(); String xresource; // locate icon xresource = null; try { xresource = bundle.getString( xprefix + ".icon" ); } catch ( MissingResourceException xex ) { } if ( xresource != null ) { try { Image xicon = AWTUtilities.getImageResource( xresource ); xmenu.setIcon( new ImageIcon( xicon ) ); } catch ( IOException ex ) { } } // locate text xresource = null; try { xresource = bundle.getString( xprefix + ".text" ); } catch ( MissingResourceException xex ) { } if ( xresource != null ) { xmenu.setText( xresource ); } return xmenu; } /** * Produce a JMenuItem using the given resource bundle, and attaching the given listeners. * <p> * The menuitem is produced with the attributes found in the resource bundle. If no * attributes are found for the menuitem, then the menuitem is returned void of any * useful attributes. * <p> * Attributes are found using the following resource ids: * <pre> * [id].menuitem.checkbox - checkbox state of the menuitem * [id].menuitem.icon - image resource name of the menuitem * [id].menuitem.text - text of the menuitem * [id].menuitem.accel - keystroke accelerator of the menuitem * [id].menuitem.command - command string of the menuitem when activated * </pre> * <p> * Keystoke accelerators are specified by supplying a resource string with * one or more of the following: * <pre> * Alt+Ctrl+Meta+Shift+[key] * </pre> * <p> * For example: AltShiftC * * @param bundle resource bundle used in obtaining resource strings
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -