Working Caps Extractor.

This commit is contained in:
gaugendre 2015-06-04 23:12:02 +02:00
commit ad9cf648b0
12 changed files with 616 additions and 0 deletions

76
.gitignore vendored Normal file
View file

@ -0,0 +1,76 @@
# Created by https://www.gitignore.io
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
*.iml
## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### Gradle ###
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
### Java ###
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

74
build.gradle Normal file
View file

@ -0,0 +1,74 @@
apply plugin: "idea"
apply plugin: "java"
repositories {
mavenCentral()
}
dependencies {
compile "com.intellij:forms_rt:7.0.3", 'org.apache.commons:commons-lang3:3.4',
'com.jgoodies:jgoodies-common:1.7.0', 'com.intellij:annotations:12.0'
runtime "com.intellij:forms_rt:7.0.3", 'org.apache.commons:commons-lang3:3.4',
'com.jgoodies:jgoodies-common:1.7.0', 'com.intellij:annotations:12.0'
}
def jarPackage(artifactName, artifactVersion, artifactClass) {
if (artifactVersion == "" || artifactVersion == null)
artifactVersion = "1.0.0"
int lastDotIndex = artifactName.lastIndexOf('.')
String name
if (lastDotIndex != -1)
name = artifactName.substring(lastDotIndex + 1, artifactName.length())
else
name = artifactName
return tasks.create("jar_${name}", Jar) {
baseName = artifactName
version = artifactVersion
String className
if (artifactClass == "" || artifactClass == null)
className = baseName.capitalize()
else
className = artifactClass
from(sourceSets.main.output) {
int firstDotIndex = baseName.indexOf('.')
String includePath
if (firstDotIndex != -1)
includePath = baseName.substring(0, firstDotIndex)
else
includePath = baseName
include "$includePath/**"
}
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
// For sources :
// from sourceSets.main.allSource
manifest {
attributes "Implementation-Title": "$className",
"Implementation-Version": "$version",
"Main-Class": "$baseName.$className"
}
}
}
def jarPackage(artifactName, artifactVersion) {
return jarPackage(artifactName, artifactVersion, "")
}
def jarPackage(artifactName) {
return jarPackage(artifactName, "")
}
artifacts {
archives jarPackage("info.augendre.caps_extractor", "0.1.0", "MainWindow")
}

View file

@ -0,0 +1,21 @@
package info.augendre.caps_extractor;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* Created by Gabriel.
*/
public class AboutAction extends AbstractAction {
public AboutAction() {
super(I18nSupport.translate("plain.about_title"));
}
@Override
public void actionPerformed(ActionEvent e) {
JDialog about = new AboutDialog();
about.pack();
about.setLocationRelativeTo(null);
about.setVisible(true);
}
}

View file

@ -0,0 +1,64 @@
<?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">
<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>
<xy x="48" y="54" width="436" height="297"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="98af6">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="OK"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="b25dc" class="javax.swing.JLabel" binding="textLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View file

