import javafx event ActionEvent import javafx event EventHandler impor

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
import javafx.stage.Window;
import jfx.messagebox.MessageBox;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by Kudryavtsev_A on 15.04.2014.
*/
public class GraphSettingsController implements Initializable
{
private static GraphControl graphControl;
public TextField sizeField = new TextField();
public ChoiceBox<String> nType = new ChoiceBox<String>();
public TextField exNumber = new TextField();
public TextField alpha0Field = new TextField();
public TextField alpha1Field = new TextField();
public TextField deltaAlphaField = new TextField();
private Stage graphStage;
public static void setGraphControl(GraphControl graphControl)
{
GraphSettingsController.graphControl = graphControl;
}
private void showMessageBox(String title, String message, int option)
{
Window thisWindow = sizeField.getScene().getWindow();
MessageBox.show(thisWindow, message, title, option);
}
public void startClick(ActionEvent actionEvent)
{
double start, end, step;
int number, size;
try
{
start = Double.valueOf(alpha0Field.getText());
end = Double.valueOf(alpha1Field.getText());
step = Double.valueOf(deltaAlphaField.getText());
number = Integer.valueOf(exNumber.getText());
size = Integer.valueOf(sizeField.getText());
} catch (NumberFormatException e)
{
showMessageBox("Внимание!", "Проверьте ввод!", MessageBox.ICON_ERROR | MessageBox.OK);
return;
}
if (end <= start || start + step > end || number < 1 || size < 1)
{
showMessageBox("Внимание!", "Проверьте ввод!", MessageBox.ICON_ERROR | MessageBox.OK);
return;
}
Mode mode;
if (nType.getValue().equals("4 соседа"))
{
mode = Mode.ONE;
} else
{
mode = Mode.TWO;
}
GraphControl.setCount(number);
GraphControl.setEnd(end);
GraphControl.setMode(mode);
GraphControl.setSize(size);
GraphControl.setStart(start);
GraphControl.setStep(step);
if (graphStage == null || !graphStage.isShowing())
{
showGraph();
}
graphControl.makeGraph();
}
private void showGraph()
{
Parent root = null;
try
{
root = FXMLLoader.load(getClass().getResource("graph.fxml"));
} catch (IOException e)
{
e.printStackTrace();
}
graphStage = new Stage();
graphStage.setTitle("Аниматор");
graphStage.getIcons().add(new Image("logo.png"));
graphStage.setScene(new Scene(root));
graphStage.show();
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
{
nType.getItems().add("4 соседа");
nType.getItems().add("8 соседей");
nType.setValue("4 соседа");
EventHandler<KeyEvent> eventHandler1 = new EventHandler<KeyEvent>()
{
@Override
public void handle(KeyEvent inputevent)
{
if (!inputevent.getCharacter().matches("\\d"))
{
inputevent.consume();
}
}
};
exNumber.addEventFilter(KeyEvent.KEY_TYPED, eventHandler1);
sizeField.addEventFilter(KeyEvent.KEY_TYPED, eventHandler1);
EventHandler<KeyEvent> eventHandler = new EventHandler<KeyEvent>()
{
@Override
public void handle(KeyEvent keyEvent)
{
if (!keyEvent.getCharacter().matches("[\\d , \\.]"))
{
keyEvent.consume();
}
}
};
alpha0Field.addEventFilter(KeyEvent.KEY_TYPED, eventHandler);
alpha1Field.addEventFilter(KeyEvent.KEY_TYPED, eventHandler);
deltaAlphaField.addEventFilter(KeyEvent.KEY_TYPED, eventHandler);
}
}