1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of CosyBeans-Common.
5 *
6 * CosyBeans-Common is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CosyBeans-Common 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 CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package com.cosylab.gui.components.util;
21
22 import java.awt.Container;
23 import java.awt.Window;
24 import java.awt.event.WindowAdapter;
25 import java.awt.event.WindowEvent;
26
27 import javax.swing.JFrame;
28
29
30 /**
31 *
32 *
33 * @author <a href="mailto:miha.kadunc@cosylab.com">Miha Kadunc</a>
34 * @version $id$
35 */
36 public class RunnerHelper {
37
38 public static void runFrame(Window frame, int width, int height) {
39 try {
40 frame.setSize(width, height);
41 frame.addWindowListener(new WindowAdapter() {
42 /**
43 * @see java.awt.event.WindowAdapter#windowClosing(WindowEvent)
44 */
45 public void windowClosing(WindowEvent e) {
46 super.windowClosing(e);
47 System.exit(0);
48 }
49 });
50 ComponentPositioner.centerOnScreen(frame);
51 frame.setVisible(true);
52 } catch (Exception e) {
53 System.out.println(">>> Exception in main");
54 e.printStackTrace();
55 }
56 }
57
58 public static void runComponent(Container c, int width, int height) {
59 try {
60
61 JFrame frame = new JFrame(c.getName());
62 frame.setContentPane(c);
63 int w = width + frame.getInsets().left + frame.getInsets().right;
64 int h = height + frame.getInsets().bottom + frame.getInsets().top;
65 runFrame(frame, w, h);
66 } catch (Exception e) {
67 System.out.println(">>> Exception in main");
68 e.printStackTrace();
69 }
70 }
71
72 }