public ExportDialogOld() { super(TabletopTool.getFrame(), "Export Screenshot", true); // The window uses about 1MB. Disposing frees this, but repeated uses // will cause more memory fragmentation. // MCL: I figure it's better to save the 1MB for low-mem systems, // but it would be even better to HIDE it, and then dispose() it // when the user clicks on the memory meter to free memory // setDefaultCloseOperation(HIDE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE); // // Initialize the panel and button actions // formPanel = new FormPanel("com/t3/client/ui/forms/exportDialog.xml"); setLayout(new GridLayout()); add(formPanel); getRootPane().setDefaultButton((JButton) formPanel.getButton("exportButton")); pack(); ExportRadioButtons.setForm(formPanel); ExportLayers.setForm(formPanel); formPanel .getButton("exportButton") .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { exportButtonAction(); } }); formPanel .getButton("cancelButton") .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { dispose(); } }); formPanel .getButton("browseButton") .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { browseButtonAction(); } }); // Run this once to make sure the dialog is in a good starting state. ExportLayers.setDefaultChecked(); enforceButtonRules(); }
// // SetForm stores the form this is attached to // public static void setForm(FormPanel form) { ExportRadioButtons.form = form; for (ExportRadioButtons button : ExportRadioButtons.values()) { try { if (form.getRadioButton(button.toString()) == null) { throw new Exception("Export Dialog has a mis-matched enum: " + button.toString()); } button.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { enforceButtonRules(); } }); } catch (Exception ex) { TabletopTool.showError( I18N.getString("dialog.screenshot.radio.button.uiImplementationError"), ex); } } }
/** * This is the top-level screen-capture routine. It sends the resulting PNG image to the location * previously selected by the user. TODO: It currently calls {@link * TabletopTool.takeMapScreenShot()} for "normal" screenshots, but that's just until this code is * considered stable enough. * * @throws Exception */ public void screenCapture() throws Exception { BufferedImage screenCap = null; TabletopTool.getFrame() .setStatusMessage(I18N.getString("dialog.screenshot.msg.GeneratingScreenshot")); ExportRadioButtons type = ExportRadioButtons.getType(); try { switch (type) { case TYPE_CURRENT_VIEW: // This uses the original screenshot code: I didn't want to touch it, so I need // to pass it the same parameter it took before. Player.Role role = ExportRadioButtons.VIEW_GM.isChecked() ? Player.Role.GM : Player.Role.PLAYER; screenCap = TabletopTool.takeMapScreenShot(new PlayerView(role)); // since old screenshot code doesn't throw exceptions, look for null if (screenCap == null) { throw new Exception(I18N.getString("dialog.screenshot.error.failedImageGeneration")); } break; case TYPE_ENTIRE_MAP: screenCap = entireMapScreenShotWithLayers(); break; default: throw new Exception(I18N.getString("dialog.screenshot.error.invalidDialogSettings")); } TabletopTool.getFrame() .setStatusMessage(I18N.getString("dialog.screenshot.msg.screenshotStreaming")); try (ByteArrayOutputStream imageOut = new ByteArrayOutputStream()) { ImageIO.write(screenCap, "png", imageOut); screenCap = null; // Free up the memory as soon as possible TabletopTool.getFrame() .setStatusMessage(I18N.getString("dialog.screenshot.msg.screenshotSaving")); exportLocation.putContent( new BufferedInputStream(new ByteArrayInputStream(imageOut.toByteArray()))); } TabletopTool.getFrame() .setStatusMessage(I18N.getString("dialog.screenshot.msg.screenshotSaved")); } catch (OutOfMemoryError e) { TabletopTool.showError("Out Of Memory", e); } catch (Exception ex) { TabletopTool.showError("screenCapture()", ex); } }