View Javadoc

1   /* ============================================================
2    * JRobin : Pure java implementation of RRDTool's functionality
3    * ============================================================
4    *
5    * Project Info:  http://www.jrobin.org
6    * Project Lead:  Sasa Markovic (saxon@jrobin.org);
7    *
8    * (C) Copyright 2003, by Sasa Markovic.
9    *
10   * Developers:    Sasa Markovic (saxon@jrobin.org)
11   *
12   *
13   * This library is free software; you can redistribute it and/or modify it under the terms
14   * of the GNU Lesser General Public License as published by the Free Software Foundation;
15   * either version 2.1 of the License, or (at your option) any later version.
16   *
17   * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18   * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19   * See the GNU Lesser General Public License for more details.
20   *
21   * You should have received a copy of the GNU Lesser General Public License along with this
22   * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23   * Boston, MA 02111-1307, USA.
24   */
25  package org.jrobin.inspector;
26  
27  import javax.swing.*;
28  import java.awt.*;
29  import java.util.Vector;
30  
31  class Util {
32  	static void centerOnScreen(Window window) {
33  		Toolkit t = Toolkit.getDefaultToolkit();
34  		Dimension screenSize = t.getScreenSize();
35  		Dimension frameSize = window.getPreferredSize();
36  		double x = (screenSize.getWidth() - frameSize.getWidth()) / 2;
37  		double y = (screenSize.getHeight() - frameSize.getHeight()) / 2;
38  		window.setLocation((int) x, (int) y);
39  	}
40  
41  	static void error(Component parent, String message) {
42  		JOptionPane.showMessageDialog(parent, message, "Error", JOptionPane.ERROR_MESSAGE);
43  	}
44  
45  	static void error(Component parent, Exception e) {
46  		e.printStackTrace();
47  		error(parent, e.toString());
48  	}
49  
50  	private static Vector<Window> windows = new Vector<Window>();
51  	private static final int WINDOW_POSITION_SHIFT = 20;
52  
53  	static void placeWindow(Window window) {
54  		int count = windows.size();
55  		if (count == 0) {
56  			centerOnScreen(window);
57  		}
58  		else {
59  			Window last = windows.get(count - 1);
60  			int x = last.getX() + WINDOW_POSITION_SHIFT;
61  			int y = last.getY() + WINDOW_POSITION_SHIFT;
62  			window.setLocation(x, y);
63  		}
64  		windows.add(window);
65  	}
66  
67  	static void dismissWindow(Window window) {
68  		windows.remove(window);
69  		if (windows.size() == 0) {
70  			System.exit(0);
71  		}
72  	}
73  }