/hg/icedtea-web: Download indicator made compact for more then o...

jvanek at icedtea.classpath.org jvanek at icedtea.classpath.org
Thu Jan 10 09:31:21 PST 2013


changeset 4118632d3c49 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=4118632d3c49
author: Jiri Vanek <jvanek at redhat.com>
date: Thu Jan 10 18:23:06 2013 +0100

	Download indicator made compact for more then one jar


diffstat:

 ChangeLog                                                     |   14 +
 NEWS                                                          |    1 +
 netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java |  193 ++++++++-
 netx/net/sourceforge/jnlp/resources/hideDownloadDetails.png   |  Bin 
 netx/net/sourceforge/jnlp/resources/showDownloadDetails.png   |  Bin 
 5 files changed, 176 insertions(+), 32 deletions(-)

diffs (353 lines):

diff -r 3e4b40d47487 -r 4118632d3c49 ChangeLog
--- a/ChangeLog	Thu Jan 10 17:57:19 2013 +0100
+++ b/ChangeLog	Thu Jan 10 18:23:06 2013 +0100
@@ -1,3 +1,17 @@
+2013-01-10  Jiri Vanek  <jvanek at redhat.com>
+
+	Download indicator made compact for more then one jar
+	* NEWS: mentioned this feature
+	* netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java:
+	(DownloadPanel) inner class were rewritten to support collapsed/detailed
+	for more then one jar in queue. 
+	(frame) window is recreated each time state is changed (preventing errors
+	on some X configurations) and is positioned to lower left corner of
+	active screen.
+	* netx/net/sourceforge/jnlp/resources/hideDownloadDetails.png
+	* adding netx/net/sourceforge/jnlp/resources/showDownloadDetails.pn h
+	Icons for "to collapsed state" and  "to detailed state"
+
 2013-01-10  Jiri Vanek  <jvanek at redhat.com>
 
 	All IcedTea-Web dialogues are centered to middle of active screen
diff -r 3e4b40d47487 -r 4118632d3c49 NEWS
--- a/NEWS	Thu Jan 10 17:57:19 2013 +0100
+++ b/NEWS	Thu Jan 10 18:23:06 2013 +0100
@@ -12,6 +12,7 @@
 * Added cs_CZ localisation
 * Splash screen for javaws and plugin
 * All IcedTea-Web dialogues are centered to middle of active screen
+* Download indicator made compact for more then one jar
 * Security updates
   - CVE-2012-3422, RH840592: Potential read from an uninitialized memory location
   - CVE-2012-3423, RH841345: Incorrect handling of not 0-terminated strings
diff -r 3e4b40d47487 -r 4118632d3c49 netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java
--- a/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java	Thu Jan 10 17:57:19 2013 +0100
+++ b/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java	Thu Jan 10 18:23:06 2013 +0100
@@ -29,6 +29,7 @@
 
 import net.sourceforge.jnlp.runtime.*;
 import net.sourceforge.jnlp.util.ImageResources;
+import net.sourceforge.jnlp.util.ScreenFinder;
 
 /**
  * Show the progress of downloads.
@@ -62,6 +63,7 @@
 
     /** shared constraint */
     static GridBagConstraints vertical;
+    static GridBagConstraints verticalNoClean;
     static GridBagConstraints verticalIndent;
     static {
         vertical = new GridBagConstraints();
@@ -70,6 +72,9 @@
         vertical.fill = GridBagConstraints.HORIZONTAL;
         vertical.anchor = GridBagConstraints.WEST;
 
+        verticalNoClean = new GridBagConstraints();
+        verticalNoClean.weightx = 1.0;
+
         verticalIndent = (GridBagConstraints) vertical.clone();
         verticalIndent.insets = new Insets(0, 10, 3, 0);
     }
@@ -101,9 +106,7 @@
 
         synchronized (frameMutex) {
             if (frame == null) {
-                frame = new JFrame(downloading + "...");
-                frame.setIconImages(ImageResources.INSTANCE.getApplicationImages());
-                frame.getContentPane().setLayout(new GridBagLayout());
+                frame=createDownloadIndicatorFrame(true);
             }
 
             if (resources != null) {
@@ -114,15 +117,13 @@
 
             frame.getContentPane().add(result, vertical);
             frame.pack();
-
-            if (!frame.isVisible()) {
-                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
-                Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
-                Dimension screen = new Dimension(screenSize.width - insets.left,
-                        screenSize.height - insets.top);
-                frame.setLocation(screen.width - frame.getWidth(),
-                        screen.height - frame.getHeight());
-            }
+            placeFrameToLowerRight();
+            result.addComponentListener(new ComponentAdapter() {
+                @Override
+                public void componentResized(ComponentEvent e) {
+                    placeFrameToLowerRight();
+                }
+            });
 
             frame.setVisible(true);
 
@@ -130,6 +131,23 @@
         }
     }
 
