git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@75 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
kascade 2008-05-02 11:15:44 +00:00
parent 5985866810
commit 49d58b1807
10 changed files with 70 additions and 101 deletions

View File

@ -90,7 +90,7 @@ public class ECUEditor extends JFrame implements WindowListener, PropertyChangeL
public ECUEditor() {
// get settings from xml
settings = settingsManager.load("A new file will be created.");
settings = settingsManager.load();
if (!settings.getRecentVersion().equalsIgnoreCase(VERSION)) {
showReleaseNotes();

View File

@ -21,7 +21,6 @@
package com.romraider;
import com.romraider.ECUEditor;
import javax.swing.SwingUtilities;
public class ECUEditorManager {
@ -33,13 +32,16 @@ public class ECUEditorManager {
public static ECUEditor getECUEditor() {
if (editor == null) {
SwingUtilities.invokeLater(new Runnable() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
editor = new ECUEditor();
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return editor;
}
}

View File

@ -21,102 +21,67 @@
package com.romraider;
import com.romraider.swing.LookAndFeelManager;
import com.romraider.util.LogManager;
import com.romraider.ECUEditor;
import static com.romraider.ECUEditorManager.getECUEditor;
import static com.romraider.logger.ecu.EcuLogger.startLogger;
import static com.romraider.swing.LookAndFeelManager.initLookAndFeel;
import static com.romraider.util.LogManager.initDebugLogging;
import com.romraider.util.SettingsManager;
import com.romraider.util.SettingsManagerImpl;
import org.apache.log4j.Logger;
import java.io.BufferedReader;
import static org.apache.log4j.Logger.getLogger;
import static javax.swing.SwingUtilities.invokeLater;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
import java.io.File;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class ECUExec {
private static final Logger LOGGER = Logger.getLogger(ECUExec.class);
private static final Logger LOGGER = getLogger(ECUExec.class);
private static final String START_LOGGER_ARG = "-logger";
private ECUExec() {
throw new UnsupportedOperationException();
}
public static void main(String args[]) {
// init debug loging
LogManager.initLogging();
// init debug logging
initDebugLogging();
// check for dodgy threading - dev only
// RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager(true));
// try create socket listener for shell opening new files
ServerSocket sock = null; // original server socket
String serverName = "localhost";
Socket clientSocket = null; // socket created by accept
PrintWriter pw = null; // socket output stream
BufferedReader br = null; // socket input stream
int serverPort = 8753;
try {
sock = new java.net.ServerSocket(serverPort); // create socket and bind to port
sock.close();
} catch (Exception ex) {
// pass filename if file present
if (args.length > 0) {
try {
Socket socket = new java.net.Socket(serverName, serverPort); // create socket and connect
pw = new java.io.PrintWriter(socket.getOutputStream(), true); // create reader and writer
br = new java.io.BufferedReader(new java.io.InputStreamReader(socket.getInputStream()));
pw.println(args[0]); // send msg to the server
String answer = br.readLine(); // get data from the server
pw.close(); // close everything
br.close();
socket.close();
} catch (Throwable e) {
LOGGER.error("Error occurred", e);
}
// after sending filename, exit
System.exit(0);
}
}
// set look and feel
LookAndFeelManager.initLookAndFeel();
initLookAndFeel();
// launch editor
ECUEditor editor = ECUEditorManager.getECUEditor();
// open files, if passed
try {
if (args.length > 0) {
editor.openImage(new File(args[0]).getCanonicalFile());
// open editor or logger
if (containsLoggerArg(args)) openLogger();
else openEditor(args);
}
private static boolean containsLoggerArg(String[] args) {
if (args.length == 0) return false;
return args[0].equals(START_LOGGER_ARG);
}
private static void openLogger() {
SettingsManager manager = new SettingsManagerImpl();
Settings settings = manager.load();
startLogger(EXIT_ON_CLOSE, settings);
}
private static void openEditor(String[] args) {
ECUEditor editor = getECUEditor();
if (args.length > 0) openRom(editor, args[0]);
}
private static void openRom(final ECUEditor editor, final String rom) {
invokeLater(new Runnable() {
public void run() {
try {
File file = new File(rom);
editor.openImage(file);
} catch (Exception ex) {
LOGGER.error("Error opening file", ex);
}
// listen for files
try {
while (true) {
sock = new java.net.ServerSocket(serverPort); // create socket and bind to port
clientSocket = sock.accept(); // wait for client to connect
pw = new java.io.PrintWriter(clientSocket.getOutputStream(), true);
br = new java.io.BufferedReader(
new java.io.InputStreamReader(clientSocket.getInputStream()));
String msg = br.readLine(); // read msg from client
// open file from client
editor.openImage(new File(msg));
pw.close(); // close everything
br.close();
clientSocket.close();
sock.close();
}
} catch (Throwable e) {
LOGGER.error("Error occurred", e);
LOGGER.error("Error opening rom", ex);
}
}
});
}
}

View File

@ -4,7 +4,7 @@ import com.romraider.util.LogManager;
public class TestNewGUI {
public static void main(String[] args) {
LogManager.initLogging();
LogManager.initDebugLogging();
NewGUI.getInstance().setVisible(true);
}
}

View File

@ -24,6 +24,7 @@ package com.romraider.logger.ecu;
import com.romraider.Settings;
import com.romraider.swing.LookAndFeelManager;
import com.romraider.util.LogManager;
import com.romraider.util.SettingsManager;
import com.romraider.util.SettingsManagerImpl;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
@ -35,7 +36,7 @@ public final class EcuLoggerExec {
public static void main(String... args) {
// init debug loging
LogManager.initLogging();
LogManager.initDebugLogging();
// check for dodgy threading - dev only
// RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager(true));
@ -44,7 +45,8 @@ public final class EcuLoggerExec {
LookAndFeelManager.initLookAndFeel();
// load settings
Settings settings = new SettingsManagerImpl().load("Using default settings.");
SettingsManager manager = new SettingsManagerImpl();
Settings settings = manager.load();
// start logger
EcuLogger.startLogger(EXIT_ON_CLOSE, settings);

View File

@ -391,7 +391,7 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
//**********************************************************************
public static void main(String[] args) {
LogManager.initLogging();
LogManager.initDebugLogging();
LookAndFeelManager.initLookAndFeel();
startTestApp(EXIT_ON_CLOSE);
}

View File

@ -1,6 +1,6 @@
package com.romraider.util;
import org.apache.log4j.PropertyConfigurator;
import static org.apache.log4j.PropertyConfigurator.configureAndWatch;
public final class LogManager {
@ -8,7 +8,7 @@ public final class LogManager {
throw new UnsupportedOperationException();
}
public static void initLogging() {
PropertyConfigurator.configure("log4j.properties");
public static void initDebugLogging() {
configureAndWatch("log4j.properties");
}
}

View File

@ -4,7 +4,7 @@ import com.romraider.Settings;
import com.romraider.swing.JProgressPane;
public interface SettingsManager {
Settings load(String settingsNotFoundMessage);
Settings load();
void save(Settings settings);

View File

@ -1,11 +1,11 @@
package com.romraider.util;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
import static com.romraider.Version.VERSION; // this is a generated class - see build.xml
import com.romraider.Settings;
import static com.romraider.Version.VERSION;
import com.romraider.swing.JProgressPane;
import com.romraider.xml.DOMSettingsBuilder;
import com.romraider.xml.DOMSettingsUnmarshaller;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import static javax.swing.JOptionPane.INFORMATION_MESSAGE;
@ -17,7 +17,7 @@ import java.io.FileNotFoundException;
public final class SettingsManagerImpl implements SettingsManager {
private static final String SETTINGS_FILE = "./settings.xml";
public Settings load(String settingsNotFoundMessage) {
public Settings load() {
try {
InputSource src = new InputSource(new FileInputStream(new File(SETTINGS_FILE)));
DOMSettingsUnmarshaller domUms = new DOMSettingsUnmarshaller();
@ -26,7 +26,7 @@ public final class SettingsManagerImpl implements SettingsManager {
Document doc = parser.getDocument();
return domUms.unmarshallSettings(doc.getDocumentElement());
} catch (FileNotFoundException e) {
showMessageDialog(null, "Settings file not found.\n" + settingsNotFoundMessage,
showMessageDialog(null, "Settings file not found.\nUsing default settings.",
"Error Loading Settings", INFORMATION_MESSAGE);
return new Settings();
} catch (Exception e) {
@ -41,7 +41,7 @@ public final class SettingsManagerImpl implements SettingsManager {
public void save(Settings settings, JProgressPane progress) {
DOMSettingsBuilder builder = new DOMSettingsBuilder();
try {
builder.buildSettings(settings, new File("./settings.xml"), progress, VERSION);
builder.buildSettings(settings, new File(SETTINGS_FILE), progress, VERSION);
} catch (Exception e) {
// ignore
}

View File

@ -139,7 +139,7 @@ public final class DOMRomUnmarshaller {
}
public static void main(String args[]) {
LogManager.initLogging();
LogManager.initDebugLogging();
DOMRomUnmarshaller um = new DOMRomUnmarshaller(new Settings(), new ECUEditor());
um.parent.dispose();
RomID romID = new RomID();