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; 016import jmri.jmrit.operations.trains.trainbuilder.TrainCommon; 017 018public class TrackEditCommentsFrame extends OperationsFrame { 019 020 // text areas 021 JTextArea commentBothTextArea = new JTextArea(5, 100); 022 JTextArea commentPickupTextArea = new JTextArea(5, 100); 023 JTextArea commentSetoutTextArea = new JTextArea(5, 100); 024 025 // scrollers 026 JScrollPane commentBothScroller = new JScrollPane(commentBothTextArea); 027 JScrollPane commentPickupScroller = new JScrollPane(commentPickupTextArea); 028 JScrollPane commentSetoutScroller = new JScrollPane(commentSetoutTextArea); 029 030 // text color choosers 031 JColorChooser commentColorChooserBoth = new JColorChooser(); 032 JColorChooser commentColorChooserPickup = new JColorChooser(); 033 JColorChooser commentColorChooserSetout = new JColorChooser(); 034 035 // text bold 036 JCheckBox boldTextBoth = new JCheckBox(); 037 JCheckBox boldTextPickup = new JCheckBox(); 038 JCheckBox boldTextSetout = new JCheckBox(); 039 040 JCheckBox printManifest = new JCheckBox(Bundle.getMessage("PrintManifest")); 041 JCheckBox printSwitchList = new JCheckBox(Bundle.getMessage("PrintSwitchList")); 042 043 JButton saveButton = new JButton(Bundle.getMessage("ButtonSave")); 044 045 Track _track; 046 047 public TrackEditCommentsFrame(Track track) { 048 super(); 049 initComponents(track); 050 } 051 052 private void initComponents(Track track) { 053 if (track == null) { 054 log.debug("Track is null can't edit track comments"); 055 return; 056 } 057 _track = track; 058 059 // Layout the panel by rows 060 setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); 061 062 JPanel panelComments = new JPanel(); 063 JScrollPane panelPane = new JScrollPane(panelComments); 064 panelComments.setLayout(new BoxLayout(panelComments, BoxLayout.Y_AXIS)); 065 066 panelPane.setBorder(BorderFactory.createTitledBorder("")); 067 068 JPanel pCb = new JPanel(); 069 pCb.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("CommentBoth"))); 070 pCb.setLayout(new GridBagLayout()); 071 addItem(pCb, commentBothScroller, 1, 0); 072 073 addItem(pCb, getColorChooserPanel(track.getCommentBothWithColor(), commentColorChooserBoth, boldTextBoth), 2, 074 0); 075 076 JPanel pCp = new JPanel(); 077 pCp.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("CommentPickup"))); 078 pCp.setLayout(new GridBagLayout()); 079 addItem(pCp, commentPickupScroller, 1, 0); 080 081 addItem(pCp, getColorChooserPanel(track.getCommentPickupWithColor(), commentColorChooserPickup, boldTextPickup), 082 2, 0); 083 084 JPanel pCs = new JPanel(); 085 pCs.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("CommentSetout"))); 086 pCs.setLayout(new GridBagLayout()); 087 addItem(pCs, commentSetoutScroller, 1, 0); 088 089 addItem(pCs, getColorChooserPanel(track.getCommentSetoutWithColor(), commentColorChooserSetout, boldTextSetout), 090 2, 0); 091 092 commentBothTextArea.setText(TrainCommon.isTextUserModified(track.getCommentBothWithColor()) 093 ? track.getCommentBothWithColor() : track.getCommentBoth()); 094 commentPickupTextArea.setText(TrainCommon.isTextUserModified(track.getCommentPickupWithColor()) 095 ? track.getCommentPickupWithColor() : track.getCommentPickup()); 096 commentSetoutTextArea.setText(TrainCommon.isTextUserModified(track.getCommentSetoutWithColor()) 097 ? track.getCommentSetoutWithColor() : track.getCommentSetout()); 098 099 boldTextBoth.setSelected(TrainCommon.isTextBold(track.getCommentBothWithColor())); 100 boldTextPickup.setSelected(TrainCommon.isTextBold(track.getCommentPickupWithColor())); 101 boldTextSetout.setSelected(TrainCommon.isTextBold(track.getCommentSetoutWithColor())); 102 103 JPanel pB = new JPanel(); 104 pB.setLayout(new GridBagLayout()); 105 addItem(pB, printManifest, 0, 0); 106 addItem(pB, printSwitchList, 1, 0); 107 addItem(pB, saveButton, 2, 0); 108 109 printManifest.setSelected(track.isPrintManifestCommentEnabled()); 110 printSwitchList.setSelected(track.isPrintSwitchListCommentEnabled()); 111 112 panelComments.add(pCb); 113 panelComments.add(pCp); 114 panelComments.add(pCs); 115 116 add(panelPane); 117 add(pB); 118 119 addButtonAction(saveButton); 120 121 setTitle(track.getName()); 122 initMinimumSize(new Dimension(Control.panelWidth600, Control.panelHeight400)); 123 } 124 125 // Buttons 126 @Override 127 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 128 if (ae.getSource() == saveButton) { 129 _track.setCommentBoth(TrainCommon.formatColorString(commentBothTextArea.getText(), 130 commentColorChooserBoth.getColor(), boldTextBoth.isSelected())); 131 _track.setCommentPickup(TrainCommon.formatColorString(commentPickupTextArea.getText(), 132 commentColorChooserPickup.getColor(), boldTextPickup.isSelected())); 133 _track.setCommentSetout(TrainCommon.formatColorString(commentSetoutTextArea.getText(), 134 commentColorChooserSetout.getColor(), boldTextSetout.isSelected())); 135 _track.setPrintManifestCommentEnabled(printManifest.isSelected()); 136 _track.setPrintSwitchListCommentEnabled(printSwitchList.isSelected()); 137 // save location file 138 OperationsXml.save(); 139 if (Setup.isCloseWindowOnSaveEnabled()) { 140 super.dispose(); 141 } 142 } 143 } 144 145 private static final Logger log = LoggerFactory.getLogger(TrackEditCommentsFrame.class 146 .getName()); 147}