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