나는 이것을 잠재적 인 답변으로 게시하지만 나에게 복잡해 보입니다. 간단히 말해, 모든 장면 컨트롤러에서 항상 업데이트를받는 클래스를 추가했습니다. Save_As 메인에서 파일 작성자 코드를 호출 할 수 있습니다. 지나치게 복잡해 보이고 다소 느리기 때문에 이것을 최종 답으로 받아들이지 않습니다.
순열 컨트롤러
package application.controller;
import application.models.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.css.PseudoClass;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import org.apache.commons.lang3.StringUtils;
import java.awt.*;
import java.io.*;
import java.util.Objects;
import static application.models.OptionsDataCollector.*;
import static application.models.OptionsDataCollector.targetPermFile;
import static application.models.OptionsFileDefaults.defaultValues;
import static application.models.ValidationForm.*;
/**
* Controller class to handle displaying the GUI showing the options required for the permutation analysis.
* PermutationAnalysisController.java
*
* @author Dennis A. Simpson
* @version 0.5beta
* @since July 9, 2016
*/
public class PermutationAnalysisController {
private Desktop desktop = Desktop.getDesktop();
@FXML private TextField segmentFile = new TextField();
@FXML private TextField cellName = new TextField();
@FXML private TextField targetGroupSize = new TextField();
@FXML private TextField libraryName = new TextField();
@FXML private TextField spawnJobs = new TextField();
@FXML private CheckBox excludeChrY = new CheckBox();
@FXML private CheckBox writeMapFile = new CheckBox();
@FXML private CheckBox segPermFile = new CheckBox();
@FXML private CheckBox targetPermFile = new CheckBox();
@FXML private TextField targetBedFile = new TextField();
@FXML private TextField freqIterations = new TextField();
@FXML private TextField repeatCount = new TextField();
@FXML private TextField bedGroup = new TextField();
@FXML private TextField progCheck = new TextField();
@FXML private Label targetGroupSizeLabel;
@FXML private Button loadValues;
private final PseudoClass errorClass = PseudoClass.getPseudoClass("error");
private final PseudoClass hiddenClass = PseudoClass.getPseudoClass("hidden");
@FXML public void initialize(){
OptionsDataCollector.runModule = "--Permutation_Analysis";
OptionsDataCollector.excludeChrY = excludeChrY;
OptionsDataCollector.writeMapFile = writeMapFile;
OptionsDataCollector.segPermFile = segPermFile;
OptionsDataCollector.targetPermFile = targetPermFile;
spawnJobs.pseudoClassStateChanged(errorClass, false);
spawnJobs.setText("1");
OptionsDataCollector.spawnJobs = spawnJobs.getText();
segmentFile.pseudoClassStateChanged(errorClass, true);
cellName.pseudoClassStateChanged(errorClass, true);
libraryName.pseudoClassStateChanged(errorClass, true);
progCheck.pseudoClassStateChanged(errorClass, false);
progCheck.setText("20000");
OptionsDataCollector.progCheck = progCheck.getText();
targetBedFile.pseudoClassStateChanged(errorClass, true);
freqIterations.pseudoClassStateChanged(errorClass, true);
repeatCount.pseudoClassStateChanged(errorClass, true);
bedGroup.pseudoClassStateChanged(errorClass, true);
targetGroupSize.pseudoClassStateChanged(hiddenClass, true);
targetGroupSize.pseudoClassStateChanged(errorClass, true);
targetGroupSizeLabel.pseudoClassStateChanged(hiddenClass, true);
targetBedFile.focusedProperty().addListener((observable, oldValue, newValue) ->{
targetBedFile.pseudoClassStateChanged(errorClass, !pathValidate(targetBedFile.getText()));
OptionsDataCollector.targetBedFile = targetBedFile.getText();
});
freqIterations.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!Objects.equals(freqIterations.getText(), "0") && numberValidate(freqIterations.getText())){
freqIterations.pseudoClassStateChanged(errorClass, false);
OptionsDataCollector.freqIterations = freqIterations.getText();
}else{
freqIterations.pseudoClassStateChanged(errorClass, true);
OptionsDataCollector.freqIterations = freqIterations.getText();
}
});
repeatCount.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!Objects.equals(repeatCount.getText(), "0") && numberValidate(repeatCount.getText())){
repeatCount.pseudoClassStateChanged(errorClass, false);
OptionsDataCollector.repeatCount = repeatCount.getText();
}else{
repeatCount.pseudoClassStateChanged(errorClass, true);
OptionsDataCollector.repeatCount = repeatCount.getText();
}
});
progCheck.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(numberValidate(progCheck.getText())){
progCheck.pseudoClassStateChanged(errorClass, false);
OptionsDataCollector.progCheck = progCheck.getText();
}else{
progCheck.pseudoClassStateChanged(errorClass, true);
OptionsDataCollector.progCheck = progCheck.getText();
}
});
spawnJobs.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!Objects.equals(spawnJobs.getText(), "0") && numberValidate(spawnJobs.getText())){
spawnJobs.pseudoClassStateChanged(errorClass, false);
OptionsDataCollector.spawnJobs = spawnJobs.getText();
}else{
spawnJobs.pseudoClassStateChanged(errorClass, true);
OptionsDataCollector.spawnJobs = spawnJobs.getText();
}
});
bedGroup.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!Objects.equals(bedGroup.getText(), "0") && numberValidate(bedGroup.getText())){
bedGroup.pseudoClassStateChanged(errorClass, false);
OptionsDataCollector.bedGroup = bedGroup.getText();
}else{
bedGroup.pseudoClassStateChanged(errorClass, true);
OptionsDataCollector.bedGroup = bedGroup.getText();
}
});
segmentFile.focusedProperty().addListener((observable, oldValue, newValue) -> {
segmentFile.pseudoClassStateChanged(errorClass, !pathValidate(segmentFile.getText()));
OptionsDataCollector.segmentFile = segmentFile.getText();
});
cellName.focusedProperty().addListener((observable, oldValue, newValue) -> {
cellName.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(cellName.getText()) &&
textValidate(cellName.getText())));
OptionsDataCollector.cellName = cellName.getText();
});
libraryName.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!StringUtils.isBlank(libraryName.getText()) && textValidate(libraryName.getText())){
libraryName.pseudoClassStateChanged(errorClass, false);
OptionsDataCollector.libraryName = libraryName.getText();
}else{
libraryName.pseudoClassStateChanged(errorClass, true);
OptionsDataCollector.libraryName = libraryName.getText();
}
});
targetPermFile.focusedProperty().addListener(((observable, oldValue, newValue) -> {
if(targetPermFile.isSelected()){
targetGroupSize.pseudoClassStateChanged(hiddenClass, false);
OptionsDataCollector.targetGroupSize = targetGroupSize.getText();
targetGroupSizeLabel.pseudoClassStateChanged(hiddenClass, false);
}
else {if (!targetPermFile.isSelected()) {
targetGroupSize.pseudoClassStateChanged(hiddenClass, true);
OptionsDataCollector.targetGroupSize = targetGroupSize.getText();
targetGroupSizeLabel.pseudoClassStateChanged(hiddenClass, true);
}}
}));
targetGroupSize.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!Objects.equals(targetGroupSize.getText(), "0") && numberValidate(targetGroupSize.getText())){
targetGroupSize.pseudoClassStateChanged(errorClass, false);
OptionsDataCollector.targetGroupSize = targetGroupSize.getText();
}else{
targetGroupSize.pseudoClassStateChanged(errorClass, true);
OptionsDataCollector.targetGroupSize = targetGroupSize.getText();
}
});
excludeChrY.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,Boolean old_val, Boolean new_val) {
OptionsDataCollector.excludeChrY = excludeChrY;
}
});
writeMapFile.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,Boolean old_val, Boolean new_val) {
OptionsDataCollector.writeMapFile = writeMapFile;
}
});
segPermFile.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,Boolean old_val, Boolean new_val) {
OptionsDataCollector.segPermFile = segPermFile;
}
});
targetPermFile.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,Boolean old_val, Boolean new_val) {
OptionsDataCollector.targetPermFile = targetPermFile;
}
});
}
@FXML
private void loadDefaultValues() throws IOException {
if(OptionsFileDefaults.inputOptionsFile == null){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Dialog");
alert.setHeaderText("You Must First Import The File With The Default Settings!");
//alert.setContentText("You Must First Import The File With The Default Settings!");
alert.showAndWait();
}else {
defaultValues();
segmentFile.setText(OptionsFileDefaults.getSegmentFile());
segmentFile.pseudoClassStateChanged(errorClass, !pathValidate(segmentFile.getText()));
OptionsDataCollector.segmentFile = segmentFile.getText();
targetBedFile.setText(OptionsFileDefaults.getTargetBedFile());
targetBedFile.pseudoClassStateChanged(errorClass, !pathValidate(targetBedFile.getText()));
OptionsDataCollector.targetBedFile = targetBedFile.getText();
cellName.setText(OptionsFileDefaults.getCellName());
cellName.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(cellName.getText()) && textValidate
(cellName.getText())));
OptionsDataCollector.cellName = cellName.getText();
libraryName.setText(OptionsFileDefaults.getLibraryName());
libraryName.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(libraryName.getText()) &&
textValidate(libraryName.getText())));
OptionsDataCollector.libraryName = libraryName.getText();
spawnJobs.setText(OptionsFileDefaults.getSpawnJobs());
spawnJobs.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(spawnJobs.getText()) &&
!Objects.equals(spawnJobs.getText(), 0) && numberValidate(spawnJobs.getText())));
OptionsDataCollector.spawnJobs = spawnJobs.getText();
freqIterations.setText(OptionsFileDefaults.getFreqIterations());
freqIterations.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(freqIterations.getText()) &&
!Objects.equals(freqIterations.getText(), 0) && numberValidate(freqIterations.getText())));
OptionsDataCollector.freqIterations = freqIterations.getText();
repeatCount.setText(OptionsFileDefaults.getRepeatCount());
repeatCount.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(repeatCount.getText()) &&
!Objects.equals(repeatCount.getText(), 0) && numberValidate(repeatCount.getText())));
OptionsDataCollector.repeatCount = repeatCount.getText();
bedGroup.setText(OptionsFileDefaults.getBedGroup());
bedGroup.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(bedGroup.getText()) &&
!Objects.equals(bedGroup.getText(), 0) && numberValidate(bedGroup.getText())));
OptionsDataCollector.bedGroup = bedGroup.getText();
progCheck.setText(OptionsFileDefaults.getProgCheck());
progCheck.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(progCheck.getText()) &&
numberValidate(progCheck.getText())));
OptionsDataCollector.progCheck = progCheck.getText();
excludeChrY.setSelected(OptionsFileDefaults.isExcludeChrY());
OptionsDataCollector.excludeChrY = excludeChrY;
writeMapFile.setSelected(OptionsFileDefaults.isWriteMapFile());
OptionsDataCollector.writeMapFile = writeMapFile;
segPermFile.setSelected(OptionsFileDefaults.isSegPermFile());
OptionsDataCollector.segPermFile = segPermFile;
targetPermFile.setSelected(OptionsFileDefaults.isTargetPermFile());
if(targetPermFile.isSelected()){targetGroupSize.pseudoClassStateChanged(hiddenClass, false);}
OptionsDataCollector.segPermFile = segPermFile;
targetGroupSize.setText(OptionsFileDefaults.getTargetGroupSize());
targetGroupSize.pseudoClassStateChanged(errorClass, !(!StringUtils.isBlank(targetGroupSize.getText()) &&
!Objects.equals(targetGroupSize.getText(), 0) && numberValidate(targetGroupSize.getText())));
OptionsDataCollector.targetGroupSize = targetGroupSize.getText();
}
}
}
OptionsDataCollector 클래스
package application.models;
import javafx.scene.control.CheckBox;
public class OptionsDataCollector{
OptionsDataCollector();
public static String runModule;
public static String segmentFile;
public static String targetBedFile;
public static String cellName;
public static String libraryName;
public static String spawnJobs;
public static String freqIterations;
public static String repeatCount;
public static String bedGroup;
public static String targetGroupSize;
public static String progCheck;
public static CheckBox excludeChrY = new CheckBox();
public static CheckBox writeMapFile = new CheckBox();
public static CheckBox targetPermFile = new CheckBox();
public static CheckBox segPermFile = new CheckBox();
public OptionsDataCollector(){
targetGroupSize = "";
excludeChrY.setSelected(false);
writeMapFile.setSelected(false);
targetPermFile.setSelected(false);
segPermFile.setSelected(false);
}
public static void generateOptionsFile(){
StringBuilder moduleSelected = new StringBuilder();
moduleSelected = OptionsFileDefaults.moduleSelected(runModule);
moduleSelected.append("--seg_copy_file\t").append(segmentFile).append("\n");
moduleSelected.append("--target_bed_file\t").append(targetBedFile).append("\n");
moduleSelected.append("--cell_name\t").append(cellName).append("\n");
moduleSelected.append("--library\t").append(libraryName).append("\n");
moduleSelected.append("--spawn\t").append(spawnJobs).append("\n");
moduleSelected.append("--freq_calc_iterations\t").append(freqIterations).append("\n");
moduleSelected.append("--repeat_count\t").append(repeatCount).append("\n");
moduleSelected.append("--bed_group\t").append(bedGroup).append("\n");
moduleSelected.append("--target_perm_group_size\t").append(targetGroupSize).append("\n");
moduleSelected.append("--prog_check\t").append(progCheck).append("\n");
if(excludeChrY.isSelected()){moduleSelected.append("--exclude_chrY\t").append("True\n");}
else {moduleSelected.append("--exclude_chrY\t").append("False\n");}
if(writeMapFile.isSelected()){moduleSelected.append("--writeMapFile\t").append("True\n");}
else {moduleSelected.append("--writeMapFile\t").append("False\n");}
if(segPermFile.isSelected()){moduleSelected.append("--seg_perm_file\t").append("True\n");}
else {moduleSelected.append("--seg_perm_file\t").append("False\n");}
if(targetPermFile.isSelected()){moduleSelected.append("--target_perm_file\t").append("True\n");}
else {moduleSelected.append("--target_perm_file\t").append("False\n");}
System.out.println(moduleSelected);
OptionsFileDefaults.fileWriter(moduleSelected, runModule);
}
}
누구나이를 정리하고보다 효율적으로하는 방법에 대한 생각을?
왜 현재 컨트롤러에 대한 참조를 'VistaNavigator'(효과적으로 뷰 모델)에 유지하지 않는 것이 좋을까요? 그런 다음 현재 컨트롤러 등을 쉽게 검색 할 수 있습니다. 컨트롤러에 모든 인터페이스를 구현할 수 있습니다.이 인터페이스에는 데이터에 액세스 할 수있는 방법 (또는 컨트롤러에서 저장 작업을 수행하는 데 필요한 기능)이 있습니다. –
원래 나는 그걸 가지고 놀았지 만, 내가 생각한 것, 결국 코드의 불필요한 중복이었습니다. –
복제 란 무엇입니까? –