1 16 package org.apache.log4j.lf5.viewer; 17 18 import javax.swing.*; 19 import java.awt.*; 20 21 27 28 30 public abstract class LogFactor5Dialog extends JDialog { 31 protected static final Font DISPLAY_FONT = new Font("Arial", Font.BOLD, 12); 35 39 43 protected LogFactor5Dialog(JFrame jframe, String message, boolean modal) { 47 super(jframe, message, modal); 48 } 49 50 public void show() { 54 pack(); 55 minimumSizeDialog(this, 200, 100); 56 centerWindow(this); 57 super.show(); 58 } 59 60 64 protected void centerWindow(Window win) { 68 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); 69 70 if (screenDim.width < win.getSize().width) { 72 win.setSize(screenDim.width, win.getSize().height); 73 } 74 75 if (screenDim.height < win.getSize().height) { 76 win.setSize(win.getSize().width, screenDim.height); 77 } 78 79 int x = (screenDim.width - win.getSize().width) / 2; 81 int y = (screenDim.height - win.getSize().height) / 2; 82 win.setLocation(x, y); 83 } 84 85 protected void wrapStringOnPanel(String message, 86 Container container) { 87 GridBagConstraints c = getDefaultConstraints(); 88 c.gridwidth = GridBagConstraints.REMAINDER; 89 c.insets = new Insets(0, 0, 0, 0); 91 GridBagLayout gbLayout = (GridBagLayout) container.getLayout(); 92 93 94 while (message.length() > 0) { 95 int newLineIndex = message.indexOf('\n'); 96 String line; 97 if (newLineIndex >= 0) { 98 line = message.substring(0, newLineIndex); 99 message = message.substring(newLineIndex + 1); 100 } else { 101 line = message; 102 message = ""; 103 } 104 Label label = new Label(line); 105 label.setFont(DISPLAY_FONT); 106 gbLayout.setConstraints(label, c); 107 container.add(label); 108 } 109 } 110 111 protected GridBagConstraints getDefaultConstraints() { 112 GridBagConstraints constraints = new GridBagConstraints(); 113 constraints.weightx = 1.0; 114 constraints.weighty = 1.0; 115 constraints.gridheight = 1; constraints.insets = new Insets(4, 4, 4, 4); 118 constraints.fill = GridBagConstraints.NONE; 120 constraints.anchor = GridBagConstraints.WEST; 122 123 return constraints; 124 } 125 126 protected void minimumSizeDialog(Component component, 127 int minWidth, 128 int minHeight) { 129 if (component.getSize().width < minWidth) 131 component.setSize(minWidth, component.getSize().height); 132 if (component.getSize().height < minHeight) 134 component.setSize(component.getSize().width, minHeight); 135 } 136 } | Popular Tags |