Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File ProgressPanel.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

6
32
3
1
148
76
7
0.22
10.67
3
2.33

Classes

Class Line # Actions
ProgressPanel 44 32 7
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.gui;
22   
23    import jalview.api.RendererListenerI;
24   
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;
30   
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;
36   
37    /**
38    * A class to manage a panel containing a label and progress bar updated by an
39    * event firing
40    *
41    * @author kmourao
42    *
43    */
 
44    public class ProgressPanel extends JPanel implements RendererListenerI
45    {
46    // max value of progress bar: values expected to be %s
47    private final int MAXVALUE = 100;
48   
49    private final String VISIBLE = "VISIBLE";
50   
51    private final String INVISIBLE = "INVISIBLE";
52   
53    // name of event property which updates the progress bar
54    private String eventName;
55   
56    private JProgressBar progressBar;
57   
58    private JLabel progressLabel;
59   
60    private JPanel labelPanel = new JPanel();
61   
62    private CardLayout labelLayout = new CardLayout();
63   
64    private JPanel barPanel = new JPanel();
65   
66    private CardLayout barLayout = new CardLayout();
67   
68    /**
69    * Construct a JPanel containing a progress bar and a label.
70    *
71    * @param eventPropertyName
72    * The name of the event property to update the progress bar
73    * @param label
74    * The label to place next to the progress bar
75    */
 
76  0 toggle public ProgressPanel(String eventPropertyName, String label, int maxwidth)
77    {
78  0 super(new BorderLayout(10, 0));
79  0 setBorder(new EmptyBorder(0, 3, 0, 0));
80   
81  0 eventName = eventPropertyName;
82  0 String labelText = label;
83   
84  0 final int w = maxwidth;
85   
86  0 progressBar = new JProgressBar()
87    {
 
88  0 toggle @Override
89    public Dimension getMaximumSize()
90    {
91  0 return new Dimension(w, 1);
92    }
93    };
94  0 progressBar.setMinimum(0);
95  0 progressBar.setPreferredSize(progressBar.getMaximumSize());
96  0 progressLabel = new JLabel(labelText);
97  0 progressLabel.setFont(new java.awt.Font("Verdana", 0, 11));
98   
99    // Use a CardLayout to stop the progress bar panel moving around when
100    // changing visibility
101  0 labelPanel.setLayout(labelLayout);
102  0 barPanel.setLayout(barLayout);
103   
104  0 labelPanel.add(progressLabel, VISIBLE);
105  0 labelPanel.add(new JPanel(), INVISIBLE);
106  0 barPanel.add(progressBar, VISIBLE);
107  0 barPanel.add(new JPanel(), INVISIBLE);
108   
109  0 labelLayout.show(labelPanel, VISIBLE);
110  0 barLayout.show(barPanel, VISIBLE);
111   
112  0 add(labelPanel, BorderLayout.WEST);
113  0 add(barPanel, BorderLayout.CENTER);
114  0 add(new JLabel(" "), BorderLayout.EAST);
115   
116  0 setBorder(BorderFactory.createLineBorder(Color.black));
117    // setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
118    }
119   
 
120  0 toggle @Override
121    /**
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
124    */
125    public void propertyChange(PropertyChangeEvent evt)
126    {
127  0 if (evt.getPropertyName().equals(eventName))
128    {
129  0 int progress = (int) evt.getNewValue();
130  0 progressBar.setValue(progress);
131   
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
135    // MAXVALUE
136  0 if (progress < MAXVALUE && !progressBar.isVisible())
137    {
138  0 labelLayout.show(labelPanel, VISIBLE);
139  0 barLayout.show(barPanel, VISIBLE);
140    }
141  0 if (progress >= MAXVALUE)
142    {
143  0 labelLayout.show(labelPanel, INVISIBLE);
144  0 barLayout.show(barPanel, INVISIBLE);
145    }
146    }
147    }
148    }