X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FProgressPanel.java;h=023080579777c0dd2c15656c66ee14168e66c893;hb=69b246bd6330f05271ca15a440c8442b03b7db6c;hp=f69f0cf6dade186c3d7bc98cb7efc46c0a0091ee;hpb=d221d910aad1d44bbc2e0a1f7ac44f5ceb575018;p=jalview.git diff --git a/src/jalview/gui/ProgressPanel.java b/src/jalview/gui/ProgressPanel.java index f69f0cf..0230805 100644 --- a/src/jalview/gui/ProgressPanel.java +++ b/src/jalview/gui/ProgressPanel.java @@ -23,8 +23,12 @@ package jalview.gui; import jalview.api.RendererListenerI; import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Dimension; import java.beans.PropertyChangeEvent; +import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JProgressBar; @@ -42,6 +46,10 @@ public class ProgressPanel extends JPanel implements RendererListenerI // 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; @@ -49,6 +57,14 @@ public class ProgressPanel extends JPanel implements RendererListenerI private JLabel progressLabel; + 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. * @@ -57,19 +73,48 @@ public class ProgressPanel extends JPanel implements RendererListenerI * @param label * The label to place next to the progress bar */ - public ProgressPanel(String eventPropertyName, String label) + public ProgressPanel(String eventPropertyName, String label, int maxwidth) { super(new BorderLayout(10, 0)); - setBorder(new EmptyBorder(0, 3, 0, 20)); + setBorder(new EmptyBorder(0, 3, 0, 0)); eventName = eventPropertyName; + String labelText = label; + + final int w = maxwidth; - progressBar = new JProgressBar(); + progressBar = new JProgressBar() + { + @Override + public Dimension getMaximumSize() + { + return new Dimension(w, 1); + } + }; progressBar.setMinimum(0); - progressLabel = new JLabel(label); - - add(progressLabel, BorderLayout.WEST); - add(progressBar, BorderLayout.CENTER); + progressBar.setPreferredSize(progressBar.getMaximumSize()); + progressLabel = new JLabel(labelText); + progressLabel.setFont(new java.awt.Font("Verdana", 0, 11)); + + // Use a CardLayout to stop the progress bar panel moving around when + // changing visibility + labelPanel.setLayout(labelLayout); + barPanel.setLayout(barLayout); + + 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); + add(new JLabel(" "), BorderLayout.EAST); + + setBorder(BorderFactory.createLineBorder(Color.black)); + // setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); } @Override @@ -82,19 +127,21 @@ public class ProgressPanel extends JPanel implements RendererListenerI if (evt.getPropertyName().equals(eventName)) { int progress = (int) evt.getNewValue(); - - System.out.println(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()) { - progressBar.setVisible(true); - progressLabel.setVisible(true); + labelLayout.show(labelPanel, VISIBLE); + barLayout.show(barPanel, VISIBLE); } - else if (progress >= MAXVALUE) + if (progress >= MAXVALUE) { - progressBar.setVisible(false); - progressLabel.setVisible(false); + labelLayout.show(labelPanel, INVISIBLE); + barLayout.show(barPanel, INVISIBLE); } } }