From dc2d21896970de7949eb1ca29b2d08cb03a4979c Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 5 Jun 2015 10:11:00 +0200 Subject: [PATCH] Refactor code into packages and extract StringUtils class. --- build.gradle | 2 +- .../caps_extractor/CapsExtractorApp.java | 22 ++++++++++++++++ .../{ => actions}/AboutAction.java | 5 +++- .../{ => actions}/HelpAction.java | 5 +++- .../caps_extractor/{ => gui}/AboutDialog.form | 2 +- .../caps_extractor/{ => gui}/AboutDialog.java | 8 +++--- .../caps_extractor/{ => gui}/HelpDialog.form | 2 +- .../caps_extractor/{ => gui}/HelpDialog.java | 3 ++- .../caps_extractor/{ => gui}/MainPanel.form | 2 +- .../caps_extractor/{ => gui}/MainPanel.java | 22 +++------------- .../caps_extractor/{ => gui}/MainWindow.java | 16 ++++-------- .../{ => util}/I18nSupport.java | 2 +- .../caps_extractor/util/StringUtils.java | 25 +++++++++++++++++++ 13 files changed, 75 insertions(+), 41 deletions(-) create mode 100644 src/main/java/info/augendre/caps_extractor/CapsExtractorApp.java rename src/main/java/info/augendre/caps_extractor/{ => actions}/AboutAction.java (74%) rename src/main/java/info/augendre/caps_extractor/{ => actions}/HelpAction.java (74%) rename src/main/java/info/augendre/caps_extractor/{ => gui}/AboutDialog.form (98%) rename src/main/java/info/augendre/caps_extractor/{ => gui}/AboutDialog.java (95%) rename src/main/java/info/augendre/caps_extractor/{ => gui}/HelpDialog.form (98%) rename src/main/java/info/augendre/caps_extractor/{ => gui}/HelpDialog.java (97%) rename src/main/java/info/augendre/caps_extractor/{ => gui}/MainPanel.form (98%) rename src/main/java/info/augendre/caps_extractor/{ => gui}/MainPanel.java (91%) rename src/main/java/info/augendre/caps_extractor/{ => gui}/MainWindow.java (69%) rename src/main/java/info/augendre/caps_extractor/{ => util}/I18nSupport.java (97%) create mode 100644 src/main/java/info/augendre/caps_extractor/util/StringUtils.java diff --git a/build.gradle b/build.gradle index 66bc2e1..d869331 100644 --- a/build.gradle +++ b/build.gradle @@ -70,5 +70,5 @@ def jarPackage(artifactName) { } artifacts { - archives jarPackage("info.augendre.caps_extractor", "0.1.0", "MainWindow") + archives jarPackage("info.augendre.caps_extractor", "0.1.0", "CapsExtractorApp") } diff --git a/src/main/java/info/augendre/caps_extractor/CapsExtractorApp.java b/src/main/java/info/augendre/caps_extractor/CapsExtractorApp.java new file mode 100644 index 0000000..e95b0f9 --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/CapsExtractorApp.java @@ -0,0 +1,22 @@ +package info.augendre.caps_extractor; + +import info.augendre.caps_extractor.gui.MainWindow; + +import javax.swing.*; + +/** + * Created on 05/06/15. + * + * @author gaugendre + */ +public class CapsExtractorApp { + public static void main(String[] args) { + try { + UIManager.setLookAndFeel( + UIManager.getSystemLookAndFeelClassName()); + } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { + e.printStackTrace(System.err); + } + new MainWindow(); + } +} diff --git a/src/main/java/info/augendre/caps_extractor/AboutAction.java b/src/main/java/info/augendre/caps_extractor/actions/AboutAction.java similarity index 74% rename from src/main/java/info/augendre/caps_extractor/AboutAction.java rename to src/main/java/info/augendre/caps_extractor/actions/AboutAction.java index 9c224e3..60dc09a 100644 --- a/src/main/java/info/augendre/caps_extractor/AboutAction.java +++ b/src/main/java/info/augendre/caps_extractor/actions/AboutAction.java @@ -1,4 +1,7 @@ -package info.augendre.caps_extractor; +package info.augendre.caps_extractor.actions; + +import info.augendre.caps_extractor.util.I18nSupport; +import info.augendre.caps_extractor.gui.AboutDialog; import javax.swing.*; import java.awt.event.ActionEvent; diff --git a/src/main/java/info/augendre/caps_extractor/HelpAction.java b/src/main/java/info/augendre/caps_extractor/actions/HelpAction.java similarity index 74% rename from src/main/java/info/augendre/caps_extractor/HelpAction.java rename to src/main/java/info/augendre/caps_extractor/actions/HelpAction.java index c5c9603..c7493dd 100644 --- a/src/main/java/info/augendre/caps_extractor/HelpAction.java +++ b/src/main/java/info/augendre/caps_extractor/actions/HelpAction.java @@ -1,4 +1,7 @@ -package info.augendre.caps_extractor; +package info.augendre.caps_extractor.actions; + +import info.augendre.caps_extractor.util.I18nSupport; +import info.augendre.caps_extractor.gui.HelpDialog; import javax.swing.*; import java.awt.event.ActionEvent; diff --git a/src/main/java/info/augendre/caps_extractor/AboutDialog.form b/src/main/java/info/augendre/caps_extractor/gui/AboutDialog.form similarity index 98% rename from src/main/java/info/augendre/caps_extractor/AboutDialog.form rename to src/main/java/info/augendre/caps_extractor/gui/AboutDialog.form index 4e7c255..1583627 100644 --- a/src/main/java/info/augendre/caps_extractor/AboutDialog.form +++ b/src/main/java/info/augendre/caps_extractor/gui/AboutDialog.form @@ -1,5 +1,5 @@ -
+ diff --git a/src/main/java/info/augendre/caps_extractor/AboutDialog.java b/src/main/java/info/augendre/caps_extractor/gui/AboutDialog.java similarity index 95% rename from src/main/java/info/augendre/caps_extractor/AboutDialog.java rename to src/main/java/info/augendre/caps_extractor/gui/AboutDialog.java index 5dca7fc..f357b18 100644 --- a/src/main/java/info/augendre/caps_extractor/AboutDialog.java +++ b/src/main/java/info/augendre/caps_extractor/gui/AboutDialog.java @@ -1,13 +1,15 @@ -package info.augendre.caps_extractor; +package info.augendre.caps_extractor.gui; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; +import info.augendre.caps_extractor.util.I18nSupport; import javax.swing.*; import java.awt.*; -import java.awt.event.*; -import java.util.ResourceBundle; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; public class AboutDialog extends JDialog { private JPanel contentPane; diff --git a/src/main/java/info/augendre/caps_extractor/HelpDialog.form b/src/main/java/info/augendre/caps_extractor/gui/HelpDialog.form similarity index 98% rename from src/main/java/info/augendre/caps_extractor/HelpDialog.form rename to src/main/java/info/augendre/caps_extractor/gui/HelpDialog.form index 67fa2e3..0ef5cf0 100644 --- a/src/main/java/info/augendre/caps_extractor/HelpDialog.form +++ b/src/main/java/info/augendre/caps_extractor/gui/HelpDialog.form @@ -1,5 +1,5 @@ - + diff --git a/src/main/java/info/augendre/caps_extractor/HelpDialog.java b/src/main/java/info/augendre/caps_extractor/gui/HelpDialog.java similarity index 97% rename from src/main/java/info/augendre/caps_extractor/HelpDialog.java rename to src/main/java/info/augendre/caps_extractor/gui/HelpDialog.java index 7adb1ff..79e2f2a 100644 --- a/src/main/java/info/augendre/caps_extractor/HelpDialog.java +++ b/src/main/java/info/augendre/caps_extractor/gui/HelpDialog.java @@ -1,8 +1,9 @@ -package info.augendre.caps_extractor; +package info.augendre.caps_extractor.gui; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; +import info.augendre.caps_extractor.util.I18nSupport; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/info/augendre/caps_extractor/MainPanel.form b/src/main/java/info/augendre/caps_extractor/gui/MainPanel.form similarity index 98% rename from src/main/java/info/augendre/caps_extractor/MainPanel.form rename to src/main/java/info/augendre/caps_extractor/gui/MainPanel.form index 0132684..da5ec49 100644 --- a/src/main/java/info/augendre/caps_extractor/MainPanel.form +++ b/src/main/java/info/augendre/caps_extractor/gui/MainPanel.form @@ -1,5 +1,5 @@ - + diff --git a/src/main/java/info/augendre/caps_extractor/MainPanel.java b/src/main/java/info/augendre/caps_extractor/gui/MainPanel.java similarity index 91% rename from src/main/java/info/augendre/caps_extractor/MainPanel.java rename to src/main/java/info/augendre/caps_extractor/gui/MainPanel.java index c531c83..551405c 100644 --- a/src/main/java/info/augendre/caps_extractor/MainPanel.java +++ b/src/main/java/info/augendre/caps_extractor/gui/MainPanel.java @@ -1,8 +1,9 @@ -package info.augendre.caps_extractor; +package info.augendre.caps_extractor.gui; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; +import info.augendre.caps_extractor.util.StringUtils; import javax.swing.*; import java.awt.*; @@ -33,7 +34,7 @@ public class MainPanel { @Override public void keyReleased(KeyEvent e) { if (parse) { - outputField.setText(extractUpperCase(inputField.getText())); + outputField.setText(StringUtils.extractUpperCase(inputField.getText())); } else { char key = e.getKeyChar(); if (Character.isUpperCase(key)) { @@ -50,23 +51,6 @@ public class MainPanel { }); } - /** - * Extracts the upper case characters from the given string. - * @param s The string where to extract upper case characters. - * @return The upper case characters found in the given string. - */ - public String extractUpperCase(String s) { - String upperCase = ""; - for (int i = 0; i < s.length(); i++) { - char current = s.charAt(i); - if (Character.isUpperCase(current)) { - upperCase += current; - } - } - - return upperCase; - } - public JPanel getContentPanel() { return contentPanel; } diff --git a/src/main/java/info/augendre/caps_extractor/MainWindow.java b/src/main/java/info/augendre/caps_extractor/gui/MainWindow.java similarity index 69% rename from src/main/java/info/augendre/caps_extractor/MainWindow.java rename to src/main/java/info/augendre/caps_extractor/gui/MainWindow.java index 6612248..0d85e0b 100644 --- a/src/main/java/info/augendre/caps_extractor/MainWindow.java +++ b/src/main/java/info/augendre/caps_extractor/gui/MainWindow.java @@ -1,4 +1,8 @@ -package info.augendre.caps_extractor; +package info.augendre.caps_extractor.gui; + +import info.augendre.caps_extractor.actions.AboutAction; +import info.augendre.caps_extractor.actions.HelpAction; +import info.augendre.caps_extractor.util.I18nSupport; import javax.swing.*; @@ -32,14 +36,4 @@ public class MainWindow extends JFrame { this.setVisible(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } - - public static void main(String[] args) { - try { - UIManager.setLookAndFeel( - UIManager.getSystemLookAndFeelClassName()); - } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { - e.printStackTrace(System.err); - } - new MainWindow(); - } } diff --git a/src/main/java/info/augendre/caps_extractor/I18nSupport.java b/src/main/java/info/augendre/caps_extractor/util/I18nSupport.java similarity index 97% rename from src/main/java/info/augendre/caps_extractor/I18nSupport.java rename to src/main/java/info/augendre/caps_extractor/util/I18nSupport.java index 59d9f54..f097dd9 100644 --- a/src/main/java/info/augendre/caps_extractor/I18nSupport.java +++ b/src/main/java/info/augendre/caps_extractor/util/I18nSupport.java @@ -20,7 +20,7 @@ * If not, see . */ -package info.augendre.caps_extractor; +package info.augendre.caps_extractor.util; import com.jgoodies.common.internal.StringLocalizer; import org.jetbrains.annotations.NonNls; diff --git a/src/main/java/info/augendre/caps_extractor/util/StringUtils.java b/src/main/java/info/augendre/caps_extractor/util/StringUtils.java new file mode 100644 index 0000000..f5b1659 --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/util/StringUtils.java @@ -0,0 +1,25 @@ +package info.augendre.caps_extractor.util; + +/** + * Created on 05/06/15. + * + * @author gaugendre + */ +public class StringUtils { + /** + * Extracts the upper case characters from the given string. + * @param s The string where to extract upper case characters. + * @return The upper case characters found in the given string. + */ + public static String extractUpperCase(String s) { + String upperCase = ""; + for (int i = 0; i < s.length(); i++) { + char current = s.charAt(i); + if (Character.isUpperCase(current)) { + upperCase += current; + } + } + + return upperCase; + } +}