⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loggerfrequencyslider.java

📁 模拟退火是一种启发式算法
💻 JAVA
字号:
package org.theblueplanet.annealing.ui;

import java.awt.Font;

import java.util.Hashtable;

import javax.swing.JLabel;
import javax.swing.JSlider;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.apache.log4j.Logger;


/**
 *  The temperature JSlider lying on the ObjectiveFunctionPanel
 *
 * @see org.theblueplanet.annealing.ui.SliderPanel
 *
 * @author     Charles M間nin
 * @since    October 29, 2001
 * @version    1.0
 */
public class LoggerFrequencySlider extends JSlider {
    private LoggerPanel parent;
    private static final int minValue         = 1;
    private static final int maxValue         = 1001;
    protected static final int defaultValue   = 100;
    private static final int majorTickSpacing = 200;
    private static final int minorTickSpacing = 25;

    private static final int fontSize    = 11;
    private static final int fontType    = Font.BOLD;
    private static final String fontName = "Dialog";
    private Font font                    = new Font(fontName, fontType, fontSize);

    protected Logger logger = Logger.getLogger("org.theblueplanet.annealing");

    /**
     *  Constructor for the LoggerFrequencySlider object
     *
     * @param  parent  The LoggerPanel
     */
    public LoggerFrequencySlider(LoggerPanel parent) {
        super(JSlider.HORIZONTAL, minValue, maxValue, defaultValue);
        logger.debug("Instantiating " + this.getClass().getName());
        this.parent = parent;
        init();
    }

    protected void setActivated(boolean enabled){
        this.setEnabled(enabled);
    }

    /**
     *  Sets parameters and adds Listener
     */
    private void init() {
        this.setToolTipText("Output to log every n iterations");
        this.setMajorTickSpacing(majorTickSpacing);
        this.setMinorTickSpacing(minorTickSpacing);
        this.setSnapToTicks(true);
        this.setPaintTicks(true);
        //Create the label table
        Hashtable labelTable = new Hashtable();
        JLabel label         = new JLabel("Always");
        label.setFont(font);
        labelTable.put(new Integer(1), label);
        for(int ii=minorTickSpacing ; ii<maxValue ; ii+=minorTickSpacing) {
            label = new JLabel();
            label.setFont(font);
            if(ii % majorTickSpacing == 0) {
                label.setText("" + ii);
                labelTable.put( new Integer( ii ), label );
            }
        }
        this.setLabelTable(labelTable);
        this.setPaintLabels(true);
        this.addChangeListener(new SliderListener());
    }

    /**
     *  Listens to the slider.
     */
    class SliderListener implements ChangeListener {
        public void stateChanged(ChangeEvent e) {
            JSlider source  = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int value;
                if ((int) source.getValue() != 1) {
                    value = (int) source.getValue() - 1;
                } else {
                    value = 1;
                }
                logger.debug("Slide value set to " + value);
                parent.setLoggerFrequency(value);
            }
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -