| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
package com.transformers.supermangletron; |
| 24 |
|
| 25 |
|
| 26 |
import java.text.SimpleDateFormat; |
| 27 |
import java.util.Date; |
| 28 |
|
| 29 |
import javax.swing.JOptionPane; |
| 30 |
|
| 31 |
import processing.app.Editor; |
| 32 |
import processing.app.tools.Tool; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class Mangler implements Tool { |
| 40 |
Editor editor; |
| 41 |
|
| 42 |
|
| 43 |
public void init(Editor editor) { |
| 44 |
this.editor = editor; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
public String getMenuTitle() { |
| 49 |
return "Mangle Selection"; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
public void run() { |
| 54 |
String sketchName = editor.getSketch().getName(); |
| 55 |
|
| 56 |
Object[] options = { "Yes, please", "No, thanks" }; |
| 57 |
int result = JOptionPane.showOptionDialog(editor, |
| 58 |
"Is " + sketchName + |
| 59 |
" ready for destruction?", |
| 60 |
"Super Mangle Tron", |
| 61 |
JOptionPane.YES_NO_OPTION, |
| 62 |
JOptionPane.QUESTION_MESSAGE, |
| 63 |
null, |
| 64 |
options, |
| 65 |
options[1]); |
| 66 |
if (result == JOptionPane.YES_OPTION) { |
| 67 |
mangleSelection(); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
protected void mangleSelection() { |
| 73 |
|
| 74 |
if (editor.getCurrentTab().getSelectedText() != null) { |
| 75 |
String selection = editor.getCurrentTab().getSelectedText(); |
| 76 |
char[] stuff = selection.toCharArray(); |
| 77 |
|
| 78 |
for (int i = 0; i < stuff.length / 10; i++) { |
| 79 |
int a = (int) (Math.random() * stuff.length); |
| 80 |
int b = (int) (Math.random() * stuff.length); |
| 81 |
if (stuff[a] == '\n' || stuff[b] == '\n') { |
| 82 |
continue; |
| 83 |
} |
| 84 |
stuff[a] = selection.charAt(b); |
| 85 |
stuff[b] = selection.charAt(a); |
| 86 |
} |
| 87 |
editor.getCurrentTab().setSelectedText(new String(stuff)); |
| 88 |
editor.statusNotice("Now that feels better, doesn't it?"); |
| 89 |
|
| 90 |
} else { |
| 91 |
|
| 92 |
editor.statusError("No selection, no dice."); |
| 93 |
} |
| 94 |
} |
| 95 |
} |