changeset 1132:50b5ae6a4a81

Initial integration of new icons and small refactoring review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-June/006940.html reviewed-by: omajid
author Mario Torre <neugens.limasoftware@gmail.com>
date Wed, 05 Jun 2013 20:26:45 +0200
parents 9917555955a0
children 265c548475e7
files client/core/src/main/java/com/redhat/thermostat/client/ui/IconDescriptor.java client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/vm/swing/LivingVMDecoratorProvider.java client/swing/src/main/java/com/redhat/thermostat/client/swing/IconResource.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/HostIconDecoratorProvider.java client/swing/src/main/resources/clean.png client/swing/src/main/resources/computer.png client/swing/src/main/resources/duke.png client/swing/src/main/resources/icons/scale-slider-vert-backdrop.png client/swing/src/main/resources/icons/scale-slider-vert.png client/swing/src/main/resources/java_application_identifier.png client/swing/src/main/resources/record.png client/swing/src/main/resources/sample.png client/swing/src/main/resources/search.png client/swing/src/main/resources/trash.png client/swing/src/test/java/com/redhat/thermostat/client/swing/IconDescriptorTest.java thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/IconResources.java thread/client-common/src/main/resources/com/redhat/thermostat/thread/client/common/gtk-media-record.png thread/client-common/src/main/resources/com/redhat/thermostat/thread/client/common/record.png thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/ThreadMainPanel.java vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/client/common/IconResources.java vm-gc/remote-collector-client-swing/src/main/java/com/redhat/thermostat/gc/remote/client/swing/ToolbarGCButton.java vm-gc/remote-collector-common/src/main/resources/com/redhat/thermostat/gc/remote/client/common/gcSmall.png vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java vm-jmx/client-swing/src/main/java/com/redhat/thermostat/vm/jmx/client/swing/internal/JmxNotificationsSwingView.java
diffstat 24 files changed, 77 insertions(+), 130 deletions(-) [+]
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/IconDescriptor.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/IconDescriptor.java	Wed Jun 05 20:26:45 2013 +0200
@@ -36,6 +36,7 @@
 
 package com.redhat.thermostat.client.ui;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -44,6 +45,9 @@
 import java.util.logging.Logger;
 
 import com.redhat.thermostat.common.utils.LoggingUtils;
+import com.redhat.thermostat.common.utils.StreamUtils;
+
+import java.io.FileInputStream;
 
 /**
  * Class that encapsulates an images raw data.
@@ -97,6 +101,22 @@
     }
     
     /**
+     * Loads an icon from the given {@link InputStream}.
+     */
+    public static IconDescriptor loadIcon(InputStream stream) throws IOException {
+        byte[] bytes = StreamUtils.readAll(stream);
+        ByteBuffer data = ByteBuffer.wrap(bytes);
+        return new IconDescriptor(data);
+    }
+    
+    /**
+     * Loads an icon from a file.
+     */
+    public static IconDescriptor loadIcon(File resource) throws IOException {
+        return loadIcon(new FileInputStream(resource));
+    }
+    
+    /**
      * Loads an icon by calling from the given resource file and {@link ClassLoader}.
      */
     public static IconDescriptor loadIcon(ClassLoader classloader, String resource) throws IOException {
@@ -104,12 +124,7 @@
         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);
+        return loadIcon(stream);
     }
 }
 
