2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.commands;
\r
21 import jalview.datamodel.*;
\r
23 public class ChangeCaseCommand implements CommandI
\r
26 public static int TO_LOWER = 0;
\r
27 public static int TO_UPPER = 1;
\r
28 public static int TOGGLE_CASE = 2;
\r
29 int caseChange = -1;
\r
32 public ChangeCaseCommand(String description,
\r
37 this.description = description;
\r
39 this.regions = regions;
\r
40 this.caseChange = caseChange;
\r
44 public String getDescription()
\r
49 public int getSize()
\r
54 public void doCommand()
\r
59 public void undoCommand()
\r
64 void changeCase(boolean doCommand)
\r
69 for (int r = 0; r < regions.length; r++)
\r
71 start = regions[r][0];
\r
72 end = regions[r][1];
\r
73 for (int s = 0; s < seqs.length; s++)
\r
75 sequence = seqs[s].getSequence();
\r
76 StringBuffer newSeq = new StringBuffer();
\r
78 if (end > sequence.length())
\r
79 end = sequence.length();
\r
83 newSeq.append(sequence.substring(0, start));
\r
86 if ( (caseChange == TO_UPPER && doCommand)
\r
87 || (caseChange == TO_LOWER && !doCommand))
\r
88 newSeq.append(sequence.substring(start, end).toUpperCase());
\r
90 else if ( (caseChange == TO_LOWER && doCommand)
\r
91 || (caseChange == TO_UPPER && !doCommand))
\r
92 newSeq.append(sequence.substring(start, end).toLowerCase());
\r
96 for (int c = start; c < end; c++)
\r
98 nextChar = sequence.charAt(c);
\r
99 if ('a' <= nextChar && nextChar <= 'z')
\r
101 // TO UPPERCASE !!!
\r
102 nextChar -= ('a' - 'A');
\r
104 else if ('A' <= nextChar && nextChar <= 'Z')
\r
106 // TO LOWERCASE !!!
\r
107 nextChar += ('a' - 'A');
\r
109 newSeq.append(nextChar);
\r
113 if (end < sequence.length())
\r
114 newSeq.append(sequence.substring(end));
\r
116 seqs[s].setSequence(newSeq.toString());
\r