aboutsummaryrefslogtreecommitdiffstats
path: root/gl4java/utils/Tool.java
blob: e4ef7dc8bb6cf7cf66dcdeb9b8de90cc2c682f3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * @(#) Tool.java 
 *
 * @author 	Sven Goethel 
 */
 
package gl4java.utils;

import java.util.*;
import java.lang.*;
import java.net.*;
import java.io.*;
import java.awt.*;
import java.applet.*;

public class Tool {

/**
  * A few Component methods for Java-VM access
  */

  public static String getVersion()
  {
  	String version = null;

	try {
		version = java.lang.System.getProperty("java.version");
	}
	catch ( SecurityException s)
	{
		version=(s.getMessage()==null)?s.toString():s.getMessage();
		System.out.println(version);
	}

	return version;
  }

  public static String getVendor()
  {
  	String vendor = null;

	try {
		vendor = java.lang.System.getProperty("java.vendor");
	}
	catch ( SecurityException s)
	{
		vendor=(s.getMessage()==null)?s.toString():s.getMessage();
		System.out.println(vendor);
	}

	return vendor;

  }

  public static String getOSName()
  {
  	String osname = null;

	try {
		osname = java.lang.System.getProperty("os.name");
	}
	catch ( SecurityException s)
	{
		osname=(s.getMessage()==null)?s.toString():s.getMessage();
		System.out.println(osname);
	}

	return osname;

  }

  public static boolean isNetscapesVM() 
  { String vendor=getVendor(); 
    return vendor!=null && vendor.indexOf("Netscape")>=0; }

  public static boolean isSunsVM() 
  { String vendor=getVendor(); 
    return vendor!=null && vendor.indexOf("Sun")>=0; }

  public static boolean isMicrosoftsVM() 
  { String vendor=getVendor(); 
    return vendor!=null && vendor.indexOf("Microsoft")>=0; }

/****************************************************************************/
/****************************************************************************/
/****************************************************************************/

/**
  * A few Component methods for easy awt-hierarchy querys
  */

  public static Point getAbsoluteCoord(Component co)
  {
	Object obj = co;
        Point absCoord = co.getLocation();
        Point p = null;

	while (obj instanceof Component) {
		Container cont = ((Component)obj).getParent();
		if( cont != null ) {
			p = cont.getLocation();
			absCoord.x+=p.x;
			absCoord.y+=p.y;
		}
		if( cont instanceof Window) {
			obj=null;
		} else obj=cont;
	}
	return absCoord;
  }	

    public  static Window getWindow(Component co)
    {
        Window f = null;
        Object obj = co;

        while (obj instanceof Component) {
                Container cont = ((Component)obj).getParent();
                if( cont instanceof Window) {
                        f=(Window)cont;
			obj=cont; // continue seeking for frame or dialog
                } else if( cont instanceof Frame) {
                        f=(Window)cont;
                        obj=null;
                } else if( cont instanceof Dialog) {
                        f=(Window)cont;
                        obj=null;
                } else obj=cont;
        }
        return f;
    }
          
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

/**
   * A few find methods to seek for Component(Shadow)s
  */


  public static boolean isInSameWindow(Component co1, Component co2)
  {	
  	if(co1==null || co2==null ) return false;

        Window f1 = getWindow(co1);
        Window f2 = getWindow(co2);

	if(f1!=null && f2!=null && f1.equals(f2))
		return true;

	return false;	
  }

}