2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.RendererListenerI;
25 import java.awt.BorderLayout;
26 import java.awt.CardLayout;
27 import java.awt.Color;
28 import java.awt.Dimension;
29 import java.beans.PropertyChangeEvent;
31 import javax.swing.BorderFactory;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
34 import javax.swing.JProgressBar;
35 import javax.swing.border.EmptyBorder;
38 * A class to manage a panel containing a label and progress bar updated by an
44 public class ProgressPanel extends JPanel implements RendererListenerI
46 // max value of progress bar: values expected to be %s
47 private final int MAXVALUE = 100;
49 private final String VISIBLE = "VISIBLE";
51 private final String INVISIBLE = "INVISIBLE";
53 // name of event property which updates the progress bar
54 private String eventName;
56 private JProgressBar progressBar;
58 private JLabel progressLabel;
60 private JPanel labelPanel = new JPanel();
62 private CardLayout labelLayout = new CardLayout();
64 private JPanel barPanel = new JPanel();
66 private CardLayout barLayout = new CardLayout();
69 * Construct a JPanel containing a progress bar and a label.
71 * @param eventPropertyName
72 * The name of the event property to update the progress bar
74 * The label to place next to the progress bar
76 public ProgressPanel(String eventPropertyName, String label, int maxwidth)
78 super(new BorderLayout(10, 0));
79 setBorder(new EmptyBorder(0, 3, 0, 0));
81 eventName = eventPropertyName;
82 String labelText = label;
84 final int w = maxwidth;
86 progressBar = new JProgressBar()
89 public Dimension getMaximumSize()
91 return new Dimension(w, 1);
94 progressBar.setMinimum(0);
95 progressBar.setPreferredSize(progressBar.getMaximumSize());
96 progressLabel = new JLabel(labelText);
97 progressLabel.setFont(new java.awt.Font("Verdana", 0, 11));
99 // Use a CardLayout to stop the progress bar panel moving around when
100 // changing visibility
101 labelPanel.setLayout(labelLayout);
102 barPanel.setLayout(barLayout);
104 labelPanel.add(progressLabel, VISIBLE);
105 labelPanel.add(new JPanel(), INVISIBLE);
106 barPanel.add(progressBar, VISIBLE);
107 barPanel.add(new JPanel(), INVISIBLE);
109 labelLayout.show(labelPanel, VISIBLE);
110 barLayout.show(barPanel, VISIBLE);
112 add(labelPanel, BorderLayout.WEST);
113 add(barPanel, BorderLayout.CENTER);
114 add(new JLabel(" "), BorderLayout.EAST);
116 setBorder(BorderFactory.createLineBorder(Color.black));
117 // setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
122 * Update the progress bar in response to the event. Expects the value
123 * supplied by the event to be in the range 0-100 i.e. a percentage
125 public void propertyChange(PropertyChangeEvent evt)
127 if (evt.getPropertyName().equals(eventName))
129 int progress = (int) evt.getNewValue();
130 progressBar.setValue(progress);
132 // switch progress bar to visible if it is not visible and current
133 // progress is less than MAXVALUE
134 // switch progress bar to invisible if it is visible and we reached
136 if (progress < MAXVALUE && !progressBar.isVisible())
138 labelLayout.show(labelPanel, VISIBLE);
139 barLayout.show(barPanel, VISIBLE);
141 if (progress >= MAXVALUE)
143 labelLayout.show(labelPanel, INVISIBLE);
144 barLayout.show(barPanel, INVISIBLE);