Debian Codegraph @

uk/ac/babraham/FastQC/Results/ResultsPanel.java

raw symbols SCIP
1 /**
2 * Copyright Copyright 2010-17 Simon Andrews
3 *
4 * This file is part of FastQC.
5 *
6 * FastQC is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FastQC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with FastQC; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 package uk.ac.babraham.FastQC.Results;
21
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.Component;
25 import java.util.Vector;
26
27 import javax.swing.DefaultListCellRenderer;
28 import javax.swing.ImageIcon;
29 import javax.swing.JLabel;
30 import javax.swing.JList;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.ListSelectionModel;
34 import javax.swing.event.ListSelectionEvent;
35 import javax.swing.event.ListSelectionListener;
36
37 import uk.ac.babraham.FastQC.Analysis.AnalysisListener;
38 import uk.ac.babraham.FastQC.Modules.QCModule;
39 import uk.ac.babraham.FastQC.Sequence.SequenceFile;
40
41 public class ResultsPanel extends JPanel implements ListSelectionListener, AnalysisListener{
42
43 private static final ImageIcon ERROR_ICON = new ImageIcon(ClassLoader.getSystemResource("uk/ac/babraham/FastQC/Resources/error.png"));
44 private static final ImageIcon WARNING_ICON = new ImageIcon(ClassLoader.getSystemResource("uk/ac/babraham/FastQC/Resources/warning.png"));
45 private static final ImageIcon OK_ICON = new ImageIcon(ClassLoader.getSystemResource("uk/ac/babraham/FastQC/Resources/tick.png"));
46
47
48 private QCModule [] modules;
49 private JList moduleList;
50 private JPanel [] panels;
51 private JPanel currentPanel = null;
52 private JLabel progressLabel;
53 private SequenceFile sequenceFile;
54
55 public ResultsPanel (SequenceFile sequenceFile) {
56 this.sequenceFile = sequenceFile;
57 setLayout(new BorderLayout());
58 progressLabel = new JLabel("Waiting to start...",JLabel.CENTER);
59 add(progressLabel,BorderLayout.CENTER);
60 }
61
62 public void valueChanged(ListSelectionEvent e) {
63 int index = moduleList.getSelectedIndex();
64 if (index >= 0) {
65 remove(currentPanel);
66 currentPanel = panels[index];
67 add(currentPanel,BorderLayout.CENTER);
68 validate();
69 repaint();
70 }
71 }
72
73 public SequenceFile sequenceFile () {
74 return sequenceFile;
75 }
76
77 public QCModule [] modules () {
78 return modules;
79 }
80
81 private class ModuleRenderer extends DefaultListCellRenderer {
82
83 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
84 if (! (value instanceof QCModule)) {
85 return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
86 }
87
88 QCModule module = (QCModule)value;
89 ImageIcon icon = OK_ICON;
90 if (module.raisesError()) {
91 icon = ERROR_ICON;
92 }
93 else if (module.raisesWarning()) {
94 icon = WARNING_ICON;
95 }
96
97 JLabel returnLabel = new JLabel(module.name(),icon,JLabel.LEFT);
98 returnLabel.setOpaque(true);
99 if (isSelected) {
100 returnLabel.setBackground(Color.LIGHT_GRAY);
101 }
102 else {
103 returnLabel.setBackground(Color.WHITE);
104 }
105
106 return returnLabel;
107 }
108
109 }
110
111 public void analysisComplete(SequenceFile file, QCModule[] rawModules) {
112 remove(progressLabel);
113
114 Vector<QCModule> modulesToDisplay = new Vector<QCModule>();
115
116 for (int m=0;m<rawModules.length;m++) {
117 if (!rawModules[m].ignoreInReport()) {
118 modulesToDisplay.add(rawModules[m]);
119 }
120 }
121
122 modules = modulesToDisplay.toArray(new QCModule[0]);
123
124 panels = new JPanel[modules.length];
125
126 for (int m=0;m<modules.length;m++) {
127 // System.err.println("Getting panel for "+modules[m].name()+" with "+modules[m].description());
128 panels[m] = modules[m].getResultsPanel();
129 }
130
131 moduleList = new JList(modules);
132 moduleList.setCellRenderer(new ModuleRenderer());
133 moduleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
134 moduleList.setSelectedIndex(0);
135 moduleList.addListSelectionListener(this);
136
137 add(new JScrollPane(moduleList),BorderLayout.WEST);
138
139 currentPanel = panels[0];
140 add(currentPanel,BorderLayout.CENTER);
141 validate();
142
143 }
144
145 public void analysisUpdated(SequenceFile file, int sequencesProcessed, int percentComplete) {
146 if (percentComplete > 99) {
147 progressLabel.setText("Read "+sequencesProcessed+" sequences");
148 }
149 else {
150 progressLabel.setText("Read "+sequencesProcessed+" sequences ("+percentComplete+"%)");
151 }
152 }
153
154 public void analysisExceptionReceived(SequenceFile file, Exception e) {
155 progressLabel.setText("Failed to process file: "+e.getLocalizedMessage());
156 }
157
158 public void analysisStarted(SequenceFile file) {
159 progressLabel.setText("Starting analysis...");
160 }
161
162
163 }