Removal of Swing remanants

This commit is contained in:
Brendan Robert 2015-03-30 00:28:19 -05:00
parent 4fc71a43a7
commit a641ac555c
4 changed files with 92 additions and 115 deletions

View File

@ -28,12 +28,8 @@ import jace.core.CPU;
import jace.core.Computer;
import jace.core.Debugger;
import jace.core.RAM;
import jace.core.RAMEvent;
import jace.core.RAMListener;
import static jace.core.Utility.*;
import java.awt.Graphics2D;
import java.awt.HeadlessException;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -50,7 +46,6 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
@ -58,11 +53,8 @@ import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTextField;
/**
* This class contains miscellaneous user-invoked actions such as debugger
@ -206,9 +198,8 @@ public class EmulatorUILogic implements Reconfigurable {
defaultKeyMapping = "ctrl+shift+b")
public static void runFile() {
Emulator.computer.pause();
JFileChooser select = new JFileChooser();
// select.showDialog(Emulator.getFrame(), "Execute binary file");
File binary = select.getSelectedFile();
FileChooser select = new FileChooser();
File binary = select.showOpenDialog(null);
if (binary == null) {
Emulator.computer.resume();
return;
@ -339,26 +330,25 @@ public class EmulatorUILogic implements Reconfigurable {
description = "Save image of visible screen",
alternatives = "Save image,save framebuffer,screenshot",
defaultKeyMapping = "ctrl+shift+s")
public static void saveScreenshot() throws HeadlessException, IOException {
JFileChooser select = new JFileChooser();
public static void saveScreenshot() throws IOException {
FileChooser select = new FileChooser();
Emulator.computer.pause();
Image i = Emulator.computer.getVideo().getFrameBuffer();
BufferedImage bufImageARGB = SwingFXUtils.fromFXImage(i, null);
// select.showSaveDialog(Emulator.getFrame());
File targetFile = select.getSelectedFile();
// BufferedImage bufImageARGB = SwingFXUtils.fromFXImage(i, null);
File targetFile = select.showSaveDialog(null);
if (targetFile == null) {
return;
}
String filename = targetFile.getName();
System.out.println("Writing screenshot to " + filename);
String extension = filename.substring(filename.lastIndexOf(".") + 1);
BufferedImage bufImageRGB = new BufferedImage(bufImageARGB.getWidth(), bufImageARGB.getHeight(), BufferedImage.OPAQUE);
Graphics2D graphics = bufImageRGB.createGraphics();
graphics.drawImage(bufImageARGB, 0, 0, null);
ImageIO.write(bufImageRGB, extension, targetFile);
graphics.dispose();
// BufferedImage bufImageRGB = new BufferedImage(bufImageARGB.getWidth(), bufImageARGB.getHeight(), BufferedImage.OPAQUE);
//
// Graphics2D graphics = bufImageRGB.createGraphics();
// graphics.drawImage(bufImageARGB, 0, 0, null);
//
// ImageIO.write(bufImageRGB, extension, targetFile);
// graphics.dispose();
}
public static final String CONFIGURATION_DIALOG_NAME = "Configuration";

View File

@ -33,11 +33,10 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import java.io.FileNotFoundException;
import java.util.Timer;
import java.util.TimerTask;
import javafx.stage.FileChooser;
/**
* Apple // Speaker Emulation Created on May 9, 2007, 9:55 PM
@ -59,18 +58,17 @@ public class Speaker extends Device {
out = null;
fileOutputActive = false;
} else {
JFileChooser fileChooser = new JFileChooser();
fileChooser.showSaveDialog(null);
File f = fileChooser.getSelectedFile();
FileChooser fileChooser = new FileChooser();
File f = fileChooser.showSaveDialog(null);
if (f == null) {
return;
}
if (f.exists()) {
int i = JOptionPane.showConfirmDialog(null, "Overwrite existing file?");
if (i != JOptionPane.OK_OPTION && i != JOptionPane.YES_OPTION) {
return;
}
}
// if (f.exists()) {
// int i = JOptionPane.showConfirmDialog(null, "Overwrite existing file?");
// if (i != JOptionPane.OK_OPTION && i != JOptionPane.YES_OPTION) {
// return;
// }
// }
try {
out = new FileOutputStream(f);
fileOutputActive = true;

View File

@ -18,45 +18,31 @@
*/
package jace.core;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import org.reflections.Reflections;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.control.Alert;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
/**
* This is a set of helper functions which do not belong anywhere else.
* Functions vary from introspection, discovery, and string/pattern matching.
@ -323,15 +309,15 @@ public class Utility {
return label;
}
public static void runModalProcess(String title, final Runnable runnable) {
// final JDialog frame = new JDialog(Emulator.getFrame());
final JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
final JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
contentPane.setLayout(new BorderLayout());
contentPane.add(new JLabel(title), BorderLayout.NORTH);
contentPane.add(progressBar, BorderLayout.CENTER);
// public static void runModalProcess(String title, final Runnable runnable) {
//// final JDialog frame = new JDialog(Emulator.getFrame());
// final JProgressBar progressBar = new JProgressBar();
// progressBar.setIndeterminate(true);
// final JPanel contentPane = new JPanel();
// contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// contentPane.setLayout(new BorderLayout());
// contentPane.add(new JLabel(title), BorderLayout.NORTH);
// contentPane.add(progressBar, BorderLayout.CENTER);
// frame.setContentPane(contentPane);
// frame.pack();
// frame.setLocationRelativeTo(null);
@ -342,7 +328,7 @@ public class Utility {
// frame.setVisible(false);
// frame.dispose();
// }).start();
}
// }
public static class RankingComparator implements Comparator<String> {
@ -438,8 +424,11 @@ public class Utility {
}
public static void gripe(final String message) {
EventQueue.invokeLater(() -> {
// JOptionPane.showMessageDialog(Emulator.getFrame(), message, "Error", JOptionPane.ERROR_MESSAGE);
Platform.runLater(() -> {
Alert errorAlert = new Alert(Alert.AlertType.ERROR);
errorAlert.setContentText(message);
errorAlert.setTitle("Error");
errorAlert.show();
});
}

View File

@ -197,7 +197,7 @@ public class MediaCache implements Serializable {
e.files = new ArrayList<>();
getLocalLibrary().add(e);
getLocalLibrary().createBlankFile(e, "Initial", !isPermanent);
getLocalLibrary().downloadImage(e, e.files.get(0), true);
// getLocalLibrary().downloadImage(e, e.files.get(0), true);
}
for (MediaEntry.MediaFile f : e.files) {
if (f.activeVersion) {
@ -340,60 +340,60 @@ public class MediaCache implements Serializable {
}
private MediaFile downloadTempCopy(MediaEntry e) {
downloadImage(e, getCurrentFile(e, false), isDownloading);
// downloadImage(e, getCurrentFile(e, false), isDownloading);
return getCurrentFile(e, false);
}
static boolean isDownloading = false;
public void downloadImage(final MediaEntry e, final MediaFile target, boolean wait) {
isDownloading = true;
Utility.runModalProcess("Loading disk image...", () -> {
InputStream in = null;
try {
URI uri = null;
try {
uri = new URI(e.source);
} catch (URISyntaxException ex) {
File f = new File(e.source);
if (f.exists()) {
uri = f.toURI();
}
}
if (uri == null) {
Utility.gripe("Unable to resolve path: " + e.source);
return;
}
in = uri.toURL().openStream();
saveFile(target, in);
} catch (MalformedURLException ex) {
Utility.gripe("Unable to resolve path: " + e.source);
Logger.getLogger(MediaCache.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Utility.gripe("Unable to download file: " + ex.getMessage());
Logger.getLogger(MediaCache.class.getName()).log(Level.SEVERE, null, ex);
} finally {
isDownloading = false;
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
Logger.getLogger(MediaCache.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
if (wait) {
int timeout = 10000;
while (timeout > 0 && isDownloading) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
return;
}
timeout -= 100;
}
}
}
//
// public void downloadImage(final MediaEntry e, final MediaFile target, boolean wait) {
// isDownloading = true;
// Utility.runModalProcess("Loading disk image...", () -> {
// InputStream in = null;
// try {
// URI uri = null;
// try {
// uri = new URI(e.source);
// } catch (URISyntaxException ex) {
// File f = new File(e.source);
// if (f.exists()) {
// uri = f.toURI();
// }
// }
// if (uri == null) {
// Utility.gripe("Unable to resolve path: " + e.source);
// return;
// }
// in = uri.toURL().openStream();
// saveFile(target, in);
// } catch (MalformedURLException ex) {
// Utility.gripe("Unable to resolve path: " + e.source);
// Logger.getLogger(MediaCache.class.getName()).log(Level.SEVERE, null, ex);
// } catch (IOException ex) {
// Utility.gripe("Unable to download file: " + ex.getMessage());
// Logger.getLogger(MediaCache.class.getName()).log(Level.SEVERE, null, ex);
// } finally {
// isDownloading = false;
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// Logger.getLogger(MediaCache.class.getName()).log(Level.SEVERE, null, ex);
// }
// }
// });
// if (wait) {
// int timeout = 10000;
// while (timeout > 0 && isDownloading) {
// try {
// Thread.sleep(100);
// } catch (InterruptedException ex) {
// return;
// }
// timeout -= 100;
// }
// }
// }
private void createBlankFile(MediaEntry e, String label, boolean isTemporary) {
MediaFile f = new MediaEntry.MediaFile();