changeset 966:bab2eabfab98

Merge
author Elliott Baron <ebaron@redhat.com>
date Mon, 11 Feb 2013 16:56:46 -0500
parents f6bc84590701 (current diff) 59dd66fbed14 (diff)
children 2dc71d3fbeed
files
diffstat 7 files changed, 87 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/IconDescriptor.java	Mon Feb 11 16:37:36 2013 -0500
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/IconDescriptor.java	Mon Feb 11 16:56:46 2013 -0500
@@ -95,35 +95,19 @@
             return false;
         return true;
     }
-
+    
     /**
-     * Loads an icon by calling
-     * {@link #createFromClassloader(ClassLoader, String)} with the system
-     * {@link ClassLoader}.
-     * 
-     * <br /><br />
-     * 
-     * This method doesn't throw {@link IOException}, it returns {@code null}
-     * on failure and logs the error.
+     * Loads an icon by calling from the given resource file and {@link ClassLoader}.
      */
-    public static IconDescriptor loadIcon(String name) {
-        try {
-            return IconDescriptor.createFromClassloader(ClassLoader.getSystemClassLoader(), name);
-        } catch (IOException e) {
-            logger.log(Level.WARNING, "Can't load " + name, e);
+    public static IconDescriptor loadIcon(ClassLoader classloader, String resource) throws IOException {
+        InputStream stream = classloader.getResourceAsStream(resource);
+        if (stream == null) {
+            throw new IOException("no resource found");
         }
-        return null;
-    }
-    
-    public static IconDescriptor createFromClassloader(ClassLoader classloader,
-                                                       String resource) throws IOException
-    {
-        InputStream stream = classloader.getResourceAsStream(resource);
-        if (stream == null) throw new IOException("no resource found");
-        
+
         byte[] bytes = new byte[stream.available()];
         stream.read(bytes, 0, bytes.length);
-        
+
         ByteBuffer data = ByteBuffer.wrap(bytes);
         return new IconDescriptor(data);
     }
--- a/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/vm/swing/DeadVMDecoratorProvider.java	Mon Feb 11 16:37:36 2013 -0500
+++ b/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/vm/swing/DeadVMDecoratorProvider.java	Mon Feb 11 16:56:46 2013 -0500
@@ -52,7 +52,7 @@
         @Override
         public IconDescriptor getIconDescriptor() {
             try {
-                return IconDescriptor.createFromClassloader(getClass().getClassLoader(), "deadvm.png");
+                return IconDescriptor.loadIcon(getClass().getClassLoader(), "deadvm.png");
             } catch (IOException e) {
                 e.printStackTrace();
                 return null;
--- a/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/vm/swing/LivingVMDecoratorProvider.java	Mon Feb 11 16:37:36 2013 -0500
+++ b/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/vm/swing/LivingVMDecoratorProvider.java	Mon Feb 11 16:56:46 2013 -0500
@@ -46,6 +46,8 @@
 import com.redhat.thermostat.client.ui.IconDescriptor;
 import com.redhat.thermostat.storage.core.VmRef;
 import com.redhat.thermostat.storage.dao.VmInfoDAO;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 public class LivingVMDecoratorProvider implements DecoratorProvider<VmRef> {
     
@@ -53,9 +55,10 @@
         @Override
         public IconDescriptor getIconDescriptor() {
             try {
-                return IconDescriptor.createFromClassloader(IconResource.class.getClassLoader(), IconResource.JAVA_APPLICATION.getPath());
+                return IconDescriptor.loadIcon(IconResource.class.getClassLoader(), IconResource.JAVA_APPLICATION.getPath());
             } catch (IOException e) {
-                e.printStackTrace();
+                Logger.getLogger(LivingVMDecoratorProvider.class.getName()).log(Level.SEVERE, e.getMessage(), e);
+
                 return null;
             }
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/Icon.java	Mon Feb 11 16:56:46 2013 -0500
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012, 2013 Red Hat, Inc.
+ * 
+ * This file is part of Thermostat.
+ * 
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ * 
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ * 
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ * 
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.client.swing.components;
+
+import com.redhat.thermostat.client.ui.IconDescriptor;
+import javax.swing.ImageIcon;
+
+/**
+ */
+@SuppressWarnings("serial")
+public class Icon extends ImageIcon {
+
+    public Icon(IconDescriptor descriptor) {
+        super(descriptor.getData().array());
+    }
+}
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/IconDescriptorTest.java	Mon Feb 11 16:37:36 2013 -0500
+++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/IconDescriptorTest.java	Mon Feb 11 16:56:46 2013 -0500
@@ -51,7 +51,7 @@
     public void test() throws IOException {
         ClassLoader classLoader = IconResource.class.getClassLoader();
         String resource = IconResource.JAVA_APPLICATION.getPath();
-        IconDescriptor descriptor = IconDescriptor.createFromClassloader(classLoader, resource);
+        IconDescriptor descriptor = IconDescriptor.loadIcon(classLoader, resource);
         ByteBuffer buffer = descriptor.getData();
         
         assertEquals(3512, buffer.capacity());
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/IconResources.java	Mon Feb 11 16:37:36 2013 -0500
+++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/IconResources.java	Mon Feb 11 16:56:46 2013 -0500
@@ -37,6 +37,9 @@
 package com.redhat.thermostat.thread.client.common;
 
 import com.redhat.thermostat.client.ui.IconDescriptor;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 public class IconResources {
 
@@ -45,14 +48,22 @@
 
     public static IconDescriptor getMonitorIcon() {
         if (monitor == null) {
-            monitor = IconDescriptor.loadIcon("com/redhat/thermostat/thread/client/common/monitor.png");
+            try {
+                monitor = IconDescriptor.loadIcon(IconResources.class.getClassLoader(), "com/redhat/thermostat/thread/client/common/monitor.png");
+            } catch (IOException ex) {
+                Logger.getLogger(IconResources.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
+            }
         }
         return monitor;
     }
     
     public static IconDescriptor getRecordIcon() {
         if (record == null) {
-            record = IconDescriptor.loadIcon("com/redhat/thermostat/thread/client/common/gtk-media-record.png");
+            try {
+                record = IconDescriptor.loadIcon(IconResources.class.getClassLoader(), "com/redhat/thermostat/thread/client/common/gtk-media-record.png");
+            } catch (IOException ex) {
+                Logger.getLogger(IconResources.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
+            }
         }
         return record;
     }
--- a/vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/client/common/IconResources.java	Mon Feb 11 16:37:36 2013 -0500
+++ b/vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/client/common/IconResources.java	Mon Feb 11 16:56:46 2013 -0500
@@ -37,6 +37,9 @@
 package com.redhat.thermostat.gc.remote.client.common;
 
 import com.redhat.thermostat.client.ui.IconDescriptor;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 public class IconResources {
 
@@ -44,7 +47,12 @@
     
     public synchronized static IconDescriptor getGCIconSmall() {
         if (gcIconSmall == null) {
-            gcIconSmall = IconDescriptor.loadIcon("com/redhat/thermostat/gc/remote/client/common/gcSmall.png");
+            try {
+                gcIconSmall = IconDescriptor.loadIcon(IconResources.class.getClassLoader(), "com/redhat/thermostat/gc/remote/client/common/gcSmall.png");
+                
+            } catch (IOException ex) {
+                Logger.getLogger(IconResources.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
+            }
         }
         return gcIconSmall;
     }