Search in sources :

Example 1 with ReportContext

use of jmri.jmrit.mailreport.ReportContext in project JMRI by JMRI.

the class ReportContextAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ev) {
    // JmriJFrame to ensure fits on screen
    final JFrame frame = new JmriJFrame(Bundle.getMessage("TitleContext"));
    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
    pane = new JTextArea();
    // add a little space at top
    pane.append("\n");
    pane.setEditable(false);
    pane.setLineWrap(true);
    pane.setWrapStyleWord(true);
    pane.setColumns(120);
    JScrollPane scroll = new JScrollPane(pane);
    frame.add(scroll, BorderLayout.CENTER);
    ReportContext r = new ReportContext();
    addString(r.getReport(true));
    // add a little space at bottom
    pane.append("\n");
    // Add button to allow copy to clipboard
    JPanel p = new JPanel();
    JButton copy = new JButton(Bundle.getMessage("ButtonCopyClip"));
    copy.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            StringSelection text = new StringSelection(pane.getText());
            clipboard.setContents(text, text);
        }
    });
    p.add(copy);
    JButton close = new JButton(Bundle.getMessage("ButtonClose"));
    close.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            frame.setVisible(false);
            frame.dispose();
        }
    });
    p.add(close);
    frame.add(p, BorderLayout.SOUTH);
    frame.pack();
    // start scrolled to top
    pane.setCaretPosition(0);
    JScrollBar b = scroll.getVerticalScrollBar();
    b.setValue(b.getMaximum());
    // show
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) StringSelection(java.awt.datatransfer.StringSelection) JScrollBar(javax.swing.JScrollBar) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) JmriJFrame(jmri.util.JmriJFrame) Clipboard(java.awt.datatransfer.Clipboard) ReportContext(jmri.jmrit.mailreport.ReportContext)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JButton (javax.swing.JButton)1 JFrame (javax.swing.JFrame)1 JPanel (javax.swing.JPanel)1 JScrollBar (javax.swing.JScrollBar)1 JScrollPane (javax.swing.JScrollPane)1 JTextArea (javax.swing.JTextArea)1 ReportContext (jmri.jmrit.mailreport.ReportContext)1 JmriJFrame (jmri.util.JmriJFrame)1