1 54 55 package com.mullassery.act.util; 56 57 import java.awt.Component ; 58 import java.awt.Dimension ; 59 import java.awt.Point ; 60 import java.awt.Toolkit ; 61 import java.util.MissingResourceException ; 62 import java.util.ResourceBundle ; 63 64 import javax.swing.JOptionPane ; 65 66 71 public final class GUIUtil { 72 public static final String ACT_GUI_BUNDLE_NAME = "com.mullassery.act.gui.actGui"; 73 public static final ResourceBundle ACT_GUI_RESOURCE_BUNDLE = 74 ResourceBundle.getBundle(GUIUtil.ACT_GUI_BUNDLE_NAME); 75 public static final String TASK = getString("ACT.xml.task"); 76 public static final String TASK_CLASS = getString("ACT.xml.class"); 77 public static final String TASK_DESCRIPTION = getString("ACT.xml.description"); 78 public static final String TASK_DISPLAY = getString("ACT.xml.display"); 79 80 public static final String TASK_GROUP = getString("ACT.xml.taskgroup"); 81 public static final String TASK_LIST = getString("ACT.xml.tasks"); 82 public static final String TASK_NAME = getString("ACT.xml.name"); 83 public static final String TASK_VISIBLE = getString("ACT.xml.visible"); 84 85 public static void centralize(Component comp) { 86 Dimension size = comp.getSize(); 87 Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); 88 int x = (scr.width - size.width) / 2; 89 int y = (scr.height - size.height) / 2; 90 comp.setBounds(x, y, size.width, size.height); 91 } 92 93 public static Point getCenter() { 94 Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); 95 return new Point (scr.width / 2, scr.height / 2); 96 } 97 98 public static final boolean getConfirmation(Component comp, String message) { 99 int ret = 100 showConfirm( 101 comp, 102 message, 103 GUIUtil.getString("ACT.confirmDialogTitle"), 104 JOptionPane.YES_NO_OPTION); 105 return (ret == JOptionPane.YES_OPTION || ret == JOptionPane.OK_OPTION); 106 } 107 108 public static final String getInput(Component comp, String message) { 109 return JOptionPane.showInputDialog( 110 comp, 111 message, 112 GUIUtil.getString("ACT.inputDialogTitle"), 113 JOptionPane.QUESTION_MESSAGE); 114 } 115 116 public static String getString(String key) { 117 try { 118 return GUIUtil.ACT_GUI_RESOURCE_BUNDLE.getString(key); 119 } catch (MissingResourceException e) { 120 return '!' + key + '!'; 121 } 122 } 123 124 public static final int showConfirm(Component comp, String message, String title, int type) { 125 return JOptionPane.showConfirmDialog(comp, message, title, type); 126 } 127 128 public static final void showErrorMessage(Component comp, String message) { 129 showMessage( 130 comp, 131 message, 132 GUIUtil.getString("ACT.errorDialogTitle"), 133 JOptionPane.ERROR_MESSAGE); 134 } 135 136 public static final void showInfoMessage(Component comp, String message) { 137 showMessage( 138 comp, 139 message, 140 GUIUtil.getString("ACT.infoDialogTitle"), 141 JOptionPane.INFORMATION_MESSAGE); 142 } 143 144 public static final void showMessage(Component comp, String message, String title, int type) { 145 JOptionPane.showMessageDialog(comp, message, title, type); 146 } 147 148 public static final void showWarningMessage(Component comp, String message) { 149 showMessage( 150 comp, 151 message, 152 GUIUtil.getString("ACT.infoDialogTitle"), 153 JOptionPane.WARNING_MESSAGE); 154 } 155 } 156 | Popular Tags |