2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
27 public static int TO_LOWER = 0;
28 public static int TO_UPPER = 1;
29 public static int TOGGLE_CASE = 2;
33 public ChangeCaseCommand(String description,
38 this.description = description;
40 this.regions = regions;
41 this.caseChange = caseChange;
45 public String getDescription()
55 public void doCommand(AlignmentI[] views)
60 public void undoCommand(AlignmentI[] views)
65 void changeCase(boolean doCommand)
70 for (int r = 0; r < regions.length; r++)
72 start = regions[r][0];
73 for (int s = 0; s < seqs.length; s++)
75 sequence = seqs[s].getSequenceAsString();
76 StringBuffer newSeq = new StringBuffer();
78 if (regions[r][1] > sequence.length())
80 end = sequence.length();
89 newSeq.append(sequence.substring(0, start));
92 if ( (caseChange == TO_UPPER && doCommand)
93 || (caseChange == TO_LOWER && !doCommand))
95 newSeq.append(sequence.substring(start, end).toUpperCase());
98 else if ( (caseChange == TO_LOWER && doCommand)
99 || (caseChange == TO_UPPER && !doCommand))
101 newSeq.append(sequence.substring(start, end).toLowerCase());
106 for (int c = start; c < end; c++)
108 nextChar = sequence.charAt(c);
109 if ('a' <= nextChar && nextChar <= 'z')
112 nextChar -= ('a' - 'A');
114 else if ('A' <= nextChar && nextChar <= 'Z')
117 nextChar += ('a' - 'A');
119 newSeq.append(nextChar);
123 if (end < sequence.length())
125 newSeq.append(sequence.substring(end));
128 seqs[s].setSequence(newSeq.toString());