📄 toleranceslider.java
字号:
package org.theblueplanet.annealing.ui;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.apache.log4j.Logger;
import org.theblueplanet.annealing.AnnealingScheme;
/**
* Description of the Class
*
* @author Charles M間nin
* @since October 29, 2001
* @version 1.0
*/
public class ToleranceSlider extends JSlider {
private AnnealingScheme scheme;
private AnnealingPanel parent;
private final static int minValue = -20;
private final static int maxValue = -1;
private static Logger logger = Logger.getLogger("org.theblueplanet.annealing");
/**
* Constructor for the ToleranceSlider object
*
* @param parent The AnnealingPanel that instantiated the ToleranceSlider
* @param scheme The Object that encapsulates the annealing parameters
*/
public ToleranceSlider(AnnealingPanel parent, AnnealingScheme scheme) {
super(JSlider.HORIZONTAL, minValue, maxValue, (int) Math.round(Math.log(scheme.getTolerance()) / Math.log(10)));
logger.debug("Instantiating " + this.getClass().getName());
this.scheme = scheme;
this.parent = parent;
init();
}
/**
* Sets parameters and adds Listener
*/
private void init() {
this.setMajorTickSpacing(2);
this.setPaintTicks(true);
this.setPaintLabels(true);
this.addChangeListener(new SliderListener());
this.setToolTipText("Log10 of convergence criterion (-20: lowest tolerance/slow | -1: highest tolerance/fast)");
}
/**
* Listens to the slider.
*/
private class SliderListener implements ChangeListener {
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
double value = (double) source.getValue();
scheme.setTolerance(Math.pow(10, value));
parent.updateSummaryPanel(scheme);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -