2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.commands;
21 import jalview.datamodel.*;
23 public class ChangeCaseCommand implements CommandI
27 public static int TO_LOWER = 0;
29 public static int TO_UPPER = 1;
31 public static int TOGGLE_CASE = 2;
39 public ChangeCaseCommand(String description, SequenceI[] seqs,
40 int[][] regions, int caseChange)
42 this.description = description;
44 this.regions = regions;
45 this.caseChange = caseChange;
49 public String getDescription()
59 public void doCommand(AlignmentI[] views)
64 public void undoCommand(AlignmentI[] views)
69 void changeCase(boolean doCommand)
74 for (int r = 0; r < regions.length; r++)
76 start = regions[r][0];
77 for (int s = 0; s < seqs.length; s++)
79 sequence = seqs[s].getSequenceAsString();
80 StringBuffer newSeq = new StringBuffer();
82 if (regions[r][1] > sequence.length())
84 end = sequence.length();
93 newSeq.append(sequence.substring(0, start));
96 if ((caseChange == TO_UPPER && doCommand)
97 || (caseChange == TO_LOWER && !doCommand))
99 newSeq.append(sequence.substring(start, end).toUpperCase());
102 else if ((caseChange == TO_LOWER && doCommand)
103 || (caseChange == TO_UPPER && !doCommand))
105 newSeq.append(sequence.substring(start, end).toLowerCase());
111 for (int c = start; c < end; c++)
113 nextChar = sequence.charAt(c);
114 if ('a' <= nextChar && nextChar <= 'z')
117 nextChar -= ('a' - 'A');
119 else if ('A' <= nextChar && nextChar <= 'Z')
122 nextChar += ('a' - 'A');
124 newSeq.append(nextChar);
128 if (end < sequence.length())
130 newSeq.append(sequence.substring(end));
133 seqs[s].setSequence(newSeq.toString());