001package jmri.jmrix.rps.trackingpanel; 002 003import java.awt.Dimension; 004import java.awt.FlowLayout; 005import java.awt.event.ActionEvent; 006import java.awt.event.ActionListener; 007import javax.swing.BoxLayout; 008import javax.swing.JButton; 009import javax.swing.JCheckBox; 010import javax.swing.JPanel; 011import javax.swing.JSeparator; 012import jmri.jmrix.rps.RpsSystemConnectionMemo; 013 014/** 015 * Frame containing the entire display tool. 016 * 017 * @author Bob Jacobsen Copyright (C) 2006, 2008 018 */ 019public class RpsTrackingFrame extends jmri.util.JmriJFrame { 020 021 RpsSystemConnectionMemo memo = null; 022 023 public RpsTrackingFrame(String s,RpsSystemConnectionMemo _memo) { 024 super(s); 025 memo = _memo; 026 } 027 028 public RpsTrackingFrame(RpsSystemConnectionMemo _memo) { 029 this("RPS Tracking Display", _memo); 030 } 031 032 @Override 033 public void dispose() { 034 panel.dispose(); 035 super.dispose(); 036 } 037 038 @Override 039 public void initComponents() { 040 041 addHelpMenu("package.jmri.jmrix.rps.trackingpanel.RpsTrackingFrame", true); 042 043 getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); 044 045 panel = new RpsTrackingPanel(memo); 046 047 // add controls; first, clear button 048 JPanel controls = new JPanel(); 049 controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS)); 050 JPanel line = new JPanel(); 051 line.setLayout(new FlowLayout()); 052 053 clearButton = new JButton("Clear"); 054 clearButton.addActionListener(new ActionListener() { 055 @Override 056 public void actionPerformed(ActionEvent event) { 057 clearButtonChanged(); 058 } 059 }); 060 line.add(clearButton); 061 062 // button for handling errors 063 showErrButton = new JCheckBox("Show error points"); 064 showErrButton.addActionListener(new ActionListener() { 065 @Override 066 public void actionPerformed(ActionEvent event) { 067 showErrButtonChanged(); 068 } 069 }); 070 line.add(showErrButton); 071 072 // button for showing receivers 073 showRecButton = new JCheckBox("Show receivers"); 074 showRecButton.addActionListener(new ActionListener() { 075 @Override 076 public void actionPerformed(ActionEvent event) { 077 showRecButtonChanged(); 078 } 079 }); 080 showRecButton.setSelected(true); 081 showRecButtonChanged(); 082 line.add(showRecButton); 083 084 // button for showing regions 085 showRegButton = new JCheckBox("Show regions"); 086 showRegButton.addActionListener(new ActionListener() { 087 @Override 088 public void actionPerformed(ActionEvent event) { 089 showRegButtonChanged(); 090 } 091 }); 092 showRegButton.setSelected(true); 093 showRegButtonChanged(); 094 line.add(showRegButton); 095 096 controls.add(line); 097 098 // configure alignment control 099 scale = new RpsTrackingControlPane(panel); 100 controls.add(scale); 101 controls.add(new JSeparator()); 102 103 panel.setSize(440, 240); 104 panel.setPreferredSize(new Dimension(440, 240)); 105 106 scale.set(-10., -10., 50., 50.); // lower left X, Y, then upper right 107 scale.update(); 108 109 // combine 110 //JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, controls, panel); 111 //getContentPane().add(split); 112 getContentPane().add(panel); 113 getContentPane().add(new JSeparator()); 114 getContentPane().add(controls); 115 116 panel.repaint(); 117 pack(); 118 119 // fix size of controls 120 Dimension d = controls.getSize(); 121 controls.setMinimumSize(d); 122 controls.setPreferredSize(d); 123 controls.setMaximumSize(d); 124 } 125 126 JButton clearButton; 127 JCheckBox showErrButton; 128 JCheckBox showRecButton; 129 JCheckBox showRegButton; 130 RpsTrackingPanel panel; 131 public RpsTrackingControlPane scale; 132 133 void showErrButtonChanged() { 134 panel.setShowErrors(showErrButton.isSelected()); 135 } 136 137 void showRecButtonChanged() { 138 panel.setShowReceivers(showRecButton.isSelected()); 139 panel.repaint(); 140 } 141 142 void showRegButtonChanged() { 143 panel.setShowRegions(showRegButton.isSelected()); 144 panel.repaint(); 145 } 146 147 void clearButtonChanged() { 148 panel.clear(); 149 } 150 151}