summaryrefslogtreecommitdiff
path: root/src/algorithmus/Case.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/algorithmus/Case.java')
-rwxr-xr-xsrc/algorithmus/Case.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/algorithmus/Case.java b/src/algorithmus/Case.java
new file mode 100755
index 0000000..06e35d6
--- /dev/null
+++ b/src/algorithmus/Case.java
@@ -0,0 +1,81 @@
+package algorithmus;
+
+import java.awt.Checkbox;
+import java.awt.CheckboxGroup;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.UnsupportedEncodingException;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+
+public class Case extends Algorithmus {
+
+ private String name = "Case";
+ private boolean low = true;
+
+ public String getName() {
+ return name;
+ }
+
+ public void options() {
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("Case");
+ frame.setSize(100, 100);
+ frame.setResizable(false);
+ Checkbox cb = new Checkbox("To Lowercase");
+ cb.setBounds(5, 5, 100, 20);
+ JButton apply = new JButton("Apply");
+ apply.setBounds(5, 30, 75, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ low = cb.getState();
+ }
+ });
+ frame.add(cb);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ public String encode(String input) {
+ try {
+ if(low)
+ return new String(lower(input.getBytes("US-ASCII")), "US-ASCII");
+ else
+ return new String(upper(input.getBytes("US-ASCII")), "US-ASCII");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return "Error";
+ }
+ }
+
+ public String decode(String input) {
+ try {
+ if(low)
+ return new String(upper(input.getBytes("US-ASCII")), "US-ASCII");
+ else
+ return new String(lower(input.getBytes("US-ASCII")), "US-ASCII");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return "Error";
+ }
+ }
+
+ private byte[] upper(byte[] ba) {
+ for(int i = 0; i<ba.length; i++)
+ if(ba[i] > 96 && ba[i] < 123)
+ ba[i] -= 32;
+ return ba;
+ }
+
+ private byte[] lower(byte[] ba) {
+ for(int i = 0; i<ba.length; i++)
+ if(ba[i] > 64 && ba[i] < 91)
+ ba[i] += 32;
+ return ba;
+ }
+
+}