KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > wizards > ResizableWizard


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 package org.eclipse.team.internal.ccvs.ui.wizards;
12
13 import org.eclipse.jface.dialogs.IDialogSettings;
14 import org.eclipse.jface.wizard.Wizard;
15 import org.eclipse.jface.wizard.WizardDialog;
16 import org.eclipse.swt.graphics.Point;
17 import org.eclipse.swt.graphics.Rectangle;
18 import org.eclipse.swt.widgets.Shell;
19
20 /**
21  * Persists the size of the wizard dialog.
22  */

23 public class ResizableWizard extends Wizard {
24     
25     private final int DEFAULT_WIDTH;
26     private final int DEFAULT_HEIGHT;
27     
28     private static final String JavaDoc BOUNDS_HEIGHT_KEY = "width"; //$NON-NLS-1$
29
private static final String JavaDoc BOUNDS_WIDTH_KEY = "height"; //$NON-NLS-1$
30

31     final String JavaDoc fSectionName;
32     
33     public ResizableWizard(String JavaDoc sectionName, IDialogSettings settings) {
34         this(sectionName, settings, 300, 400);
35     }
36     
37     protected ResizableWizard(String JavaDoc sectionName, IDialogSettings settings, int defaultWidth, int defaultHeight) {
38         DEFAULT_WIDTH= defaultWidth;
39         DEFAULT_HEIGHT= defaultHeight;
40         fSectionName= sectionName;
41         setDialogSettings(settings);
42     }
43     
44     protected static int open(Shell shell, ResizableWizard wizard) {
45         final WizardDialog dialog= new WizardDialog(shell, wizard);
46         dialog.setMinimumPageSize(wizard.loadSize());
47         return dialog.open();
48     }
49     
50     public void saveSize() {
51         final Rectangle bounds= getContainer().getCurrentPage().getControl().getParent().getClientArea();
52         final IDialogSettings settings= getDialogSettings();
53         if (settings == null)
54             return;
55         
56         IDialogSettings section= settings.getSection(fSectionName);
57         if (section == null)
58             section= settings.addNewSection(fSectionName);
59         
60         section.put(BOUNDS_WIDTH_KEY, bounds.width);
61         section.put(BOUNDS_HEIGHT_KEY, bounds.height);
62     }
63     
64     public Point loadSize() {
65         final Point size= new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
66         
67         final IDialogSettings settings= getDialogSettings();
68         if (settings == null)
69             return size;
70         
71         final IDialogSettings section= settings.getSection(fSectionName);
72         if (section == null)
73             return size;
74
75         try {
76             size.x= section.getInt(BOUNDS_WIDTH_KEY);
77             size.y= section.getInt(BOUNDS_HEIGHT_KEY);
78         } catch (NumberFormatException JavaDoc e) {
79         }
80         return size;
81     }
82
83
84     public boolean performFinish() {
85         saveSize();
86         return true;
87     }
88 }
89
Popular Tags