|
@@ -34,13 +34,14 @@ public class TimePanel extends JPanel implements ActionListener{
|
|
|
|
|
|
final JButton timeBackwardBtn = new JButton();
|
|
|
JTextField iterationsField;
|
|
|
- final JLabel iterationsLabel=new JLabel(" Iterations ");
|
|
|
+ final JLabel iterationsLabel=new JLabel("Iterations:" , SwingConstants.CENTER);
|
|
|
+ JLabel hint = new JLabel("Invalid", SwingConstants.RIGHT);
|
|
|
private final JPanel btnAndSpeedPanel = new JPanel();
|
|
|
private final JPanel speedPanel = new JPanel();
|
|
|
private final JPanel timeBtnPanel = new JPanel();
|
|
|
private final JPanel iterationsPanel=new JPanel();
|
|
|
private final JPanel timePanel=new JPanel();
|
|
|
- private LabelHint iterationsLblHint;
|
|
|
+ //private LabelHint iterationsLblHint;
|
|
|
JSlider timeSlider = new JSlider() {
|
|
|
/**
|
|
|
*
|
|
@@ -275,34 +276,44 @@ public class TimePanel extends JPanel implements ActionListener{
|
|
|
btnAndSpeedPanel.setBorder(null);
|
|
|
btnAndSpeedPanel.add(timeBtnPanel, BorderLayout.NORTH);
|
|
|
btnAndSpeedPanel.add(speedPanel, BorderLayout.CENTER);
|
|
|
- iterationsPanel.setLayout(new GridLayout(3,1));
|
|
|
- iterationsPanel.add(iterationsLabel, BorderLayout.NORTH);
|
|
|
- iterationsLblHint=new LabelHint(iterationsLabel);
|
|
|
+ iterationsPanel.setLayout(new GridBagLayout());
|
|
|
+ GridBagConstraints c = new GridBagConstraints();
|
|
|
+ c.anchor = GridBagConstraints.CENTER;
|
|
|
+ c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ c.gridx = 0;
|
|
|
+ c.gridy = 0;
|
|
|
+ iterationsPanel.add(iterationsLabel, c);
|
|
|
+ //iterationsLblHint=new LabelHint(iterationsLabel);
|
|
|
+ hint.setForeground(Color.red);
|
|
|
+ hint.setText(" ");
|
|
|
iterationsField=new JTextField(6);//Considering hundreds of thousands in an extreme case
|
|
|
iterationsField.setText(""+cont.getModel().getIterations());
|
|
|
+ iterationsField.setToolTipText("0-" + MAX_ITERATIONS );
|
|
|
iterationsField.addActionListener(this);
|
|
|
iterationsField.addCaretListener((e)->
|
|
|
{
|
|
|
try{
|
|
|
int a=Integer.parseInt(iterationsField.getText());
|
|
|
iterationsField.setBackground(Color.WHITE);//red stings
|
|
|
- if(
|
|
|
- a!=
|
|
|
- SingletonControl
|
|
|
- .getInstance()
|
|
|
- .getControl()
|
|
|
- .getModel()
|
|
|
- .getIterations()
|
|
|
- )iterationsLblHint.go("Press ENTER");
|
|
|
+ //this.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "like Enter")); that is lagging
|
|
|
+ hint.setText(" ");
|
|
|
}catch(NumberFormatException n){
|
|
|
- iterationsLblHint.go("Invalid");
|
|
|
iterationsField.setBackground(GUI.PALE_RED);//red stings
|
|
|
+ hint.setText("Invalid");
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
- iterationsPanel.add(iterationsField);
|
|
|
- iterationsPanel.add(new JLabel(), BorderLayout.SOUTH);
|
|
|
- timePanel.setLayout(new BorderLayout());
|
|
|
+ iterationsField.addFocusListener(new java.awt.event.FocusAdapter() {
|
|
|
+ public void focusLost (java.awt.event.FocusEvent evt) {
|
|
|
+ updateIterationsInput();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ c.gridy = 1;
|
|
|
+ iterationsPanel.add(iterationsField, c);
|
|
|
+ c.gridy = 2;
|
|
|
+ iterationsPanel.add(hint, c);
|
|
|
+ //iterationsPanel.add(new JLabel(), BorderLayout.SOUTH);
|
|
|
+ timePanel.setLayout(new BorderLayout());;
|
|
|
timePanel.add(iterationsPanel, BorderLayout.WEST);
|
|
|
timePanel.add(timeSlider, BorderLayout.CENTER);
|
|
|
this.add(btnAndSpeedPanel, BorderLayout.WEST);
|
|
@@ -354,9 +365,17 @@ public class TimePanel extends JPanel implements ActionListener{
|
|
|
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent arg0) {//I dislike anon classes.
|
|
|
+ updateIterationsInput();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Update the Text field and apply valid changes to update Iterations from to model.
|
|
|
+ * <p>
|
|
|
+ * Executed by user input.
|
|
|
+ */
|
|
|
+ private void updateIterationsInput() {
|
|
|
try{
|
|
|
int iterations=Integer.parseInt(iterationsField.getText());
|
|
|
- iterationsLblHint.reset();
|
|
|
+ //iterationsLblHint.reset();
|
|
|
boolean resetField=true;
|
|
|
if(iterations<1)iterations=1;
|
|
|
else if(iterations>MAX_ITERATIONS)iterations=MAX_ITERATIONS;
|