git://source.jalview.org
/
jalview.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e2a9bda
)
JAL-2587 Keep progress bar panel in position regardless of visibility
author
kiramt
<k.mourao@dundee.ac.uk>
Wed, 9 Aug 2017 10:20:34 +0000
(11:20 +0100)
committer
kiramt
<k.mourao@dundee.ac.uk>
Wed, 9 Aug 2017 10:20:34 +0000
(11:20 +0100)
src/jalview/gui/ProgressPanel.java
patch
|
blob
|
history
diff --git
a/src/jalview/gui/ProgressPanel.java
b/src/jalview/gui/ProgressPanel.java
index
6a70f6a
..
5417a1d
100644
(file)
--- a/
src/jalview/gui/ProgressPanel.java
+++ b/
src/jalview/gui/ProgressPanel.java
@@
-23,6
+23,7
@@
package jalview.gui;
import jalview.api.RendererListenerI;
import java.awt.BorderLayout;
import jalview.api.RendererListenerI;
import java.awt.BorderLayout;
+import java.awt.CardLayout;
import java.beans.PropertyChangeEvent;
import javax.swing.JLabel;
import java.beans.PropertyChangeEvent;
import javax.swing.JLabel;
@@
-42,6
+43,10
@@
public class ProgressPanel extends JPanel implements RendererListenerI
// max value of progress bar: values expected to be %s
private final int MAXVALUE = 100;
// max value of progress bar: values expected to be %s
private final int MAXVALUE = 100;
+ private final String VISIBLE = "VISIBLE";
+
+ private final String INVISIBLE = "INVISIBLE";
+
// name of event property which updates the progress bar
private String eventName;
// name of event property which updates the progress bar
private String eventName;
@@
-49,7
+54,13
@@
public class ProgressPanel extends JPanel implements RendererListenerI
private JLabel progressLabel;
private JLabel progressLabel;
- private String labelText;
+ private JPanel labelPanel = new JPanel();
+
+ private CardLayout labelLayout = new CardLayout();
+
+ private JPanel barPanel = new JPanel();
+
+ private CardLayout barLayout = new CardLayout();
/**
* Construct a JPanel containing a progress bar and a label.
/**
* Construct a JPanel containing a progress bar and a label.
@@
-65,14
+76,27
@@
public class ProgressPanel extends JPanel implements RendererListenerI
setBorder(new EmptyBorder(0, 3, 0, 20));
eventName = eventPropertyName;
setBorder(new EmptyBorder(0, 3, 0, 20));
eventName = eventPropertyName;
- labelText = label;
+ String labelText = label;
progressBar = new JProgressBar();
progressBar.setMinimum(0);
progressLabel = new JLabel(labelText);
progressBar = new JProgressBar();
progressBar.setMinimum(0);
progressLabel = new JLabel(labelText);
+
+ // Use a CardLayout to stop the progress bar panel moving around when
+ // changing visibility
+ labelPanel.setLayout(labelLayout);
+ barPanel.setLayout(barLayout);
- add(progressLabel, BorderLayout.WEST);
- add(progressBar, BorderLayout.CENTER);
+ labelPanel.add(progressLabel, VISIBLE);
+ labelPanel.add(new JPanel(), INVISIBLE);
+ barPanel.add(progressBar, VISIBLE);
+ barPanel.add(new JPanel(), INVISIBLE);
+
+ labelLayout.show(labelPanel, VISIBLE);
+ barLayout.show(barPanel, VISIBLE);
+
+ add(labelPanel, BorderLayout.WEST);
+ add(barPanel, BorderLayout.CENTER);
}
@Override
}
@Override
@@
-85,19
+109,21
@@
public class ProgressPanel extends JPanel implements RendererListenerI
if (evt.getPropertyName().equals(eventName))
{
int progress = (int) evt.getNewValue();
if (evt.getPropertyName().equals(eventName))
{
int progress = (int) evt.getNewValue();
-
- System.out.println(progress);
-
progressBar.setValue(progress);
progressBar.setValue(progress);
+
+ // switch progress bar to visible if it is not visible and current
+ // progress is less than MAXVALUE
+ // switch progress bar to invisible if it is visible and we reached
+ // MAXVALUE
if (progress < MAXVALUE && !progressBar.isVisible())
{
if (progress < MAXVALUE && !progressBar.isVisible())
{
- progressBar.setVisible(true);
- progressLabel.setText(labelText);
+ labelLayout.show(labelPanel, VISIBLE);
+ barLayout.show(barPanel, VISIBLE);
}
else if (progress >= MAXVALUE)
{
}
else if (progress >= MAXVALUE)
{
- progressBar.setVisible(false);
- progressLabel.setText(" "); // keep visible so panel stays visible
+ labelLayout.show(labelPanel, INVISIBLE);
+ barLayout.show(barPanel, INVISIBLE);
}
}
}
}
}
}