/*
 *  RFPhaseShakerMain.java
 *
 *  Created on Feb. 25 2009
 */
package xal.app.rfphaseshaker;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.net.*;

import xal.extension.application.*;
import xal.extension.smf.application.AcceleratorApplication;

/**
 *  RFPhaseShakerMain is a concrete subclass of ApplicationAdaptor for the
 *  Quad shaker application.
 *
 *@author     shishlo
 */

public class RFPhaseShakerMain extends ApplicationAdaptor {

	/**
	 *  Constructor
	 */
	public RFPhaseShakerMain() { }


	/**
	 *  Returns the text file suffixes of files this application can open.
	 *
	 *@return    Suffixes of readable files
	 */
	public String[] readableDocumentTypes() {
		return new String[]{"rfsh"};
	}


	/**
	 *  Returns the text file suffixes of files this application can write.
	 *
	 *@return    Suffixes of writable files
	 */
	public String[] writableDocumentTypes() {
		return new String[]{"rfsh"};
	}


	/**
	 *  Returns an instance of the RFPhaseShaker application document.
	 *
	 *@return    An instance of RFPhaseShaker application document.
	 */
	public XalDocument newEmptyDocument() {
		return new RFPhaseShakerDocument();
	}


	/**
	 *  Returns an instance of the RFPhaseShaker application document corresponding
	 *  to the specified URL.
	 *
	 *@param  url  The URL of the file to open.
	 *@return      An instance of an RFPhaseShaker application document.
	 */
	public XalDocument newDocument(java.net.URL url) {
		return new RFPhaseShakerDocument(url);
	}


	/**
	 *  Specifies the name of the RFPhaseShaker application.
	 *
	 *@return    Name of the application.
	 */
	public String applicationName() {
		return "RF Phase Shaker";
	}


	/**
	 *  Activates the preference panel for the RFPhaseShaker application.
	 *
	 *@param  document  The document whose preferences are being changed.
	 */
	public void editPreferences(XalDocument document) {
		((RFPhaseShakerDocument) document).editPreferences();
	}


	/**
	 *  Specifies whether the RFPhaseShaker application will send standard output
	 *  and error to the console.
	 *
	 *@return    true or false.
	 */
	public boolean usesConsole() {
		String usesConsoleProperty = System.getProperty("usesConsole");
		if(usesConsoleProperty != null) {
			return Boolean.valueOf(usesConsoleProperty).booleanValue();
		} else {
			return true;
		}
	}


	/**
	 *  The main method of the application.
	 *
	 *@param  args  The command line arguments
	 */
	public static void main(String[] args) {

		if(args.length == 0) {

			RFPhaseShakerMain doc = new RFPhaseShakerMain();

			try {
				AcceleratorApplication.launch(doc);
			} catch(Exception exception) {
				System.err.println(exception.getMessage());
				exception.printStackTrace();
				JOptionPane.showMessageDialog(null, exception.getMessage(),
						exception.getClass().getName(), JOptionPane.WARNING_MESSAGE);
			}
			return;
		}

		RFPhaseShakerMain doc = new RFPhaseShakerMain();

		URL[] predefConfURLArr = new URL[args.length];

		for(int i = 0; i < args.length; i++) {
			predefConfURLArr[i] = doc.getClass().getResource("config/" + args[i]);
		}

		try {
			AcceleratorApplication.launch(doc, predefConfURLArr);
		} catch(Exception exception) {
			System.err.println(exception.getMessage());
			exception.printStackTrace();
			JOptionPane.showMessageDialog(null, exception.getMessage(),
					exception.getClass().getName(), JOptionPane.WARNING_MESSAGE);
		}
	}
}


@@ -2502,38 +2502,16 @@
 ) %7B%0A
-%0A
 %09%09
-if(args.length == 0) %7B%0A%0A%09%09%09
+final 
 RFPh
@@ -2516,35 +2516,42 @@
 PhaseShakerMain 
-doc
+appAdaptor
  = new RFPhaseSh
@@ -2566,386 +2566,121 @@
 ();%0A
-%0A
 %09%09
-%09try %7B%0A%09%09%09%09AcceleratorApplication.launch(doc);%0A%09%09%09%7D catch(Exception exception) %7B%0A%09%09%09%09System.err.println(exception.getMessage());%0A%09%09%09%09exception.printStackTrace();%0A%09%09%09%09JOptionPane.showMessageDialog(null, exception.getMessage(),%0A%09%09%09%09%09%09exception.getClass().getName(), JOptionPane.WARNING_MESSAGE)
+URL%5B%5D predefConfURLArr = null;%0A%0A%0A%09%09if ( args.length == 0 ) %7B%0A%09%09%09predefConfURLArr = new URL%5B0%5D
 ;%0A
-%09
 %09%09%7D%0A%09%09
-%09return;%0A%09%09%7D%0A%0A%09%09RFPhaseShakerMain doc = new RFPhaseShakerMain();%0A%0A%09%09URL%5B%5D 
+else %7B%0A%09%09%09
 pred
@@ -2720,27 +2720,37 @@
 h%5D;%0A
-%0A
+%09
 %09%09for
-(
+ ( 
 int i
+ndex
  = 0; i
+ndex
  %3C a
@@ -2766,14 +2766,20 @@
 h; i
+ndex
 ++
+ 
 ) %7B%0A
+%09
 %09%09%09p
@@ -2799,26 +2799,26 @@
 rr%5Bi
-%5D = doc.getClass()
+ndex%5D = appAdaptor
 .get
@@ -2825,17 +2825,21 @@
 Resource
-(
+URL( 
 %22config/
@@ -2852,11 +2852,21 @@
 gs%5Bi
-%5D);
+ndex%5D );%0A%09%09%09%7D
 %0A%09%09%7D
@@ -2908,19 +2908,27 @@
 .launch(
-doc
+ appAdaptor
 , predef
@@ -2941,20 +2941,24 @@
 LArr
+ 
 );%0A%09%09%7D
- 
+%0A%09%09
 catch
+ 
 (Exc
@@ -3089,16 +3089,17 @@
 eDialog(
+ 
 null, ex
@@ -3123,14 +3123,9 @@
 e(),
-%0A%09%09%09%09%09
+ 
 exce
@@ -3179,16 +3179,17 @@
 _MESSAGE
+ 
 );%0A%09%09%7D%0A%09

Load the RF Phase Shaker configuration files using the application adaptor’s getResourceURL() method.