📄 pushbuttoncontrols.java
字号:
/*** This code class was written by Kent Paul Dolan. Most of its contents** were removed from Scott Robert Ladd's Traveller.java and** TravellerWorld.java source files; see those files for Scott's** copyright rules. See accompanying file TravellerDoc.html for status** of the modifications here (an extensive refactoring and rewrite) for** your use.*/package com.well.www.user.xanthian.java.ui;import java.awt.*;import java.awt.event.*;import com.coyotegulch.genetic.*;import com.coyotegulch.ui.*;import com.well.www.user.xanthian.java.tools.*;public class PushButtonControls{/*** Private event listening classes for toolbar buttons.*/ private static class ActionStop implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Stop\" pushed" ); } TravellerWorld.getTravellerWorld().stop(); setButtonsStopped(); TravellerStatus.signalStop(); } } private static class ActionResume implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Resume\" pushed" ); } TravellerStatus.signalResume(); setButtonsRunning(); TravellerWorld.getTravellerWorld().start(); } } private static class ActionStart implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Start\" pushed" ); } setButtonsRunning(); TravellerStatus.signalStart(); PermutationController.newProblem(); TravellerWorld.getTravellerWorld().start(); } } private static class ActionTestAgain implements ActionListener { // This is purely a convenience class, introduced // for the instrumented versions of Traveller, // to simplify running long series of tests with the // same configuration settings. It performs the // same actions with one "Test Again" button press // as pressing "Stop", "Create New Cities", "Start" // in that order. This in turn is purely motivated // by the slowness of accurately pointing at each // button with the touch pad of the computer where // these changes are being developed. KPD. public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Test Again\" pushed" ); } // Need to turn this off early, to cure multi-bounce problems; // cannot wait world to stop, which takes until the end of the // generation processing. m_btnToolbar[BTN_TESTAGAIN].setEnabled(false);/*** KPD FIXME I don't yet know a way to invoke the buttons' actions from** code, so replicate their contents, instead. Yes I do, pull the code out separately and execute it independently. Do as time allows.*/ // do button Stop actions TravellerWorld.getTravellerWorld().stop(); setButtonsStopped(); TravellerStatus.signalStop(); // do button Create New Cities actions // create world image TravellerWorld.newWorld(); // set button status // setButtonsStopped(); // do button Start actions setButtonsRunning(); TravellerStatus.signalStart(); PermutationController.newProblem(); TravellerWorld.getTravellerWorld().start(); } } private static class ActionReset implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Reset\" pushed" ); } setButtonsNewProblem(); TravellerStatus.signalReset(); // new chromosomes TravellerWorld.getTravellerWorld().resetChromosomes(); ((TravellerWorld.getTravellerWorld()).getRouteCanvas()).redraw(); ((TravellerWorld.getTravellerWorld()).getRouteCanvas()).repaint(); } } private static class ActionNewCities implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"New Cities\" pushed" ); } // create world image TravellerWorld.newWorld(); // set button status setButtonsNewProblem(); TravellerStatus.signalNewCities(); } } // arrays of listeners to be assigned to controls private static ActionListener [] m_btnToolbarListeners = { new ActionStop(), new ActionResume(), new ActionStart(), new ActionTestAgain(), new ActionReset(), new ActionNewCities() }; private static class ActionConfigChange implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Change Configuration\" pushed" ); } setButtonsChanging(); } } private static class ActionConfigSet implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Set Configuration\" pushed" ); } saveConfig(); setButtonsNewProblem(); // create world image TravellerWorld.newWorld(); } } private static class ActionConfigDefault implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Restore Default\" pushed" ); } loadDefaultConfig(); } } private static ActionListener [] m_btnConfigListeners = { new ActionConfigChange(), new ActionConfigSet(), new ActionConfigDefault() }; private static class ActionHeuristicsOn implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Enable All Heuristics\" pushed" ); } CheckBoxControls.heuristicsOn(); } } private static class ActionHeuristicsOff implements ActionListener { public void actionPerformed(ActionEvent event) { if (CheckBoxControls.getState(CheckBoxControls.CBC_DEBUG_PRINTOUTS)) { System.out.println ( "in Traveller.java, button \"Disable All Heuristics\" pushed" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -