1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.lf5.viewer;
18
19 import javax.swing.*;
20 import java.awt.*;
21
22 /***
23 * LogFactor5Dialog
24 *
25 * @author Richard Hurst
26 * @author Brad Marlborough
27 */
28
29
30
31 public abstract class LogFactor5Dialog extends JDialog {
32
33
34
35 protected static final Font DISPLAY_FONT = new Font("Arial", Font.BOLD, 12);
36
37
38
39
40
41
42
43
44
45
46
47 protected LogFactor5Dialog(JFrame jframe, String message, boolean modal) {
48 super(jframe, message, modal);
49 }
50
51
52
53
54 public void show() {
55 pack();
56 minimumSizeDialog(this, 200, 100);
57 centerWindow(this);
58 super.show();
59 }
60
61
62
63
64
65
66
67
68 protected void centerWindow(Window win) {
69 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
70
71
72 if (screenDim.width < win.getSize().width) {
73 win.setSize(screenDim.width, win.getSize().height);
74 }
75
76 if (screenDim.height < win.getSize().height) {
77 win.setSize(win.getSize().width, screenDim.height);
78 }
79
80
81 int x = (screenDim.width - win.getSize().width) / 2;
82 int y = (screenDim.height - win.getSize().height) / 2;
83 win.setLocation(x, y);
84 }
85
86 protected void wrapStringOnPanel(String message,
87 Container container) {
88 GridBagConstraints c = getDefaultConstraints();
89 c.gridwidth = GridBagConstraints.REMAINDER;
90
91 c.insets = new Insets(0, 0, 0, 0);
92 GridBagLayout gbLayout = (GridBagLayout) container.getLayout();
93
94
95 while (message.length() > 0) {
96 int newLineIndex = message.indexOf('\n');
97 String line;
98 if (newLineIndex >= 0) {
99 line = message.substring(0, newLineIndex);
100 message = message.substring(newLineIndex + 1);
101 } else {
102 line = message;
103 message = "";
104 }
105 Label label = new Label(line);
106 label.setFont(DISPLAY_FONT);
107 gbLayout.setConstraints(label, c);
108 container.add(label);
109 }
110 }
111
112 protected GridBagConstraints getDefaultConstraints() {
113 GridBagConstraints constraints = new GridBagConstraints();
114 constraints.weightx = 1.0;
115 constraints.weighty = 1.0;
116 constraints.gridheight = 1;
117
118 constraints.insets = new Insets(4, 4, 4, 4);
119
120 constraints.fill = GridBagConstraints.NONE;
121
122 constraints.anchor = GridBagConstraints.WEST;
123
124 return constraints;
125 }
126
127 protected void minimumSizeDialog(Component component,
128 int minWidth,
129 int minHeight) {
130
131 if (component.getSize().width < minWidth)
132 component.setSize(minWidth, component.getSize().height);
133
134 if (component.getSize().height < minHeight)
135 component.setSize(component.getSize().width, minHeight);
136 }
137
138
139
140 }