Refactor code into packages and extract StringUtils class.

This commit is contained in:
Gabriel Augendre 2015-06-05 10:11:00 +02:00
parent 88484c1e47
commit dc2d218969
13 changed files with 75 additions and 41 deletions

View file

@ -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")
}

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="info.augendre.caps_extractor.AboutDialog">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="info.augendre.caps_extractor.gui.AboutDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>

View file

@ -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;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="info.augendre.caps_extractor.HelpDialog">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="info.augendre.caps_extractor.gui.HelpDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>

View file

@ -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.*;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="info.augendre.caps_extractor.MainPanel">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="info.augendre.caps_extractor.gui.MainPanel">
<grid id="27dc6" binding="contentPanel" default-binding="true" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>

View file

@ -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;
}

View file

@ -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();
}
}

View file

@ -20,7 +20,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
package info.augendre.caps_extractor;
package info.augendre.caps_extractor.util;
import com.jgoodies.common.internal.StringLocalizer;
import org.jetbrains.annotations.NonNls;

View file

@ -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;
}
}