KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > DialogUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.internal.ide;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.jface.dialogs.ErrorDialog;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.PartInitException;
20
21 /**
22  * Utility class to help with dialogs.
23  * <p>
24  * Note that a copy of this class exists in the
25  * org.eclipse.ui.internal package.
26  * </p>
27  */

28 public class DialogUtil {
29
30     /**
31      * Prevent instantiation.
32      */

33     private DialogUtil() {
34     }
35
36     /**
37      * Open an error style dialog for PartInitException by
38      * including any extra information from the nested
39      * CoreException if present.
40      */

41     public static void openError(Shell parent, String JavaDoc title, String JavaDoc message,
42             PartInitException exception) {
43         // Check for a nested CoreException
44
CoreException nestedException = null;
45         IStatus status = exception.getStatus();
46         if (status != null && status.getException() instanceof CoreException) {
47             nestedException = (CoreException) status.getException();
48         }
49
50         if (nestedException != null) {
51             // Open an error dialog and include the extra
52
// status information from the nested CoreException
53
ErrorDialog.openError(parent, title, message, nestedException
54                     .getStatus());
55         } else {
56             // Open a regular error dialog since there is no
57
// extra information to display
58
MessageDialog.openError(parent, title, message);
59         }
60     }
61
62     /**
63      * Return the number of rows available in the current display using the
64      * current font.
65      * @param parent The Composite whose Font will be queried.
66      * @return int The result of the display size divided by the font size.
67      */

68     public static int availableRows(Composite parent) {
69
70         int fontHeight = (parent.getFont().getFontData())[0].getHeight();
71         int displayHeight = parent.getDisplay().getClientArea().height;
72
73         return displayHeight / fontHeight;
74     }
75
76     /**
77      * Return whether or not the font in the parent is the size of a regular
78      * font. Typically used to know if a font is smaller than the High Contrast
79      * Font. This method is used to make layout decisions based on screen space.
80      *
81      * @param parent The Composite whose Font will be queried.
82      * @return boolean. True if there are more than 50 lines of possible
83      * text in the display.
84      */

85     public static boolean inRegularFontMode(Composite parent) {
86
87         return availableRows(parent) > 50;
88     }
89 }
90
Popular Tags