📄 defaultseditor.java
字号:
double x = 0;
try{
x = ((Double)spinner.getValue()).doubleValue();
}catch(NumberFormatException nfe){
// null
}catch(ClassCastException cce){
//null
}
if (x < 0)
x = 0;
if (x > 1)
x = 1;
spinner.setValue(new Double(x));
Defaults.set(property, Double.toString(x));
}
});
cont.add(label);
cont.add(spinner);
}
/**
* Adds an input field to chose a for a Distribution.
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
*/
protected void addInputDistribution(String text, final String property, Container cont) {
// Creates a Map with Distributions Names, then delegates addInputCombo to create graphical
// components
Map distributions = new TreeMap();
Distribution[] all = Distribution.findAll();
for (int i=0; i<all.length; i++)
distributions.put(all[i].getClass().getName(), all[i].getName());
addInputCombo(text, property, cont, distributions);
}
/**
* Adds an input field to chose a for a Routing strategy. Uses reflection to find all
* available strategies
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
*/
protected void addInputRouting(String text, final String property, Container cont) {
// Creates a Map with Routing Strategies Names, then delegates addInputCombo to create
// graphical components
Map distributions = new TreeMap();
RoutingStrategy[] all = RoutingStrategy.findAll();
for (int i=0; i<all.length; i++)
distributions.put(all[i].getClass().getName(), all[i].toString());
addInputCombo(text, property, cont, distributions);
}
/**
* Adds an input field to chose a for a Queue strategy. Uses reflection to find all
* available strategies
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
*/
protected void addInputQueueStrategy(String text, final String property, Container cont) {
// Creates a Map with Queue Strategies Names, then delegates addInputCombo to create
// graphical components
Map distributions = new TreeMap();
Field[] fields = jmt.gui.jmodel.JMODELConstants.class.getFields();
try {
for (int i=0; i<fields.length; i++)
if (fields[i].getName().startsWith("QUEUE_STRATEGY_"))
distributions.put(fields[i].get(null).toString(), fields[i].get(null).toString());
} catch (IllegalAccessException ex) {
System.err.println("A security manager has blocked reflection");
ex.printStackTrace();
}
addInputCombo(text, property, cont, distributions);
}
/**
* Adds an input field to chose a for a Drop Rule. Uses reflection to find all
* available strategies
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
*/
protected void addInputDropRule(String text, final String property, Container cont) {
// Creates a Map with Queue Strategies Names, then delegates addInputCombo to create
// graphical components
Map distributions = new TreeMap();
Field[] fields = jmt.gui.jmodel.JMODELConstants.class.getFields();
try {
for (int i=0; i<fields.length; i++)
if (fields[i].getName().startsWith("FINITE_"))
distributions.put(fields[i].get(null).toString(), fields[i].get(null).toString());
} catch (IllegalAccessException ex) {
System.err.println("A security manager has blocked reflection");
ex.printStackTrace();
}
addInputCombo(text, property, cont, distributions);
}
/**
* Adds an input field to chose a number from a Spinner. A special infinite value can be chosen
* with a checkbox
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
* @param minvalue minimum value allowed for this property
* @param infvalue special value to be stored for infinite selection
*/
protected void addInputInfSpinner(String text, final String property, Container cont, final int minvalue, final int infvalue) {
// This one is a clone of addInputSpinner but adds a checkbox to select Infinity
JLabel label;
label = new JLabel(text+":");
final JSpinner spinner = new JSpinner();
final JCheckBox inf_button = new JCheckBox();
inf_button.setText("Infinite");
JPanel internal = new JPanel(new BorderLayout(5,0));
internal.add(inf_button, BorderLayout.EAST);
internal.add(spinner, BorderLayout.CENTER);
label.setLabelFor(internal);
// If current default is infinity hides spinner and selects inf_button
if (Defaults.getAsInteger(property).intValue() == infvalue) {
spinner.setValue(new Integer(minvalue));
spinner.setEnabled(false);
inf_button.setSelected(true);
}
else
spinner.setValue(Defaults.getAsInteger(property));
// Adds a listener to support inf_button change events
inf_button.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (inf_button.isSelected()) {
spinner.setEnabled(false);
Defaults.set(property, Integer.toString(infvalue));
}
else {
spinner.setEnabled(true);
Defaults.set(property, spinner.getValue().toString());
}
}
});
// Sets maximum size to minimal one, otherwise springLayout will stretch this
internal.setMaximumSize(new Dimension(internal.getMaximumSize().width,
internal.getMinimumSize().height));
spinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
//stop editing text inside spinner
try{
spinner.commitEdit();
}catch(ParseException pe){
//if string does not represent a number, return
return;
}
//new number of classes
int x = minvalue;
try{
x = ((Integer)spinner.getValue()).intValue();
}catch(NumberFormatException nfe){
//null
}catch(ClassCastException cce){
//null
}
if (x < minvalue)
x = minvalue;
spinner.setValue(new Integer(x));
Defaults.set(property, Integer.toString(x));
}
});
cont.add(label);
cont.add(internal);
}
/**
* Adds a ComboBox to select a boolean property
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
*/
protected void addBooleanComboBox(String text, final String property, Container cont) {
JLabel label = new JLabel(text+":");
JComboBox combo = new JComboBox(new Object[]{Boolean.TRUE.toString(), Boolean.FALSE.toString()});
combo.setName(property);
label.setLabelFor(combo);
combo.setSelectedItem(Defaults.get(property));
// Sets maximum size to minimal one, otherwise springLayout will stretch this
combo.setMaximumSize(new Dimension(combo.getMaximumSize().width,
combo.getMinimumSize().height));
combo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
Defaults.set(property, (String)e.getItem());
}
});
cont.add(label);
cont.add(combo);
}
protected void addInputAnimationSpinner(String text, final String booleanProperty,final String valueProperty, Container cont, final int minvalue, final int maxvalue) {
// This one is a clone of addInputSpinner but adds a checkbox to select Infinity
JLabel label;
label = new JLabel(text+":");
final JSpinner spinner = new JSpinner();
final JCheckBox animation_button = new JCheckBox();
animation_button.setText("Animation");
JPanel internal = new JPanel(new BorderLayout(5,0));
internal.add(animation_button, BorderLayout.EAST);
internal.add(spinner, BorderLayout.CENTER);
label.setLabelFor(internal);
// If current default is !animation hides spinner and deselects animation_button
if (Defaults.getAsBoolean(booleanProperty).booleanValue()) {
spinner.setEnabled(true);
animation_button.setSelected(true);
}
else {
spinner.setEnabled(false);
animation_button.setSelected(false);
}
spinner.setValue(Defaults.getAsInteger(valueProperty));
// Adds a listener to support animation_button change events
animation_button.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (animation_button.isSelected()) {
spinner.setEnabled(true);
Defaults.set(booleanProperty,"true");
}
else {
spinner.setEnabled(false);
Defaults.set(booleanProperty,"false");
}
}
});
// Sets maximum size to minimal one, otherwise springLayout will stretch this
internal.setMaximumSize(new Dimension(internal.getMaximumSize().width,
internal.getMinimumSize().height));
spinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
//stop editing text inside spinner
try{
spinner.commitEdit();
}catch(ParseException pe){
//if string does not represent a number, return
return;
}
//new number of represented classes
int x = 0;
try{
x = ((Integer)spinner.getValue()).intValue();
}catch(NumberFormatException nfe){
//null
}catch(ClassCastException cce){
//null
}
if ((x < minvalue) || (x > maxvalue))
x = Defaults.getAsInteger(valueProperty).intValue();
spinner.setValue(new Integer(x));
Defaults.set(valueProperty, Integer.toString(x));
}
});
cont.add(label);
cont.add(internal);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -