1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.test.assistant.views;
25 
26 
27 import java.lang.reflect.Field;
28 import java.lang.reflect.Modifier;
29 import java.util.HashMap;
30 
31 import org.eclipse.swt.graphics.Image;
32 import org.eclipse.swt.graphics.Rectangle;
33 import org.openoffice.test.vcl.client.SmartId;
34 import org.openoffice.test.vcl.widgets.VclControl;
35 
36 public class ControlInfo {
37 
38 	private static final HashMap<Long, String> vcltypes = new  HashMap<Long, String>();
39 
40 	static {
41 		Field[] fields = VclControl.class.getDeclaredFields();
42 		for (Field field : fields) {
43 			int modifiers = field.getModifiers();
44 			if (modifiers == (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL) && field.getType() == Integer.TYPE) {
45 				try {
46 					int v = (Integer) field.get(null);
vcltypes.put(long)v, field.getName()47 					vcltypes.put((long)v, field.getName());
48 				} catch (Exception e) {
49 					//ignore
50 				}
51 			}
52 		}
53 	}
54 
55 	public SmartId id;
56 
57 	public long type;
58 
59 	public String tip;
60 
61 	public Image appearance;
62 
63 	public Rectangle rectangle;
64 
65 	public String name;
66 
ControlInfo(SmartId id, long type, String tip)67 	public ControlInfo(SmartId id, long type, String tip) {
68 		super();
69 		this.id = id;
70 		this.type = type;
71 		this.tip = tip;
72 	}
73 
getVclType()74 	public String getVclType() {
75 		return vcltypes.get(type);
76 	}
77 
shot()78 	public void shot() {
79 		if (id.getId() != 0 || id.getSid() != null) {
80 			VclControl vclControl = new VclControl(id);
81 			try {
82 				if (!vclControl.exists())
83 					return;
84 				java.awt.Rectangle rect = vclControl.getScreenRectangle();
85 //				Display display = Display.getDefault();
86 //				GC gc = new GC(display);
87 				rectangle = new Rectangle(rect.x, rect.y, rect.width, rect.height);
88 //				appearance = new Image(display, rectangle);
89 //				gc.copyArea(appearance, 0, 0);
90 //				gc.dispose();
91 			} catch (Throwable t) {
92 
93 			}
94 
95 		}
96 	}
97 
dispose()98 	public void dispose() {
99 		if (appearance != null)
100 			appearance.dispose();
101 	}
102 }
103