Browse Source

Benutzerstudienmaßnahme: Iterations JTextfield FocusLeft + VisualFancy

Tom Troppmann 6 years ago
parent
commit
1efc2e2b7d
2 changed files with 28 additions and 15 deletions
  1. 2 1
      src/ui/view/GUI.java
  2. 26 14
      src/ui/view/TimePanel.java

+ 2 - 1
src/ui/view/GUI.java

@@ -2078,7 +2078,8 @@ public class GUI implements CategoryListener {
 		mItemBattery.addActionListener(actionEvent -> {
 			new NewPopUp(controller,Option.Battery, frmCyberPhysical);
 		});
-		btnAdd.addActionListener(actionEvent -> btnAddPopUp.show(btnAdd, 0, 0));
+		btnAdd.addActionListener(actionEvent -> btnAddPopUp.show(btnAdd, -1, +20));
+		btnAdd.setToolTipText("Add a new Category or Item to the library.");
 		toolBar.add(btnAdd);
 		/**
 		 * Help Menu Action Listeners

+ 26 - 14
src/ui/view/TimePanel.java

@@ -34,13 +34,13 @@ 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);
 	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() {
 		/**
 		 *
@@ -277,31 +277,35 @@ public class TimePanel extends JPanel implements ActionListener{
 		btnAndSpeedPanel.add(speedPanel, BorderLayout.CENTER);
 		iterationsPanel.setLayout(new GridLayout(3,1));
 		iterationsPanel.add(iterationsLabel, BorderLayout.NORTH);
-		iterationsLblHint=new LabelHint(iterationsLabel);
+		//iterationsLblHint=new LabelHint(iterationsLabel);
+		JLabel hint = new JLabel("Invalid", SwingConstants.RIGHT);
+		hint.setForeground(Color.red);
+		hint.setVisible(false);
 		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.setVisible(false);
 				}catch(NumberFormatException n){
-					iterationsLblHint.go("Invalid");
 					iterationsField.setBackground(GUI.PALE_RED);//red stings
+					hint.setVisible(true);
 				}
 			}
 		);
+		iterationsField.addFocusListener(new java.awt.event.FocusAdapter() {
+			    public void focusLost (java.awt.event.FocusEvent evt) {
+			    	updateIterationsInput();
+			    }
+			});
 		iterationsPanel.add(iterationsField);
-		iterationsPanel.add(new JLabel(), BorderLayout.SOUTH);
+		iterationsPanel.add(hint);
+		//iterationsPanel.add(new JLabel(), BorderLayout.SOUTH);
 		timePanel.setLayout(new BorderLayout());
 		timePanel.add(iterationsPanel, BorderLayout.WEST);
 		timePanel.add(timeSlider, BorderLayout.CENTER);
@@ -354,9 +358,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;