Add copy to clipboard.

This commit is contained in:
gaugendre 2015-06-04 23:37:34 +02:00
parent 593e59a4b1
commit 249e6994db
4 changed files with 127 additions and 34 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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.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"> <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"/> <margin top="10" left="10" bottom="10" right="10"/>
<constraints> <constraints>
<xy x="20" y="20" width="736" height="400"/> <xy x="20" y="20" width="736" height="400"/>
@ -8,40 +8,76 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="9b3fe" class="javax.swing.JTextField" binding="inputField"> <grid id="16f10" layout-manager="GridLayoutManager" row-count="2" 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> <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"> <grid row="0" column="0" row-span="2" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<preferred-size width="400" height="-1"/>
</grid>
</constraints> </constraints>
<properties/> <properties/>
</component> <border type="none"/>
<component id="e1e93" class="javax.swing.JTextField" binding="outputField"> <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>
<editable value="false"/>
<focusable value="false"/>
</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>
<grid id="c4e26" 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> <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"> <grid row="2" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<preferred-size width="150" height="-1"/>
</grid>
</constraints> </constraints>
<properties/> <properties/>
</component> <border type="none"/>
<component id="afb81" class="javax.swing.JLabel"> <children>
<component id="f9025" class="javax.swing.JButton" binding="copyToClipboardButton" default-binding="true">
<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 resource-bundle="info/augendre/caps_extractor/strings" key="button.to_clipboard"/>
</properties>
</component>
</children>
</grid>
<hspacer id="86f2c">
<constraints> <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"/> <grid row="2" 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> </constraints>
<properties> </hspacer>
<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> </children>
</grid> </grid>
</form> </form>

View file

@ -2,9 +2,14 @@ package info.augendre.caps_extractor;
import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -16,6 +21,7 @@ public class MainPanel {
private JTextField inputField; private JTextField inputField;
private JPanel contentPanel; private JPanel contentPanel;
private JTextField outputField; private JTextField outputField;
private JButton copyToClipboardButton;
private boolean parse; private boolean parse;
public MainPanel() { public MainPanel() {
@ -38,6 +44,15 @@ public class MainPanel {
} }
} }
}); });
copyToClipboardButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String myString = outputField.getText();
StringSelection stringSelection = new StringSelection(myString);
Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
clpbrd.setContents(stringSelection, null);
}
});
} }
private String extractUpperCase(String s) { private String extractUpperCase(String s) {
@ -72,17 +87,30 @@ public class MainPanel {
*/ */
private void $$$setupUI$$$() { private void $$$setupUI$$$() {
contentPanel = new JPanel(); contentPanel = new JPanel();
contentPanel.setLayout(new GridLayoutManager(2, 2, new Insets(10, 10, 10, 10), -1, -1)); contentPanel.setLayout(new GridLayoutManager(3, 3, new Insets(10, 10, 10, 10), -1, -1));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPanel.add(panel1, new GridConstraints(0, 0, 2, 3, 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));
inputField = new JTextField(); 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)); panel1.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(); 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)); outputField.setEditable(false);
outputField.setFocusable(false);
panel1.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(); final JLabel label1 = new JLabel();
this.$$$loadLabelText$$$(label1, ResourceBundle.getBundle("info/augendre/caps_extractor/strings").getString("label.input")); 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)); panel1.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(); final JLabel label2 = new JLabel();
this.$$$loadLabelText$$$(label2, ResourceBundle.getBundle("info/augendre/caps_extractor/strings").getString("label.output")); 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)); panel1.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));
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
contentPanel.add(panel2, new GridConstraints(2, 1, 1, 2, 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));
copyToClipboardButton = new JButton();
this.$$$loadButtonText$$$(copyToClipboardButton, ResourceBundle.getBundle("info/augendre/caps_extractor/strings").getString("button.to_clipboard"));
panel2.add(copyToClipboardButton, 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 Spacer spacer1 = new Spacer();
contentPanel.add(spacer1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
label1.setLabelFor(inputField); label1.setLabelFor(inputField);
label2.setLabelFor(outputField); label2.setLabelFor(outputField);
} }
@ -114,6 +142,33 @@ public class MainPanel {
} }
} }
/**
* @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 * @noinspection ALL
*/ */

View file

@ -7,3 +7,4 @@ plain.title=Caps Extractor
help.content=Enter some text in the first box.<br>\ help.content=Enter some text in the first box.<br>\
All the upper case letters will be reflected in the latter box. All the upper case letters will be reflected in the latter box.
plain.help_title=Help plain.help_title=Help
button.to_clipboard=Copy to clipboard

View file

@ -7,3 +7,4 @@ plain.title=Extracteur de majuscules
help.content=Entrez du texte dans le premier champ.<br>\ help.content=Entrez du texte dans le premier champ.<br>\
Toutes les lettres majuscules seront r\u00E9p\u00E9t\u00E9es dans le second champ. Toutes les lettres majuscules seront r\u00E9p\u00E9t\u00E9es dans le second champ.
plain.help_title=Aide plain.help_title=Aide
button.to_clipboard=Copier dans le presse-papiers