Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -ru ./src/editor/GlobalPanel.java /home/diego/workspace/editor2012/src/editor/GlobalPanel.java
- --- ./src/editor/GlobalPanel.java 2009-11-21 11:22:47.000000000 +0000
- +++ /home/diego/workspace/editor2012/src/editor/GlobalPanel.java 2012-01-02 22:14:00.000000000 +0000
- @@ -18,6 +18,33 @@
- *
- * You should have received a copy of the GNU General Public License
- * along with PES Editor. If not, see <http://www.gnu.org/licenses/>.
- + *
- + *
- + * The functions:
- + *
- + * public static String capitalizeFully(String str, char[] delimiters)
- + * private static String capitalize(String str, char[] delimiters)
- + * private static boolean isDelimiter(char ch, char[] delimiters)
- + *
- + * have been derived from the Apache Commons 2.5 WordUtils package, under the
- + * Apache License, Version 2.0, that can be downloaded from:
- + *
- + * http://commons.apache.org/lang/
- + *
- + * Licensed to the Apache Software Foundation (ASF) under one or more
- + * contributor license agreements. See the NOTICE file distributed with
- + * this work for additional information regarding copyright ownership.
- + * The ASF licenses this file to You under the Apache License, Version 2.0
- + * (the "License"); you may not use this file except in compliance with
- + * the License. You may obtain a copy of the License at
- + *
- + * http://www.apache.org/licenses/LICENSE-2.0
- + *
- + * Unless required by applicable law or agreed to in writing, software
- + * distributed under the License is distributed on an "AS IS" BASIS,
- + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- + * See the License for the specific language governing permissions and
- + * limitations under the License.
- */
- package editor;
- @@ -44,7 +71,7 @@
- private JComboBox opBox;
- - private JButton doButton;
- + private JButton doButton, uppercaseButton, lowercaseButton;
- private JComboBox scopeBox;
- @@ -81,8 +108,10 @@
- JPanel panel99 = new JPanel();
- JPanel scopePanel = new JPanel(new GridLayout(2, 3));
- JPanel main = new JPanel(new GridLayout(0, 1));
- + JPanel casepanel = new JPanel();
- scopePanel.setBorder(BorderFactory.createTitledBorder("Scope"));
- panel99.setBorder(BorderFactory.createTitledBorder("Adjustment"));
- + casepanel.setBorder(BorderFactory.createTitledBorder("Modify player names"));
- scopeBox = new JComboBox(scopes);
- teamBox = new JComboBox();
- checkBox = new JCheckBox();
- @@ -334,6 +363,39 @@
- }
- }
- });
- +
- + uppercaseButton = new JButton("To uppercase");
- + uppercaseButton.addActionListener(new ActionListener() {
- + public void actionPerformed(ActionEvent a) {
- + for (int p = 1; p < Player.total; p++) {
- + Player play = new Player(of, p, 0);
- + String newName = play.name.toUpperCase();
- + play.setName(newName);
- + }
- + }
- + });
- +
- +
- + lowercaseButton = new JButton("Capitalize");
- + lowercaseButton.addActionListener(new ActionListener() {
- + public void actionPerformed(ActionEvent a) {
- + char delimiters[] = {' ', '.', '-', '\''};
- + for (int p = 1; p < Player.total; p++) {
- + Player play = new Player(of, p, 0);
- + String newName = capitalizeFully(play.name, delimiters);
- +
- + if (play.name.startsWith("MC"))
- + newName = "Mc" + capitalizeFully(newName.substring(2), delimiters);
- +
- + //newName.spl
- +
- + play.setName(newName);
- + }
- + }
- + });
- +
- +
- +
- scopePanel.add(new JLabel("Registered Position:"));
- scopePanel.add(new JLabel("Exclude Team:"));
- scopePanel.add(new JLabel("Created Players:"));
- @@ -344,8 +406,11 @@
- panel99.add(opBox);
- panel99.add(numField);
- panel99.add(doButton);
- + casepanel.add(uppercaseButton);
- + casepanel.add(lowercaseButton);
- main.add(scopePanel);
- main.add(panel99);
- + main.add(casepanel);
- add(main);
- }
- @@ -475,4 +540,53 @@
- return result;
- }
- +
- + public static String capitalizeFully(String str, char[] delimiters) {
- + int delimLen = (delimiters == null ? -1 : delimiters.length);
- + if (str == null || str.length() == 0 || delimLen == 0) {
- + return str;
- + }
- + str = str.toLowerCase();
- + return capitalize(str, delimiters);
- + }
- +
- +
- + private static String capitalize(String str, char[] delimiters) {
- + int delimLen = (delimiters == null ? -1 : delimiters.length);
- + if (str == null || str.length() == 0 || delimLen == 0) {
- + return str;
- + }
- +
- + int strLen = str.length();
- + StringBuffer buffer = new StringBuffer(strLen);
- + boolean capitalizeNext = true;
- + for (int i = 0; i < strLen; i++) {
- + char ch = str.charAt(i);
- + if (isDelimiter(ch, delimiters)) {
- + buffer.append(ch);
- + capitalizeNext = true;
- + } else if (capitalizeNext) {
- + buffer.append(Character.toTitleCase(ch));
- + capitalizeNext = false;
- + } else {
- + buffer.append(ch);
- + }
- + }
- +
- + return buffer.toString();
- + }
- +
- + private static boolean isDelimiter(char ch, char[] delimiters) {
- + if (delimiters == null) {
- + return Character.isWhitespace(ch);
- + }
- + for (int i = 0, isize = delimiters.length; i < isize; i++) {
- + if (ch == delimiters[i]) {
- + return true;
- + }
- + }
- + return false;
- + }
- +
- +
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement