001package jmri.configurexml; 002 003import java.awt.event.ActionEvent; 004import java.io.File; 005import javax.swing.JFileChooser; 006 007import jmri.util.swing.JmriJOptionPane; 008 009/** 010 * Load configuration information from an XML file. 011 * <p> 012 * The file context for this is the "user" file chooser. 013 * <p> 014 * This will load whatever information types are present in the file. See 015 * {@link jmri.ConfigureManager} for information on the various types of 016 * information stored in configuration files. 017 * 018 * @author Bob Jacobsen Copyright (C) 2002 019 * @see jmri.jmrit.XmlFile 020 */ 021public class LoadXmlUserAction extends LoadXmlConfigAction { 022 023 static private File currentFile = null; 024 025 public LoadXmlUserAction() { 026 this(Bundle.getMessage("MenuItemLoad")); 027 } 028 029 public LoadXmlUserAction(String s) { 030 super(s); 031 } 032 033 @Override 034 public void actionPerformed(ActionEvent e) { 035 JFileChooser userFileChooser = getUserFileChooser(); 036 userFileChooser.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG); 037 userFileChooser.setApproveButtonText(Bundle.getMessage("ButtonOpen")); 038 // Cancel button can't be localized like userFileChooser.setCancelButtonText() TODO 039 userFileChooser.setDialogTitle(Bundle.getMessage("LoadTitle")); 040 041 boolean results = loadFile(userFileChooser); 042 if (results) { 043 log.debug("load was successful"); 044 setCurrentFile(userFileChooser.getSelectedFile()); 045 } else { 046 log.debug("load failed"); 047 JmriJOptionPane.showMessageDialog(null, 048 Bundle.getMessage("LoadHasErrors") + "\n" 049 + Bundle.getMessage("CheckPreferences") + "\n" 050 + Bundle.getMessage("ConsoleWindowHasInfo"), 051 Bundle.getMessage("LoadError"), JmriJOptionPane.ERROR_MESSAGE); 052 setCurrentFile(null); 053 } 054 } 055 056 /** 057 * Used by e.g. jmri.jmrit.mailreport.ReportPanel et al to know last load 058 * 059 * @return the last file loaded using this action; returns null if this 060 * action was not called or if the last time this action was called, 061 * no file was loaded 062 */ 063 public static File getCurrentFile() { 064 return currentFile; 065 } 066 067 private static void setCurrentFile(File arg) { 068 currentFile = arg; 069 } 070 071 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoadXmlUserAction.class); 072 073}