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 for (int s = 0; s < seqs.length; s++)
\r
74 sequence = seqs[s].getSequenceAsString();
\r
75 StringBuffer newSeq = new StringBuffer();
\r
77 if (regions[r][1] > sequence.length())
\r
78 end = sequence.length();
\r
80 end = regions[r][1];
\r
84 newSeq.append(sequence.substring(0, start));
\r
87 if ( (caseChange == TO_UPPER && doCommand)
\r
88 || (caseChange == TO_LOWER && !doCommand))
\r
89 newSeq.append(sequence.substring(start, end).toUpperCase());
\r
91 else if ( (caseChange == TO_LOWER && doCommand)
\r
92 || (caseChange == TO_UPPER && !doCommand))
\r
93 newSeq.append(sequence.substring(start, end).toLowerCase());
\r
97 for (int c = start; c < end; c++)
\r
99 nextChar = sequence.charAt(c);
\r
100 if ('a' <= nextChar && nextChar <= 'z')
\r
102 // TO UPPERCASE !!!
\r
103 nextChar -= ('a' - 'A');
\r
105 else if ('A' <= nextChar && nextChar <= 'Z')
\r
107 // TO LOWERCASE !!!
\r
108 nextChar += ('a' - 'A');
\r
110 newSeq.append(nextChar);
\r
114 if (end < sequence.length())
\r
115 newSeq.append(sequence.substring(end));
\r
117 seqs[s].setSequence(newSeq.toString());
\r