124 lines
4.5 KiB
Java
124 lines
4.5 KiB
Java
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;
|
|
}
|
|
}
|