1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d.gui;
21
22 import camera3d.*;
23 import java.awt.*;
24 import javax.swing.*;
25 import java.awt.image.BufferedImage;
26
27
28
29 /***
30 * Manages the loading and supplying of application cursors to other classes.<BR>
31 * Implements the singleton design pattern.
32 * @author Fábio de Miranda, Carlos da Silva dos Santos
33 */
34
35 public class CursorManager {
36
37 private static CursorManager manager;
38
39 static {
40 manager = new CursorManager();
41 }
42
43 /*
44 private static final int NORMAL_CURSOR = -2;
45 private static final int ROTATION_CURSOR = 0;
46 private static final int SCALING_CURSOR = 1;
47 private static final int TRANSLATION_CURSOR = 2;
48 */
49
50 Cursor[] cursor = new Cursor[6];
51
52 /***
53 * Provides access to the single instance of this class.
54 */
55 public static CursorManager getCursorManager(){
56 if (manager == null){
57 manager = new CursorManager();
58 }
59 return manager;
60 }
61
62 private CursorManager() {
63 ImageIcon translationIcon = new ImageIcon(this.getClass().getResource("icons/TransIcon.gif"));
64 ImageIcon rotationIcon = new ImageIcon(this.getClass().getResource("icons/RotIcon.gif"));
65 ImageIcon scaleIcon = new ImageIcon(this.getClass().getResource("icons/ScaleIcon.gif"));
66
67 /*
68 BufferedImage bim = new BufferedImage(32, 32, BufferedImage.TYPE_4BYTE_ABGR);
69 Graphics gim = bim.getGraphics();
70 gim.drawImage(image5.getImage(), 0, 0, null);
71
72 cursor = Toolkit.getDefaultToolkit().createCustomCursor(bim,
73 new Point(8, 8), "cross");
74 canvas.setCursor(cursor);
75 */
76
77
78 cursor[0] = makeCursor(translationIcon, "Translation");
79 cursor[1] = makeCursor(rotationIcon, "Rotation");
80 cursor[2] = makeCursor(scaleIcon, "Scale");
81 }
82
83 /***
84 * Returns the appropriate cursor for a given transformation type.
85 * @param type Type of transformation which returned cursor is to represent
86 * @return The proper cursor for representing the type of transformation requested (translation, rotation, etc)
87 */
88 public Cursor getTransformationCursor(TransformType type){
89 if(type==TransformType.TRANSLATION){
90 return cursor[0];
91 }else if(type==TransformType.ROTATION){
92 return cursor[1];
93 }else if(type==TransformType.SCALING){
94 return cursor[2];
95 }else{
96 return Cursor.getDefaultCursor();
97 }
98 }
99
100 /* Actually builds the cursor, given its Icon and its name. */
101 private Cursor makeCursor(ImageIcon icon, String name){
102 /*
103 BufferedImage bim = new BufferedImage(32, 32, BufferedImage.TYPE_4BYTE_ABGR);
104 Graphics gim = bim.getGraphics();
105 gim.drawImage(image5.getImage(), 0, 0, null);
106
107 cursor = Toolkit.getDefaultToolkit().createCustomCursor(bim,
108 new Point(8, 8), "cross");
109 canvas.setCursor(cursor);
110 */
111 BufferedImage bim = new BufferedImage(32, 32, BufferedImage.TYPE_4BYTE_ABGR);
112 Graphics gim = bim.getGraphics();
113 gim.drawImage(icon.getImage(), 0,0,null);
114 return Toolkit.getDefaultToolkit().createCustomCursor(bim, new Point(8, 8), name);
115 }
116
117 }
This page was automatically generated by Maven