KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > Utility


1 package sellwin.gui;
2
3 import java.util.*;
4 import java.awt.*;
5 import javax.swing.*;
6 import javax.naming.*;
7 import javax.ejb.*;
8
9 // SellWin http://sourceforge.net/projects/sellwincrm
10
//Contact support@open-app.com for commercial help with SellWin
11
//This software is provided "AS IS", without a warranty of any kind.
12

13 /**
14  * This class has some simple GUI routines that save
15  * some extra lines of code.
16  */

17 public class Utility {
18     /**
19      * set the text of a text area
20      * @param f the text area we are setting
21      * @param from the text we are setting with
22      */

23     public static void strSet(JTextArea f, String JavaDoc from) {
24         if (from != null) {
25             f.setText(from);
26             f.setCaretPosition(0);
27         }
28         else
29             f.setText("");
30     }
31     /**
32      * set the text portion of a text field
33      * @param f a text field we are setting
34      * @param from a string we are setting to
35      */

36     public static void strSet(JTextField f, String JavaDoc from) {
37         if (from != null) {
38             f.setText(from);
39             f.setCaretPosition(0);
40         }
41         else
42             f.setText("");
43     }
44     /**
45      * set the index of a combo box to a given item
46      * @param b the combo box we are setting
47      * @param item the item in the combo box we are setting
48      * with
49      */

50     public static void comboSet(JComboBox b, Object JavaDoc item) {
51         if (item != null)
52             b.setSelectedItem(item);
53         else
54             b.setSelectedIndex(0);
55     }
56
57     /**
58      * loop thru all the components of a container and
59      * call setLang() for those that implement the
60      * GUIChars interface
61      */

62     public static void setLang(Container container) {
63         Component[] components = container.getComponents();
64         Component c;
65
66         for (int i=0;i<components.length;i++) {
67             c = components[i];
68             if (c instanceof Container) {
69                 Utility.setLang((Container)c);
70             }
71         
72             if (c instanceof GUIChars) {
73                 ((GUIChars)c).setLang();
74             }
75
76             if (c instanceof JDialog) {
77                 if (c instanceof GUIChars)
78                     ((GUIChars)c).setLang();
79                 else
80                     Utility.setLang((Container)c);
81         
82             }
83
84         }
85     }
86
87     public static InitialContext getEJBContext(String JavaDoc host, String JavaDoc port)
88         throws NamingException {
89
90         Hashtable props = new Hashtable();
91         props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
92         props.put("java.naming.provider.url","jnp://"+host+":"+port);
93         props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
94
95         InitialContext ic = new InitialContext(props);
96         return ic;
97     }
98 }
99
Popular Tags