Class | Line # | Actions | |||
---|---|---|---|---|---|
OrderCommand | 33 | 10 | 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.commands; | |
22 | ||
23 | import jalview.analysis.AlignmentSorter; | |
24 | import jalview.datamodel.AlignmentI; | |
25 | import jalview.datamodel.SequenceI; | |
26 | ||
27 | /** | |
28 | * An undoable command to reorder the sequences in an alignment. | |
29 | * | |
30 | * @author gmcarstairs | |
31 | * | |
32 | */ | |
33 | public class OrderCommand implements CommandI | |
34 | { | |
35 | String description; | |
36 | ||
37 | /* | |
38 | * The sequence order before sorting (target order for an undo) | |
39 | */ | |
40 | SequenceI[] seqs; | |
41 | ||
42 | /* | |
43 | * The sequence order specified by this command | |
44 | */ | |
45 | SequenceI[] seqs2; | |
46 | ||
47 | /* | |
48 | * The alignment the command acts on | |
49 | */ | |
50 | AlignmentI al; | |
51 | ||
52 | /** | |
53 | * Constructor given the 'undo' sequence order, and the (already) sorted | |
54 | * alignment. | |
55 | * | |
56 | * @param description | |
57 | * a text label for the 'undo' menu option | |
58 | * @param seqs | |
59 | * the sequence order for undo | |
60 | * @param al | |
61 | * the alignment as ordered by this command | |
62 | */ | |
63 | 1 | public OrderCommand(String description, SequenceI[] seqs, AlignmentI al) |
64 | { | |
65 | 1 | this.description = description; |
66 | 1 | this.seqs = seqs; |
67 | 1 | this.seqs2 = al.getSequencesArray(); |
68 | 1 | this.al = al; |
69 | 1 | doCommand(null); |
70 | } | |
71 | ||
72 | 2 | public String getDescription() |
73 | { | |
74 | 2 | return description; |
75 | } | |
76 | ||
77 | 1 | public int getSize() |
78 | { | |
79 | 1 | return 1; |
80 | } | |
81 | ||
82 | 1 | public void doCommand(AlignmentI[] views) |
83 | { | |
84 | 1 | AlignmentSorter.setOrder(al, seqs2); |
85 | } | |
86 | ||
87 | 0 | public void undoCommand(AlignmentI[] views) |
88 | { | |
89 | 0 | AlignmentSorter.setOrder(al, seqs); |
90 | } | |
91 | ||
92 | /** | |
93 | * Returns the sequence order used to sort, or before sorting if undo=true. | |
94 | * | |
95 | * @param undo | |
96 | * @return | |
97 | */ | |
98 | 0 | public SequenceI[] getSequenceOrder(boolean undo) |
99 | { | |
100 | 0 | return undo ? seqs : seqs2; |
101 | } | |
102 | } |