root / branches / v2_0_0_prep / extensions / org.gvsig.mkmvnproject / templates / UIAPI / org.gvsig.fortunecookies / org.gvsig.fortunecookies.main / src / main / java / org / gvsig / fortunecookies / main / Main.java @ 32378
History | View | Annotate | Download (3.84 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.fortunecookies.main; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
|
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JFrame; |
32 |
import javax.swing.JMenu; |
33 |
import javax.swing.JMenuBar; |
34 |
import javax.swing.JMenuItem; |
35 |
import javax.swing.JToolBar; |
36 |
|
37 |
import org.gvsig.fortunecookies.FortuneCookieLocator; |
38 |
import org.gvsig.fortunecookies.FortuneCookieManager; |
39 |
import org.gvsig.fortunecookies.FortuneCookieService; |
40 |
import org.gvsig.fortunecookies.swing.FortuneCookieSwingLocator; |
41 |
import org.gvsig.fortunecookies.swing.FortuneCookieUIManager; |
42 |
import org.gvsig.fortunecookies.swing.FortuneCookieWindowManager; |
43 |
import org.gvsig.fortunecookies.swing.JFortuneCookieServicePanel; |
44 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
45 |
import org.gvsig.tools.service.ServiceException; |
46 |
|
47 |
public class Main { |
48 |
|
49 |
FortuneCookieManager manager; |
50 |
FortuneCookieUIManager uimanager; |
51 |
|
52 |
public static void main( String args[] ) { |
53 |
Main main = new Main();
|
54 |
main.show(); |
55 |
} |
56 |
|
57 |
public void show() { |
58 |
|
59 |
org.apache.log4j.BasicConfigurator.configure(); |
60 |
|
61 |
new DefaultLibrariesInitializer().fullInitialize();
|
62 |
manager = FortuneCookieLocator.getManager(); |
63 |
|
64 |
// Asignamos el locator e iniciamos la instancia
|
65 |
uimanager = FortuneCookieSwingLocator.getUIManager(); |
66 |
//manager = uimanager.getManager();
|
67 |
|
68 |
|
69 |
JFrame frame = new JFrame("Fortune Cookie"); |
70 |
|
71 |
// Create the menu bar.
|
72 |
JMenuBar menuBar = new JMenuBar(); |
73 |
|
74 |
// Build the menu.
|
75 |
JMenu menu_file = new JMenu("File"); |
76 |
JMenuItem menuItem_get = new JMenuItem("Get a fortune cookie"); |
77 |
menuItem_get.addActionListener(new ActionListener(){ |
78 |
public void actionPerformed(ActionEvent e) { |
79 |
showFortuneCookie(manager); |
80 |
} |
81 |
}); |
82 |
menu_file.add(menuItem_get); |
83 |
|
84 |
|
85 |
JMenuItem menuItem_exit = new JMenuItem("Exit"); |
86 |
menuItem_exit.addActionListener(new ActionListener(){ |
87 |
public void actionPerformed(ActionEvent e) { |
88 |
System.exit(0); |
89 |
} |
90 |
}); |
91 |
menu_file.add(menuItem_exit); |
92 |
|
93 |
menuBar.add(menu_file); |
94 |
|
95 |
JToolBar toolBar = new JToolBar(); |
96 |
|
97 |
JButton get = new JButton("Get a fortune cookie"); |
98 |
get.addActionListener(new ActionListener(){ |
99 |
|
100 |
public void actionPerformed(ActionEvent arg0) { |
101 |
showFortuneCookie(manager); |
102 |
} |
103 |
|
104 |
}); |
105 |
toolBar.add(get); |
106 |
|
107 |
frame.setPreferredSize(new Dimension(160, 100)); |
108 |
frame.add(menuBar, BorderLayout.NORTH);
|
109 |
frame.add(toolBar, BorderLayout.LINE_END);
|
110 |
|
111 |
//Display the window.
|
112 |
frame.pack(); |
113 |
frame.setVisible(true);
|
114 |
|
115 |
} |
116 |
|
117 |
public void showFortuneCookie(FortuneCookieManager manager) { |
118 |
try {
|
119 |
|
120 |
FortuneCookieService service = (FortuneCookieService) manager.getFortuneCookieService(); |
121 |
JFortuneCookieServicePanel panel = uimanager.createFortuneCookie(service); |
122 |
uimanager.getWindowManager().showWindow( |
123 |
panel, |
124 |
"Fortune Cookie",
|
125 |
FortuneCookieWindowManager.MODE_WINDOW |
126 |
); |
127 |
|
128 |
} catch (ServiceException e) {
|
129 |
e.printStackTrace(); |
130 |
} |
131 |
} |
132 |
|
133 |
} |