001 /****************************************************************************** 002 * Copyright (C) MActor Developers. All rights reserved. * 003 * ---------------------------------------------------------------------------* 004 * This file is part of MActor. * 005 * * 006 * MActor is free software; you can redistribute it and/or modify * 007 * it under the terms of the GNU General Public License as published by * 008 * the Free Software Foundation; either version 2 of the License, or * 009 * (at your option) any later version. * 010 * * 011 * MActor is distributed in the hope that it will be useful, * 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 014 * GNU General Public License for more details. * 015 * * 016 * You should have received a copy of the GNU General Public License * 017 * along with MActor; if not, write to the Free Software * 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * 019 ******************************************************************************/ 020 package org.mactor.ui.gui; 021 022 import java.awt.Component; 023 import java.text.SimpleDateFormat; 024 import java.util.Calendar; 025 026 import javax.swing.Icon; 027 import javax.swing.ImageIcon; 028 import javax.swing.JOptionPane; 029 030 import org.apache.log4j.Logger; 031 import org.mactor.framework.MactorException; 032 033 public class GuiUtil { 034 protected static Logger log = Logger.getLogger(GuiUtil.class); 035 private static final SimpleDateFormat sdf = new SimpleDateFormat("d MMM HH:mm:ss.SSS"); 036 public static final Icon loadIcon(String name) { 037 return new ImageIcon(GuiUtil.class.getResource(name)); 038 } 039 public static final String format(Calendar time) { 040 if (time == null) 041 return ""; 042 return sdf.format(time.getTime()); 043 } 044 public static final void showGuiError(Component component, Exception e) { 045 if (e instanceof MactorException) 046 log.info(e.getMessage()); 047 else 048 log.warn("Unexpected exception:" + e.getMessage()); 049 JOptionPane.showMessageDialog(component, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 050 } 051 public static final void showInfo(Component component, String info) { 052 JOptionPane.showMessageDialog(component, info); 053 } 054 }