1+ package com .xwintop .xJavaFxTool .controller .codeTools ;
2+
3+ import cn .hutool .core .util .RandomUtil ;
4+ import com .xwintop .xJavaFxTool .services .codeTools .RandomGeneratorToolService ;
5+ import com .xwintop .xJavaFxTool .view .codeTools .RandomGeneratorToolView ;
6+ import com .xwintop .xcore .util .UuidUtil ;
7+ import javafx .event .ActionEvent ;
8+ import javafx .fxml .FXML ;
9+ import lombok .Getter ;
10+ import lombok .Setter ;
11+ import lombok .extern .slf4j .Slf4j ;
12+
13+ import java .net .URL ;
14+ import java .util .ResourceBundle ;
15+
16+ /**
17+ * @ClassName: RandomGeneratorToolController
18+ * @Description: 随机数生成工具
19+ * @author: xufeng
20+ * @date: 2019/6/15 0015 0:52
21+ */
22+
23+ @ Getter
24+ @ Setter
25+ @ Slf4j
26+ public class RandomGeneratorToolController extends RandomGeneratorToolView {
27+ private RandomGeneratorToolService randomGeneratorToolService = new RandomGeneratorToolService (this );
28+
29+ @ Override
30+ public void initialize (URL location , ResourceBundle resources ) {
31+ initView ();
32+ initEvent ();
33+ initService ();
34+ }
35+
36+ private void initView () {
37+ }
38+
39+ private void initEvent () {
40+ }
41+
42+ private void initService () {
43+ }
44+
45+ @ FXML
46+ private void generateUUID (ActionEvent event ) {
47+ uuidResult .setText (UuidUtil .get32UUID ());
48+ }
49+
50+ @ FXML
51+ private void generateNumber (ActionEvent event ) {
52+ String flo = floor .getText ();
53+ String cei = ceil .getText ();
54+ int p = stringToInt (precision .getText ());
55+ int f = stringToInt (flo );
56+ int c = stringToInt (cei );
57+ numberResult .setText (String .valueOf (RandomUtil .randomInt (f , c )));
58+ }
59+
60+ @ FXML
61+ private void generateEmail (ActionEvent event ) {
62+ String email = RandomUtil .randomString (RandomUtil .randomInt (3 , 10 )) + "@" + RandomUtil .randomString (RandomUtil .BASE_CHAR , RandomUtil .randomInt (3 , 5 )) + "." + RandomUtil .randomString (RandomUtil .BASE_CHAR , RandomUtil .randomInt (1 , 5 ));
63+ emailResult .setText (email );
64+ }
65+
66+ @ FXML
67+ private void generateLowerCase (ActionEvent event ) {
68+ lowerCaseResult .setText (RandomUtil .randomString (RandomUtil .BASE_CHAR , getLength (lowerCaseLength .getText ())));
69+ }
70+
71+ @ FXML
72+ private void generateUpperCase (ActionEvent event ) {
73+ upperCaseResult .setText (RandomUtil .randomString (RandomUtil .BASE_CHAR , getLength (upperCaseLength .getText ())).toUpperCase ());
74+ }
75+
76+ @ FXML
77+ private void generateLetter (ActionEvent event ) {
78+ letterResult .setText (RandomUtil .randomString (RandomUtil .BASE_CHAR + RandomUtil .BASE_CHAR .toUpperCase (), getLength (letterLength .getText ())));
79+ }
80+
81+ @ FXML
82+ private void generateString (ActionEvent event ) {
83+ stringResult .setText (RandomUtil .randomString (getLength (stringLength .getText ())));
84+ }
85+
86+ @ FXML
87+ private void generateText (ActionEvent event ) {
88+ textResult .setText (RandomUtil .randomString (RandomUtil .BASE_CHAR + RandomUtil .BASE_CHAR .toUpperCase () + "~!@#$%^&*()_+{}:\" <>?`-=[];'\\ |,./" , getLength (textLength .getText ())));
89+ }
90+
91+ public static int stringToInt (String integer ) {
92+ int result = 0 ;
93+ try {
94+ result = Integer .parseInt (integer .trim ());
95+ } catch (Exception e ) {
96+ log .warn ("转换异常" + e .getMessage ());
97+ }
98+ return result > -1 ? result : 0 ;
99+ }
100+
101+ private int getLength (String len ) {
102+ int length = 0 ;
103+ try {
104+ length = Integer .parseInt (len .trim ());
105+ } catch (Exception e ) {
106+ log .warn ("转换异常" + e .getMessage ());
107+ }
108+ return length < 1 ? RandomUtil .randomInt (9 , 16 ) : length ;
109+ }
110+ }
0 commit comments