From e8b652ecf315a4d2b8797a9e1287c549635f3f1d Mon Sep 17 00:00:00 2001 From: Yngve Inntjore Levinsen Date: Mon, 7 Mar 2016 16:34:19 +0100 Subject: [PATCH 1/5] removed unused imports --- apps/launcher/src/xal/app/launcher/App.java | 5 ----- apps/launcher/src/xal/app/launcher/FileWatcher.java | 2 -- .../src/xal/app/launcher/HostConfigurationController.java | 2 -- apps/launcher/src/xal/app/launcher/LaunchDocument.java | 3 --- apps/launcher/src/xal/app/launcher/RunController.java | 3 --- 5 files changed, 15 deletions(-) diff --git a/apps/launcher/src/xal/app/launcher/App.java b/apps/launcher/src/xal/app/launcher/App.java index ae2ac35e5..f0b93e7be 100644 --- a/apps/launcher/src/xal/app/launcher/App.java +++ b/apps/launcher/src/xal/app/launcher/App.java @@ -10,12 +10,7 @@ package xal.app.launcher; -import xal.tools.data.*; -import xal.tools.xml.XmlDataAdaptor; -import xal.tools.messaging.MessageCenter; - import java.io.*; -import java.net.*; import java.util.*; import java.util.regex.*; import java.util.jar.*; diff --git a/apps/launcher/src/xal/app/launcher/FileWatcher.java b/apps/launcher/src/xal/app/launcher/FileWatcher.java index 6335e0a54..1cbf686d2 100644 --- a/apps/launcher/src/xal/app/launcher/FileWatcher.java +++ b/apps/launcher/src/xal/app/launcher/FileWatcher.java @@ -8,13 +8,11 @@ package xal.app.launcher; -import xal.tools.StringJoiner; import xal.tools.data.*; import java.io.*; import java.net.URL; import java.util.*; -import java.util.regex.Pattern; /** Watches specified folders for new files of particular types */ diff --git a/apps/launcher/src/xal/app/launcher/HostConfigurationController.java b/apps/launcher/src/xal/app/launcher/HostConfigurationController.java index aa6f4dd1c..3fe5a2f5d 100644 --- a/apps/launcher/src/xal/app/launcher/HostConfigurationController.java +++ b/apps/launcher/src/xal/app/launcher/HostConfigurationController.java @@ -8,13 +8,11 @@ package xal.app.launcher; -import xal.extension.application.*; import xal.extension.bricks.WindowReference; import xal.extension.widgets.swing.KeyValueTableModel; import xal.tools.data.KeyValueRecordListener; import javax.swing.*; -import javax.swing.event.*; import javax.swing.table.*; import java.awt.event.*; import java.util.*; diff --git a/apps/launcher/src/xal/app/launcher/LaunchDocument.java b/apps/launcher/src/xal/app/launcher/LaunchDocument.java index 2f0135137..da2941a13 100644 --- a/apps/launcher/src/xal/app/launcher/LaunchDocument.java +++ b/apps/launcher/src/xal/app/launcher/LaunchDocument.java @@ -13,13 +13,10 @@ import xal.extension.application.*; import xal.tools.data.*; import xal.tools.xml.XmlDataAdaptor; -import xal.tools.IconLib; import xal.extension.bricks.WindowReference; import xal.tools.messaging.MessageCenter; import java.net.URL; -import java.awt.event.*; -import javax.swing.event.*; import javax.swing.*; import javax.swing.text.*; diff --git a/apps/launcher/src/xal/app/launcher/RunController.java b/apps/launcher/src/xal/app/launcher/RunController.java index 95bf1af74..f5a7937a0 100644 --- a/apps/launcher/src/xal/app/launcher/RunController.java +++ b/apps/launcher/src/xal/app/launcher/RunController.java @@ -13,11 +13,8 @@ import java.awt.Point; import java.awt.event.*; -import java.io.File; import java.util.*; import javax.swing.*; -import javax.swing.event.*; -import javax.swing.table.*; /** Controller for synchronizing the application view to the model */ From 63b94df8fdfde8e11b9f42fcdd59c34f8ccb797b Mon Sep 17 00:00:00 2001 From: Yngve Inntjore Levinsen Date: Mon, 7 Mar 2016 16:38:21 +0100 Subject: [PATCH 2/5] removed unused variables and commented out unused function making use of unused variable WINDOW_REFERENCE --- .../app/launcher/FileWatcherController.java | 5 +---- .../launcher/HostConfigurationController.java | 10 ++++------ .../src/xal/app/launcher/LaunchModel.java | 20 +++++++++---------- .../src/xal/app/launcher/RulesController.java | 2 -- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/apps/launcher/src/xal/app/launcher/FileWatcherController.java b/apps/launcher/src/xal/app/launcher/FileWatcherController.java index 38f9e2bb7..f8c6287b0 100644 --- a/apps/launcher/src/xal/app/launcher/FileWatcherController.java +++ b/apps/launcher/src/xal/app/launcher/FileWatcherController.java @@ -18,8 +18,6 @@ /** manage the File Watcher interface */ public class FileWatcherController { - /** The main model of this document */ - final private LaunchModel MODEL; /** file watcher */ final private FileWatcher FILE_WATCHER; @@ -34,7 +32,6 @@ public class FileWatcherController { /** Constructor */ @SuppressWarnings( "unchecked" ) // need to cast JList to appropriate element type public FileWatcherController( final LaunchModel model, final WindowReference windowReference ) { - MODEL = model; FILE_WATCHER = model.getFileWatcher(); FOLDER_CHOOSER = new JFileChooser(); @@ -54,8 +51,8 @@ public FileWatcherController( final LaunchModel model, final WindowReference win /** refresh the view with the model data */ - @SuppressWarnings( "unchecked" ) // TODO: JList supports generics in Java 7 or later private void refreshView() { + // TODO: JList supports generics in Java 7 or later final List folders = FILE_WATCHER.getFolders(); WATCH_FOLDER_LIST.setListData( new Vector( folders ) ); } diff --git a/apps/launcher/src/xal/app/launcher/HostConfigurationController.java b/apps/launcher/src/xal/app/launcher/HostConfigurationController.java index 3fe5a2f5d..9afb680a5 100644 --- a/apps/launcher/src/xal/app/launcher/HostConfigurationController.java +++ b/apps/launcher/src/xal/app/launcher/HostConfigurationController.java @@ -49,13 +49,13 @@ public HostConfigurationController( final LaunchModel model, final WindowReferen MODEL = model; HOST_SETTINGS_TABLE_MODEL = new HostSettingsTableModel( model ); - final JTable hostTable = (JTable)windowReference.getView( "HostTable" ); + final JTable hostTable = (JTable)WINDOW_REFERENCE.getView( "HostTable" ); hostTable.setModel( HOST_SETTINGS_TABLE_MODEL ); hostTable.getColumnModel().getColumn( HostSettingsTableModel.ENABLE_COLUMN ).setMaxWidth( 75 ); HOST_CONFIGURATION = model.getLauncher().getHostConfiguration(); - HOST_COMMAND_TABLE = (JTable)windowReference.getView( "HostCommandTable" ); + HOST_COMMAND_TABLE = (JTable)WINDOW_REFERENCE.getView( "HostCommandTable" ); HOST_COMMAND_TABLE_MODEL = new KeyValueTableModel<>( _hostCommands, "value" ); HOST_COMMAND_TABLE_MODEL.setColumnName( "value", "Command" ); @@ -67,9 +67,8 @@ public void recordModified( final KeyValueTableModel tableModel, }); HOST_COMMAND_TABLE.setModel( HOST_COMMAND_TABLE_MODEL ); - final JButton deleteHostCommandButton = (JButton)windowReference.getView( "DeleteHostCommandButton" ); + final JButton deleteHostCommandButton = (JButton)WINDOW_REFERENCE.getView( "DeleteHostCommandButton" ); deleteHostCommandButton.addActionListener( new ActionListener() { - private static final long serialVersionUID = 1L; public void actionPerformed( final ActionEvent event ) { final int[] selectedRows = HOST_COMMAND_TABLE.getSelectedRows(); @@ -84,9 +83,8 @@ public void actionPerformed( final ActionEvent event ) { } }); - final JButton addHostCommandButton = (JButton)windowReference.getView( "AddHostCommandButton" ); + final JButton addHostCommandButton = (JButton)WINDOW_REFERENCE.getView( "AddHostCommandButton" ); addHostCommandButton.addActionListener( new ActionListener() { - private static final long serialVersionUID = 1L; public void actionPerformed( final ActionEvent event ) { final int selectedRow = HOST_COMMAND_TABLE.getSelectedRow(); diff --git a/apps/launcher/src/xal/app/launcher/LaunchModel.java b/apps/launcher/src/xal/app/launcher/LaunchModel.java index c72f6e149..81ce11b34 100644 --- a/apps/launcher/src/xal/app/launcher/LaunchModel.java +++ b/apps/launcher/src/xal/app/launcher/LaunchModel.java @@ -164,16 +164,16 @@ private Rule getRule( final File file ) { } - /** get the first rule that matches the specified application */ - private Rule getRule( final App application ) { - final List rules = new ArrayList( RULES ); - for ( final Rule rule : rules ) { - if ( rule.matches( application ) ) { - return rule; - } - } - return null; - } +// /** get the first rule that matches the specified application */ +// private Rule getRule( final App application ) { +// final List rules = new ArrayList( RULES ); +// for ( final Rule rule : rules ) { +// if ( rule.matches( application ) ) { +// return rule; +// } +// } +// return null; +// } /** launch the specified application using the first matching rule */ diff --git a/apps/launcher/src/xal/app/launcher/RulesController.java b/apps/launcher/src/xal/app/launcher/RulesController.java index 9c6c5ebdd..b81bc911b 100644 --- a/apps/launcher/src/xal/app/launcher/RulesController.java +++ b/apps/launcher/src/xal/app/launcher/RulesController.java @@ -91,7 +91,6 @@ public void recordModified( final KeyValueTableModel tableModel, final JButton deleteRuleCommandButton = (JButton)windowReference.getView( "DeleteRuleCommandButton" ); deleteRuleCommandButton.addActionListener( new ActionListener() { - private static final long serialVersionUID = 1L; public void actionPerformed( final ActionEvent event ) { final int[] selectedRows = RULE_COMMAND_TABLE.getSelectedRows(); @@ -108,7 +107,6 @@ public void actionPerformed( final ActionEvent event ) { final JButton addRuleCommandButton = (JButton)windowReference.getView( "AddRuleCommandButton" ); addRuleCommandButton.addActionListener( new ActionListener() { - private static final long serialVersionUID = 1L; public void actionPerformed( final ActionEvent event ) { final int selectedRow = RULE_COMMAND_TABLE.getSelectedRow(); From 38e6c7617bee6d3dd5052eb502935eb03980545b Mon Sep 17 00:00:00 2001 From: Yngve Inntjore Levinsen Date: Wed, 9 Mar 2016 15:54:54 +0100 Subject: [PATCH 3/5] minor changes tried to improve the column resize added version and author column --- apps/launcher/src/xal/app/launcher/App.java | 471 +++++++++--------- .../src/xal/app/launcher/RunController.java | 295 +++++------ 2 files changed, 398 insertions(+), 368 deletions(-) diff --git a/apps/launcher/src/xal/app/launcher/App.java b/apps/launcher/src/xal/app/launcher/App.java index f0b93e7be..6c792ea6d 100644 --- a/apps/launcher/src/xal/app/launcher/App.java +++ b/apps/launcher/src/xal/app/launcher/App.java @@ -24,226 +24,253 @@ * @author tap */ public class App implements Comparable { - /** pattern for identifying script notes */ - static private final Pattern SCRIPT_NOTES_PATTERN; - - /** Path to the executable */ - private final File FILE; - - /** rule */ - private final Rule RULE; - - /** Text describing this application */ - private String _notes; - - /** label for this application */ - private String _label; - - /** time of last run */ - private Date _lastLaunchTime; - - - static { - SCRIPT_NOTES_PATTERN = Pattern.compile( "^#\\s+(\\w+\\s+[\\w\\s\\p{Punct}]+)$" ); - } - - - /** - * Constructor - * @param file The file of the executable. - * @param rule the rule used to generate the app - */ - public App( final File file, final Rule rule ) { - FILE = file; - RULE = rule; - - _lastLaunchTime = null; - _label = file.getName().split( "[.]" )[0]; - - parseInfo( file ); - } - - - /** get the rule */ - public Rule getRule() { - return RULE; - } - - - /** get the command to run the application in a local environment */ - public List getCommands() { - return RULE.getCommands( this ); - } - - - /** get the file to which the app refers */ - public File getFile() { - return FILE; - } - - - /** - * Get the path to the application - * @return the path to the application - */ - public String getPath() { - return FILE.getPath(); - } - - - /** - * Get the label to display identifying this application - * @return the short name of the file path of the executable - */ - public String getLabel() { - return _label; - } - - - /** get the time of the last run for this app */ - public Date getLastLaunchTime() { - return _lastLaunchTime; - } - - - /** set the last run time */ - public void setLastLaunchTime( final Date runTime ) { - _lastLaunchTime = runTime; - } - - - /** - * Test if the executable exists - * @return true if the executable exists and false if not - */ - public boolean exists() { - return FILE.exists(); - } - - - /** - * Get the notes associated with the application - * @return The notes associated with the application - */ - public String getNotes() { - return _notes; - } - - - /** - * Get the string representation of this instance - * @return the label - * @see #getLabel - */ - public String toString() { - return getLabel(); - } - - - /** parse notes from the file */ - private void parseInfo( final File file ) { - if ( file.canRead() ) { - final String filename = file.getName(); - final int typeIndex = filename.lastIndexOf( "." ); - if ( typeIndex >= 0 && typeIndex < filename.length() ) { - final String type = file.getName().substring( typeIndex + 1 ); - if ( type != null && type.length() > 0 ) { - if ( type.equals( "rb" ) || type.equals( "py" ) ) { - parseScriptHeader( file ); - } - else if ( type.equals( "jar" ) ) { - parseJarAppInfo( file ); - } - else { - return; - } - } - else { - return; - } - } - else { - return; - } - } - else { - return; - } - } - - - /** parse a standard script header for notes */ - private void parseScriptHeader( final File file ) { - try { - final BufferedReader reader = new BufferedReader( new FileReader( file ) ); - try { - int count = 0; - while ( count++ < 10 ) { // only attempt to read the first 10 lines - final String line = reader.readLine(); - final Matcher matcher = SCRIPT_NOTES_PATTERN.matcher( line ); - if ( matcher.matches() && matcher.groupCount() > 0 ) { - _notes = matcher.group(1); - return; - } - } - return; - } - finally { - reader.close(); - } - } - catch ( Exception exception ) { - return; - } - } - - - /** open the application's jar file, find the about properties and return the description */ - private void parseJarAppInfo( final File file ) { - try { - final JarFile jarFile = new JarFile( file ); - try { - final Enumeration entryEnum = jarFile.entries(); - while ( entryEnum.hasMoreElements() ) { - final JarEntry entry = entryEnum.nextElement(); - final String entryName = entry.getName(); - if ( entryName.endsWith( "About.properties" ) ) { - final Properties properties = new Properties(); - final InputStream propertyStream = jarFile.getInputStream( entry ); - properties.load( propertyStream ); - try { - _notes = properties.getProperty( "description" ); - _label = properties.getProperty( "name" ); - } - finally { - propertyStream.close(); - } - } - } - return; - } - catch ( Exception exception ) { - return; - } - finally { - jarFile.close(); - } - } - catch ( Exception exception ) { - exception.printStackTrace(); - return; - } - } - - - /** - * Compare two instances. The two instances are compared by label and the - * comparison is based on alphebetical sorting. - * @param app the other App against which to compare - * @return a positive number if this comes after the argument, negative if this comes before and 0 if they are equal - * @see #getLabel - */ - public int compareTo( final App app ) { - return getLabel().compareToIgnoreCase( app.getLabel() ); - } + /** pattern for identifying script notes */ + static private final Pattern SCRIPT_NOTES_PATTERN; + + /** Path to the executable */ + private final File FILE; + + /** rule */ + private final Rule RULE; + + /** Text describing this application */ + private String _notes; + + /** label for this application */ + private String _label; + + /** version for this application */ + private String _version; + + /** author(-s) of this application */ + private String _authors; + + /** time of last run */ + private Date _lastLaunchTime; + + + static { + SCRIPT_NOTES_PATTERN = Pattern.compile( "^#\\s+(\\w+\\s+[\\w\\s\\p{Punct}]+)$" ); + } + + + /** + * Constructor + * @param file The file of the executable. + * @param rule the rule used to generate the app + */ + public App( final File file, final Rule rule ) { + FILE = file; + RULE = rule; + + _lastLaunchTime = null; + _label = file.getName().split( "[.]" )[0]; + + parseInfo( file ); + } + + + /** get the rule */ + public Rule getRule() { + return RULE; + } + + + /** get the command to run the application in a local environment */ + public List getCommands() { + return RULE.getCommands( this ); + } + + + /** get the file to which the app refers */ + public File getFile() { + return FILE; + } + + + /** + * Get the path to the application + * @return the path to the application + */ + public String getPath() { + return FILE.getPath(); + } + + + /** + * Get the label to display identifying this application + * @return the short name of the file path of the executable + */ + public String getLabel() { + return _label; + } + + + /** + * Get the version of this application + * @return the application version + */ + public String getVersion() { + return _version; + } + + + /** + * Get the authors of this application + * @return authors of the application + */ + public String getAuthor() { + return _authors; + } + + + + /** get the time of the last run for this app */ + public Date getLastLaunchTime() { + return _lastLaunchTime; + } + + + /** set the last run time */ + public void setLastLaunchTime( final Date runTime ) { + _lastLaunchTime = runTime; + } + + + /** + * Test if the executable exists + * @return true if the executable exists and false if not + */ + public boolean exists() { + return FILE.exists(); + } + + + /** + * Get the notes associated with the application + * @return The notes associated with the application + */ + public String getNotes() { + return _notes; + } + + + /** + * Get the string representation of this instance + * @return the label + * @see #getLabel + */ + public String toString() { + return getLabel(); + } + + + /** parse notes from the file */ + private void parseInfo( final File file ) { + if ( file.canRead() ) { + final String filename = file.getName(); + final int typeIndex = filename.lastIndexOf( "." ); + if ( typeIndex >= 0 && typeIndex < filename.length() ) { + final String type = file.getName().substring( typeIndex + 1 ); + if ( type != null && type.length() > 0 ) { + if ( type.equals( "rb" ) || type.equals( "py" ) ) { + parseScriptHeader( file ); + } + else if ( type.equals( "jar" ) ) { + parseJarAppInfo( file ); + } + else { + return; + } + } + else { + return; + } + } + else { + return; + } + } + else { + return; + } + } + + + /** parse a standard script header for notes */ + private void parseScriptHeader( final File file ) { + try { + final BufferedReader reader = new BufferedReader( new FileReader( file ) ); + try { + int count = 0; + while ( count++ < 10 ) { // only attempt to read the first 10 lines + final String line = reader.readLine(); + final Matcher matcher = SCRIPT_NOTES_PATTERN.matcher( line ); + if ( matcher.matches() && matcher.groupCount() > 0 ) { + _notes = matcher.group(1); + return; + } + } + return; + } + finally { + reader.close(); + } + } + catch ( Exception exception ) { + return; + } + } + + + /** open the application's jar file, find the about properties and return the description */ + private void parseJarAppInfo( final File file ) { + try { + final JarFile jarFile = new JarFile( file ); + try { + final Enumeration entryEnum = jarFile.entries(); + while ( entryEnum.hasMoreElements() ) { + final JarEntry entry = entryEnum.nextElement(); + final String entryName = entry.getName(); + if ( entryName.endsWith( "About.properties" ) ) { + final Properties properties = new Properties(); + final InputStream propertyStream = jarFile.getInputStream( entry ); + properties.load( propertyStream ); + try { + _notes = properties.getProperty( "description" ); + _label = properties.getProperty( "name" ); + _version = properties.getProperty( "version" ); + _authors = properties.getProperty( "authors" ); + } + finally { + propertyStream.close(); + } + } + } + return; + } + catch ( Exception exception ) { + return; + } + finally { + jarFile.close(); + } + } + catch ( Exception exception ) { + exception.printStackTrace(); + return; + } + } + + + /** + * Compare two instances. The two instances are compared by label and the + * comparison is based on alphebetical sorting. + * @param app the other App against which to compare + * @return a positive number if this comes after the argument, negative if this comes before and 0 if they are equal + * @see #getLabel + */ + public int compareTo( final App app ) { + return getLabel().compareToIgnoreCase( app.getLabel() ); + } } diff --git a/apps/launcher/src/xal/app/launcher/RunController.java b/apps/launcher/src/xal/app/launcher/RunController.java index f5a7937a0..0eaa54251 100644 --- a/apps/launcher/src/xal/app/launcher/RunController.java +++ b/apps/launcher/src/xal/app/launcher/RunController.java @@ -19,153 +19,156 @@ /** Controller for synchronizing the application view to the model */ public class RunController { - /** The main model of this document */ - final private LaunchModel MODEL; - - /** file watcher */ - final private FileWatcher FILE_WATCHER; - - /** table of applications that can be run */ - final private JTable APP_TABLE; - - /** table model for displaying the applications */ - final private KeyValueFilteredTableModel APP_TABLE_MODEL; - - /** filter field */ - final private JTextField FILTER_FIELD; - - - /** Constructor */ - public RunController( final LaunchModel model, final WindowReference windowReference ) { - MODEL = model; - FILE_WATCHER = model.getFileWatcher(); - - final JButton appFilterClearButton = (JButton)windowReference.getView( "AppFilterClearButton" ); - appFilterClearButton.addActionListener( clearFilterAction() ); - - final JButton refreshAppsButton = (JButton)windowReference.getView( "AppsRefreshButton" ); - refreshAppsButton.addActionListener( refreshAppsAction() ); - - final JButton appLaunchButton = (JButton)windowReference.getView( "AppLaunchButton" ); - appLaunchButton.addActionListener( runAction() ); - - FILTER_FIELD = (JTextField)windowReference.getView( "AppFilterField" ); - FILTER_FIELD.putClientProperty( "JTextField.variant", "search" ); - FILTER_FIELD.putClientProperty( "JTextField.Search.Prompt", "Application Filter" ); - - APP_TABLE = (JTable)windowReference.getView( "AppTable" ); - APP_TABLE.setAutoResizeMode( JTable.AUTO_RESIZE_LAST_COLUMN ); - APP_TABLE.setAutoCreateRowSorter( true ); - APP_TABLE.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); - APP_TABLE_MODEL = new KeyValueFilteredTableModel( new ArrayList(), "label", "lastLaunchTime", "rule.kind", "notes" ); - APP_TABLE_MODEL.setMatchingKeyPaths( "label", "rule.kind", "file.name", "notes" ); - APP_TABLE_MODEL.setColumnName( "rule.kind", "Kind" ); - APP_TABLE_MODEL.setColumnClass( "lastLaunchTime", Date.class ); - APP_TABLE_MODEL.setInputFilterComponent( FILTER_FIELD ); - APP_TABLE.setModel( APP_TABLE_MODEL ); - APP_TABLE.addMouseListener( appTableClickHandler() ); - APP_TABLE.addMouseMotionListener( appTableMouseMonitor() ); - - APP_TABLE.getColumnModel().getColumn( 3 ).setPreferredWidth( 300 ); // allot space for the notes - - refreshView(); - } - - - /** run the selected application */ - private void runSelectedApplication() { - final int selectedRow = APP_TABLE.getSelectedRow(); - if ( selectedRow >= 0 ) { - final int modelRow = APP_TABLE.convertRowIndexToModel( selectedRow ); - final App application = APP_TABLE_MODEL.getRecordAtRow( modelRow ); - System.out.println( "Run: " + application.getPath() ); - try { - MODEL.launchApplication( application ); - } - catch( Exception exception ) { - exception.printStackTrace(); - JOptionPane.showMessageDialog( APP_TABLE, exception.getMessage(), "Error Running Application", JOptionPane.WARNING_MESSAGE ); - } - } - } - - - /** refresh the view with the model data */ - private void refreshView() { - final List applications = MODEL.getApplications(); - APP_TABLE_MODEL.setRecords( applications ); - } - - - /** action to refresh the list of applications */ - private AbstractAction refreshAppsAction() { - return new AbstractAction() { + /** The main model of this document */ + final private LaunchModel MODEL; + + /** table of applications that can be run */ + final private JTable APP_TABLE; + + /** table model for displaying the applications */ + final private KeyValueFilteredTableModel APP_TABLE_MODEL; + + /** filter field */ + final private JTextField FILTER_FIELD; + + + /** Constructor */ + public RunController( final LaunchModel model, final WindowReference windowReference ) { + MODEL = model; + + final JButton appFilterClearButton = (JButton)windowReference.getView( "AppFilterClearButton" ); + appFilterClearButton.addActionListener( clearFilterAction() ); + + final JButton refreshAppsButton = (JButton)windowReference.getView( "AppsRefreshButton" ); + refreshAppsButton.addActionListener( refreshAppsAction() ); + + final JButton appLaunchButton = (JButton)windowReference.getView( "AppLaunchButton" ); + appLaunchButton.addActionListener( runAction() ); + + FILTER_FIELD = (JTextField)windowReference.getView( "AppFilterField" ); + FILTER_FIELD.putClientProperty( "JTextField.variant", "search" ); + FILTER_FIELD.putClientProperty( "JTextField.Search.Prompt", "Application Filter" ); + + APP_TABLE = (JTable)windowReference.getView( "AppTable" ); + APP_TABLE.setAutoResizeMode( JTable.AUTO_RESIZE_ALL_COLUMNS ); + APP_TABLE.setAutoCreateRowSorter( true ); + APP_TABLE.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + APP_TABLE_MODEL = new KeyValueFilteredTableModel( new ArrayList(), "label", "lastLaunchTime", "notes", "rule.kind", "version", "author" ); + APP_TABLE_MODEL.setMatchingKeyPaths( "label", "file.name", "notes", "rule.kind", "version", "author" ); + APP_TABLE_MODEL.setColumnName( "rule.kind", "Kind" ); + APP_TABLE_MODEL.setColumnClass( "lastLaunchTime", Date.class ); + APP_TABLE_MODEL.setInputFilterComponent( FILTER_FIELD ); + APP_TABLE.setModel( APP_TABLE_MODEL ); + APP_TABLE.addMouseListener( appTableClickHandler() ); + APP_TABLE.addMouseMotionListener( appTableMouseMonitor() ); + + APP_TABLE.getColumnModel().getColumn( 2 ).setPreferredWidth( 600 ); // try to get more space for the description + APP_TABLE.getColumnModel().getColumn(0).setPreferredWidth(200); // 1/3 of description + APP_TABLE.getColumnModel().getColumn(5).setPreferredWidth(150); // a bit less than application name (label) + // the next three never become long strings.. + APP_TABLE.getColumnModel().getColumn(1).setMaxWidth(100); + APP_TABLE.getColumnModel().getColumn(1).setPreferredWidth(100); + APP_TABLE.getColumnModel().getColumn(3).setMaxWidth(70); + APP_TABLE.getColumnModel().getColumn(4).setMaxWidth(50); + + refreshView(); + } + + + /** run the selected application */ + private void runSelectedApplication() { + final int selectedRow = APP_TABLE.getSelectedRow(); + if ( selectedRow >= 0 ) { + final int modelRow = APP_TABLE.convertRowIndexToModel( selectedRow ); + final App application = APP_TABLE_MODEL.getRecordAtRow( modelRow ); + System.out.println( "Run: " + application.getPath() ); + try { + MODEL.launchApplication( application ); + } + catch( Exception exception ) { + exception.printStackTrace(); + JOptionPane.showMessageDialog( APP_TABLE, exception.getMessage(), "Error Running Application", JOptionPane.WARNING_MESSAGE ); + } + } + } + + + /** refresh the view with the model data */ + private void refreshView() { + final List applications = MODEL.getApplications(); + APP_TABLE_MODEL.setRecords( applications ); + } + + + /** action to refresh the list of applications */ + private AbstractAction refreshAppsAction() { + return new AbstractAction() { private static final long serialVersionUID = 1L; - - public void actionPerformed( final ActionEvent event ) { - MODEL.refreshApplications(); - refreshView(); - } - }; - } - - - /** action to clear the filter field */ - private AbstractAction clearFilterAction() { - return new AbstractAction() { + + public void actionPerformed( final ActionEvent event ) { + MODEL.refreshApplications(); + refreshView(); + } + }; + } + + + /** action to clear the filter field */ + private AbstractAction clearFilterAction() { + return new AbstractAction() { private static final long serialVersionUID = 1L; - - public void actionPerformed( final ActionEvent event ) { - FILTER_FIELD.setText( "" ); - } - }; - } - - - /** action to run the selected application */ - private AbstractAction runAction() { - return new AbstractAction() { + + public void actionPerformed( final ActionEvent event ) { + FILTER_FIELD.setText( "" ); + } + }; + } + + + /** action to run the selected application */ + private AbstractAction runAction() { + return new AbstractAction() { private static final long serialVersionUID = 1L; - - public void actionPerformed( final ActionEvent event ) { - runSelectedApplication(); - } - }; - } - - - /** handler of application table selection events */ - private MouseListener appTableClickHandler() { - return new MouseAdapter() { - public void mouseClicked( final MouseEvent event ) { - switch ( event.getClickCount() ) { - case 2: - runSelectedApplication(); - break; - default: - break; - } - } - }; - } - - - /** mouse motion listener to set the tool tip on the application under the mouse */ - private MouseMotionListener appTableMouseMonitor() { - return new MouseMotionAdapter() { - public void mouseMoved( final MouseEvent event ) { - final Point eventPoint = event.getPoint(); - final int row = APP_TABLE.rowAtPoint( eventPoint ); - final int column = APP_TABLE.columnAtPoint( eventPoint ); - if ( row >= 0 ) { - final Object cellValue = APP_TABLE_MODEL.getValueAt( row, column ); - final String tip = cellValue != null ? cellValue.toString() : null; - APP_TABLE.setToolTipText( tip != null && tip.length() > 20 ? tip : null ); - } - else { - APP_TABLE.setToolTipText( null ); - } - } - }; - } + + public void actionPerformed( final ActionEvent event ) { + runSelectedApplication(); + } + }; + } + + + /** handler of application table selection events */ + private MouseListener appTableClickHandler() { + return new MouseAdapter() { + public void mouseClicked( final MouseEvent event ) { + switch ( event.getClickCount() ) { + case 2: + runSelectedApplication(); + break; + default: + break; + } + } + }; + } + + + /** mouse motion listener to set the tool tip on the application under the mouse */ + private MouseMotionListener appTableMouseMonitor() { + return new MouseMotionAdapter() { + public void mouseMoved( final MouseEvent event ) { + final Point eventPoint = event.getPoint(); + final int row = APP_TABLE.rowAtPoint( eventPoint ); + final int column = APP_TABLE.columnAtPoint( eventPoint ); + if ( row >= 0 ) { + final Object cellValue = APP_TABLE_MODEL.getValueAt( row, column ); + final String tip = cellValue != null ? cellValue.toString() : null; + APP_TABLE.setToolTipText( tip != null && tip.length() > 20 ? tip : null ); + } + else { + APP_TABLE.setToolTipText( null ); + } + } + }; + } } From 969ca15776d84d886f050a6d48dbb678f0d746e1 Mon Sep 17 00:00:00 2001 From: Yngve Inntjore Levinsen Date: Wed, 9 Mar 2016 15:55:25 +0100 Subject: [PATCH 4/5] bumped version to 3.0 updated date --- apps/launcher/resources/About.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/launcher/resources/About.properties b/apps/launcher/resources/About.properties index 1dce8405f..39f2a4c55 100644 --- a/apps/launcher/resources/About.properties +++ b/apps/launcher/resources/About.properties @@ -1,6 +1,6 @@ name = Launcher -version = 2.0 -date = May 5, 2009 -authors = Tom Pelaia +version = 3.0 +date = March 9, 2016 +authors = Tom Pelaia (SNS), Yngve Inntjore Levinsen (ESS) organization = Spallation Neutron Source description = The launcher allows users to launch XAL applications. From 5b3d9cf02a87f30d93d5e35330ad612b98cc5086 Mon Sep 17 00:00:00 2001 From: Yngve Inntjore Levinsen Date: Sat, 23 Apr 2016 14:58:48 +0200 Subject: [PATCH 5/5] ignore vim backup files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index dfa870ffa..2f3215095 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build/**/* /.classpath /.project /doc +*.un~