List of usage examples for javafx.event ActionEvent ActionEvent
public ActionEvent()
From source file:jp.toastkid.script.Controller.java
@Override public void initialize(final URL location, final ResourceBundle resources) { scripterInput.setParagraphGraphicFactory(LineNumberFactory.get(scripterInput)); scripterOutput.setParagraphGraphicFactory(LineNumberFactory.get(scripterOutput)); scriptLanguage.setOnAction(e -> { if (subscription != null) { subscription.unsubscribe();/*from www . j a va2s . c o m*/ } subscription = findRunner().initHighlight(scripterInput).highlight(); scripterInput.replaceText(scripterInput.getText()); }); scriptLanguage.getSelectionModel().select(0); scriptLanguage.fireEvent(new ActionEvent()); scripterInput.setOnKeyPressed((e) -> { if (RUN_SCRIPT.match(e)) { runScript(); } }); requestFocus(); }
From source file:com.mycompany.trafficimportfileconverter2.Main2Controller.java
private void initDateArrays() { //populate arrays; datePickers[0] = date1;// w w w . jav a 2 s.com datePickers[1] = date2; datePickers[2] = date3; datePickers[3] = date4; datePickers[4] = date5; datePickers[5] = date6; datePickers[6] = date7; dateChecks[0] = chkDay1; dateChecks[1] = chkDay2; dateChecks[2] = chkDay3; dateChecks[3] = chkDay4; dateChecks[4] = chkDay5; dateChecks[5] = chkDay6; dateChecks[6] = chkDay7; dayLabels[0] = lbl1; dayLabels[1] = lbl2; dayLabels[2] = lbl3; dayLabels[3] = lbl4; dayLabels[4] = lbl5; dayLabels[5] = lbl6; dayLabels[6] = lbl7; //set property to icrement all others if selected. datePickers[0].setOnAction(new EventHandler() { public void handle(Event t) { System.out.println("I've been touched!!!"); if (chkAutoInc.isSelected() && datePickers[0].getValue() != null) { for (int i = 1; i < dateChecks.length; i++) { datePickers[i].setValue(datePickers[i - 1].getValue().plusDays(1)); } } } }); //if the checkbox is checked after setting the date, trigger event. chkAutoInc.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { datePickers[0].fireEvent(new ActionEvent()); datePickers[0].setValue(datePickers[0].getValue()); } } }); for (int i = 0; i < datePickers.length; i++) { final int x = i; datePickers[i].valueProperty().addListener(new ChangeListener<LocalDate>() { @Override public void changed(ObservableValue<? extends LocalDate> observable, LocalDate oldValue, LocalDate newValue) { dates.set(x, newValue); dayLabels[x].setText(newValue.getDayOfWeek().name()); datePickers[x].setStyle("-fx-background-color: red"); dayLabels[x].setStyle("-fx-background-color: red"); } }); } //set select all functionality chkSelectAll.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { for (int i = 0; i < dateChecks.length; i++) { dateChecks[i].setSelected(newValue); } lblSelectAll.setText(newValue ? "Uncheck to: Unselect All" : "Check to: Select All"); } }); //default to include everything. chkSelectAll.setSelected(true); }
From source file:genrsa.GenRSAController.java
/** * Mtodo usado cuando se pulsa enter al meter los bits de generar de manera automtica una clave * @param keyEvent/*ww w. jav a2s . co m*/ */ public void processAutomaticGeneration2(KeyEvent keyEvent) { if (keyEvent.getCode() == KeyCode.ENTER) { processAutomaticGeneration(new ActionEvent()); } }
From source file:genrsa.GenRSAController.java
/** * Mtodo usado cuando se pulsa enter al meter los primos p y q o la clave pblica * @param keyEvent/*from ww w.ja va 2 s . co m*/ */ public void processManualGeneration2(KeyEvent keyEvent) { if (keyEvent.getCode() == KeyCode.ENTER) { this.processManualGeneration(new ActionEvent()); } }
From source file:de.bayern.gdi.gui.Controller.java
private void loadGUIComponents() { switch (downloadConfig.getServiceType()) { case "ATOM": loadAtom();//from ww w. j a va 2 s . co m break; case "WFS2_BASIC": initialiseCrsChooser(); initializeBoundingBox(); initializeDataFormatChooser(); break; case "WFS2_SIMPLE": loadWfsSimple(); break; case "WFS2_SQL": initialiseCrsChooser(); initializeDataFormatChooser(); initializeCqlTextArea(); break; default: setStatusTextUI(I18n.format("status.config.invalid-xml")); break; } List<DownloadConfig.ProcessingStep> steps = downloadConfig.getProcessingSteps(); factory.removeAllChainAttributes(chainContainer); if (steps != null) { chkChain.setSelected(true); handleChainCheckbox(new ActionEvent()); for (DownloadConfig.ProcessingStep iStep : steps) { factory.addChainAttribute(chainContainer, iStep.getName(), iStep.getParams()); } } else { chkChain.setSelected(false); handleChainCheckbox(new ActionEvent()); } }
From source file:snpviewer.SnpViewer.java
@Override public void initialize(URL url, ResourceBundle rb) { labelSplitPane.setDividerPositions(); chromSplitPane.setDividerPositions(); Pane lpane = (Pane) horizontalSplit.getItems().get(0); SplitPane.setResizableWithParent(lpane, false); //mnemonics/shortcuts for menus mainMenu.useSystemMenuBarProperty().set(true); fileMenu.setMnemonicParsing(true);/*from w w w. jav a 2s.co m*/ sampleMenu.setMnemonicParsing(true); goMenu.setMnemonicParsing(true); helpMenu.setMnemonicParsing(true); newProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN)); loadProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.SHORTCUT_DOWN)); addAffSampleMenu.setAccelerator( new KeyCodeCombination(KeyCode.A, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); addUnSampleMenu.setAccelerator( new KeyCodeCombination(KeyCode.U, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); nextChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.EQUALS, KeyCombination.SHORTCUT_DOWN)); prevChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, KeyCombination.SHORTCUT_DOWN)); firstChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.SHORTCUT_DOWN)); lastChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT0, KeyCombination.SHORTCUT_DOWN)); redrawMenu.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN)); cacheChromsMenu.setAccelerator( new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); saveToPngMenu.setAccelerator( new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); autoFindRegions.setAccelerator(new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN)); //need to disable hideSavedRegionsMenu accelerator for linux - doesn't work for check menus hideSavedRegionsMenu.setAccelerator( new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); clearSavedRegionsMenu.setAccelerator( new KeyCodeCombination(KeyCode.X, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); displaySavedsRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.T, KeyCombination.SHORTCUT_DOWN)); outputSavedRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN)); removeSampleMenu.setAccelerator( new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); //set radio menu item toggle group ArrayList<RadioMenuItem> callQualityRadios = new ArrayList<>( Arrays.asList(noFilteringRadio, filter99, filter95, filter90, filter85)); ToggleGroup callQualityToggle = new ToggleGroup(); for (RadioMenuItem r : callQualityRadios) { r.setToggleGroup(callQualityToggle); } noFilteringRadio.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(null); } }); filter99.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.01); } }); filter95.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.05); } }); filter90.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.10); } }); filter85.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.15); } }); nextChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { selectNextChromosome(true); } }); prevChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { selectNextChromosome(false); } }); firstChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { if (!cancelButton.isDisabled()) { cancelButton.fire(); } if (!chromosomeSelector.isDisabled()) { chromosomeSelector.getSelectionModel().selectFirst(); } } }); lastChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { if (!cancelButton.isDisabled()) { cancelButton.fire(); } if (!chromosomeSelector.isDisabled()) { chromosomeSelector.getSelectionModel().selectLast(); } } }); hideSavedRegionsMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { showHideSavedRegions(); } }); colorComp.addAll(Arrays.asList(colorComponants)); //selection context menu final ContextMenu scm = new ContextMenu(); final MenuItem scmItem1 = new MenuItem("Display Flanking SNP IDs"); scmItem1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * flanking snp ids and coordinates */ displayFlankingSnpIDs(dragSelectRectangle); } }); final MenuItem scmItem2 = new MenuItem("Write Selected Region to File"); scmItem2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and report back * write SNPs in region to file */ writeRegionToFile(dragSelectRectangle); } }); } }); final MenuItem scmItem3 = new MenuItem("Add To Saved Regions"); scmItem3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * write SNPs in region to file */ saveSelection(); } }); final MenuItem scmItem4 = new MenuItem("Show/Hide Saved Regions"); scmItem4.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * write SNPs in region to file */ hideSavedRegionsMenu.selectedProperty().setValue(!hideSavedRegionsMenu.isSelected()); hideSavedRegionsMenu.fire(); } }); final MenuItem scmItem5 = new MenuItem("Zoom Region"); scmItem5.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and report back * write SNPs in region to file */ zoomRegion(dragSelectRectangle); } }); } }); final MenuItem scmItem6 = new MenuItem("Write Saved Regions to File"); scmItem6.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and report back * write SNPs in region to file */ writeSavedRegionsToFile(); } }); } }); scm.getItems().add(scmItem1); scm.getItems().add(scmItem2); scm.getItems().add(scmItem3); scm.getItems().add(scmItem4); scm.getItems().add(scmItem5); scm.getItems().add(scmItem6); //overlayPane context menu ocm = new ContextMenu(); final MenuItem ocmItem1 = new MenuItem("Save Image to File"); ocmItem1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { drawPaneToPng(); } }); } }); ocm.getItems().add(ocmItem1); ocm.getItems().add(scmItem4); ocm.getItems().add(scmItem6); //color selections colorComponantSelector.getItems().clear(); colorComponantSelector.getItems().add("AA"); colorComponantSelector.getItems().add("BB"); colorComponantSelector.getItems().add("AB"); colorComponantSelector.getItems().add("Selection Outline"); colorComponantSelector.getItems().add("Selection Fill"); colorComponantSelector.getItems().add("Saved Region Outline"); colorComponantSelector.getItems().add("Saved Region Fill"); colorComponantSelector.getSelectionModel().selectFirst(); colorPicker.setValue(colorComponants[0]); colorComponantSelector.getSelectionModel().selectedIndexProperty() .addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue ov, Number value, Number new_value) { colorPicker.setValue(colorComp.get(new_value.intValue())); colorPicker.fireEvent(new ActionEvent()); } }); colorPicker.setOnAction(new EventHandler() { @Override public void handle(Event t) { if (!colorComp.get(colorComponantSelector.getSelectionModel().getSelectedIndex()) .equals(colorPicker.getValue())) { colorComp.set(colorComponantSelector.getSelectionModel().getSelectedIndex(), colorPicker.getValue()); saveProject(); //colorComponants[colorComponantSelector.getSelectionModel().getSelectedIndex()] = colorPicker.getValue(); if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.fill.value) { dragSelectRectangle.setFill(colorPicker.getValue()); } else if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.line.value) { dragSelectRectangle.setStroke(colorPicker.getValue()); } else if (colorComponantSelector.getSelectionModel() .getSelectedIndex() == Colors.saveLine.value) { for (Rectangle r : savedRegionsDisplay) { r.setStroke(colorPicker.getValue()); } } else if (colorComponantSelector.getSelectionModel() .getSelectedIndex() == Colors.saveFill.value) { for (Rectangle r : savedRegionsDisplay) { r.setFill(colorPicker.getValue()); } } else { removeSavedChromosomeImages(); if (redrawCheckBox.isSelected()) { refreshView(null, true); } } } } }); /*perform appropriate action when user selects a chromosome * from the chromosome choice box */ chromosomeSelector.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue ov, Number value, Number new_value) { chromosomeBoxList = chromosomeSelector.getItems().toArray(); if (new_value.intValue() > -1) { chromosomeSelected((String) chromosomeBoxList[new_value.intValue()]); } } }); chromosomeSelector.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode() == KeyCode.UP) { ke.consume(); chromosomeSelector.show(); } } }); selectionOverlayPane.heightProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) { windowResized(new ActionEvent()); } }); selectionOverlayPane.widthProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) { windowResized(new ActionEvent()); } }); /*upon addition of a new affected file adjust components accordingly * i.e. ensure appropriate chromosomes are in the choice box * adjust the split panes to fit all files and redisplay */ affObserve.addListener(new ListChangeListener() { @Override public void onChanged(ListChangeListener.Change change) { change.next();/*from the javadoc * 'Go to the next change. In initial state is invalid a require * a call to next() before calling other methods. The first * next() call will make this object represent the first change. */ if (change.getRemovedSize() > 0) { List<SnpFile> both = new ArrayList<>(unFiles); both.addAll(affFiles); recheckChromosomeSelector(both);//need to check all files again, not just affFiles } else if (change.getAddedSize() > 0) { addToChromosomeSelector(affFiles); } } }); /*as above * but for unaffected files */ unObserve.addListener(new ListChangeListener() { @Override public void onChanged(ListChangeListener.Change change) { change.next(); if (change.getRemovedSize() > 0) { List<SnpFile> both = new ArrayList<>(unFiles); both.addAll(affFiles); recheckChromosomeSelector(both);//need to check all files again, not just unFiles } else if (change.getAddedSize() > 0) { addToChromosomeSelector(unFiles); } } }); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1) { try { ChromosomeLength chromLength = new ChromosomeLength(genomeVersion); String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel() .getSelectedIndex()]; double coordinate = chromLength.getLength(currentChrom) / chromSplitPane.getWidth() * e.getX(); positionIndicator.setText(nf.format(coordinate)); } catch (Exception ex) { positionIndicator.setText("Build Error!"); } } } }); /*handle mouse dragging and effect on dragSelectRectangle * */ dragSelectRectangle.widthProperty().bind(dragSelectRectX.subtract(dragSelectRectInitX)); dragSelectRectangle.heightProperty().bind(selectionOverlayPane.heightProperty()); //dragSelectRectangle.strokeProperty().set(colorComponants[Colors.line.value]); dragSelectRectangle.setStrokeWidth(4.0); //dragSelectRectangle.setBlendMode(BlendMode.SCREEN); dragSelectRectangle.setOpacity(0.45); dragSelectRectangle.setVisible(false); selectionOverlayPane.getChildren().add(dragSelectRectangle); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (scm.isShowing()) { scm.hide(); } if (!e.isPrimaryButtonDown()) { if (e.isSecondaryButtonDown()) { //check we're not overlapping selection if (e.getX() >= dragSelectRectangle.getX() && e.getX() <= (dragSelectRectangle.getX() + dragSelectRectangle.getWidth())) { return; } //check we're not overlapping saved regions for (Rectangle r : savedRegionsDisplay) { if (r.isVisible() && e.getX() >= r.getX() && e.getX() <= r.getX() + r.getWidth()) { return; } } if (chromosomeSelector.getSelectionModel().isEmpty()) { ocmItem1.setDisable(true); } else { ocmItem1.setDisable(false); } ocm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY()); return; } } if (ocm.isShowing()) { ocm.hide(); } dragSelectRectangle.strokeProperty().set(colorComp.get(Colors.line.value)); dragSelectRectangle.fillProperty().set(colorComp.get(Colors.fill.value)); dragSelectRectX.set(0); dragSelectRectangle.setVisible(true); dragSelectRectangle.setX(e.getX()); dragSelectRectangle.setY(0); dragSelectRectInitX.set(e.getX()); anchorInitX.set(e.getX()); } }); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (!e.isPrimaryButtonDown()) { return; } dragSelectRectangle.setVisible(true); if (e.getX() > anchorInitX.doubleValue()) {//dragging to the right if (e.getX() <= selectionOverlayPane.getLayoutX() + selectionOverlayPane.getWidth()) { //mouse is before the edge of the pane dragSelectRectInitX.set(anchorInitX.doubleValue()); dragSelectRectX.set(e.getX()); } else { //mouse is over the edge dragSelectRectX.set(selectionOverlayPane.getWidth()); } } else { if (e.getX() > selectionOverlayPane.getLayoutX()) { dragSelectRectInitX.set(e.getX()); dragSelectRectangle.setX(e.getX()); dragSelectRectX.set(anchorInitX.doubleValue()); } else { dragSelectRectInitX.set(0); dragSelectRectangle.setX(0); /* the two lines below are just to trigger * dragSelectRectangle.widthProperty listener * so that start coordinate changes to 1 */ dragSelectRectX.set(anchorInitX.doubleValue() + 1); dragSelectRectX.set(anchorInitX.doubleValue() + 1); } } } }); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { //dragSelectRectX.set(e.getX()); if (!e.isPrimaryButtonDown()) { return; } dragSelectRectangle.setVisible(true); if (dragSelectRectangle.getWidth() == 0) { clearDragSelectRectangle(); } } }); dragSelectRectangle.widthProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Object oldValue, Object newRectWidth) { if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1 && dragSelectRectangle.getWidth() > 0) { try { ChromosomeLength chromLength = new ChromosomeLength(genomeVersion); String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel() .getSelectedIndex()]; double startCoordinate = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth() * dragSelectRectangle.getX(); double selectionWidth = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth() * dragSelectRectangle.getWidth(); if (dragSelectRectangle.getX() == 0) { startCoordinate = 1; } selectionIndicator.setText("chr" + currentChrom + ":" + nf.format(startCoordinate) + "-" + nf.format(startCoordinate + selectionWidth)); } catch (Exception ex) { selectionIndicator.setText("Build Error!"); } } else { selectionIndicator.setText(""); } } }); dragSelectRectangle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (e.getButton() == MouseButton.SECONDARY) { if (chromosomeSelector.getSelectionModel().isEmpty()) { scmItem1.setDisable(true); scmItem2.setDisable(true); } else { scmItem1.setDisable(false); scmItem2.setDisable(false); } if (ocm.isShowing()) { ocm.hide(); } scm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY()); } } }); }
From source file:snpviewer.SnpViewer.java
public void resetColours(ActionEvent e) { colorComp.clear();// w w w.java 2 s .c om colorComp.addAll(Arrays.asList(colorComponants)); for (int ci = 0; ci < colorComp.size(); ci++) { colorComponantSelector.getSelectionModel().clearAndSelect(ci); colorPicker.setValue(colorComp.get(ci)); colorPicker.fireEvent(new ActionEvent()); } colorComponantSelector.getSelectionModel().selectFirst(); removeSavedChromosomeImages(); refreshView((String) chromosomeSelector.getSelectionModel().getSelectedItem(), true); }
From source file:snpviewer.SnpViewer.java
public void loadColourScheme(ActionEvent e) { FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters()//ww w .j a v a 2 s . c o m .add(new FileChooser.ExtensionFilter("SNP Viewer Colour Scheme", "*.svcols")); fileChooser.setTitle("Open SNP Viewer Colour Scheme (.svcols) file"); File loadFile = fileChooser.showOpenDialog(mainWindow); if (loadFile != null) { try { ObjectInputStream is = new ObjectInputStream( new BufferedInputStream(new FileInputStream(loadFile))); ArrayList<Color> loadedColors = new ArrayList<>(); for (Color c : colorComp) { String colorString = (String) is.readObject(); loadedColors.add(Color.valueOf(colorString)); } for (int ci = 0; ci < loadedColors.size(); ci++) { colorComponantSelector.getSelectionModel().clearAndSelect(ci); colorPicker.setValue(loadedColors.get(ci)); colorPicker.fireEvent(new ActionEvent()); } colorComponantSelector.getSelectionModel().selectFirst(); colorComp.clear(); colorComp.addAll(loadedColors); is.close(); saveProject(); removeSavedChromosomeImages(); refreshView((String) chromosomeSelector.getSelectionModel().getSelectedItem(), true); } catch (IOException | ClassNotFoundException ex) { } } }
From source file:snpviewer.SnpViewer.java
public void loadProject() { if (projectRunning) { /*setProgressMode(true); DialogResponse response = Dialogs.showConfirmDialog(null, "Do you want to save your current project before starting a new one?", "Save Current Project?", "SNP View"); if (DialogResponse.YES.equals(response)){ boolean saved = saveProject();//from w ww.j a va2s . c om if (! saved){ setProgressMode(false); return; }else{ Dialogs.showInformationDialog(null, projectFile.getName() + " saved sucessfully", "Save Successful", "SNP View"); } }else if (DialogResponse.CANCEL.equals(response)){ setProgressMode(false); return; }*/ } loadProjectButton.setDisable(true); newProjectButton.setDisable(true); FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("SNP Viewer Projects", "*.svproj")); fileChooser.setTitle("Open SNP Viewer Project (.svproj) file"); //setProgressMode(false); File loadFile = fileChooser.showOpenDialog(mainWindow); loadProjectButton.setDisable(false); newProjectButton.setDisable(false); if (loadFile != null) { try { ObjectInputStream is = new ObjectInputStream( new BufferedInputStream(new FileInputStream(loadFile))); try { projectFile = null; projectLabel.setText("Project: none"); chromSplitPane.getItems().clear(); labelSplitPane.getItems().clear(); clearDragSelectRectangle(); savedRegions.clear(); savedRegionsDisplay.clear(); savedRegionsReference.clear(); selectionOverlayPane.getChildren().clear(); selectionOverlayPane.getChildren().add(dragSelectRectangle); resetObservables(); genomeVersion = ""; qualityFilter = null; noFilteringRadio.setSelected(true); chromosomeSelector.getItems().clear(); projectFile = (File) is.readObject();//get rid of this? projectFile = loadFile;//allow relative referencing ArrayList<Color> loadedColors = new ArrayList<>(); ArrayList<SnpFile> tempAff = new ArrayList<>(); ArrayList<SnpFile> tempUn = new ArrayList<>(); tempAff.addAll((ArrayList<SnpFile>) is.readObject()); tempUn.addAll((ArrayList<SnpFile>) is.readObject()); ArrayList<SnpFile> tempBoth = new ArrayList<>(); tempBoth.addAll(tempAff); tempBoth.addAll(tempUn); genomeVersion = (String) is.readObject(); qualityFilter = (Double) is.readObject(); buildLabel.setText(genomeVersion); snpViewSaveDirectory = (File) is.readObject(); savedRegions = (ArrayList<RegionSummary>) is.readObject(); String projectName = projectFile.getName().replaceAll(".svproj", ""); if (!snpViewSaveDirectory.exists()) { snpViewSaveDirectory = new File( projectFile.getParentFile() + "/" + projectName + " SNP Viewer files"); if (!snpViewSaveDirectory.exists()) { DialogResponse response = Dialogs.showErrorDialog(null, "Can't find project directory (" + snpViewSaveDirectory.getName() + ") - do you " + "want to try to find it?", "Project directory " + "not found", "SnpViewer", Dialogs.DialogOptions.YES_NO); if (DialogResponse.YES.equals(response)) { DirectoryChooser dirChooser = new DirectoryChooser(); dirChooser.setTitle("Locate Project Folder"); snpViewSaveDirectory = dirChooser.showDialog(mainWindow); if (snpViewSaveDirectory == null) { returnToInitialState(); return; } } else { returnToInitialState(); return; } } } boolean check = checkProjectFolder(snpViewSaveDirectory, tempBoth); if (!check) { Dialogs.showErrorDialog(null, "Corrupt project" + " folder - missing files.", "Invalid " + "project folder.", "SnpViewer"); returnToInitialState(); return; } for (Color c : colorComp) { String colorString = (String) is.readObject(); loadedColors.add(Color.valueOf(colorString)); } for (int ci = 0; ci < loadedColors.size(); ci++) { colorComponantSelector.getSelectionModel().clearAndSelect(ci); colorPicker.setValue(loadedColors.get(ci)); colorPicker.fireEvent(new ActionEvent()); } affObserve.addAll(tempAff); unObserve.addAll(tempUn); colorComponantSelector.getSelectionModel().selectFirst(); colorComp.clear(); colorComp.addAll(loadedColors); is.close(); setQualityLabel(); checkQualitySelection(); saveProject(); projectLabel.setText("Project: " + projectFile.getName()); //addToChromosomeSelector(affFiles); //addToChromosomeSelector(unFiles); if (!chromosomeSelector.getItems().isEmpty()) { chromosomeSelector.getSelectionModel().selectFirst(); } if (chromosomeSelector.isDisabled()) { chromosomeSelector.setDisable(false); } //setProgressMode(false); if (affObserve.isEmpty() && unObserve.isEmpty()) { resetView(); } projectRunning = true; } catch (IOException | ClassNotFoundException ex) { resetView(); projectLabel.setText("Project: none"); savedRegions.clear(); savedRegionsDisplay.clear(); savedRegionsReference.clear(); resetObservables(); genomeVersion = ""; qualityFilter = null; noFilteringRadio.setSelected(true); chromosomeSelector.getItems().clear(); ex.printStackTrace(); Dialogs.showErrorDialog(null, "Could not load project file", "Load Failed", "SNP Viewer", ex); } } catch (IOException ex) { resetView(); projectLabel.setText("Project: none"); savedRegions.clear(); savedRegionsDisplay.clear(); savedRegionsReference.clear(); resetObservables(); genomeVersion = ""; qualityFilter = null; noFilteringRadio.setSelected(true); chromosomeSelector.getItems().clear(); ex.printStackTrace(); Dialogs.showErrorDialog(null, "Could not load project file - IO error", "Load Failed", "SNP Viewer", ex); } } }