📄 niterationsslider.java
字号:
package org.theblueplanet.annealing.ui;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.apache.log4j.Logger;
import org.theblueplanet.annealing.AnnealingScheme;
/**
* JSlider to set the number of iterations before cooling is applied
*
* @author Charles M間nin
* @since October 29, 2001
* @version 1.0
*/
public class NIterationsSlider extends JSlider {
private AnnealingScheme scheme;
private AnnealingPanel parent;
private static final int minValue = 0;
private static final int maxValue = 100;
private static Logger logger = Logger.getLogger("org.theblueplanet.annealing");
/**
* Constructor for the NIterationsSlider object
*
* @param parent The AnnealingPanel that instantiated the NIterationsSlider
* @param scheme The Object that encapsulates the annealing parameters
*/
public NIterationsSlider(AnnealingPanel parent, AnnealingScheme scheme) {
super(JSlider.HORIZONTAL, minValue, maxValue, scheme.getNIterations());
logger.debug("Instantiating " + this.getClass().getName());
this.scheme = scheme;
this.parent = parent;
init();
}
/**
* Sets parameters and adds Listener
*/
private void init() {
this.setToolTipText("Number of iterations before cooling is applied");
this.setMajorTickSpacing(10);
this.setMinorTickSpacing(5);
this.setPaintTicks(true);
this.setPaintLabels(true);
this.addChangeListener(new SliderListener());
}
private class SliderListener implements ChangeListener {
/**
* The slider listener
*
* @param e The Event triggered
*/
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
int value = (int) source.getValue();
scheme.setNIterations(value);
parent.updateSummaryPanel(scheme);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -