aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2013-01-10 18:23:06 +0100
committerJiri Vanek <[email protected]>2013-01-10 18:23:06 +0100
commit05fbe64d15224e9e651231f86694e33799d5d39f (patch)
treeb2ac6230ecdb52ba82d18977b6fb9bcbe92299fb
parentf38ac428ba5289313c21623a267cedcde554bf95 (diff)
Download indicator made compact for more then one jar
-rw-r--r--ChangeLog14
-rw-r--r--NEWS1
-rw-r--r--netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java191
-rw-r--r--netx/net/sourceforge/jnlp/resources/hideDownloadDetails.pngbin0 -> 862 bytes
-rw-r--r--netx/net/sourceforge/jnlp/resources/showDownloadDetails.pngbin0 -> 860 bytes
5 files changed, 175 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a6b27f..18d47b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2013-01-10 Jiri Vanek <[email protected]>
+ 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 <[email protected]>
+
All IcedTea-Web dialogues are centered to middle of active screen
* NEWS: mentioned this feature
* netx/net/sourceforge/jnlp/JNLPSplashScreen.java:
diff --git a/NEWS b/NEWS
index a7e7aba..3ff6118 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ New in release 1.4 (2012-XX-XX):
* 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 --git a/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java b/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java
index 915a9ff..0a95b3a 100644
--- a/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java
+++ b/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java
@@ -29,6 +29,7 @@ import javax.jnlp.*;
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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
/** shared constraint */
static GridBagConstraints vertical;
+ static GridBagConstraints verticalNoClean;
static GridBagConstraints verticalIndent;
static {
vertical = new GridBagConstraints();
@@ -70,6 +72,9 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 class DefaultDownloadIndicator implements DownloadIndicator {
}
}
+ 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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
* 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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
* name.
*/
protected DownloadPanel(String downloadName) {
+ self = this;
setLayout(new GridBagLayout());
-
this.downloadName = downloadName;
- this.add(header, vertical);
+ 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);
+ }
+ }
+ 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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
/**
* 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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
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 --git a/netx/net/sourceforge/jnlp/resources/hideDownloadDetails.png b/netx/net/sourceforge/jnlp/resources/hideDownloadDetails.png
new file mode 100644
index 0000000..d215900
--- /dev/null
+++ b/netx/net/sourceforge/jnlp/resources/hideDownloadDetails.png
Binary files differ
diff --git a/netx/net/sourceforge/jnlp/resources/showDownloadDetails.png b/netx/net/sourceforge/jnlp/resources/showDownloadDetails.png
new file mode 100644
index 0000000..55e20f1
--- /dev/null
+++ b/netx/net/sourceforge/jnlp/resources/showDownloadDetails.png
Binary files differ