commit ad9cf648b0ff78619ca945822b7fd0c920af4707 Author: gaugendre Date: Thu Jun 4 23:12:02 2015 +0200 Working Caps Extractor. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cbf71d --- /dev/null +++ b/.gitignore @@ -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* + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..66bc2e1 --- /dev/null +++ b/build.gradle @@ -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") +} diff --git a/src/main/java/info/augendre/caps_extractor/AboutAction.java b/src/main/java/info/augendre/caps_extractor/AboutAction.java new file mode 100644 index 0000000..9c224e3 --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/AboutAction.java @@ -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); + } +} diff --git a/src/main/java/info/augendre/caps_extractor/AboutDialog.form b/src/main/java/info/augendre/caps_extractor/AboutDialog.form new file mode 100644 index 0000000..4e7c255 --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/AboutDialog.form @@ -0,0 +1,64 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/info/augendre/caps_extractor/AboutDialog.java b/src/main/java/info/augendre/caps_extractor/AboutDialog.java new file mode 100644 index 0000000..5dca7fc --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/AboutDialog.java @@ -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("" + + "

" + I18nSupport.translate("plain.dev") + " : Gabriel Augendre" + + "<gabriel@augendre.info>

" + + ""); + + // 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; + } +} diff --git a/src/main/java/info/augendre/caps_extractor/I18nSupport.java b/src/main/java/info/augendre/caps_extractor/I18nSupport.java new file mode 100644 index 0000000..59d9f54 --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/I18nSupport.java @@ -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 . + */ + +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); + } +} diff --git a/src/main/java/info/augendre/caps_extractor/MainPanel.form b/src/main/java/info/augendre/caps_extractor/MainPanel.form new file mode 100644 index 0000000..fe3d30e --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/MainPanel.form @@ -0,0 +1,47 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/info/augendre/caps_extractor/MainPanel.java b/src/main/java/info/augendre/caps_extractor/MainPanel.java new file mode 100644 index 0000000..028d81a --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/MainPanel.java @@ -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; + } +} diff --git a/src/main/java/info/augendre/caps_extractor/MainWindow.java b/src/main/java/info/augendre/caps_extractor/MainWindow.java new file mode 100644 index 0000000..babe6f6 --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/MainWindow.java @@ -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(); + } +} diff --git a/src/main/java/info/augendre/caps_extractor/util/annotations.xml b/src/main/java/info/augendre/caps_extractor/util/annotations.xml new file mode 100644 index 0000000..f24d93c --- /dev/null +++ b/src/main/java/info/augendre/caps_extractor/util/annotations.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/resources/info/augendre/caps_extractor/strings.properties b/src/main/resources/info/augendre/caps_extractor/strings.properties new file mode 100644 index 0000000..37c864f --- /dev/null +++ b/src/main/resources/info/augendre/caps_extractor/strings.properties @@ -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 \ No newline at end of file diff --git a/src/main/resources/info/augendre/caps_extractor/strings_fr.properties b/src/main/resources/info/augendre/caps_extractor/strings_fr.properties new file mode 100644 index 0000000..572f143 --- /dev/null +++ b/src/main/resources/info/augendre/caps_extractor/strings_fr.properties @@ -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 \ No newline at end of file