KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > Policy


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 - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build;
12
13 import java.util.*;
14 import org.eclipse.core.runtime.*;
15
16 /**
17  * Utility class used to help with NLS'ing messages, creating progress monitors, etc.
18  */

19 public class Policy {
20
21     /**
22      * Return a progress monitor for the given monitor. Ensures that the resulting
23      * monitor is not <code>null</code>.
24      *
25      * @param monitor the monitor to wrap, or <code>null</code>
26      * @return IProgressMonitor
27      */

28     public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
29         if (monitor == null)
30             return new NullProgressMonitor();
31         return monitor;
32     }
33
34     /**
35      * Create a sub progress monitor with the given units of work, for the given monitor.
36      *
37      * @param monitor the parent monitor, or <code>null</code>
38      * @param ticks the number of units of work
39      * @return IProgressMonitor
40      */

41     public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) {
42         if (monitor == null)
43             return new NullProgressMonitor();
44         if (monitor instanceof NullProgressMonitor)
45             return monitor;
46         return new SubProgressMonitor(monitor, ticks);
47     }
48
49     /**
50      * Create a sub progress monitor with the given number of units of work and in the
51      * given style, for the specified parent monitor.
52      *
53      * @param monitor the parent monitor, or <code>null</code>
54      * @param ticks the number of units of work
55      * @param style the style of the sub progress monitor
56      * @return IProgressMonitor
57      */

58     public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks, int style) {
59         if (monitor == null)
60             return new NullProgressMonitor();
61         if (monitor instanceof NullProgressMonitor)
62             return monitor;
63         return new SubProgressMonitor(monitor, ticks, style);
64     }
65
66     /**
67      * Print a debug message to the console. If the given boolean is
68      * <code>true</code> then pre-pend the message with the current date.
69      */

70     public static void debug(boolean includeDate, String JavaDoc message) {
71         if (includeDate)
72             message = new Date(System.currentTimeMillis()).toString() + " - " + message; //$NON-NLS-1$
73
System.out.println(message);
74     }
75 }
76
Popular Tags