📄 annealingschemeframe.java
字号:
package org.theblueplanet.annealing.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import org.apache.log4j.Logger;
import org.theblueplanet.annealing.AnnealingScheme;
import org.theblueplanet.annealing.Driver;
import org.theblueplanet.annealing.FileAppenderManager;
import org.theblueplanet.util.SwingUtil;
import org.theblueplanet.util.TimerThread;
/**
* The Mother Frame for the UI layer of the JSimul package
*
* @author Charles M間nin
* @since October 29, 2001
* @version 1.0
*/
public class AnnealingSchemeFrame extends JFrame {
private AnnealingScheme annealingScheme;
private ObjectiveFunctionPanel objectiveFunctionPanel;
private AnnealingPanel annealingPanel;
private NavigationPanel navigationPanel;
private FileAppenderManager fileAppenderManager = new FileAppenderManager();
private JPanel mainPanel = new JPanel(new BorderLayout());
private Runnable driver;
private int view = 0;
private static final int pause = 1000;
private static final int frameWidth = 750;
private static final int frameHeight = 325;
private static final String title = "JSimul";
private static Logger logger = Logger.getLogger("org.theblueplanet.annealing");
private int loggerFrequency = LoggerFrequencySlider.defaultValue;
/**
* Constructor for the AnnealingSchemeFrame object
*
* @param annealingScheme The Object that encapsulates the annealing parameters
*
* @exception ClassNotFoundException Description of Exception
* @exception InstantiationException Description of Exception
* @exception IllegalAccessException Description of Exception
*/
public AnnealingSchemeFrame(AnnealingScheme annealingScheme)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
super();
logger.debug("Instantiating " + this.getClass().getName());
this.annealingScheme = annealingScheme;
init();
display();
}
/**
* Sets up default parameters for the JFrame
*
* @exception ClassNotFoundException Description of Exception
* @exception InstantiationException Description of Exception
* @exception IllegalAccessException Description of Exception
*/
private void init()
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
this.setTitle(title);
this.setSize(new Dimension(frameWidth, frameHeight));
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
view = 1;
navigationPanel = new NavigationPanel(this);
mainPanel.add(navigationPanel, BorderLayout.SOUTH);
mainPanel.setDoubleBuffered(true);
objectiveFunctionPanel = new ObjectiveFunctionPanel(this, annealingScheme);
objectiveFunctionPanel.setDoubleBuffered(true);
annealingPanel = new AnnealingPanel(annealingScheme);
annealingPanel.setDoubleBuffered(true);
SwingUtil.center(this);
}
/**
* Constructs & displays the JFrame as a function of the value of the
* view parameter
*/
protected void display() {
if (getView() == 1) {
mainPanel.remove(annealingPanel);
mainPanel.add(objectiveFunctionPanel, BorderLayout.NORTH);
} else if (getView() == 2) {
try {
annealingScheme.setOfClass();
annealingScheme.setMethod();
annealingScheme.setDefaultOffset();
fileAppenderManager.updateFileAppender();
mainPanel.remove(objectiveFunctionPanel);
annealingPanel.refresh(annealingScheme);
mainPanel.add(annealingPanel, BorderLayout.CENTER);
} catch (Exception e) {
setView(1);
logger.error(e.getMessage());
}
}
this.setContentPane(mainPanel);
this.setVisible(true);
}
public void setFileAppenderState(int state) {
fileAppenderManager.setDesiredState(state);
}
protected void setLoggerFrequency(int loggerFrequency) {
this.loggerFrequency = loggerFrequency;
logger.debug("LoggerFrequency set to " + loggerFrequency);
}
protected int getLoggerFrequency() {
return loggerFrequency;
}
/**
* Calls on the Driver object to start the Simulated Annealing algorithm
*
* @see org.theblueplanet.annealing.Driver
*/
protected void launchAnnealing() {
try {
driver = new Driver(annealingScheme, loggerFrequency);
Thread driverThread = new Thread(driver);
driverThread.start();
// Pause until the driver thread returns
while(driverThread.isAlive()) {
TimerThread timer = new TimerThread(pause);
timer.start();
}
annealingPanel.refresh(annealingScheme);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Sets the View attribute of the AnnealingSchemeFrame object
*
* @param view The new View value
*/
public void setView(int view) {
this.view = view;
}
/**
* Gets the View attribute of the AnnealingSchemeFrame object
*
* @return The View value
*/
public int getView() {
return view;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -