📄 temperatureslider.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;
/**
* The temperature JSlider lying on the SliderPanel
*
* @see org.theblueplanet.annealing.ui.SliderPanel
*
* @author Charles M間nin
* @since October 29, 2001
* @version 1.0
*/
public class TemperatureSlider extends JSlider {
private AnnealingScheme scheme;
private AnnealingPanel parent;
private static final int minValue = 0;
private static final int maxValue = 9;
private static Logger logger = Logger.getLogger("org.theblueplanet.annealing");
/**
* Constructor for the TemperatureSlider object
*
* @param parent The AnnealingPanel that instantiated the TemperatureSlider
* @param scheme The Object that encapsulates the annealing parameters
*/
public TemperatureSlider(AnnealingPanel parent, AnnealingScheme scheme) {
super(JSlider.HORIZONTAL, minValue, maxValue, (int) Math.round(Math.log(scheme.getTemperature()) / 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.setToolTipText("Log10 of initial temperature");
this.setMajorTickSpacing(1);
this.setSnapToTicks(true);
this.setPaintTicks(true);
this.setPaintLabels(true);
this.addChangeListener(new SliderListener());
}
/**
* 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.setTemperature(Math.pow(10, value));
parent.updateSummaryPanel(scheme);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -