151 lines
6.8 KiB
Java
151 lines
6.8 KiB
Java
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.*;
|
|
import java.awt.datatransfer.Clipboard;
|
|
import java.awt.datatransfer.StringSelection;
|
|
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 JButton copyToClipboardButton;
|
|
private boolean parse;
|
|
|
|
public MainPanel() {
|
|
parse = false;
|
|
inputField.addKeyListener(new KeyAdapter() {
|
|
@Override
|
|
public void keyReleased(KeyEvent e) {
|
|
outputField.setText(StringUtils.extractUpperCase(inputField.getText()));
|
|
}
|
|
});
|
|
copyToClipboardButton.addActionListener(e -> {
|
|
String myString = outputField.getText();
|
|
StringSelection stringSelection = new StringSelection(myString);
|
|
Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
clpbrd.setContents(stringSelection, null);
|
|
});
|
|
}
|
|
|
|
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(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();
|
|
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.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();
|
|
this.$$$loadLabelText$$$(label1, ResourceBundle.getBundle("info/augendre/caps_extractor/strings").getString("label.input"));
|
|
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();
|
|
this.$$$loadLabelText$$$(label2, ResourceBundle.getBundle("info/augendre/caps_extractor/strings").getString("label.output"));
|
|
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);
|
|
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
|
|
*/
|
|
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 contentPanel;
|
|
}
|
|
}
|