~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/DialogSettingsHelper.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.cdt.make.internal.ui;
13
 
 
14
 
import org.eclipse.jface.dialogs.IDialogSettings;
15
 
import org.eclipse.swt.graphics.Point;
16
 
import org.eclipse.swt.widgets.Shell;
17
 
 
18
 
/**
19
 
 * Helper class for dealing with setting and restoring dialog settings.
20
 
 */
21
 
public class DialogSettingsHelper {
22
 
        
23
 
        /**
24
 
         * Persists the location and dimensions of the shell in the
25
 
         * Debug UI Plugin dialog settings under the provided dialog settings section name
26
 
         * 
27
 
         * @param shell The shell whose geometry is to be stored
28
 
         * @param dialogSettingsSectionName The name of the dialog settings section
29
 
         */
30
 
        public static void persistShellGeometry(Shell shell, String dialogSettingsSectionName) {
31
 
                Point shellLocation = shell.getLocation();
32
 
                Point shellSize = shell.getSize();
33
 
                IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
34
 
                settings.put(IMakeUIPreferenceConstants.DIALOG_ORIGIN_X, shellLocation.x);
35
 
                settings.put(IMakeUIPreferenceConstants.DIALOG_ORIGIN_Y, shellLocation.y);
36
 
                settings.put(IMakeUIPreferenceConstants.DIALOG_WIDTH, shellSize.x);
37
 
                settings.put(IMakeUIPreferenceConstants.DIALOG_HEIGHT, shellSize.y);
38
 
        }
39
 
        
40
 
        private static IDialogSettings getDialogSettings(String dialogSettingsSectionName) {
41
 
                IDialogSettings settings = MakeUIPlugin.getDefault().getDialogSettings();
42
 
                IDialogSettings section = settings.getSection(dialogSettingsSectionName);
43
 
                if (section == null) {
44
 
                        section = settings.addNewSection(dialogSettingsSectionName);
45
 
                } 
46
 
                return section;
47
 
        }
48
 
        
49
 
        /**
50
 
         * Returns the initial size which is the larger of the <code>initialSize</code> or
51
 
         * the size persisted in the Debug UI Plugin dialog settings under the provided dialog setttings section name.
52
 
         * If no size is persisted in the settings, the <code>initialSize</code> is returned. 
53
 
         * 
54
 
         * @param initialSize The initialSize to compare against
55
 
         * @param dialogSettingsSectionName The name of the dialog settings section
56
 
         * @return the initial size
57
 
         */
58
 
        public static Point getInitialSize(String dialogSettingsSectionName, Point initialSize) {
59
 
                IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
60
 
                try {
61
 
                        int x, y;
62
 
                        x = settings.getInt(IMakeUIPreferenceConstants.DIALOG_WIDTH);
63
 
                        y = settings.getInt(IMakeUIPreferenceConstants.DIALOG_HEIGHT);
64
 
                        return new Point(Math.max(x, initialSize.x), Math.max(y, initialSize.y));
65
 
                } catch (NumberFormatException e) {
66
 
                }
67
 
                return initialSize;
68
 
        }
69
 
        
70
 
        /**
71
 
         * Returns the initial location which is persisted in the Debug UI Plugin dialog settings
72
 
         * under the provided dialog setttings section name.
73
 
         * If location is not persisted in the settings, the <code>null</code> is returned. 
74
 
         * 
75
 
         * @param dialogSettingsSectionName The name of the dialog settings section
76
 
         * @return The initial location or <code>null</code>
77
 
         */
78
 
        public static Point getInitialLocation(String dialogSettingsSectionName) {
79
 
                IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
80
 
                try {
81
 
                        int x= settings.getInt(IMakeUIPreferenceConstants.DIALOG_ORIGIN_X);
82
 
                        int y= settings.getInt(IMakeUIPreferenceConstants.DIALOG_ORIGIN_Y);
83
 
                        return new Point(x,y);
84
 
                } catch (NumberFormatException e) {
85
 
                }
86
 
                return null;
87
 
        }
88
 
}