| 1 | /** |
| 2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.deduced.viewer.web.shared; |
| 17 | |
| 18 | import java.util.Date; |
| 19 | |
| 20 | import com.google.gwt.dom.client.Style; |
| 21 | import com.google.gwt.user.client.ui.Panel; |
| 22 | import com.google.gwt.user.client.ui.Widget; |
| 23 | |
| 24 | /** |
| 25 | * |
| 26 | * Class of various utility methods |
| 27 | * |
| 28 | * @author Steve McDuff |
| 29 | * |
| 30 | */ |
| 31 | public class Utilities |
| 32 | { |
| 33 | |
| 34 | /** |
| 35 | * test if two objects are equals while gracefully handling null values |
| 36 | * |
| 37 | * @param object1 the first object |
| 38 | * @param object2 the second object |
| 39 | * @return true if both objects are null or both objects are equal. |
| 40 | */ |
| 41 | public static boolean equals( |
| 42 | Object object1, Object object2) |
| 43 | { |
| 44 | if (object1 == object2) |
| 45 | { |
| 46 | return true; |
| 47 | } |
| 48 | if ((object1 == null) || (object2 == null)) |
| 49 | { |
| 50 | return false; |
| 51 | } |
| 52 | return object1.equals(object2); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * get time stamp in milliseconds |
| 57 | * |
| 58 | * @return the time stamp in milliseconds |
| 59 | */ |
| 60 | public static long getTimeStampInMilliseconds() |
| 61 | { |
| 62 | Date date = new Date(); |
| 63 | return date.getTime(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * add Widget To Root Panel |
| 68 | * |
| 69 | * @param widgetToAdd widget to add |
| 70 | * @param panel root panel |
| 71 | */ |
| 72 | public static void addWidgetToPanel( |
| 73 | Widget widgetToAdd, Panel panel) |
| 74 | { |
| 75 | if (panel != null) |
| 76 | { |
| 77 | panel.add(widgetToAdd); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * set Style Attribute |
| 83 | * |
| 84 | * @param currentStyle the style |
| 85 | * @param attribute the attribute |
| 86 | * @param value the value |
| 87 | */ |
| 88 | public static native void setStyleAttribute( |
| 89 | Style currentStyle, String attribute, String value) /*-{ |
| 90 | currentStyle[attribute] = value; |
| 91 | }-*/; |
| 92 | |
| 93 | } |