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