📄 valuatorcontrols.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.ui.*;import com.well.www.user.xanthian.java.tools.*;public class ValuatorControls{ private final static int VAL_CONFIG_NUMCITIES = 0; private final static int VAL_CONFIG_POPSIZE = 1; private final static int VAL_CONFIG_MUTERATE = 2; private final static int BTN_SUB_1000 = 0; private final static int BTN_SUB_100 = 1; private final static int BTN_SUB_10 = 2; private final static int BTN_SUB_1 = 3; private final static int BTN_ADD_1 = 4; private final static int BTN_ADD_10 = 5; private final static int BTN_ADD_100 = 6; private final static int BTN_ADD_1000 = 7; private final static int BTN_COUNT = 8; private final static String VALUES_NAME = "旅行商参数设置菜单"; private static EdgedPanel m_valuesPanel = null; private static TravellerFrame m_valuesFrame = null; private final static String [] VAL_CONFIG_LABEL = { "城市数: ", "群体大小: ", "变异概率 0.01%: " };/*** This may not be used / useful.*/ private final static String [] VAL_CONFIG_DEF = { "4", // nodes / cities "4", // travelers / genomes /chromosomes "1" // tenths of a percent of mutation rate }; // configuration private static int m_numCities = 0; private static int m_popSize = 0; private static int m_mutationRate = 0; private static Label [] m_valuatorTextFields; private static Button [][] m_btnAddSub;/*** KPD Added extra increment and decrement buttons to save wear and tear** on mouse buttons and nerves. Ugly, but nice. Changed size of applet** window frame to compensate. Modified limits of population and city** count to allow more flexibility, now that it isn't such a pain to set** the sizes over a wide range. Minimum path is a triangle, minimum** population is the elite genome, plus two more.*/ private static class DecNumCities_1000 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_numCities > 3) { m_numCities -= 1000; if (m_numCities < 3) m_numCities = 3; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } } private static class DecNumCities_100 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_numCities > 3) { m_numCities -= 100; if (m_numCities < 3) m_numCities = 3; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } } private static class DecNumCities_10 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_numCities > 3) { m_numCities -= 10; if (m_numCities < 3) m_numCities = 3; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } } private static class DecNumCities_1 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_numCities > 3) { m_numCities -= 1; if (m_numCities < 3) m_numCities = 3; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } } private static class IncNumCities_1 implements ActionListener { public void actionPerformed(ActionEvent event) { m_numCities += 1; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } private static class IncNumCities_10 implements ActionListener { public void actionPerformed(ActionEvent event) { m_numCities += 10; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } private static class IncNumCities_100 implements ActionListener { public void actionPerformed(ActionEvent event) { m_numCities += 100; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } private static class IncNumCities_1000 implements ActionListener { public void actionPerformed(ActionEvent event) { m_numCities += 1000; m_valuatorTextFields[VAL_CONFIG_NUMCITIES].setText(String.valueOf(m_numCities)); m_valuatorTextFields[VAL_CONFIG_NUMCITIES].repaint(); } } private static class DecPopSize_1000 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_popSize > 3) { m_popSize -= 1000; if (m_popSize < 3) m_popSize = 3; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } } private static class DecPopSize_100 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_popSize > 3) { m_popSize -= 100; if (m_popSize < 3) m_popSize = 3; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } } private static class DecPopSize_10 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_popSize > 3) { m_popSize -= 10; if (m_popSize < 3) m_popSize = 3; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } } private static class DecPopSize_1 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_popSize > 3) { m_popSize -= 1; if (m_popSize < 3) m_popSize = 3; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } } private static class IncPopSize_1 implements ActionListener { public void actionPerformed(ActionEvent event) { m_popSize += 1; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } private static class IncPopSize_10 implements ActionListener { public void actionPerformed(ActionEvent event) { m_popSize += 10; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } private static class IncPopSize_100 implements ActionListener { public void actionPerformed(ActionEvent event) { m_popSize += 100; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } private static class IncPopSize_1000 implements ActionListener { public void actionPerformed(ActionEvent event) { m_popSize += 1000; m_valuatorTextFields[VAL_CONFIG_POPSIZE].setText(String.valueOf(m_popSize)); m_valuatorTextFields[VAL_CONFIG_POPSIZE].repaint(); } } private static class DecMutation_1000 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate > 0) { m_mutationRate -= 1000; if (m_mutationRate < 0) { m_mutationRate = 0; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static class DecMutation_100 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate > 0) { m_mutationRate -= 100; if (m_mutationRate < 0) { m_mutationRate = 0; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static class DecMutation_10 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate > 0) { m_mutationRate -= 10; if (m_mutationRate < 0) { m_mutationRate = 0; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static class DecMutation_1 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate > 0) { m_mutationRate -= 1; if (m_mutationRate < 0) { m_mutationRate = 0; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static class IncMutation_1 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate < 10000) { m_mutationRate += 1; if (m_mutationRate > 10000) { m_mutationRate = 10000; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static class IncMutation_10 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate < 10000) { m_mutationRate += 10; if (m_mutationRate > 10000) { m_mutationRate = 10000; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static class IncMutation_100 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate < 10000) { m_mutationRate += 100; if (m_mutationRate > 10000) { m_mutationRate = 10000; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static class IncMutation_1000 implements ActionListener { public void actionPerformed(ActionEvent event) { if (m_mutationRate < 10000) { m_mutationRate += 1000; if (m_mutationRate > 10000) { m_mutationRate = 10000; } m_valuatorTextFields[VAL_CONFIG_MUTERATE] .setText( mutationRateAsString() ); m_valuatorTextFields[VAL_CONFIG_MUTERATE].repaint(); } } } private static ActionListener [][] m_cfgAddSubListeners = { { new DecNumCities_1000(), new DecNumCities_100(),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -