KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > mrtg > client > Util


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  * Arne Vandamme (cobralord@jrobin.org)
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.mrtg.client;
26
27 import javax.swing.*;
28 import java.awt.*;
29
30 class Util {
31
32     static JPanel getPanelFor(JComponent comp1, JComponent comp2) {
33         JPanel panel = new JPanel();
34         panel.setLayout(new FlowLayout(FlowLayout.LEFT));
35         panel.add(comp1);
36         panel.add(comp2);
37         return panel;
38     }
39
40     static JPanel getPanelFor(JComponent comp1, JComponent comp2, JComponent comp3) {
41         JPanel panel = new JPanel();
42         panel.setLayout(new FlowLayout(FlowLayout.LEFT));
43         panel.add(comp1);
44         panel.add(comp2);
45         panel.add(comp3);
46         return panel;
47     }
48
49     static void error(Component parent, String JavaDoc message) {
50         JOptionPane.showMessageDialog(parent, message, "Error", JOptionPane.ERROR_MESSAGE);
51     }
52
53     static void warn(Component parent, String JavaDoc message) {
54         JOptionPane.showMessageDialog(parent, message, "Warning", JOptionPane.WARNING_MESSAGE);
55     }
56
57     static void info(Component parent, String JavaDoc message) {
58         JOptionPane.showMessageDialog(parent, message, "Info", JOptionPane.INFORMATION_MESSAGE);
59     }
60
61     static void centerOnScreen(Window window) {
62         Toolkit t = Toolkit.getDefaultToolkit();
63         Dimension screenSize = t.getScreenSize();
64         Dimension frameSize = window.getPreferredSize();
65         double x = (screenSize.getWidth() - frameSize.getWidth()) / 2;
66         double y = (screenSize.getHeight() - frameSize.getHeight()) / 2;
67         window.setLocation((int) x, (int) y);
68     }
69
70     static final JButton PLACEHOLDER_BUTTON = new JButton("123456789012");
71     static final Dimension BUTTON_SIZE = PLACEHOLDER_BUTTON.getPreferredSize();
72
73     static JButton standardButton(String JavaDoc caption) {
74         JButton button = new JButton(caption);
75         button.setPreferredSize(BUTTON_SIZE);
76         button.setMinimumSize(BUTTON_SIZE);
77         button.setMaximumSize(BUTTON_SIZE);
78         return button;
79     }
80
81     static final JButton BIG_PLACEHOLDER_BUTTON = new JButton("12345678901234567");
82     static final Dimension BIG_BUTTON_SIZE = BIG_PLACEHOLDER_BUTTON.getPreferredSize();
83
84     static JButton largeButton(String JavaDoc caption) {
85         JButton button = new JButton(caption);
86         button.setPreferredSize(BIG_BUTTON_SIZE);
87         button.setMinimumSize(BIG_BUTTON_SIZE);
88         button.setMaximumSize(BIG_BUTTON_SIZE);
89         return button;
90     }
91
92     static final JLabel PLACEHOLDER_LABEL = new JLabel("nnnnnnnnnnnnnnn");
93     static final Dimension LABEL_SIZE = PLACEHOLDER_LABEL.getPreferredSize();
94
95     static JLabel standardLabel(String JavaDoc text) {
96         JLabel label = new JLabel(text);
97         label.setPreferredSize(LABEL_SIZE);
98         return label;
99     }
100
101     static JLabel standardLabel() {
102         return standardLabel("");
103     }
104
105     static final int INPUT_FIELD_SIZE = 20;
106
107     static JTextField standardTextField() {
108         JTextField textField = new JTextField();
109         textField.setColumns(INPUT_FIELD_SIZE);
110         return textField;
111     }
112
113     static final int SCROLL_PANE_HEIGHT = 30;
114
115     static JScrollPane standardScrollPane(JComponent component) {
116         JTextField placeholder = Util.standardTextField();
117         int width = (int)placeholder.getPreferredSize().getWidth();
118         JScrollPane pane = new JScrollPane(component);
119         pane.setPreferredSize(new Dimension(width, 150));
120         return pane;
121     }
122 }
123
Popular Tags