001package apps; 002 003import java.awt.event.ActionEvent; 004import java.io.BufferedReader; 005import java.io.IOException; 006import java.io.InputStream; 007import java.io.InputStreamReader; 008import java.nio.charset.StandardCharsets; 009import javax.swing.*; 010import javax.swing.border.EmptyBorder; 011 012import jmri.util.FileUtil; 013import jmri.util.swing.JmriPanel; 014import jmri.util.swing.WindowInterface; 015 016/** 017 * Swing action to display the JMRI license 018 * 019 * @author Bob Jacobsen Copyright (C) 2004, 2010 020 */ 021public class LicenseAction extends jmri.util.swing.JmriAbstractAction { 022 023 public LicenseAction() { 024 super("License"); 025 } 026 027 public LicenseAction(String s, Icon i, WindowInterface w) { 028 super(s, i, w); 029 } 030 031 public LicenseAction(String s, WindowInterface w) { 032 super(s, w); 033 } 034 035 @Override 036 public void actionPerformed(ActionEvent ev) { 037 // here we can set a title 038 039 JFrame frame = new jmri.util.JmriJFrame(); // to ensure fits 040 frame.setTitle(Bundle.getMessage("TitleLicense")); 041 042 JPanel pane = new JPanel(); 043 // pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); 044 045 // insert stuff from makePanel() here 046 pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); 047 048 JTextPane textPane = new JTextPane(); 049 pane.add(textPane); 050 JScrollPane scroll = new JScrollPane(pane); 051 scroll.setBorder(new EmptyBorder(10, 10, 10, 10)); 052 053 // get the file 054 InputStream is = FileUtil.findInputStream("resources/COPYING", FileUtil.Location.INSTALLED); // NOI18N 055 056 String t; 057 058 try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.US_ASCII); // file stored as ASCII // NOI18N 059 BufferedReader r = new BufferedReader(isr)) { 060 StringBuilder buf = new StringBuilder(); 061 while (r.ready()) { 062 buf.append(r.readLine()); 063 buf.append("\n"); 064 } 065 t = buf.toString(); 066 } catch (IOException ex) { 067 t = "JMRI is distributed under a license. For license information, see the JMRI website http://jmri.org"; 068 } 069 textPane.setText(t); 070 // set up display 071 textPane.setEditable(false); 072 // start scrolled to top 073 textPane.setCaretPosition(0); 074 075 frame.getContentPane().add(scroll); 076 077 frame.pack(); 078 frame.setVisible(true); 079 } 080 081 @Override 082 public JmriPanel makePanel() { 083 // do nothing 084 return null; 085 } 086 087} 088