1 11 12 package org.eclipse.debug.internal.ui; 13 14 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; 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 24 31 public static void persistShellGeometry(Shell shell, String dialogSettingsSectionName) { 32 Point shellLocation = shell.getLocation(); 33 Point shellSize = shell.getSize(); 34 IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); 35 settings.put(IDebugPreferenceConstants.DIALOG_ORIGIN_X, shellLocation.x); 36 settings.put(IDebugPreferenceConstants.DIALOG_ORIGIN_Y, shellLocation.y); 37 settings.put(IDebugPreferenceConstants.DIALOG_WIDTH, shellSize.x); 38 settings.put(IDebugPreferenceConstants.DIALOG_HEIGHT, shellSize.y); 39 } 40 41 private static IDialogSettings getDialogSettings(String dialogSettingsSectionName) { 42 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 43 IDialogSettings section = settings.getSection(dialogSettingsSectionName); 44 if (section == null) { 45 section = settings.addNewSection(dialogSettingsSectionName); 46 } 47 return section; 48 } 49 50 59 public static Point getInitialSize(String dialogSettingsSectionName, Point initialSize) { 60 IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); 61 try { 62 int x, y; 63 x = settings.getInt(IDebugPreferenceConstants.DIALOG_WIDTH); 64 y = settings.getInt(IDebugPreferenceConstants.DIALOG_HEIGHT); 65 return new Point(Math.max(x, initialSize.x), Math.max(y, initialSize.y)); 66 } catch (NumberFormatException e) { 67 } 68 return initialSize; 69 } 70 71 79 public static Point getInitialLocation(String dialogSettingsSectionName) { 80 IDialogSettings settings = getDialogSettings(dialogSettingsSectionName); 81 try { 82 int x= settings.getInt(IDebugPreferenceConstants.DIALOG_ORIGIN_X); 83 int y= settings.getInt(IDebugPreferenceConstants.DIALOG_ORIGIN_Y); 84 return new Point(x,y); 85 } catch (NumberFormatException e) { 86 } 87 return null; 88 } 89 } 90 | Popular Tags |