/** Handle click on Defaults button. */ private void handleDefaults() { int answer = DialogManager.askQuestion(this, "default-keys"); if (answer == 0) { actions.setDefaultKeyBindings(); handleFuncListSelect(); } }
/** * Will save the currently selected image as the image of the class if OK is pressed. * * <p>If performed on the current world this will allow for previewing of the currently selected * image, but revert to the original background image of cancelled. * * @param e ignored */ public void actionPerformed(ActionEvent e) { final World currentWorld = WorldHandler.getInstance().getWorld(); // save the original background if possible final GreenfootImage originalBackground = ((currentWorld == null) ? null : WorldVisitor.getBackgroundImage(currentWorld)); // allow the previewing if we are setting the image of the current world. ImageSelectionWatcher watcher = null; if (currentWorld != null && currentWorld.getClass().getName().equals(classView.getGClass().getQualifiedName())) { watcher = new ImageSelectionWatcher() { @Override public void imageSelected(final File imageFile) { if (imageFile != null) { Simulation.getInstance() .runLater( new Runnable() { @Override public void run() { if (WorldHandler.getInstance().getWorld() == currentWorld) { currentWorld.setBackground(imageFile.getAbsolutePath()); } } }); } } }; } // initialise our image library frame JFrame gfFrame = GreenfootMain.getInstance().getFrame(); ImageLibFrame imageLibFrame = new ImageLibFrame(gfFrame, classView, watcher); DialogManager.centreDialog(imageLibFrame); imageLibFrame.setVisible(true); // set the image of the class to the selected file if (imageLibFrame.getResult() == ImageLibFrame.OK) { File currentImageFile = imageLibFrame.getSelectedImageFile(); setClassImage(classView, gclassRole, currentImageFile); gfFrame.repaint(); } // or if cancelled reset the world background to the original format // to avoid white screens or preview images being left there. else if (currentWorld != null && imageLibFrame.getResult() == ImageLibFrame.CANCEL) { Simulation.getInstance() .runLater( new Runnable() { @Override public void run() { currentWorld.setBackground(originalBackground); } }); } }
/** Save the terminal text to file. */ public void save() { initialise(); String fileName = FileUtility.getFileName( this, Config.getString("terminal.save.title"), Config.getString("terminal.save.buttonText"), null, false); if (fileName != null) { File f = new File(fileName); if (f.exists()) { if (DialogManager.askQuestion(this, "error-file-exists") != 0) return; } try { FileWriter writer = new FileWriter(fileName); text.write(writer); writer.close(); } catch (IOException ex) { DialogManager.showError(this, "error-save-file"); } } }