1 11 12 package org.eclipse.ant.internal.ui.preferences; 13 14 import org.eclipse.ant.internal.ui.AntUIPlugin; 15 import org.eclipse.jface.dialogs.IDialogSettings; 16 import org.eclipse.swt.graphics.Point; 17 import org.eclipse.swt.widgets.Shell; 18 19 22 public class DialogSettingsHelper { 23 public static final String DIALOG_ORIGIN_X = AntUIPlugin.PI_ANTUI + ".ATTR_ANT_DIALOG_X_ORIGIN"; public static final String DIALOG_ORIGIN_Y = AntUIPlugin.PI_ANTUI + ".ATTR_ANT_DIALOG_Y_ORIGIN"; public static final String DIALOG_WIDTH = AntUIPlugin.PI_ANTUI + ".ATTR_ANT_DIALOG_WIDTH"; public static final String DIALOG_HEIGHT = AntUIPlugin.PI_ANTUI + ".ATTR_ANT_DIALOG_HEIGHT"; 28 35 public static void persistShellGeometry(Shell shell, String dialogSettingsSectionName) { 36 Point shellLocation = shell.getLocation(); 37 Point shellSize = shell.getSize(); 38 IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); 39 settings.put(DIALOG_ORIGIN_X, shellLocation.x); 40 settings.put(DIALOG_ORIGIN_Y, shellLocation.y); 41 settings.put(DIALOG_WIDTH, shellSize.x); 42 settings.put(DIALOG_HEIGHT, shellSize.y); 43 } 44 45 private static IDialogSettings getDialogSettings(String dialogSettingsSectionName) { 46 IDialogSettings settings = AntUIPlugin.getDefault().getDialogSettings(); 47 IDialogSettings section = settings.getSection(dialogSettingsSectionName); 48 if (section == null) { 49 section = settings.addNewSection(dialogSettingsSectionName); 50 } 51 return section; 52 } 53 54 63 public static Point getInitialSize(String dialogSettingsSectionName, Point initialSize) { 64 IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); 65 try { 66 int x, y; 67 x = settings.getInt(DIALOG_WIDTH); 68 y = settings.getInt(DIALOG_HEIGHT); 69 return new Point(Math.max(x, initialSize.x), Math.max(y, initialSize.y)); 70 } catch (NumberFormatException e) { 71 } 72 return initialSize; 73 } 74 75 83 public static Point getInitialLocation(String dialogSettingsSectionName) { 84 IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); 85 try { 86 int x= settings.getInt(DIALOG_ORIGIN_X); 87 int y= settings.getInt(DIALOG_ORIGIN_Y); 88 return new Point(x,y); 89 } catch (NumberFormatException e) { 90 } 91 return null; 92 } 93 } 94 | Popular Tags |