mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-07 04:28:00 +02:00
Finished automated GUI generation out of a Options Tree
This commit is contained in:
parent
f13fcf39e1
commit
c989b9f025
@ -1,41 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class BooleanOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
public BooleanOption(String name, boolean initialValue) {
|
||||
|
||||
super(name, String.valueOf(initialValue));
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JLabel l = new JLabel(this.getIdentifier());
|
||||
l.setPreferredSize(new Dimension(l.getPreferredSize().width+10, l.getPreferredSize().height));
|
||||
|
||||
this.add(l, BorderLayout.CENTER);
|
||||
|
||||
JCheckBox checkBox = new JCheckBox();
|
||||
checkBox.setSelected(initialValue);
|
||||
checkBox.addChangeListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent arg0) {
|
||||
setValue(String.valueOf(((JCheckBox)arg0.getSource()).isSelected()));
|
||||
}
|
||||
});
|
||||
|
||||
this.add(checkBox, BorderLayout.WEST);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
public abstract class ChildOption extends Option {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4648294833934457776L;
|
||||
|
||||
private String value;
|
||||
|
||||
public ChildOption(String identifier, String value) {
|
||||
super(identifier);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public final void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public final String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
public class EmptyOption extends Option {
|
||||
|
||||
public EmptyOption() {
|
||||
super("");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 5058363675498808020L;
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
import javax.swing.InputVerifier;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class EmptyVerifier extends InputVerifier {
|
||||
|
||||
@Override
|
||||
public boolean verify(JComponent input) {
|
||||
JTextField text = (JTextField)input;
|
||||
ChildOption parent = (ChildOption) text.getParent();
|
||||
|
||||
try{
|
||||
parent.setValue(text.getText());
|
||||
return true;
|
||||
}
|
||||
catch(Exception e) {
|
||||
text.setText(parent.getValue());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
|
||||
public class IntegerOption extends TextFieldOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
public IntegerOption(String name, int initialValue, int width) {
|
||||
|
||||
super(name, String.valueOf(initialValue), width, new IntegerVerifier("Only integers are allowed in this field."));
|
||||
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
import javax.swing.InputVerifier;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class IntegerVerifier extends InputVerifier {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public IntegerVerifier(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(JComponent input) {
|
||||
JTextField text = (JTextField)input;
|
||||
ChildOption parent = (ChildOption) text.getParent();
|
||||
|
||||
try{
|
||||
Integer.parseInt(text.getText());
|
||||
parent.setValue(text.getText());
|
||||
return true;
|
||||
}
|
||||
catch(Exception e) {
|
||||
JOptionPane.showMessageDialog(text, errorMessage);
|
||||
|
||||
text.setText(parent.getValue());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class LogLevelOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1609308017422576285L;
|
||||
|
||||
public LogLevelOption(String identifier, String initialValue) {
|
||||
|
||||
super(identifier, initialValue);
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
this.add(new JLabel(this.getIdentifier()), BorderLayout.CENTER);
|
||||
|
||||
JComboBox box = new JComboBox();
|
||||
|
||||
String options[] = { "off", "low", "med", "high" };
|
||||
|
||||
boolean found = false;
|
||||
|
||||
box.addItemListener(new ItemListener() {
|
||||
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent arg0) {
|
||||
setValue(arg0.getItem().toString());
|
||||
}
|
||||
});
|
||||
|
||||
for(String s : options) {
|
||||
box.addItem(s);
|
||||
if(s.equals(initialValue)) { box.setSelectedItem(s); found = true; }
|
||||
}
|
||||
|
||||
|
||||
if(!found) box.setSelectedItem("off");
|
||||
|
||||
this.add(box, BorderLayout.WEST);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public abstract class Option extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6710455693749974103L;
|
||||
|
||||
private final String identifier;
|
||||
|
||||
public Option(String identifier) {
|
||||
this.identifier = identifier;
|
||||
this.setMinimumSize(new Dimension(this.getPreferredSize().height, this.getPreferredSize().width));
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
public class StringOption extends TextFieldOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
public StringOption(String name, String initialValue, int width) {
|
||||
super(name, initialValue, width, new EmptyVerifier());
|
||||
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.InputVerifier;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public abstract class TextFieldOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8189248456599421250L;
|
||||
|
||||
public TextFieldOption(String name, String initialValue, int width, final InputVerifier inputVerifier) {
|
||||
|
||||
super(name, String.valueOf(initialValue));
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
this.add(new JLabel(this.getIdentifier()), BorderLayout.CENTER);
|
||||
|
||||
JTextField textField = new JTextField();
|
||||
textField.setText(this.getValue());
|
||||
textField.setColumns(width);
|
||||
textField.setInputVerifier(inputVerifier);
|
||||
|
||||
this.add(textField, BorderLayout.WEST);
|
||||
|
||||
}
|
||||
}
|
@ -1,16 +1,26 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.gui.ParentOptionGui;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.BooleanOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.IntegerOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.LogLevelOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.MediumStringOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.Option;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ParentOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.LongStringOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ShortStringOption;
|
||||
|
||||
public class Wizard extends JFrame {
|
||||
|
||||
/**
|
||||
@ -20,11 +30,6 @@ public class Wizard extends JFrame {
|
||||
|
||||
private static final String pre = " ";
|
||||
|
||||
private static final int numberWidth = 4;
|
||||
private static final int wordWidth = 10;
|
||||
private static final int fileWidth = 20;
|
||||
private static final int textWidth = 60;
|
||||
|
||||
public Wizard() {
|
||||
|
||||
JScrollPane scrollable = new JScrollPane();
|
||||
@ -36,21 +41,19 @@ public class Wizard extends JFrame {
|
||||
JPanel inside = new JPanel();
|
||||
scrollable.setViewportView(inside);
|
||||
|
||||
inside.setLayout(new FlowLayout());
|
||||
|
||||
|
||||
inside.setLayout(new BoxLayout(inside,BoxLayout.Y_AXIS));
|
||||
|
||||
final ParentOption root = new ParentOption("");
|
||||
inside.add(root);
|
||||
|
||||
ParentOption loggingNode = new ParentOption("logging");
|
||||
root.add(loggingNode);
|
||||
|
||||
loggingNode.add(new StringOption("filename", "plugins/NoCheat/nocheat.log", fileWidth));
|
||||
loggingNode.add(new LogLevelOption("logtofile", "low"));
|
||||
loggingNode.add(new LogLevelOption("logtoconsole", "high"));
|
||||
loggingNode.add(new LogLevelOption("logtochat", "med"));
|
||||
loggingNode.add(new LogLevelOption("logtoirc", "med"));
|
||||
loggingNode.add(new StringOption("logtoirctag", "nocheat", wordWidth));
|
||||
loggingNode.add(new MediumStringOption("filename", "plugins/NoCheat/nocheat.log"));
|
||||
loggingNode.add(new LogLevelOption("logtofile", LogLevelOption.Options.LOW));
|
||||
loggingNode.add(new LogLevelOption("logtoconsole", LogLevelOption.Options.HIGH));
|
||||
loggingNode.add(new LogLevelOption("logtochat", LogLevelOption.Options.MED));
|
||||
loggingNode.add(new LogLevelOption("logtoirc", LogLevelOption.Options.MED));
|
||||
loggingNode.add(new ShortStringOption("logtoirctag", "nocheat"));
|
||||
|
||||
ParentOption activeNode = new ParentOption("active");
|
||||
root.add(activeNode);
|
||||
@ -65,29 +68,29 @@ public class Wizard extends JFrame {
|
||||
ParentOption speedhackNode = new ParentOption("speedhack");
|
||||
root.add(speedhackNode);
|
||||
|
||||
speedhackNode.add(new StringOption("logmessage", "\"%1$s sent %2$d move events, but only %3$d were allowed. Speedhack?\"", textWidth));
|
||||
speedhackNode.add(new LongStringOption("logmessage", "\"%1$s sent %2$d move events, but only %3$d were allowed. Speedhack?\""));
|
||||
|
||||
{
|
||||
ParentOption speedhackLimitsNode = new ParentOption("limits");
|
||||
speedhackNode.add(speedhackLimitsNode);
|
||||
|
||||
speedhackLimitsNode.add(new IntegerOption("low", 30, numberWidth));
|
||||
speedhackLimitsNode.add(new IntegerOption("med", 45, numberWidth));
|
||||
speedhackLimitsNode.add(new IntegerOption("high", 60, numberWidth));
|
||||
speedhackLimitsNode.add(new IntegerOption("low", 30));
|
||||
speedhackLimitsNode.add(new IntegerOption("med", 45));
|
||||
speedhackLimitsNode.add(new IntegerOption("high", 60));
|
||||
|
||||
ParentOption speedhackActionNode = new ParentOption("action");
|
||||
speedhackNode.add(speedhackActionNode);
|
||||
|
||||
speedhackActionNode.add(new StringOption("low", "loglow cancel", fileWidth));
|
||||
speedhackActionNode.add(new StringOption("med", "logmed cancel", fileWidth));
|
||||
speedhackActionNode.add(new StringOption("high", "loghigh cancel", fileWidth));
|
||||
speedhackActionNode.add(new MediumStringOption("low", "loglow cancel"));
|
||||
speedhackActionNode.add(new MediumStringOption("med", "logmed cancel"));
|
||||
speedhackActionNode.add(new MediumStringOption("high", "loghigh cancel"));
|
||||
}
|
||||
|
||||
ParentOption movingNode = new ParentOption("moving");
|
||||
root.add(movingNode);
|
||||
|
||||
movingNode.add(new StringOption("logmessage", "\"Moving violation: %1$s from %2$s (%4$.1f, %5$.1f, %6$.1f) to %3$s (%7$.1f, %8$.1f, %9$.1f)\"", textWidth));
|
||||
movingNode.add(new StringOption("summarymessage", "\"Moving summary of last ~%2$d seconds: %1$s total Violations: (%3$d,%4$d,%5$d)\"", textWidth));
|
||||
movingNode.add(new LongStringOption("logmessage", "\"Moving violation: %1$s from %2$s (%4$.1f, %5$.1f, %6$.1f) to %3$s (%7$.1f, %8$.1f, %9$.1f)\""));
|
||||
movingNode.add(new LongStringOption("summarymessage", "\"Moving summary of last ~%2$d seconds: %1$s total Violations: (%3$d,%4$d,%5$d)\""));
|
||||
movingNode.add(new BooleanOption("allowflying", false));
|
||||
movingNode.add(new BooleanOption("allowfakesneak", true));
|
||||
|
||||
@ -95,9 +98,9 @@ public class Wizard extends JFrame {
|
||||
ParentOption movingActionNode = new ParentOption("action");
|
||||
movingNode.add(movingActionNode);
|
||||
|
||||
movingActionNode.add(new StringOption("low", "loglow cancel", fileWidth));
|
||||
movingActionNode.add(new StringOption("med", "logmed cancel", fileWidth));
|
||||
movingActionNode.add(new StringOption("high", "loghigh cancel", fileWidth));
|
||||
movingActionNode.add(new MediumStringOption("low", "loglow cancel"));
|
||||
movingActionNode.add(new MediumStringOption("med", "logmed cancel"));
|
||||
movingActionNode.add(new MediumStringOption("high", "loghigh cancel"));
|
||||
}
|
||||
|
||||
ParentOption airbuildNode = new ParentOption("airbuild");
|
||||
@ -107,32 +110,32 @@ public class Wizard extends JFrame {
|
||||
ParentOption airbuildLimitsNode = new ParentOption("limits");
|
||||
airbuildNode.add(airbuildLimitsNode);
|
||||
|
||||
airbuildLimitsNode.add(new IntegerOption("low", 30, numberWidth));
|
||||
airbuildLimitsNode.add(new IntegerOption("med", 45, numberWidth));
|
||||
airbuildLimitsNode.add(new IntegerOption("high", 60, numberWidth));
|
||||
airbuildLimitsNode.add(new IntegerOption("low", 30));
|
||||
airbuildLimitsNode.add(new IntegerOption("med", 45));
|
||||
airbuildLimitsNode.add(new IntegerOption("high", 60));
|
||||
|
||||
ParentOption airbuildActionNode = new ParentOption("action");
|
||||
airbuildNode.add(airbuildActionNode);
|
||||
|
||||
airbuildActionNode.add(new StringOption("low", "loglow cancel", fileWidth));
|
||||
airbuildActionNode.add(new StringOption("med", "logmed cancel", fileWidth));
|
||||
airbuildActionNode.add(new StringOption("high", "loghigh cancel", fileWidth));
|
||||
airbuildActionNode.add(new MediumStringOption("low", "loglow cancel"));
|
||||
airbuildActionNode.add(new MediumStringOption("med", "logmed cancel"));
|
||||
airbuildActionNode.add(new MediumStringOption("high", "loghigh cancel"));
|
||||
}
|
||||
|
||||
ParentOption bedteleportNode = new ParentOption("bedteleport");
|
||||
root.add(bedteleportNode);
|
||||
|
||||
bedteleportNode.add(new EmptyOption());
|
||||
|
||||
ParentOption itemdupeNode = new ParentOption("itemdupe");
|
||||
root.add(itemdupeNode);
|
||||
|
||||
itemdupeNode.add(new EmptyOption());
|
||||
|
||||
ParentOption bogusitemsNode = new ParentOption("bogusitems");
|
||||
root.add(bogusitemsNode);
|
||||
|
||||
bogusitemsNode.add(new EmptyOption());
|
||||
ParentOptionGui root2 = new ParentOptionGui(root);
|
||||
|
||||
inside.add(root2);
|
||||
|
||||
JButton b = new JButton("TEST");
|
||||
|
||||
@ -145,7 +148,7 @@ public class Wizard extends JFrame {
|
||||
JOptionPane.showMessageDialog(null, s);
|
||||
} });
|
||||
|
||||
|
||||
b.setAlignmentY(0.0F);
|
||||
inside.add(b);
|
||||
|
||||
inside.doLayout();
|
||||
|
@ -0,0 +1,99 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.InputVerifier;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.BooleanOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.LogLevelOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.TextFieldOption;
|
||||
|
||||
public class ChildOptionGuiFactory {
|
||||
|
||||
public static JComponent create(ChildOption option) {
|
||||
|
||||
if(option instanceof BooleanOption) {
|
||||
return createBoolean((BooleanOption)option);
|
||||
}
|
||||
else if(option instanceof TextFieldOption) {
|
||||
return createTextField((TextFieldOption)option);
|
||||
}
|
||||
else if(option instanceof LogLevelOption) {
|
||||
return createLogLevel((LogLevelOption)option);
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unknown ChildOption " + option);
|
||||
}
|
||||
|
||||
private static JComboBox createLogLevel(final LogLevelOption option) {
|
||||
|
||||
final JComboBox comboBox = new JComboBox();
|
||||
|
||||
for(LogLevelOption.Options o : LogLevelOption.Options.values())
|
||||
comboBox.addItem(o);
|
||||
|
||||
comboBox.setSelectedItem(option.getOptionValue());
|
||||
|
||||
comboBox.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
option.setValue((LogLevelOption.Options)comboBox.getSelectedItem());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private static JCheckBox createBoolean(final BooleanOption option) {
|
||||
|
||||
final JCheckBox checkBox = new JCheckBox();
|
||||
checkBox.setSelected(option.getBooleanValue());
|
||||
checkBox.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
option.setValue(checkBox.isSelected());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
private static JTextField createTextField(final TextFieldOption option) {
|
||||
|
||||
final JTextField textField = new JTextField(option.getValue());
|
||||
|
||||
if(option.hasPreferredLength()) {
|
||||
textField.setColumns(option.getPreferredLength());
|
||||
}
|
||||
|
||||
textField.setInputVerifier(new InputVerifier() {
|
||||
|
||||
@Override
|
||||
public boolean verify(JComponent arg0) {
|
||||
|
||||
if(option.setValue(textField.getText())){
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(textField, "Illegal value for this field");
|
||||
textField.setText(option.getValue());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return textField;
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.Option;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ParentOption;
|
||||
|
||||
public class ParentOptionGui extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 5277750257203546802L;
|
||||
|
||||
private ParentOption option;
|
||||
private LinkedList<Option> children = new LinkedList<Option>();
|
||||
|
||||
public ParentOptionGui(ParentOption option) {
|
||||
this.option = option;
|
||||
|
||||
if(option.getIdentifier().length() > 0) {
|
||||
this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(2, 2,
|
||||
2, 2, Color.BLACK), " " + option.getIdentifier() + " "),
|
||||
BorderFactory.createEmptyBorder(5,5,5,5))));
|
||||
}
|
||||
this.setLayout(new GridBagLayout());
|
||||
|
||||
for(Option o : this.option.getChildOptions()) {
|
||||
add(o);
|
||||
children.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Option option) {
|
||||
if(option instanceof ParentOption) {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = children.size();
|
||||
c.gridwidth = 3; // Spans over both columns
|
||||
c.anchor = GridBagConstraints.WEST;
|
||||
c.ipadx = 5;
|
||||
c.ipady = 15;
|
||||
c.weightx = 1;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
this.add(new ParentOptionGui((ParentOption)option), c);
|
||||
}
|
||||
else if(option instanceof ChildOption)
|
||||
{
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = children.size();
|
||||
c.gridwidth = 1; // Spans over both columns
|
||||
c.anchor = GridBagConstraints.WEST;
|
||||
c.ipadx = 10;
|
||||
c.weightx = 0;
|
||||
|
||||
this.add(new JLabel(option.getIdentifier() + ":"), c);
|
||||
|
||||
c.gridx = 1;
|
||||
c.gridy = children.size();
|
||||
c.gridwidth = 1; // Spans over both columns
|
||||
c.anchor = GridBagConstraints.WEST;
|
||||
c.ipadx = 5;
|
||||
c.weightx = 0;
|
||||
|
||||
JComponent child = ChildOptionGuiFactory.create((ChildOption)option);
|
||||
|
||||
this.add(child, c);
|
||||
|
||||
c.gridx = 2;
|
||||
c.gridy = children.size();
|
||||
c.gridwidth = 1; // Spans over both columns
|
||||
c.anchor = GridBagConstraints.WEST;
|
||||
c.ipadx = 5;
|
||||
c.weightx = 1;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
this.add(Box.createHorizontalGlue(), c);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
|
||||
public class BooleanOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
private boolean value;
|
||||
|
||||
public BooleanOption(String name, boolean initialValue) {
|
||||
|
||||
super(name);
|
||||
this.value = initialValue;
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return Boolean.toString(value);
|
||||
}
|
||||
|
||||
public boolean getBooleanValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
public abstract class ChildOption extends Option {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4648294833934457776L;
|
||||
|
||||
public ChildOption(String identifier) {
|
||||
|
||||
super(identifier);
|
||||
}
|
||||
|
||||
|
||||
public abstract String getValue();
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
|
||||
public class IntegerOption extends TextFieldOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
public IntegerOption(String name, int initialValue) {
|
||||
|
||||
super(name, String.valueOf(initialValue), 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value) {
|
||||
|
||||
if(!super.isValid(value)) return false;
|
||||
|
||||
try {
|
||||
Integer.parseInt(value);
|
||||
return true;
|
||||
}
|
||||
catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
|
||||
public class LogLevelOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1609308017422576285L;
|
||||
|
||||
private Options value;
|
||||
|
||||
|
||||
public enum Options {
|
||||
OFF("never"), LOW("all messages"), MED("important messages"), HIGH("very important messages");
|
||||
|
||||
private final String value;
|
||||
|
||||
private Options(String s) {
|
||||
this.value = s;
|
||||
}
|
||||
|
||||
public String getValue() { return this.value; }
|
||||
|
||||
public static Options getOption(String s) {
|
||||
if("off".equals(s))
|
||||
return OFF;
|
||||
else if("low".equals(s))
|
||||
return LOW;
|
||||
else if("med".equals(s))
|
||||
return MED;
|
||||
else if("high".equals(s))
|
||||
return HIGH;
|
||||
else
|
||||
return OFF;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return this.name() + ": " + getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public LogLevelOption(String identifier, Options initialValue) {
|
||||
|
||||
super(identifier);
|
||||
this.value = initialValue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value.getValue();
|
||||
}
|
||||
|
||||
public void setValue(Options value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Options getOptionValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
public class LongStringOption extends TextFieldOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
public LongStringOption(String name, String initialValue) {
|
||||
super(name, initialValue, 60);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
public class MediumStringOption extends TextFieldOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
public MediumStringOption(String name, String initialValue) {
|
||||
super(name, initialValue, 30);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
|
||||
public class Option {
|
||||
|
||||
private final String identifier;
|
||||
|
||||
public Option(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
|
||||
public class ParentOption extends Option {
|
||||
|
||||
@ -18,18 +16,6 @@ public class ParentOption extends Option {
|
||||
|
||||
public ParentOption(String identifier) {
|
||||
super(identifier);
|
||||
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
this.setAlignmentX(1.0F);
|
||||
|
||||
if(identifier.length() > 0) {
|
||||
this.setBorder(
|
||||
BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder(identifier),
|
||||
BorderFactory.createEmptyBorder(5,5,5,5)));
|
||||
}
|
||||
else
|
||||
this.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||
}
|
||||
|
||||
public final Collection<Option> getChildOptions() {
|
||||
@ -37,8 +23,9 @@ public class ParentOption extends Option {
|
||||
}
|
||||
|
||||
public final void add(Option option) {
|
||||
|
||||
children.addLast(option);
|
||||
|
||||
super.add(option);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
public class ShortStringOption extends TextFieldOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2258827414736580449L;
|
||||
|
||||
public ShortStringOption(String name, String initialValue) {
|
||||
super(name, initialValue, 10);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
public abstract class TextFieldOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8189248456599421250L;
|
||||
|
||||
private String value;
|
||||
private int length = -1;
|
||||
|
||||
public TextFieldOption(String name, String initialValue, int preferredLength) {
|
||||
|
||||
super(name);
|
||||
this.value = initialValue;
|
||||
this.length = preferredLength;
|
||||
}
|
||||
|
||||
public TextFieldOption(String name, String initialValue) {
|
||||
|
||||
super(name);
|
||||
this.value = initialValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public boolean setValue(String value) {
|
||||
if(isValid(value)) {
|
||||
this.value = value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isValid(String value) {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
public int getPreferredLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public boolean hasPreferredLength() {
|
||||
return length != -1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user