+     public static JFrame createDownloadIndicatorFrame(boolean undecorated) throws HeadlessException {
+        JFrame f = new JFrame(downloading + "...");
+        f.setUndecorated(undecorated);
+        f.setIconImages(ImageResources.INSTANCE.getApplicationImages());
+        f.getContentPane().setLayout(new GridBagLayout());
+        return f;
+    }
+
+    /**
+     * This places indicator to lower right corner of active monitor.
+     */
+    private static void placeFrameToLowerRight() throws HeadlessException {
+       Rectangle bounds = ScreenFinder.getCurrentScreenSizeWithoutBounds();
+        frame.setLocation(bounds.width+bounds.x - frame.getWidth(),
+                bounds.height+bounds.y - frame.getHeight());
+    }
+
     /**
      * Remove a download service listener that was obtained by
      * calling the getDownloadListener method from the shared
@@ -163,13 +181,31 @@
      * Groups the url progress in a panel.
      */
     static class DownloadPanel extends JPanel implements DownloadServiceListener {
+        private final DownloadPanel self;
 
+        private static enum States{
+            ONE_JAR, COLLAPSED, DETAILED;
+         }
+        
+        private static final String DETAILS=R("ButShowDetails");
+        private static final String HIDE_DETAILS=R("ButHideDetails");   
         /** the download name */
         private String downloadName;
-
         /** Downloading part: */
         private JLabel header = new JLabel();
-
+        /** Show/hide detailsButton button: */
+        private final JButton detailsButton;
+        private static final URL magnifyGlassUrl = ClassLoader.getSystemResource("net/sourceforge/jnlp/resources/showDownloadDetails.png");
+        private static final URL redCrossUrl = ClassLoader.getSystemResource("net/sourceforge/jnlp/resources/hideDownloadDetails.png");
+        private static final Icon magnifyGlassIcon = new ImageIcon(magnifyGlassUrl);
+        private static final Icon redCrossIcon = new ImageIcon(redCrossUrl);
+        /** used  instead of detailsButton button in case of one jar*/
+        private JLabel delimiter = new JLabel("");  
+        /** all already created progress bars*/
+        private List<ProgressPanel> progressPanels = new ArrayList<ProgressPanel>();
+        private States state=States.ONE_JAR;
+        private ProgressPanel mainProgressPanel;
+        
         /** list of URLs being downloaded */
         private List<URL> urls = new ArrayList<URL>();
 
@@ -181,12 +217,52 @@
          * name.
          */
         protected DownloadPanel(String downloadName) {
+            self = this;
             setLayout(new GridBagLayout());
+            this.downloadName = downloadName;
+            this.add(header, verticalNoClean);
+            header.setFont(header.getFont().deriveFont(Font.BOLD));
+            this.add(delimiter, vertical);
+            detailsButton = new JButton(magnifyGlassIcon);
+            int w = magnifyGlassIcon.getIconWidth();
+            int h = magnifyGlassIcon.getIconHeight();
+            detailsButton.setPreferredSize(new Dimension(w + 2, h + 2));
+            detailsButton.addActionListener(new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    if (state == States.DETAILED) {
+                        state = States.COLLAPSED;
+                        detailsButton.setToolTipText(DETAILS);
+                        detailsButton.setIcon(magnifyGlassIcon);
+                        for (ProgressPanel progressPanel : progressPanels) {
+                            remove(progressPanel);
+                        }
+                        add(mainProgressPanel, verticalIndent);
+                        recreateFrame(true);
+                    } else {
+                        state = States.DETAILED;
+                        detailsButton.setToolTipText(HIDE_DETAILS);
+                        detailsButton.setIcon(redCrossIcon);
+                        remove(mainProgressPanel);
+                        for (ProgressPanel progressPanel : progressPanels) {
+                            add(progressPanel, verticalIndent);
+                        }
+                        recreateFrame(false);
+                    }
+                }
 
-            this.downloadName = downloadName;
-            this.add(header, vertical);
-            header.setFont(header.getFont().deriveFont(Font.BOLD));
-
+                public void recreateFrame(boolean undecorated) throws HeadlessException {
+                    JFrame oldFrame = frame;
+                    frame = createDownloadIndicatorFrame(undecorated);
+                    frame.getContentPane().add(self, vertical);
+                    synchronized (frameMutex) {
+                        frame.pack();
+                        placeFrameToLowerRight();
+                    }
+                    frame.setVisible(true);
+                    oldFrame.dispose();
+                }
+            });
             setOverallPercent(0);
         }
 
