2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
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());