@ -0,0 +1,93 @@
package info.augendre.caps_extractor;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ResourceBundle;
public class AboutDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JLabel textLabel;
public AboutDialog() {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
this.setTitle(I18nSupport.translate("plain.about_title"));
buttonOK.addActionListener(e -> onOK());
textLabel.setText("<HTML>" +
"<p><strong>" + I18nSupport.translate("plain.dev") + " </strong>: Gabriel Augendre" +
"&lt;gabriel@augendre.info&gt;</p>" +
"</HTML>");
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void onOK() {
dispose();
}
private void onCancel() {
dispose();
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
buttonOK = new JButton();
buttonOK.setText("OK");
panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JPanel panel3 = new JPanel();
panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
textLabel = new JLabel();
textLabel.setText("Label");
panel3.add(textLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contentPane;
}
}

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2013 Philippe VIENNE
*
* This file is a part of SpeleoGraph
*
* SpeleoGraph is free software: you can redistribute
* it and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* SpeleoGraph is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public
* License along with SpeleoGraph.
* If not, see <http://www.gnu.org/licenses/>.
*/
package info.augendre.caps_extractor;
import com.jgoodies.common.internal.StringLocalizer;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.PropertyKey;
import java.text.MessageFormat;
import java.util.ResourceBundle;
/**
* Distributed on licence GNU GPL V3.
*/
public class I18nSupport implements StringLocalizer {
@NonNls
private static final ResourceBundle bundle = ResourceBundle.getBundle("info/augendre/caps_extractor/strings");
public static String translate
(@PropertyKey(resourceBundle = "info.augendre.caps_extractor.strings")
String key, Object... params) {
String value = bundle.getString(key);
if (params.length > 0) return MessageFormat.format(value, params);
return value;
}
/**
* Returns a localized String for the given key.
*
* @param key the key used to look up the localized String
* @return the localized String
*/
@Override
public String getString(@PropertyKey(resourceBundle = "info.augendre.caps_extractor.strings") String key) {
return translate(key);
}
}

View file

@ -0,0 +1,47 @@
<?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">
<grid id="27dc6" binding="contentPanel" default-binding="true" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="736" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="9b3fe" class="javax.swing.JTextField" binding="inputField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="400" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="e1e93" class="javax.swing.JTextField" binding="outputField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="afb81" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="9b3fe"/>
<text resource-bundle="info/augendre/caps_extractor/strings" key="label.input"/>
</properties>
</component>
<component id="c58ce" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="e1e93"/>
<text resource-bundle="info/augendre/caps_extractor/strings" key="label.output"/>
</properties>
</component>
</children>
</grid>
</form>

View file

@ -0,0 +1,123 @@
package info.augendre.caps_extractor;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ResourceBundle;
/**
* Created by Gabriel.
*/
public class MainPanel {
private JTextField inputField;
private JPanel contentPanel;
private JTextField outputField;
private boolean parse;
public MainPanel() {
parse = false;
inputField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
parse = e.getKeyCode() == KeyEvent.VK_BACK_SPACE || inputField.getSelectedText() != null;
}
@Override
public void keyReleased(KeyEvent e) {
if (parse) {
outputField.setText(extractUpperCase(inputField.getText()));
} else {
char key = e.getKeyChar();
if (Character.isUpperCase(key)) {
outputField.setText(outputField.getText() + key);
}
}
}
});
}
private 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;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPanel = new JPanel();
contentPanel.setLayout(new GridLayoutManager(2, 2, new Insets(10, 10, 10, 10), -1, -1));
inputField = new JTextField();
contentPanel.add(inputField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(400, -1), null, 0, false));
outputField = new JTextField();
contentPanel.add(outputField, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
final JLabel label1 = new JLabel();
this.$$$loadLabelText$$$(label1, ResourceBundle.getBundle("info/augendre/caps_extractor/strings").getString("label.input"));
contentPanel.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label2 = new JLabel();
this.$$$loadLabelText$$$(label2, ResourceBundle.getBundle("info/augendre/caps_extractor/strings").getString("label.output"));
contentPanel.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
label1.setLabelFor(inputField);
label2.setLabelFor(outputField);
}
/**
* @noinspection ALL
*/
private void $$$loadLabelText$$$(JLabel component, String text) {
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '&') {
i++;
if (i == text.length()) break;
if (!haveMnemonic && text.charAt(i) != '&') {
haveMnemonic = true;
mnemonic = text.charAt(i);
mnemonicIndex = result.length();
}
}
result.append(text.charAt(i));
}
component.setText(result.toString());
if (haveMnemonic) {
component.setDisplayedMnemonic(mnemonic);
component.setDisplayedMnemonicIndex(mnemonicIndex);
}
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contentPanel;
}
}

View file

@ -0,0 +1,44 @@
package info.augendre.caps_extractor;
import javax.swing.*;
import java.util.ResourceBundle;
/**
* Created by Gabriel.
*/
public class MainWindow extends JFrame {
public MainWindow() {
super(I18nSupport.translate("plain.title"));
this.setup();
}
public JMenuBar createMenu() {
JMenuBar menuBar = new JMenuBar();
JMenu help = new JMenu(I18nSupport.translate("menu.help"));
menuBar.add(help);
JMenuItem about = new JMenuItem(new AboutAction());
help.add(about);
return menuBar;
}
public void setup() {
MainPanel mainPanel = new MainPanel();
JPanel contentPanel = mainPanel.getContentPanel();
this.setJMenuBar(createMenu());
this.setContentPane(contentPanel);
this.pack();
this.setLocationRelativeTo(null);
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

@ -0,0 +1,5 @@
<root>
<item name='java.util.ResourceBundle'>
<annotation name='org.jetbrains.annotations.NonNls'/>
</item>
</root>

View file

@ -0,0 +1,6 @@
label.input=&Input\:
label.output=&Output\:
plain.about_title=A propos
plain.dev=Developer
menu.help=Help
plain.title=Caps Extractor

View file

@ -0,0 +1,6 @@
label.input=&Entr\u00E9e \:
label.output=&Sortie \:
plain.about_title=A propos
plain.dev=D\u00E9veloppeur
menu.help=Aide
plain.title=Extracteur de majuscules