@@ -196,14 +272,32 @@
         protected void addProgressPanel(URL url, String version) {
             if (!urls.contains(url)) {
                 ProgressPanel panel = new ProgressPanel(url, version);
-
-                add(panel, verticalIndent);
+                if (state != States.COLLAPSED) {
+                    add(panel, verticalIndent);
+                }
+                progressPanels.add(panel);
+                urls.add(url);
+                panels.add(panel); 
+                //download indicator does not know about added jars
+                //When only one jar is added to downlaod queue then its progress is 
+                //shown, and there is no show detail button.
+                //When second one is added, then it already knows that there will
+                //be two or more jars, so it swap to collapsed state in count of two.
+                //no later, no sooner
+                if (panels.size() == 2){
+                    remove(panels.get(0));
+                    remove(panels.get(1));
+                    remove(delimiter);
+                    add(detailsButton,vertical);
+                    mainProgressPanel=new ProgressPanel();
+                    add(mainProgressPanel, verticalIndent);
+                    state=States.COLLAPSED;
+                }
                 synchronized (frameMutex) {
                     frame.pack();
+                    placeFrameToLowerRight();
                 }
 
-                urls.add(url);
-                panels.add(panel);
             }
         }
 
@@ -219,10 +313,10 @@
                         addProgressPanel(url, version);
 
                     setOverallPercent(overallPercent);
-
                     ProgressPanel panel = panels.get(urls.indexOf(url));
                     panel.setProgress(readSoFar, total);
                     panel.repaint();
+
                 }
             };
             SwingUtilities.invokeLater(r);
@@ -230,12 +324,27 @@
 
         /**
          * Sets the overall percent completed.
+         * should be called via invokeLater
          */
         public void setOverallPercent(int percent) {
             // don't get whole string from resource and sub in
             // values because it'll be doing a MessageFormat for
             // each update.
             header.setText(downloading + " " + downloadName + ": " + percent + "% " + complete + ".");
+            Container c = header.getParent();
+            //we need to adapt both panels and also frame to new length of header text
+            while (c != null) {
+                c.invalidate();
+                c.validate();
+                if (c instanceof  Window){
+                    ((Window) c).pack();
+                }
+                c=c.getParent();
+            }
+            if (mainProgressPanel != null) {
+                mainProgressPanel.setProgress(percent, 100);
+                mainProgressPanel.repaint();
+            }
         }
 
         /**
@@ -276,12 +385,28 @@
 
         private long total;
         private long readSoFar;
+        private Dimension size = new Dimension(80, 15);
 
+        ProgressPanel() {
+            bar.setMinimumSize(size);
+            bar.setPreferredSize(size);
+            bar.setOpaque(false);
+
+            setLayout(new GridBagLayout());
+
+            GridBagConstraints gbc = new GridBagConstraints();
+            styleGridBagConstraints(gbc);
+            add(bar, gbc);
+        }
+        
         ProgressPanel(URL url, String version) {
-            JLabel location = new JLabel(" " + url.getHost() + "/" + url.getFile());
+            this(" " + url.getHost() + "/" + url.getFile(),version);
+        }
+        ProgressPanel(String caption, String version) {
+            JLabel location = new JLabel(caption);
 
-            bar.setMinimumSize(new Dimension(80, 15));
-            bar.setPreferredSize(new Dimension(80, 15));
+            bar.setMinimumSize(size);
+            bar.setPreferredSize(size);
             bar.setOpaque(false);
 
             setLayout(new GridBagLayout());
@@ -291,12 +416,8 @@
             gbc.fill = GridBagConstraints.NONE;
             gbc.gridwidth = GridBagConstraints.RELATIVE;
             add(bar, gbc);
-
-            gbc.insets = new Insets(0, 3, 0, 0);
-            gbc.weightx = 1.0;
-            gbc.fill = GridBagConstraints.HORIZONTAL;
-            gbc.gridwidth = GridBagConstraints.REMAINDER;
-            gbc.anchor = GridBagConstraints.WEST;
+            
+            styleGridBagConstraints(gbc);
             add(location, gbc);
         }
 
@@ -325,6 +446,14 @@
                 g.fillRect(x + 1, y + 1, divide - 1, h - 1);
             }
         }
+
+        private void styleGridBagConstraints(GridBagConstraints gbc) {
+            gbc.insets = new Insets(0, 3, 0, 0);
+            gbc.weightx = 1.0;
+            gbc.fill = GridBagConstraints.HORIZONTAL;
+            gbc.gridwidth = GridBagConstraints.REMAINDER;
+            gbc.anchor = GridBagConstraints.WEST;
+        }
     };
 
 }
diff -r 3e4b40d47487 -r 4118632d3c49 netx/net/sourceforge/jnlp/resources/hideDownloadDetails.png
Binary file netx/net/sourceforge/jnlp/resources/hideDownloadDetails.png has changed
diff -r 3e4b40d47487 -r 4118632d3c49 netx/net/sourceforge/jnlp/resources/showDownloadDetails.png
Binary file netx/net/sourceforge/jnlp/resources/showDownloadDetails.png has changed



More information about the distro-pkg-dev mailing list