Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
PCAPanel | 64 | 184 | 66 | ||
PCAPanel.PCAPrinter | 373 | 18 | 7 |
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 java.awt.BorderLayout; | |
24 | import java.awt.Color; | |
25 | import java.awt.Dimension; | |
26 | import java.awt.Graphics; | |
27 | import java.awt.event.ActionEvent; | |
28 | import java.awt.event.ActionListener; | |
29 | import java.awt.print.PageFormat; | |
30 | import java.awt.print.Printable; | |
31 | import java.awt.print.PrinterException; | |
32 | import java.awt.print.PrinterJob; | |
33 | ||
34 | import javax.swing.ButtonGroup; | |
35 | import javax.swing.JMenuItem; | |
36 | import javax.swing.JProgressBar; | |
37 | import javax.swing.JRadioButtonMenuItem; | |
38 | import javax.swing.event.InternalFrameAdapter; | |
39 | import javax.swing.event.InternalFrameEvent; | |
40 | ||
41 | import jalview.analysis.scoremodels.ScoreModels; | |
42 | import jalview.api.AlignViewportI; | |
43 | import jalview.api.analysis.ScoreModelI; | |
44 | import jalview.api.analysis.SimilarityParamsI; | |
45 | import jalview.bin.Console; | |
46 | import jalview.datamodel.Alignment; | |
47 | import jalview.datamodel.AlignmentI; | |
48 | import jalview.datamodel.AlignmentView; | |
49 | import jalview.datamodel.HiddenColumns; | |
50 | import jalview.datamodel.SequenceI; | |
51 | import jalview.gui.ImageExporter.ImageWriterI; | |
52 | import jalview.gui.JalviewColourChooser.ColourChooserListener; | |
53 | import jalview.io.exceptions.ImageOutputException; | |
54 | import jalview.jbgui.GPCAPanel; | |
55 | import jalview.math.RotatableMatrix.Axis; | |
56 | import jalview.util.ImageMaker; | |
57 | import jalview.util.MessageManager; | |
58 | import jalview.viewmodel.AlignmentViewport; | |
59 | import jalview.viewmodel.PCAModel; | |
60 | ||
61 | /** | |
62 | * The panel holding the Principal Component Analysis 3-D visualisation | |
63 | */ | |
64 | public class PCAPanel extends GPCAPanel | |
65 | implements Runnable, IProgressIndicator | |
66 | { | |
67 | private static final int MIN_WIDTH = 470; | |
68 | ||
69 | private static final int MIN_HEIGHT = 250; | |
70 | ||
71 | private RotatableCanvas rc; | |
72 | ||
73 | AlignmentPanel ap; | |
74 | ||
75 | AlignmentViewport av; | |
76 | ||
77 | private PCAModel pcaModel; | |
78 | ||
79 | private int top = 0; | |
80 | ||
81 | private IProgressIndicator progressBar; | |
82 | ||
83 | private boolean working; | |
84 | ||
85 | String newPcaTitle = null; | |
86 | /** | |
87 | * Constructor given sequence data, a similarity (or distance) score model | |
88 | * name, and score calculation parameters | |
89 | * | |
90 | * @param alignPanel | |
91 | * @param modelName | |
92 | * @param params | |
93 | */ | |
94 | 2 | public PCAPanel(AlignmentPanel alignPanel, String modelName, |
95 | SimilarityParamsI params) | |
96 | { | |
97 | 2 | super(); |
98 | 2 | this.setFrameIcon(null); |
99 | 2 | this.av = alignPanel.av; |
100 | 2 | this.ap = alignPanel; |
101 | 2 | boolean nucleotide = av.getAlignment().isNucleotide(); |
102 | ||
103 | 2 | progressBar = new ProgressBar(statusPanel, statusBar); |
104 | ||
105 | 2 | addInternalFrameListener(new InternalFrameAdapter() |
106 | { | |
107 | 2 | @Override |
108 | public void internalFrameClosed(InternalFrameEvent e) | |
109 | { | |
110 | 2 | close_actionPerformed(); |
111 | } | |
112 | }); | |
113 | ||
114 | 2 | boolean selected = av.getSelectionGroup() != null |
115 | && av.getSelectionGroup().getSize() > 0; | |
116 | 2 | AlignmentView seqstrings = av.getAlignmentView(selected); |
117 | 2 | SequenceI[] seqs; |
118 | 2 | if (!selected) |
119 | { | |
120 | 2 | seqs = av.getAlignment().getSequencesArray(); |
121 | } | |
122 | else | |
123 | { | |
124 | 0 | seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment()); |
125 | } | |
126 | ||
127 | 2 | ScoreModelI scoreModel = ScoreModels.getInstance() |
128 | .getScoreModel(modelName, ap); | |
129 | 2 | setPcaModel( |
130 | new PCAModel(seqstrings, seqs, nucleotide, scoreModel, params)); | |
131 | ||
132 | 2 | newPcaTitle = alignPanel.alignFrame.formCalculationTitle( |
133 | MessageManager.formatMessage("label.calc_title", "PCA", | |
134 | getPcaModel().getScoreModelName()), | |
135 | selected, ap.alignFrame.getTitle()); | |
136 | ||
137 | 2 | PaintRefresher.Register(this, av.getSequenceSetId()); |
138 | ||
139 | 2 | setRotatableCanvas(new RotatableCanvas(alignPanel)); |
140 | 2 | this.getContentPane().add(getRotatableCanvas(), BorderLayout.CENTER); |
141 | ||
142 | 2 | addKeyListener(getRotatableCanvas()); |
143 | 2 | validate(); |
144 | } | |
145 | ||
146 | /** | |
147 | * Ensure references to potentially very large objects (the PCA matrices) are | |
148 | * nulled when the frame is closed | |
149 | */ | |
150 | 2 | protected void close_actionPerformed() |
151 | { | |
152 | 2 | setPcaModel(null); |
153 | 2 | if (this.rc != null) |
154 | { | |
155 | 2 | this.rc.sequencePoints = null; |
156 | 2 | this.rc.setAxisEndPoints(null); |
157 | 2 | this.rc = null; |
158 | } | |
159 | } | |
160 | ||
161 | 0 | @Override |
162 | protected void bgcolour_actionPerformed() | |
163 | { | |
164 | 0 | String ttl = MessageManager.getString("label.select_background_colour"); |
165 | 0 | ColourChooserListener listener = new ColourChooserListener() |
166 | { | |
167 | 0 | @Override |
168 | public void colourSelected(Color c) | |
169 | { | |
170 | 0 | rc.setBgColour(c); |
171 | 0 | rc.repaint(); |
172 | } | |
173 | }; | |
174 | 0 | JalviewColourChooser.showColourChooser(this, ttl, rc.getBgColour(), |
175 | listener); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Calculates the PCA and displays the results | |
180 | */ | |
181 | 1 | @Override |
182 | public void run() | |
183 | { | |
184 | 1 | working = true; |
185 | 1 | long progId = System.currentTimeMillis(); |
186 | 1 | IProgressIndicator progress = this; |
187 | 1 | String message = MessageManager.getString("label.pca_recalculating"); |
188 | 1 | if (getParent() == null) |
189 | { | |
190 | 1 | progress = ap.alignFrame; |
191 | 1 | message = MessageManager.getString("label.pca_calculating"); |
192 | } | |
193 | 1 | progress.setProgressBar(message, progId); |
194 | 1 | try |
195 | { | |
196 | 1 | getPcaModel().calculate(); |
197 | ||
198 | 1 | xCombobox.setSelectedIndex(0); |
199 | 1 | yCombobox.setSelectedIndex(1); |
200 | 1 | zCombobox.setSelectedIndex(2); |
201 | ||
202 | 1 | getPcaModel().updateRc(getRotatableCanvas()); |
203 | // rc.invalidate(); | |
204 | 1 | setTop(getPcaModel().getTop()); |
205 | ||
206 | } catch (OutOfMemoryError er) | |
207 | { | |
208 | 0 | new OOMWarning("calculating PCA", er); |
209 | 0 | working = false; |
210 | 0 | return; |
211 | } finally | |
212 | { | |
213 | 1 | progress.setProgressBar("", progId); |
214 | } | |
215 | ||
216 | 1 | repaint(); |
217 | 1 | if (getParent() == null) |
218 | { | |
219 | 1 | Desktop.addInternalFrame(this, newPcaTitle, |
220 | 475, 450); | |
221 | 1 | this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); |
222 | } | |
223 | 1 | working = false; |
224 | } | |
225 | ||
226 | /** | |
227 | * Updates the PCA display after a change of component to use for x, y or z | |
228 | * axis | |
229 | */ | |
230 | 12 | @Override |
231 | protected void doDimensionChange() | |
232 | { | |
233 | 12 | if (getTop() == 0) |
234 | { | |
235 | 12 | return; |
236 | } | |
237 | ||
238 | 0 | int dim1 = getTop() - xCombobox.getSelectedIndex(); |
239 | 0 | int dim2 = getTop() - yCombobox.getSelectedIndex(); |
240 | 0 | int dim3 = getTop() - zCombobox.getSelectedIndex(); |
241 | 0 | getPcaModel().updateRcView(dim1, dim2, dim3); |
242 | 0 | getRotatableCanvas().resetView(); |
243 | } | |
244 | ||
245 | /** | |
246 | * Sets the selected checkbox item index for PCA dimension (1, 2, 3...) for | |
247 | * the given axis (X/Y/Z) | |
248 | * | |
249 | * @param index | |
250 | * @param axis | |
251 | */ | |
252 | 3 | public void setSelectedDimensionIndex(int index, Axis axis) |
253 | { | |
254 | 3 | switch (axis) |
255 | { | |
256 | 1 | case X: |
257 | 1 | xCombobox.setSelectedIndex(index); |
258 | 1 | break; |
259 | 1 | case Y: |
260 | 1 | yCombobox.setSelectedIndex(index); |
261 | 1 | break; |
262 | 1 | case Z: |
263 | 1 | zCombobox.setSelectedIndex(index); |
264 | 1 | break; |
265 | 0 | default: |
266 | } | |
267 | } | |
268 | ||
269 | 0 | @Override |
270 | protected void outputValues_actionPerformed() | |
271 | { | |
272 | 0 | CutAndPasteTransfer cap = new CutAndPasteTransfer(); |
273 | 0 | try |
274 | { | |
275 | 0 | cap.setText(getPcaModel().getDetails()); |
276 | 0 | Desktop.addInternalFrame(cap, |
277 | MessageManager.getString("label.pca_details"), 500, 500); | |
278 | } catch (OutOfMemoryError oom) | |
279 | { | |
280 | 0 | new OOMWarning("opening PCA details", oom); |
281 | 0 | cap.dispose(); |
282 | } | |
283 | } | |
284 | ||
285 | 0 | @Override |
286 | protected void showLabels_actionPerformed() | |
287 | { | |
288 | 0 | getRotatableCanvas().showLabels(showLabels.getState()); |
289 | } | |
290 | ||
291 | 0 | @Override |
292 | protected void print_actionPerformed() | |
293 | { | |
294 | 0 | PCAPrinter printer = new PCAPrinter(); |
295 | 0 | printer.start(); |
296 | } | |
297 | ||
298 | /** | |
299 | * If available, shows the data which formed the inputs for the PCA as a new | |
300 | * alignment | |
301 | */ | |
302 | 0 | @Override |
303 | public void originalSeqData_actionPerformed() | |
304 | { | |
305 | // JAL-2647 disabled after load from project (until save to project done) | |
306 | 0 | if (getPcaModel().getInputData() == null) |
307 | { | |
308 | 0 | Console.info( |
309 | "Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action."); | |
310 | 0 | return; |
311 | } | |
312 | // decide if av alignment is sufficiently different to original data to | |
313 | // warrant a new window to be created | |
314 | // create new alignment window with hidden regions (unhiding hidden regions | |
315 | // yields unaligned seqs) | |
316 | // or create a selection box around columns in alignment view | |
317 | // test Alignment(SeqCigar[]) | |
318 | 0 | char gc = '-'; |
319 | 0 | try |
320 | { | |
321 | // we try to get the associated view's gap character | |
322 | // but this may fail if the view was closed... | |
323 | 0 | gc = av.getGapCharacter(); |
324 | } catch (Exception ex) | |
325 | { | |
326 | } | |
327 | ||
328 | 0 | Object[] alAndColsel = getPcaModel().getInputData() |
329 | .getAlignmentAndHiddenColumns(gc); | |
330 | ||
331 | 0 | if (alAndColsel != null && alAndColsel[0] != null) |
332 | { | |
333 | // AlignmentOrder origorder = new AlignmentOrder(alAndColsel[0]); | |
334 | ||
335 | 0 | AlignmentI al = new Alignment((SequenceI[]) alAndColsel[0]); |
336 | 0 | AlignmentI dataset = (av != null && av.getAlignment() != null) |
337 | ? av.getAlignment().getDataset() | |
338 | : null; | |
339 | 0 | if (dataset != null) |
340 | { | |
341 | 0 | al.setDataset(dataset); |
342 | } | |
343 | ||
344 | 0 | if (true) |
345 | { | |
346 | // make a new frame! | |
347 | 0 | AlignFrame af = new AlignFrame(al, (HiddenColumns) alAndColsel[1], |
348 | AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); | |
349 | ||
350 | // >>>This is a fix for the moment, until a better solution is | |
351 | // found!!<<< | |
352 | // af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer()); | |
353 | ||
354 | // af.addSortByOrderMenuItem(ServiceName + " Ordering", | |
355 | // msaorder); | |
356 | ||
357 | 0 | Desktop.addInternalFrame(af, MessageManager.formatMessage( |
358 | "label.original_data_for_params", new String[] | |
359 | { this.title }), AlignFrame.DEFAULT_WIDTH, | |
360 | AlignFrame.DEFAULT_HEIGHT); | |
361 | } | |
362 | } | |
363 | /* | |
364 | * CutAndPasteTransfer cap = new CutAndPasteTransfer(); for (int i = 0; i < | |
365 | * seqs.length; i++) { cap.appendText(new jalview.util.Format("%-" + 15 + | |
366 | * "s").form( seqs[i].getName())); cap.appendText(" " + seqstrings[i] + | |
367 | * "\n"); } | |
368 | * | |
369 | * Desktop.addInternalFrame(cap, "Original Data", 400, 400); | |
370 | */ | |
371 | } | |
372 | ||
373 | class PCAPrinter extends Thread implements Printable | |
374 | { | |
375 | 0 | @Override |
376 | public void run() | |
377 | { | |
378 | 0 | PrinterJob printJob = PrinterJob.getPrinterJob(); |
379 | 0 | PageFormat defaultPage = printJob.defaultPage(); |
380 | 0 | PageFormat pf = printJob.pageDialog(defaultPage); |
381 | ||
382 | 0 | if (defaultPage == pf) |
383 | { | |
384 | /* | |
385 | * user cancelled | |
386 | */ | |
387 | 0 | return; |
388 | } | |
389 | ||
390 | 0 | printJob.setPrintable(this, pf); |
391 | ||
392 | 0 | if (printJob.printDialog()) |
393 | { | |
394 | 0 | try |
395 | { | |
396 | 0 | printJob.print(); |
397 | } catch (Exception PrintException) | |
398 | { | |
399 | 0 | PrintException.printStackTrace(); |
400 | } | |
401 | } | |
402 | } | |
403 | ||
404 | 0 | @Override |
405 | public int print(Graphics pg, PageFormat pf, int pi) | |
406 | throws PrinterException | |
407 | { | |
408 | 0 | pg.translate((int) pf.getImageableX(), (int) pf.getImageableY()); |
409 | ||
410 | 0 | getRotatableCanvas().drawBackground(pg); |
411 | 0 | getRotatableCanvas().drawScene(pg); |
412 | 0 | if (getRotatableCanvas().drawAxes) |
413 | { | |
414 | 0 | getRotatableCanvas().drawAxes(pg); |
415 | } | |
416 | ||
417 | 0 | if (pi == 0) |
418 | { | |
419 | 0 | return Printable.PAGE_EXISTS; |
420 | } | |
421 | else | |
422 | { | |
423 | 0 | return Printable.NO_SUCH_PAGE; |
424 | } | |
425 | } | |
426 | } | |
427 | ||
428 | 0 | public void makePCAImage(ImageMaker.TYPE type) |
429 | { | |
430 | 0 | int width = getRotatableCanvas().getWidth(); |
431 | 0 | int height = getRotatableCanvas().getHeight(); |
432 | 0 | ImageWriterI writer = new ImageWriterI() |
433 | { | |
434 | 0 | @Override |
435 | public void exportImage(Graphics g) throws Exception | |
436 | { | |
437 | 0 | RotatableCanvas canvas = getRotatableCanvas(); |
438 | 0 | canvas.drawBackground(g); |
439 | 0 | canvas.drawScene(g); |
440 | 0 | if (canvas.drawAxes) |
441 | { | |
442 | 0 | canvas.drawAxes(g); |
443 | } | |
444 | } | |
445 | }; | |
446 | 0 | String pca = MessageManager.getString("label.pca"); |
447 | 0 | ImageExporter exporter = new ImageExporter(writer, null, type, pca); |
448 | 0 | try |
449 | { | |
450 | 0 | exporter.doExport(null, this, width, height, pca); |
451 | } catch (ImageOutputException ioex) | |
452 | { | |
453 | 0 | Console.error("Unexpected error whilst writing " + type.toString(), |
454 | ioex); | |
455 | } | |
456 | } | |
457 | ||
458 | 0 | @Override |
459 | protected void viewMenu_menuSelected() | |
460 | { | |
461 | 0 | buildAssociatedViewMenu(); |
462 | } | |
463 | ||
464 | /** | |
465 | * Builds the menu showing the choice of possible views (for the associated | |
466 | * sequence data) to which the PCA may be linked | |
467 | */ | |
468 | 0 | void buildAssociatedViewMenu() |
469 | { | |
470 | 0 | AlignmentPanel[] aps = PaintRefresher |
471 | .getAssociatedPanels(av.getSequenceSetId()); | |
472 | 0 | if (aps.length == 1 && getRotatableCanvas().av == aps[0].av) |
473 | { | |
474 | 0 | associateViewsMenu.setVisible(false); |
475 | 0 | return; |
476 | } | |
477 | ||
478 | 0 | associateViewsMenu.setVisible(true); |
479 | ||
480 | 0 | if ((viewMenu |
481 | .getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem)) | |
482 | { | |
483 | 0 | viewMenu.insertSeparator(viewMenu.getItemCount() - 1); |
484 | } | |
485 | ||
486 | 0 | associateViewsMenu.removeAll(); |
487 | ||
488 | 0 | JRadioButtonMenuItem item; |
489 | 0 | ButtonGroup buttonGroup = new ButtonGroup(); |
490 | 0 | int iSize = aps.length; |
491 | ||
492 | 0 | for (int i = 0; i < iSize; i++) |
493 | { | |
494 | 0 | final AlignmentPanel panel = aps[i]; |
495 | 0 | item = new JRadioButtonMenuItem(panel.av.getViewName(), |
496 | panel.av == getRotatableCanvas().av); | |
497 | 0 | buttonGroup.add(item); |
498 | 0 | item.addActionListener(new ActionListener() |
499 | { | |
500 | 0 | @Override |
501 | public void actionPerformed(ActionEvent evt) | |
502 | { | |
503 | 0 | selectAssociatedView(panel); |
504 | } | |
505 | }); | |
506 | ||
507 | 0 | associateViewsMenu.add(item); |
508 | } | |
509 | ||
510 | 0 | final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem( |
511 | "All Views"); | |
512 | ||
513 | 0 | buttonGroup.add(itemf); |
514 | ||
515 | 0 | itemf.setSelected(getRotatableCanvas().isApplyToAllViews()); |
516 | 0 | itemf.addActionListener(new ActionListener() |
517 | { | |
518 | 0 | @Override |
519 | public void actionPerformed(ActionEvent evt) | |
520 | { | |
521 | 0 | getRotatableCanvas().setApplyToAllViews(itemf.isSelected()); |
522 | } | |
523 | }); | |
524 | 0 | associateViewsMenu.add(itemf); |
525 | ||
526 | } | |
527 | ||
528 | /* | |
529 | * (non-Javadoc) | |
530 | * | |
531 | * @see | |
532 | * jalview.jbgui.GPCAPanel#outputPoints_actionPerformed(java.awt.event.ActionEvent | |
533 | * ) | |
534 | */ | |
535 | 0 | @Override |
536 | protected void outputPoints_actionPerformed() | |
537 | { | |
538 | 0 | CutAndPasteTransfer cap = new CutAndPasteTransfer(); |
539 | 0 | try |
540 | { | |
541 | 0 | cap.setText(getPcaModel().getPointsasCsv(false, |
542 | xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(), | |
543 | zCombobox.getSelectedIndex())); | |
544 | 0 | Desktop.addInternalFrame(cap, MessageManager |
545 | .formatMessage("label.points_for_params", new String[] | |
546 | { this.getTitle() }), 500, 500); | |
547 | } catch (OutOfMemoryError oom) | |
548 | { | |
549 | 0 | new OOMWarning("exporting PCA points", oom); |
550 | 0 | cap.dispose(); |
551 | } | |
552 | } | |
553 | ||
554 | /* | |
555 | * (non-Javadoc) | |
556 | * | |
557 | * @see | |
558 | * jalview.jbgui.GPCAPanel#outputProjPoints_actionPerformed(java.awt.event | |
559 | * .ActionEvent) | |
560 | */ | |
561 | 0 | @Override |
562 | protected void outputProjPoints_actionPerformed() | |
563 | { | |
564 | 0 | CutAndPasteTransfer cap = new CutAndPasteTransfer(); |
565 | 0 | try |
566 | { | |
567 | 0 | cap.setText(getPcaModel().getPointsasCsv(true, |
568 | xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(), | |
569 | zCombobox.getSelectedIndex())); | |
570 | 0 | Desktop.addInternalFrame(cap, MessageManager.formatMessage( |
571 | "label.transformed_points_for_params", new String[] | |
572 | { this.getTitle() }), 500, 500); | |
573 | } catch (OutOfMemoryError oom) | |
574 | { | |
575 | 0 | new OOMWarning("exporting transformed PCA points", oom); |
576 | 0 | cap.dispose(); |
577 | } | |
578 | } | |
579 | ||
580 | /* | |
581 | * (non-Javadoc) | |
582 | * | |
583 | * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) | |
584 | */ | |
585 | 0 | @Override |
586 | public void setProgressBar(String message, long id) | |
587 | { | |
588 | 0 | progressBar.setProgressBar(message, id); |
589 | // if (progressBars == null) | |
590 | // { | |
591 | // progressBars = new Hashtable(); | |
592 | // progressBarHandlers = new Hashtable(); | |
593 | // } | |
594 | // | |
595 | // JPanel progressPanel; | |
596 | // Long lId = Long.valueOf(id); | |
597 | // GridLayout layout = (GridLayout) statusPanel.getLayout(); | |
598 | // if (progressBars.get(lId) != null) | |
599 | // { | |
600 | // progressPanel = (JPanel) progressBars.get(Long.valueOf(id)); | |
601 | // statusPanel.remove(progressPanel); | |
602 | // progressBars.remove(lId); | |
603 | // progressPanel = null; | |
604 | // if (message != null) | |
605 | // { | |
606 | // statusBar.setText(message); | |
607 | // } | |
608 | // if (progressBarHandlers.contains(lId)) | |
609 | // { | |
610 | // progressBarHandlers.remove(lId); | |
611 | // } | |
612 | // layout.setRows(layout.getRows() - 1); | |
613 | // } | |
614 | // else | |
615 | // { | |
616 | // progressPanel = new JPanel(new BorderLayout(10, 5)); | |
617 | // | |
618 | // JProgressBar progressBar = new JProgressBar(); | |
619 | // progressBar.setIndeterminate(true); | |
620 | // | |
621 | // progressPanel.add(new JLabel(message), BorderLayout.WEST); | |
622 | // progressPanel.add(progressBar, BorderLayout.CENTER); | |
623 | // | |
624 | // layout.setRows(layout.getRows() + 1); | |
625 | // statusPanel.add(progressPanel); | |
626 | // | |
627 | // progressBars.put(lId, progressPanel); | |
628 | // } | |
629 | // // update GUI | |
630 | // // setMenusForViewport(); | |
631 | // validate(); | |
632 | } | |
633 | ||
634 | 0 | @Override |
635 | public void registerHandler(final long id, | |
636 | final IProgressIndicatorHandler handler) | |
637 | { | |
638 | 0 | progressBar.registerHandler(id, handler); |
639 | // if (progressBarHandlers == null || | |
640 | // !progressBars.contains(Long.valueOf(id))) | |
641 | // { | |
642 | // throw new | |
643 | // Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler")); | |
644 | // } | |
645 | // progressBarHandlers.put(Long.valueOf(id), handler); | |
646 | // final JPanel progressPanel = (JPanel) progressBars.get(Long.valueOf(id)); | |
647 | // if (handler.canCancel()) | |
648 | // { | |
649 | // JButton cancel = new JButton( | |
650 | // MessageManager.getString("action.cancel")); | |
651 | // final IProgressIndicator us = this; | |
652 | // cancel.addActionListener(new ActionListener() | |
653 | // { | |
654 | // | |
655 | // @Override | |
656 | // public void actionPerformed(ActionEvent e) | |
657 | // { | |
658 | // handler.cancelActivity(id); | |
659 | // us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", | |
660 | // new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id); | |
661 | // } | |
662 | // }); | |
663 | // progressPanel.add(cancel, BorderLayout.EAST); | |
664 | // } | |
665 | } | |
666 | ||
667 | /** | |
668 | * | |
669 | * @return true if any progress bars are still active | |
670 | */ | |
671 | 0 | @Override |
672 | public boolean operationInProgress() | |
673 | { | |
674 | 0 | return progressBar.operationInProgress(); |
675 | } | |
676 | ||
677 | 0 | @Override |
678 | protected void resetButton_actionPerformed() | |
679 | { | |
680 | 0 | int t = getTop(); |
681 | 0 | setTop(0); // ugly - prevents dimensionChanged events from being processed |
682 | 0 | xCombobox.setSelectedIndex(0); |
683 | 0 | yCombobox.setSelectedIndex(1); |
684 | 0 | setTop(t); |
685 | 0 | zCombobox.setSelectedIndex(2); |
686 | } | |
687 | ||
688 | /** | |
689 | * Answers true if PCA calculation is in progress, else false | |
690 | * | |
691 | * @return | |
692 | */ | |
693 | 0 | public boolean isWorking() |
694 | { | |
695 | 0 | return working; |
696 | } | |
697 | ||
698 | /** | |
699 | * Answers the selected checkbox item index for PCA dimension for the X, Y or | |
700 | * Z axis of the display | |
701 | * | |
702 | * @param axis | |
703 | * @return | |
704 | */ | |
705 | 3 | public int getSelectedDimensionIndex(Axis axis) |
706 | { | |
707 | 3 | switch (axis) |
708 | { | |
709 | 1 | case X: |
710 | 1 | return xCombobox.getSelectedIndex(); |
711 | 1 | case Y: |
712 | 1 | return yCombobox.getSelectedIndex(); |
713 | 1 | default: |
714 | 1 | return zCombobox.getSelectedIndex(); |
715 | } | |
716 | } | |
717 | ||
718 | 1 | public void setShowLabels(boolean show) |
719 | { | |
720 | 1 | showLabels.setSelected(show); |
721 | } | |
722 | ||
723 | /** | |
724 | * Sets the input data used to calculate the PCA. This is provided for | |
725 | * 'restore from project', which does not currently support this (AL-2647), so | |
726 | * sets the value to null, and hides the menu option for "Input Data...". J | |
727 | * | |
728 | * @param data | |
729 | */ | |
730 | 1 | public void setInputData(AlignmentView data) |
731 | { | |
732 | 1 | getPcaModel().setInputData(data); |
733 | 1 | originalSeqData.setVisible(data != null); |
734 | } | |
735 | ||
736 | 10 | public AlignViewportI getAlignViewport() |
737 | { | |
738 | 10 | return av; |
739 | } | |
740 | ||
741 | 10 | public PCAModel getPcaModel() |
742 | { | |
743 | 10 | return pcaModel; |
744 | } | |
745 | ||
746 | 4 | public void setPcaModel(PCAModel pcaModel) |
747 | { | |
748 | 4 | this.pcaModel = pcaModel; |
749 | } | |
750 | ||
751 | 24 | public RotatableCanvas getRotatableCanvas() |
752 | { | |
753 | 24 | return rc; |
754 | } | |
755 | ||
756 | 2 | public void setRotatableCanvas(RotatableCanvas rc) |
757 | { | |
758 | 2 | this.rc = rc; |
759 | } | |
760 | ||
761 | 12 | public int getTop() |
762 | { | |
763 | 12 | return top; |
764 | } | |
765 | ||
766 | 2 | public void setTop(int top) |
767 | { | |
768 | 2 | this.top = top; |
769 | } | |
770 | ||
771 | /** | |
772 | * set the associated view for this PCA. | |
773 | * | |
774 | * @param panel | |
775 | */ | |
776 | 1 | public void selectAssociatedView(AlignmentPanel panel) |
777 | { | |
778 | 1 | getRotatableCanvas().setApplyToAllViews(false); |
779 | ||
780 | 1 | ap = panel; |
781 | 1 | av = panel.av; |
782 | ||
783 | 1 | getRotatableCanvas().av = panel.av; |
784 | 1 | getRotatableCanvas().ap = panel; |
785 | 1 | PaintRefresher.Register(PCAPanel.this, panel.av.getSequenceSetId()); |
786 | } | |
787 | ||
788 | 0 | @Override |
789 | public JProgressBar getProgressBar(long id) | |
790 | { | |
791 | 0 | return progressBar.getProgressBar(id); |
792 | } | |
793 | ||
794 | 0 | public String getMessage(long id) |
795 | { | |
796 | 0 | return progressBar.getMessage(id); |
797 | } | |
798 | ||
799 | 0 | public void setProgressBarMessage(long id, String message) |
800 | { | |
801 | 0 | progressBar.setProgressBarMessage(id, message); |
802 | } | |
803 | } |