KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > DialogSettingsHelper


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11  
12 package org.eclipse.jdt.internal.debug.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 /**
20  * Helper class for dealing with setting and restoring dialog settings.
21  */

22 public class DialogSettingsHelper {
23     
24     /**
25      * Persists the location and dimensions of the shell in the Java
26      * Debug UI Plugin dialog settings under the provided dialog settings section name
27      *
28      * @param shell The shell whose geometry is to be stored
29      * @param dialogSettingsSectionName The name of the dialog settings section
30      */

31     public static void persistShellGeometry(Shell shell, String JavaDoc 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 JavaDoc dialogSettingsSectionName) {
42         IDialogSettings settings = JDIDebugUIPlugin.getDefault().getDialogSettings();
43         IDialogSettings section = settings.getSection(dialogSettingsSectionName);
44         if (section == null) {
45             section = settings.addNewSection(dialogSettingsSectionName);
46         }
47         return section;
48     }
49     
50     /**
51      * Returns the initial size which is the larger of the <code>initialSize</code> or
52      * the size persisted in the Java Debug UI Plugin dialog settings under the provided dialog setttings section name.
53      * If no size is persisted in the settings, the <code>initialSize</code> is returned.
54      *
55      * @param initialSize The initialSize to compare against
56      * @param dialogSettingsSectionName The name of the dialog settings section
57      * @return the initial size
58      */

59     public static Point getInitialSize(String JavaDoc 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 JavaDoc e) {
67         }
68         return initialSize;
69     }
70     
71     /**
72      * Returns the initial location which is persisted in the Java Debug UI Plugin dialog settings
73      * under the provided dialog setttings section name.
74      * If location is not persisted in the settings, the <code>null</code> is returned.
75      *
76      * @param dialogSettingsSectionName The name of the dialog settings section
77      * @return The initial location or <code>null</code>
78      */

79     public static Point getInitialLocation(String JavaDoc 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 JavaDoc e) {
86         }
87         return null;
88     }
89 }
90
Popular Tags