001package jmri.jmrit.operations.locations.tools;
002
003import java.awt.Dimension;
004import java.awt.GridBagLayout;
005
006import javax.swing.*;
007
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011import jmri.jmrit.operations.OperationsFrame;
012import jmri.jmrit.operations.OperationsXml;
013import jmri.jmrit.operations.locations.Track;
014import jmri.jmrit.operations.setup.Control;
015import jmri.jmrit.operations.setup.Setup;
016
017public class TrackEditCommentsFrame extends OperationsFrame {
018
019    // text areas
020    JTextArea commentBothTextArea = new JTextArea(5, 100);
021    JScrollPane commentBothScroller = new JScrollPane(commentBothTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
022            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
023
024    JTextArea commentPickupTextArea = new JTextArea(5, 100);
025    JScrollPane commentPickupScroller = new JScrollPane(commentPickupTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
026            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
027
028    JTextArea commentSetoutTextArea = new JTextArea(5, 100);
029    JScrollPane commentSetoutScroller = new JScrollPane(commentSetoutTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
030            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
031
032    Dimension minScrollerDim = new Dimension(1200, 300);
033
034    JButton saveButton = new JButton(Bundle.getMessage("ButtonSave"));
035    
036    JCheckBox printManifest = new JCheckBox(Bundle.getMessage("PrintManifest"));
037    JCheckBox printSwitchList = new JCheckBox(Bundle.getMessage("PrintSwitchList"));
038
039    Track _track;
040
041    public TrackEditCommentsFrame(Track track) {
042        super();
043        initComponents(track);
044    }
045
046    private void initComponents(Track track) {
047        if (track == null) {
048            log.debug("Track is null can't edit track comments");
049            return;
050        }
051        _track = track;
052        // the following code sets the frame's initial state
053        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
054
055        JPanel pCb = new JPanel();
056        pCb.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("CommentBoth")));
057        pCb.setLayout(new GridBagLayout());
058        commentBothScroller.setMinimumSize(minScrollerDim);
059        addItem(pCb, commentBothScroller, 1, 0);
060
061        JPanel pCp = new JPanel();
062        pCp.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("CommentPickup")));
063        pCp.setLayout(new GridBagLayout());
064        commentPickupScroller.setMinimumSize(minScrollerDim);
065        addItem(pCp, commentPickupScroller, 1, 0);
066
067        JPanel pCs = new JPanel();
068        pCs.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("CommentSetout")));
069        pCs.setLayout(new GridBagLayout());
070        commentSetoutScroller.setMinimumSize(minScrollerDim);
071        addItem(pCs, commentSetoutScroller, 1, 0);
072
073        commentBothTextArea.setText(track.getCommentBoth());
074        commentPickupTextArea.setText(track.getCommentPickup());
075        commentSetoutTextArea.setText(track.getCommentSetout());
076
077        JPanel pB = new JPanel();
078        pB.setLayout(new GridBagLayout());
079        addItem(pB, printManifest, 0, 0);
080        addItem(pB, printSwitchList, 1, 0);
081        addItem(pB, saveButton, 2, 0);
082        
083        printManifest.setSelected(track.isPrintManifestCommentEnabled());
084        printSwitchList.setSelected(track.isPrintSwitchListCommentEnabled());
085
086        getContentPane().add(pCb);
087        getContentPane().add(pCp);
088        getContentPane().add(pCs);
089        getContentPane().add(pB);
090
091        addButtonAction(saveButton);
092
093        setTitle(track.getName());
094        initMinimumSize(new Dimension(Control.panelHeight400, Control.panelWidth600));
095    }
096
097    // Buttons
098    @Override
099    public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
100        if (ae.getSource() == saveButton) {
101            _track.setCommentBoth(commentBothTextArea.getText());
102            _track.setCommentPickup(commentPickupTextArea.getText());
103            _track.setCommentSetout(commentSetoutTextArea.getText());
104            _track.setPrintManifestCommentEnabled(printManifest.isSelected());
105            _track.setPrintSwitchListCommentEnabled(printSwitchList.isSelected());
106            // save location file
107            OperationsXml.save();
108            if (Setup.isCloseWindowOnSaveEnabled()) {
109                super.dispose();
110            }
111        }
112    }
113
114    private final static Logger log = LoggerFactory.getLogger(TrackEditCommentsFrame.class
115            .getName());
116}