KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > Utils


1 package org.enhydra.shark.corbaclient;
2
3 import java.util.*;
4 import java.awt.*;
5
6 /**
7 * Implements various usefull static methods.
8 */

9 public class Utils {
10
11    /**
12     * Take the given string and chop it up into a series
13     * of strings on given boundries. This is useful
14     * for trying to get an array of strings out of the
15     * resource file.
16     */

17    public static String JavaDoc[] tokenize(String JavaDoc input,String JavaDoc boundary) {
18       if (input==null) input="";
19       Vector v = new Vector();
20       StringTokenizer t = new StringTokenizer(input,boundary);
21       String JavaDoc cmd[];
22
23       while (t.hasMoreTokens())
24          v.addElement(t.nextToken());
25       cmd = new String JavaDoc[v.size()];
26       for (int i = 0; i < cmd.length; i++)
27          cmd[i] = (String JavaDoc)v.elementAt(i);
28
29       return cmd;
30    }
31
32    /** Returns the class name without package. */
33    public static String JavaDoc getUnqualifiedClassName (Class JavaDoc cls) {
34       String JavaDoc name=cls.getName();
35       int lastDot=name.lastIndexOf(".");
36       if (lastDot>=0) {
37          name=name.substring(lastDot+1,name.length());
38       }
39       return name;
40    }
41
42    public static void center (Window w) {
43       // set location to be centered
44
//Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
45
Rectangle screenSize = GraphicsEnvironment
46          .getLocalGraphicsEnvironment()
47          .getDefaultScreenDevice()
48          .getDefaultConfiguration()
49          .getBounds();
50
51       int width=w.getWidth();
52       int height=w.getHeight();
53       if (width>screenSize.width-50) {
54          width=screenSize.width-50;
55       }
56       if (height>screenSize.height-100) {
57          height=screenSize.height-100;
58       }
59       w.setBounds((screenSize.width-width)/2,(screenSize.height-height)/2,
60             width,height);
61    }
62 }
63
Popular Tags