--- a/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/vm/swing/LivingVMDecoratorProvider.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/client/living-vm-filter/swing/src/main/java/com/redhat/thermostat/client/filter/vm/swing/LivingVMDecoratorProvider.java	Wed Jun 05 20:26:45 2013 +0200
@@ -54,13 +54,14 @@
     private class LivingVMDecorator implements Decorator {
         @Override
         public IconDescriptor getIconDescriptor() {
+            IconDescriptor icon = null;
             try {
-                return IconDescriptor.loadIcon(IconResource.class.getClassLoader(), IconResource.JAVA_APPLICATION.getPath());
-            } catch (IOException e) {
-                Logger.getLogger(LivingVMDecoratorProvider.class.getName()).log(Level.SEVERE, e.getMessage(), e);
-
-                return null;
+                icon = IconResource.JAVA_APPLICATION.toIconDescriptor();
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                Logger.getLogger(LivingVMDecoratorProvider.class.getName()).log(Level.SEVERE, ioe.getMessage(), ioe);
             }
+            return icon;
         }
         
         @Override
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/IconResource.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/IconResource.java	Wed Jun 05 20:26:45 2013 +0200
@@ -36,39 +36,36 @@
 
 package com.redhat.thermostat.client.swing;
 
-import java.io.File;
+import com.redhat.thermostat.client.swing.components.Icon;
+import com.redhat.thermostat.client.ui.IconDescriptor;
 
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Provides access to various icons.
  */
 public class IconResource {
-    /* FIXME we need to pick up the icons dynamically */
-
+    
+    private boolean fromFileSytem = false;
+    
     private static final String ICON_PREFIX = "/usr/share/icons/gnome/";
 
-    // an icon that should always be available and indicate that the actual icon
-    // is missing.
-    public static final IconResource MISSING_ICON = null;
-
-    public static final IconResource JAVA_APPLICATION = new IconResource("duke.png");
-    public static final IconResource HOST = new IconResource(ICON_PREFIX + "16x16/devices/computer.png");
+    public static final IconResource JAVA_APPLICATION = new IconResource("java_application_identifier.png");
+    public static final IconResource HOST = new IconResource("computer.png");
+    public static final IconResource SEARCH = new IconResource("search.png");
+    public static final IconResource RECORD = new IconResource("record.png");
+    public static final IconResource SAMPLE = new IconResource("sample.png");
+    public static final IconResource CLEAN = new IconResource("clean.png");
+    public static final IconResource TRASH = new IconResource("trash.png");
     
-    public static final IconResource ERROR = new IconResource(ICON_PREFIX + "48x48/status/dialog-error.png");
-    public static final IconResource QUESTION = new IconResource(ICON_PREFIX + "48x48/status/dialog-question.png");
-    public static final IconResource WARNING = new IconResource(ICON_PREFIX + "48x48/status/dialog-warning.png");
+    // TODO: add a proper one for this
+    public static final IconResource HISTORY = RECORD;
 
-    public static final IconResource COMPUTER = new IconResource(ICON_PREFIX + "48x48/devices/computer.png");
-    public static final IconResource NETWORK_SERVER = new IconResource(ICON_PREFIX + "48x48/places/network-server.png");
-    public static final IconResource NETWORK_GROUP = new IconResource(ICON_PREFIX + "48x48/places/network-workgroup.png");
-
-    public static final IconResource ARROW_RIGHT = new IconResource(ICON_PREFIX + "48x48/actions/go-next.png");
-
-    public static final IconResource SEARCH = new IconResource(ICON_PREFIX + "16x16/actions/search.png");
-
-    public static final IconResource RECORD = new IconResource(ICON_PREFIX + "16x16/actions/media-record.png");
+    // TODO: those should either go into appropriate modules or be converted into internal icons 
+    public static final IconResource ARROW_RIGHT = new IconResource(ICON_PREFIX + "48x48/actions/go-next.png", true);
 
     private final String path;
 
@@ -76,24 +73,34 @@
         this.path = descriptor;
     }
 
-    public static IconResource fromPath(String path) {
-        // TODO implement this
-        return null;
+    private IconResource(String descriptor, boolean fromFileSytem) {
+        this.path = descriptor;
+        this.fromFileSytem = fromFileSytem;
     }
 
     public Icon getIcon() {
-        if (new File(path).exists()) {
-            return new ImageIcon(path);
+        try {
+            IconDescriptor descriptor = toIconDescriptor();
+            return new Icon(descriptor);
+            
+        } catch (IOException ex) {
+            Logger.getLogger(IconResource.class.getName()).log(Level.WARNING, "can't load icon: " + getPath(), ex);
         }
         return null;
     }
 
-    public String getPath() {
+    String getPath() {
         return path;
     }
-
-    public String getUrl() {
-        return "file:" + getPath();
+    
+    public IconDescriptor toIconDescriptor() throws IOException {
+        IconDescriptor icon = null;
+        if (fromFileSytem) {
+            icon = IconDescriptor.loadIcon(new File(getPath()));
+        } else {
+            icon = IconDescriptor.loadIcon(IconResource.class.getClassLoader(), getPath());
+        }
+        return icon;
     }
 }
 
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/HostIconDecoratorProvider.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/HostIconDecoratorProvider.java	Wed Jun 05 20:26:45 2013 +0200
@@ -71,8 +71,7 @@
         public IconDecorator() {
             IconDescriptor icon = null;
             try {
-                InputStream in = new FileInputStream(IconResource.HOST.getPath());
-                icon = new IconDescriptor(ByteBuffer.wrap(StreamUtils.readAll(in)));
+                icon = IconResource.HOST.toIconDescriptor();
             } catch (IOException ioe) {
                 ioe.printStackTrace();
             }
Binary file client/swing/src/main/resources/clean.png has changed
Binary file client/swing/src/main/resources/computer.png has changed
Binary file client/swing/src/main/resources/duke.png has changed
Binary file client/swing/src/main/resources/icons/scale-slider-vert-backdrop.png has changed
Binary file client/swing/src/main/resources/icons/scale-slider-vert.png has changed
Binary file client/swing/src/main/resources/java_application_identifier.png has changed
Binary file client/swing/src/main/resources/record.png has changed
Binary file client/swing/src/main/resources/sample.png has changed
Binary file client/swing/src/main/resources/search.png has changed
Binary file client/swing/src/main/resources/trash.png has changed
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/IconDescriptorTest.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/IconDescriptorTest.java	Wed Jun 05 20:26:45 2013 +0200
@@ -54,7 +54,7 @@
         IconDescriptor descriptor = IconDescriptor.loadIcon(classLoader, resource);
         ByteBuffer buffer = descriptor.getData();
         
-        assertEquals(3512, buffer.capacity());
+        assertEquals(841, buffer.capacity());
         
         byte[] data = buffer.array();
         
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/IconResources.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/IconResources.java	Wed Jun 05 20:26:45 2013 +0200
@@ -44,7 +44,6 @@
 public class IconResources {
 
     private static IconDescriptor monitor;
-    private static IconDescriptor record;
 
     public static IconDescriptor getMonitorIcon() {
         if (monitor == null) {
@@ -56,16 +55,5 @@
         }
         return monitor;
     }
-    
-    public static IconDescriptor getRecordIcon() {
-        if (record == null) {
-            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;
-    }
 }
 
Binary file thread/client-common/src/main/resources/com/redhat/thermostat/thread/client/common/gtk-media-record.png has changed
Binary file thread/client-common/src/main/resources/com/redhat/thermostat/thread/client/common/record.png has changed
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/ThreadMainPanel.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/ThreadMainPanel.java	Wed Jun 05 20:26:45 2013 +0200
@@ -38,20 +38,18 @@
 
 import javax.swing.BoxLayout;
 import javax.swing.GroupLayout;
-import javax.swing.ImageIcon;
 import javax.swing.GroupLayout.Alignment;
 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
 
+import com.redhat.thermostat.client.swing.IconResource;
 import com.redhat.thermostat.client.swing.components.ActionToggleButton;
 import com.redhat.thermostat.client.swing.components.HeaderPanel;
 import com.redhat.thermostat.shared.locale.Translate;
-import com.redhat.thermostat.thread.client.common.IconResources;
 import com.redhat.thermostat.thread.client.common.locale.LocaleResources;
 
 @SuppressWarnings("serial")
 class ThreadMainPanel extends JPanel {
-
     private static final Translate<LocaleResources> t = LocaleResources.createLocalizer();
     private JSplitPane splitPane;
     
@@ -66,7 +64,7 @@
         JPanel content = new JPanel();
         headerPanel.setContent(content);
         
-        toggleButton = new ActionToggleButton(new ImageIcon(IconResources.getRecordIcon().getData().array()));
+        toggleButton = new ActionToggleButton(IconResource.SAMPLE.getIcon());
         toggleButton.setName("recordButton");
         headerPanel.addToolBarButton(toggleButton);
         
--- a/vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/client/common/IconResources.java	Wed Jun 05 20:26:44 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * 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.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 {
-
-    private static IconDescriptor gcIconSmall;
-    
-    public synchronized static IconDescriptor getGCIconSmall() {
-        if (gcIconSmall == null) {
-            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;
-    }
-}
-
--- a/vm-gc/remote-collector-client-swing/src/main/java/com/redhat/thermostat/gc/remote/client/swing/ToolbarGCButton.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/vm-gc/remote-collector-client-swing/src/main/java/com/redhat/thermostat/gc/remote/client/swing/ToolbarGCButton.java	Wed Jun 05 20:26:45 2013 +0200
@@ -39,11 +39,8 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
-import javax.swing.ImageIcon;
-
+import com.redhat.thermostat.client.swing.IconResource;
 import com.redhat.thermostat.client.swing.components.ActionButton;
-
-import com.redhat.thermostat.gc.remote.client.common.IconResources;
 import com.redhat.thermostat.gc.remote.client.common.LocaleResources;
 import com.redhat.thermostat.gc.remote.client.common.RequestGCAction;
 import com.redhat.thermostat.shared.locale.LocalizedString;
@@ -60,7 +57,7 @@
     }
     
     private ToolbarGCButton(RequestGCAction action, LocalizedString text) {
-        super(new ImageIcon(IconResources.getGCIconSmall().getData().array()), text);
+        super(IconResource.CLEAN.getIcon(), text);
         
         setToolTipText(text.getContents());
         this.action = action;
Binary file vm-gc/remote-collector-common/src/main/resources/com/redhat/thermostat/gc/remote/client/common/gcSmall.png has changed
--- a/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java	Wed Jun 05 20:26:45 2013 +0200
@@ -50,6 +50,7 @@
 
 import com.redhat.thermostat.client.core.views.BasicView;
 import com.redhat.thermostat.client.swing.ComponentVisibleListener;
+import com.redhat.thermostat.client.swing.IconResource;
 import com.redhat.thermostat.client.swing.SwingComponent;
 import com.redhat.thermostat.client.swing.components.ActionToggleButton;
 import com.redhat.thermostat.client.swing.components.HeaderPanel;
@@ -59,7 +60,6 @@
 import com.redhat.thermostat.shared.locale.Translate;
 import com.redhat.thermostat.vm.heap.analysis.client.core.HeapDumpListView;
 import com.redhat.thermostat.vm.heap.analysis.client.core.HeapDumpListView.ListAction;
-import com.redhat.thermostat.vm.heap.analysis.client.core.HeapIconResources;
 import com.redhat.thermostat.vm.heap.analysis.client.core.HeapView;
 import com.redhat.thermostat.vm.heap.analysis.client.core.chart.OverviewChart;
 import com.redhat.thermostat.vm.heap.analysis.client.locale.LocaleResources;
@@ -123,8 +123,10 @@
         overview.setContent(stack);
         overview.addHierarchyListener(new ViewVisibleListener());
 
-        Icon listDumpIcon = new Icon(HeapIconResources.getIcon(HeapIconResources.LIST_DUMPS));
+        // TODO
+        //Icon takeDumpIcon = new Icon(HeapIconResources.getIcon(HeapIconResources.LIST_DUMPS));
         
+        Icon listDumpIcon = IconResource.HISTORY.getIcon();
         showHeapListButton = new ActionToggleButton(listDumpIcon, translator.localize(LocaleResources.LIST_DUMPS_ACTION).getContents());
         showHeapListButton.setToolTipText(translator.localize(LocaleResources.LIST_DUMPS_ACTION).getContents());
         showHeapListButton.setName("LIST_DUMPS_ACTION");
--- a/vm-jmx/client-swing/src/main/java/com/redhat/thermostat/vm/jmx/client/swing/internal/JmxNotificationsSwingView.java	Wed Jun 05 20:26:44 2013 +0200
+++ b/vm-jmx/client-swing/src/main/java/com/redhat/thermostat/vm/jmx/client/swing/internal/JmxNotificationsSwingView.java	Wed Jun 05 20:26:45 2013 +0200
@@ -110,7 +110,7 @@
             }
         });
 
-        toolbarButton = new ActionToggleButton(IconResource.RECORD.getIcon(), translate.localize(LocaleResources.NOTIFICATIONS_ENABLE).getContents());
+        toolbarButton = new ActionToggleButton(IconResource.SAMPLE.getIcon(), translate.localize(LocaleResources.NOTIFICATIONS_ENABLE).getContents());
         toolbarButton.setName("toggleNotifications");
         toolbarButton.setToolTipText(translate.localize(LocaleResources.NOTIFICATIONS_ENABLE_DESCRIPTION).getContents());
         toolbarButton.addActionListener(new java.awt.event.ActionListener() {