|
4 | 4 | import java.net.URL; |
5 | 5 | import java.util.ResourceBundle; |
6 | 6 |
|
| 7 | +import com.sun.jna.Platform; |
7 | 8 | import org.apache.commons.io.FileUtils; |
8 | 9 |
|
9 | 10 | import com.xwintop.xcore.util.javafx.AlertUtil; |
|
27 | 28 | */ |
28 | 29 |
|
29 | 30 | public class LinuxPathToWindowsPathController implements Initializable { |
30 | | - @FXML |
31 | | - private TextField textFieldLinuxPath; |
32 | | - @FXML |
33 | | - private ChoiceBox<String> choiceBoxChooseLUN; |
34 | | - @FXML |
35 | | - private Button buttonCreateWindowsPath; |
36 | | - @FXML |
37 | | - private TextField textFieldWindowsPath; |
38 | | - @FXML |
39 | | - private Button buttonCreateLinuxPath; |
| 31 | + @FXML |
| 32 | + private TextField textFieldLinuxPath; |
| 33 | + @FXML |
| 34 | + private ChoiceBox<String> choiceBoxChooseLUN; |
| 35 | + @FXML |
| 36 | + private Button buttonCreateWindowsPath; |
| 37 | + @FXML |
| 38 | + private TextField textFieldWindowsPath; |
| 39 | + @FXML |
| 40 | + private Button buttonCreateLinuxPath; |
40 | 41 |
|
41 | | - @Override |
42 | | - public void initialize(URL location, ResourceBundle resources) { |
43 | | - initView(); |
44 | | - initEvent(); |
45 | | - } |
| 42 | + @Override |
| 43 | + public void initialize(URL location, ResourceBundle resources) { |
| 44 | + initView(); |
| 45 | + initEvent(); |
| 46 | + } |
46 | 47 |
|
47 | | - private void initView() { |
48 | | - ObservableList<String> observableList = choiceBoxChooseLUN.getItems(); |
49 | | - for (char c = 'A'; c <= 'Z'; c++) { |
50 | | - String dirName = c + ":/"; |
51 | | - File win = new File(dirName); |
52 | | - if (win.exists()) { |
53 | | - observableList.add(dirName); |
54 | | - } |
55 | | - } |
56 | | - choiceBoxChooseLUN.setValue(observableList.get(0)); |
57 | | - } |
58 | | - |
59 | | - private void initEvent() { |
60 | | - textFieldLinuxPath.setOnKeyReleased(new EventHandler<KeyEvent>() { |
61 | | - @Override |
62 | | - public void handle(KeyEvent event) { |
63 | | - if(event.getCode() == KeyCode.ENTER){ |
64 | | - createWindowsPath(null); |
65 | | - } |
66 | | - } |
67 | | - }); |
68 | | - } |
| 48 | + private void initView() { |
| 49 | + if (Platform.isWindows()) { |
| 50 | + ObservableList<String> observableList = choiceBoxChooseLUN.getItems(); |
| 51 | + for (char c = 'A'; c <= 'Z'; c++) { |
| 52 | + String dirName = c + ":/"; |
| 53 | + File win = new File(dirName); |
| 54 | + if (win.exists()) { |
| 55 | + observableList.add(dirName); |
| 56 | + } |
| 57 | + } |
| 58 | + } else { |
| 59 | + choiceBoxChooseLUN.getItems().add("/"); |
| 60 | + } |
| 61 | + choiceBoxChooseLUN.setValue(choiceBoxChooseLUN.getItems().get(0)); |
| 62 | + } |
69 | 63 |
|
70 | | - @FXML |
71 | | - private void createWindowsPath(ActionEvent event){ |
72 | | - try { |
73 | | - String folderPath = choiceBoxChooseLUN.getValue()+textFieldLinuxPath.getText(); |
74 | | - FileUtils.forceMkdir(new File(folderPath)); |
75 | | - textFieldWindowsPath.setText(folderPath); |
76 | | - } catch (Exception e) { |
77 | | - AlertUtil.showWarnAlert("转换异常,请检查路径。"); |
78 | | - } |
79 | | - } |
| 64 | + private void initEvent() { |
| 65 | + textFieldLinuxPath.setOnKeyReleased(new EventHandler<KeyEvent>() { |
| 66 | + @Override |
| 67 | + public void handle(KeyEvent event) { |
| 68 | + if (event.getCode() == KeyCode.ENTER) { |
| 69 | + createWindowsPath(null); |
| 70 | + } |
| 71 | + } |
| 72 | + }); |
| 73 | + } |
80 | 74 |
|
81 | | - @FXML |
82 | | - private void createLinuxPath(ActionEvent event) { |
83 | | - } |
| 75 | + @FXML |
| 76 | + private void createWindowsPath(ActionEvent event) { |
| 77 | + try { |
| 78 | + String folderPath = choiceBoxChooseLUN.getValue() + textFieldLinuxPath.getText(); |
| 79 | + FileUtils.forceMkdir(new File(folderPath)); |
| 80 | + textFieldWindowsPath.setText(folderPath); |
| 81 | + } catch (Exception e) { |
| 82 | + AlertUtil.showWarnAlert("转换异常,请检查路径。"); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + @FXML |
| 87 | + private void createLinuxPath(ActionEvent event) { |
| 88 | + } |
84 | 89 |
|
85 | 90 | } |
0 commit comments