Add working project
This commit is contained in:
commit
5b4d557e7d
11 changed files with 622 additions and 0 deletions
60
.gitignore
vendored
Normal file
60
.gitignore
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
|
||||
# Created by https://www.gitignore.io/api/intellij,java,maven
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/
|
||||
|
||||
## File-based project format:
|
||||
*.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
|
||||
fabric.properties
|
||||
|
||||
### Intellij Patch ###
|
||||
*.iml
|
||||
|
||||
|
||||
### 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*
|
||||
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
|
91
pom.xml
Normal file
91
pom.xml
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>info.augendre</groupId>
|
||||
<artifactId>name-picker</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>ihm-base</id>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>info.augendre.name_picker.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<finalName>name-picker</finalName>
|
||||
</configuration>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.1</version>
|
||||
<configuration>
|
||||
<show>private</show>
|
||||
<nohelp>true</nohelp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.intellij</groupId>
|
||||
<artifactId>forms_rt</artifactId>
|
||||
<version>7.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.1</version>
|
||||
<configuration>
|
||||
<show>public</show>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
|
@ -0,0 +1,41 @@
|
|||
package info.augendre.name_picker;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by gaugendre on 18/04/2016 13:32.
|
||||
*/
|
||||
public class ChooseFileAction extends AbstractAction {
|
||||
private JFrame parent;
|
||||
private MainPanel mainPanel;
|
||||
|
||||
public ChooseFileAction(MainPanel mainPanel) {
|
||||
this.mainPanel = mainPanel;
|
||||
this.parent = mainPanel.getMainFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File file = null;
|
||||
FileDialog dialog;
|
||||
String mHomeDir = System.getProperty("user.home");
|
||||
|
||||
dialog = new FileDialog(parent, "Save", FileDialog.LOAD);
|
||||
dialog.setDirectory(mHomeDir);
|
||||
dialog.setLocationRelativeTo(null);
|
||||
dialog.setVisible(true);
|
||||
|
||||
if (dialog.getFile() != null) {
|
||||
mHomeDir = dialog.getDirectory();
|
||||
file = new File(mHomeDir + dialog.getFile());
|
||||
}
|
||||
|
||||
if (file != null) {
|
||||
mainPanel.setNamesFile(file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
104
src/main/java/info/augendre/name_picker/ComputeResults.java
Normal file
104
src/main/java/info/augendre/name_picker/ComputeResults.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
package info.augendre.name_picker;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.Normalizer;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by gaugendre on 18/04/2016 13:56.
|
||||
*/
|
||||
public class ComputeResults implements Runnable {
|
||||
private final int LENGTH = 6;
|
||||
private final String VOWELS = "aeiouy";
|
||||
private final MainPanel mainPanel;
|
||||
private File file;
|
||||
|
||||
public ComputeResults(MainPanel mainPanel) {
|
||||
this.file = mainPanel.getNamesFile();
|
||||
this.mainPanel = mainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Path filePath = Paths.get(file.getAbsolutePath());
|
||||
List<String> validStrings = Files.lines(filePath).parallel().filter(this::isValid).collect(Collectors.toList());
|
||||
mainPanel.getValidNamesList().setListData(validStrings.toArray());
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
System.err.println("ERR: Le fichier source n'existe pas ou le fichier de destination ne peut être crée ou ouvert.");
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("ERR: entrée/sortie.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValid(String s) {
|
||||
s = Normalizer.normalize(s, Normalizer.Form.NFD);
|
||||
s = s.replaceAll("\\p{M}", "");
|
||||
s = s.toLowerCase();
|
||||
return lengthValidator(s)
|
||||
&& vowelsAlternanceValidator(s)
|
||||
&& containsValidator(s)
|
||||
&& touchesOnceValidator(s)
|
||||
&& noLetterRepeatValidator(s);
|
||||
}
|
||||
|
||||
private boolean lengthValidator(String s) {
|
||||
return s.length() == LENGTH;
|
||||
}
|
||||
|
||||
private boolean vowelsAlternanceValidator(String s) {
|
||||
boolean previousIsVowel = isVowel(s.charAt(0));
|
||||
|
||||
for (int i = 1; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
boolean currentIsVowel = isVowel(c);
|
||||
|
||||
if (currentIsVowel && previousIsVowel || !currentIsVowel && !previousIsVowel) {
|
||||
return false;
|
||||
}
|
||||
previousIsVowel = currentIsVowel;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isVowel(char o) {
|
||||
o = Character.toLowerCase(o);
|
||||
return VOWELS.indexOf(o) >= 0;
|
||||
}
|
||||
|
||||
private boolean containsValidator(String s) {
|
||||
return s.charAt(s.length() - 1) != 'a' && s.indexOf('h') < 0;
|
||||
}
|
||||
|
||||
private boolean touchesOnceValidator(String s) {
|
||||
return (s.contains("b") ? 1 : 0) +
|
||||
(s.contains("m") ? 1 : 0) +
|
||||
(s.contains("p") ? 1 : 0) == 1;
|
||||
}
|
||||
|
||||
private boolean noLetterRepeatValidator(String s) {
|
||||
Map<Character, Integer> map = new HashMap<>();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char current = s.charAt(i);
|
||||
int count = map.getOrDefault(current, 0) + 1;
|
||||
if (count > 1) {
|
||||
return false;
|
||||
}
|
||||
map.put(current, count + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
45
src/main/java/info/augendre/name_picker/Main.java
Normal file
45
src/main/java/info/augendre/name_picker/Main.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package info.augendre.name_picker;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* Created by gaugendre on 18/04/2016 12:51.
|
||||
*/
|
||||
public class Main implements Runnable {
|
||||
private JPanel mainPanel;
|
||||
private JFrame mainFrame;
|
||||
private final static String CLOSE = "close";
|
||||
private final static int AFC = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
|
||||
private final static KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
|
||||
|
||||
public Main() {
|
||||
mainFrame = new JFrame("Name Picker");
|
||||
this.mainPanel = new MainPanel(mainFrame).getMainPanel();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(new Main());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
// Add key binding
|
||||
mainPanel.getInputMap(AFC).put(escapeStroke, CLOSE);
|
||||
mainPanel.getActionMap().put(CLOSE, new QuitAction(mainFrame));
|
||||
|
||||
mainFrame.setContentPane(mainPanel);
|
||||
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
mainFrame.pack();
|
||||
mainFrame.setLocationRelativeTo(null);
|
||||
mainFrame.setVisible(true);
|
||||
}
|
||||
}
|
112
src/main/java/info/augendre/name_picker/MainPanel.form
Normal file
112
src/main/java/info/augendre/name_picker/MainPanel.form
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="info.augendre.name_picker.MainPanel">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="521" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="64ec4" binding="containerPanel" layout-manager="GridLayoutManager" row-count="2" 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="1" 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>
|
||||
<grid id="4bab" binding="inputPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" 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="b2f30" class="javax.swing.JTextField" binding="fileNameField">
|
||||
<constraints>
|
||||
<grid row="0" column="0" 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="250" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<editable value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6c941" class="javax.swing.JButton" binding="chooseAFileButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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 resource-bundle="GUI" key="button.choosefile"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="db110" class="javax.swing.JButton" binding="computeButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="2" 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 resource-bundle="GUI" key="button.compute"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="9d447" 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="1" 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" title-resource-bundle="GUI" title-key="label.valid_names"/>
|
||||
<children>
|
||||
<scrollpane id="e66c2" binding="namesListScrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none">
|
||||
<title-color color="-4473925"/>
|
||||
</border>
|
||||
<children>
|
||||
<component id="b6741" class="javax.swing.JList" binding="validNamesList" custom-create="true">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="a4215">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="5" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="4c8a8">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="5" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="a82ec">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="2" indent="1" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="5"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="290d9">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="2" indent="1" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="5"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
142
src/main/java/info/augendre/name_picker/MainPanel.java
Normal file
142
src/main/java/info/augendre/name_picker/MainPanel.java
Normal file
|
@ -0,0 +1,142 @@
|
|||
package info.augendre.name_picker;
|
||||
|
||||
import com.intellij.uiDesigner.core.GridConstraints;
|
||||
import com.intellij.uiDesigner.core.GridLayoutManager;
|
||||
import com.intellij.uiDesigner.core.Spacer;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by gaugendre on 18/04/2016 12:57.
|
||||
*/
|
||||
public class MainPanel {
|
||||
private final JFrame mainFrame;
|
||||
private JPanel mainPanel;
|
||||
private JButton chooseAFileButton;
|
||||
private JTextField fileNameField;
|
||||
private JButton computeButton;
|
||||
private JList<String> validNamesList;
|
||||
private JPanel inputPanel;
|
||||
private JPanel containerPanel;
|
||||
private JScrollPane namesListScrollPane;
|
||||
private File namesFile;
|
||||
|
||||
public MainPanel(JFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
$$$setupUI$$$();
|
||||
chooseAFileButton.addActionListener(new ChooseFileAction(this));
|
||||
computeButton.addActionListener(e -> computeResults());
|
||||
}
|
||||
|
||||
public void computeResults() {
|
||||
SwingUtilities.invokeLater(new ComputeResults(this));
|
||||
}
|
||||
|
||||
public JPanel getMainPanel() {
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
public File getNamesFile() {
|
||||
return namesFile;
|
||||
}
|
||||
|
||||
public void setNamesFile(File namesFile) {
|
||||
this.namesFile = namesFile;
|
||||
fileNameField.setText(namesFile.getAbsolutePath());
|
||||
mainFrame.pack();
|
||||
computeResults();
|
||||
}
|
||||
|
||||
public JFrame getMainFrame() {
|
||||
return mainFrame;
|
||||
}
|
||||
|
||||
public JList getValidNamesList() {
|
||||
return validNamesList;
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
validNamesList = new JList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer
|
||||
* >>> IMPORTANT!! <<<
|
||||
* DO NOT edit this method OR call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
createUIComponents();
|
||||
mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new GridLayoutManager(3, 3, new Insets(0, 0, 0, 0), -1, -1));
|
||||
containerPanel = new JPanel();
|
||||
containerPanel.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
mainPanel.add(containerPanel, new GridConstraints(1, 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));
|
||||
inputPanel = new JPanel();
|
||||
inputPanel.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1));
|
||||
containerPanel.add(inputPanel, 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));
|
||||
fileNameField = new JTextField();
|
||||
fileNameField.setEditable(false);
|
||||
inputPanel.add(fileNameField, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(250, -1), null, 0, false));
|
||||
chooseAFileButton = new JButton();
|
||||
this.$$$loadButtonText$$$(chooseAFileButton, ResourceBundle.getBundle("GUI").getString("button.choosefile"));
|
||||
inputPanel.add(chooseAFileButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
computeButton = new JButton();
|
||||
this.$$$loadButtonText$$$(computeButton, ResourceBundle.getBundle("GUI").getString("button.compute"));
|
||||
inputPanel.add(computeButton, new GridConstraints(0, 2, 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 panel1 = new JPanel();
|
||||
panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
containerPanel.add(panel1, new GridConstraints(1, 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));
|
||||
panel1.setBorder(BorderFactory.createTitledBorder(ResourceBundle.getBundle("GUI").getString("label.valid_names")));
|
||||
namesListScrollPane = new JScrollPane();
|
||||
panel1.add(namesListScrollPane, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
|
||||
namesListScrollPane.setViewportView(validNamesList);
|
||||
final Spacer spacer1 = new Spacer();
|
||||
mainPanel.add(spacer1, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, 1, null, new Dimension(5, -1), null, 0, false));
|
||||
final Spacer spacer2 = new Spacer();
|
||||
mainPanel.add(spacer2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, 1, null, new Dimension(5, -1), null, 0, false));
|
||||
final Spacer spacer3 = new Spacer();
|
||||
mainPanel.add(spacer3, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 5), null, 1, false));
|
||||
final Spacer spacer4 = new Spacer();
|
||||
mainPanel.add(spacer4, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 5), null, 1, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$loadButtonText$$$(AbstractButton 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.setMnemonic(mnemonic);
|
||||
component.setDisplayedMnemonicIndex(mnemonicIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return mainPanel;
|
||||
}
|
||||
}
|
21
src/main/java/info/augendre/name_picker/QuitAction.java
Normal file
21
src/main/java/info/augendre/name_picker/QuitAction.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package info.augendre.name_picker;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
/**
|
||||
* Created by gaugendre on 18/04/2016 13:00.
|
||||
*/
|
||||
public class QuitAction extends AbstractAction {
|
||||
private JFrame mainFrame;
|
||||
|
||||
public QuitAction(JFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mainFrame.dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
3
src/main/resources/GUI.properties
Normal file
3
src/main/resources/GUI.properties
Normal file
|
@ -0,0 +1,3 @@
|
|||
button.choosefile=Choose a file
|
||||
button.compute=Compute
|
||||
label.valid_names=Valid names
|
3
src/main/resources/GUI_fr.properties
Normal file
3
src/main/resources/GUI_fr.properties
Normal file
|
@ -0,0 +1,3 @@
|
|||
button.choosefile=Choisissez un fichier
|
||||
button.compute=Calcul
|
||||
label.valid_names=Noms conformes
|
0
src/test/java/.gitkeep
Normal file
0
src/test/java/.gitkeep
Normal file
Loading…
Reference in a new issue