1 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 message) { 50 JOptionPane.showMessageDialog(parent, message, "Error", JOptionPane.ERROR_MESSAGE); 51 } 52 53 static void warn(Component parent, String message) { 54 JOptionPane.showMessageDialog(parent, message, "Warning", JOptionPane.WARNING_MESSAGE); 55 } 56 57 static void info(Component parent, String 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 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 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 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 |