001package jmri.jmrit.revhistory.swing; 002 003import java.awt.event.ActionEvent; 004import javax.swing.AbstractAction; 005import javax.swing.JFrame; 006import javax.swing.JScrollPane; 007import javax.swing.JTextArea; 008import jmri.InstanceManager; 009import jmri.jmrit.revhistory.FileHistory; 010import jmri.util.JmriJFrame; 011 012/** 013 * Swing action to display the file revision history 014 * 015 * @author Bob Jacobsen Copyright (C) 2009, 2022 016 */ 017public class FileHistoryAction extends AbstractAction { 018 019 public FileHistoryAction(String s) { 020 super(s); 021 } 022 023 public FileHistoryAction() { 024 this("File History"); 025 } 026 027 @Override 028 public void actionPerformed(ActionEvent e) { 029 JFrame frame = new JmriJFrame() { 030 }; // JmriJFrame to ensure fits on screen 031 032 frame.setTitle(Bundle.getMessage("TitleFileHistory")); 033 034 JTextArea pane = new JTextArea(); 035 pane.append("\n"); // add a little space at top 036 pane.setEditable(false); 037 038 JScrollPane scroll = new JScrollPane(pane); 039 frame.getContentPane().add(scroll); 040 041 FileHistory r = InstanceManager.getNullableDefault(FileHistory.class); 042 if (r == null) { 043 pane.append("<No History Found>\n"); 044 } else { 045 pane.append(r.toString()); 046 } 047 048 pane.append("\n"); // add a little space at bottom 049 // start scrolled to top 050 pane.setCaretPosition(0); 051 052 frame.pack(); 053 054 // show 055 frame.setVisible(true); 056 } 057}