001/*============================================================================* 002 * WARNING This class contains automatically modified code. WARNING * 003 * * 004 * The method initComponents() and the variable declarations between the * 005 * "// Variables declaration - do not modify" and * 006 * "// End of variables declaration" comments will be overwritten if modified * 007 * by hand. Using the NetBeans IDE to edit this file is strongly recommended. * 008 * * 009 * See http://jmri.org/help/en/html/doc/Technical/NetBeansGUIEditor.shtml for * 010 * more information. * 011 *============================================================================*/ 012package jmri.web.server; 013 014import java.beans.PropertyChangeEvent; 015import java.beans.PropertyChangeListener; 016import java.util.ArrayList; 017import java.util.Enumeration; 018import javax.swing.ButtonGroup; 019import javax.swing.GroupLayout; 020import javax.swing.JCheckBox; 021import javax.swing.JComponent; 022import javax.swing.JLabel; 023import javax.swing.JPanel; 024import javax.swing.JRadioButton; 025import javax.swing.JScrollPane; 026import javax.swing.JSpinner; 027import javax.swing.JTextField; 028import javax.swing.LayoutStyle; 029import javax.swing.ListSelectionModel; 030import javax.swing.SpinnerNumberModel; 031import javax.swing.event.ListDataEvent; 032import javax.swing.event.ListDataListener; 033import jmri.InstanceManager; 034import jmri.swing.DefaultEditableListModel; 035import jmri.swing.DefaultListCellEditor; 036import jmri.swing.EditableList; 037import jmri.swing.PreferencesPanel; 038import org.jdesktop.beansbinding.AutoBinding; 039import org.jdesktop.beansbinding.BeanProperty; 040import org.jdesktop.beansbinding.BindingGroup; 041import org.jdesktop.beansbinding.Bindings; 042import org.jdesktop.beansbinding.ELProperty; 043import org.openide.util.lookup.ServiceProvider; 044 045/** 046 * 047 * @author Randall Wood 048 */ 049@ServiceProvider(service = PreferencesPanel.class) 050public class FrameServletPreferencesPanel extends JPanel implements ListDataListener, PreferencesPanel { 051 052 /** 053 * Creates new form FrameServletPreferencesPanel 054 */ 055 public FrameServletPreferencesPanel() { 056 initComponents(); 057 } 058 059 /** 060 * This method is called from within the constructor to initialize the form. 061 * WARNING: Do NOT modify this code. The content of this method is always 062 * regenerated by the Form Editor. 063 */ 064 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 065 private void initComponents() { 066 bindingGroup = new BindingGroup(); 067 068 framesEnabled = new ButtonGroup(); 069 preferences = InstanceManager.getDefault(WebServerPreferences.class); 070 enableFramesPnl = new JPanel(); 071 enableFrames = new JRadioButton(); 072 clickDelay = new JSpinner(); 073 refreshDelay = new JSpinner(); 074 useAjax = new JCheckBox(); 075 refreshDelayLbl = new JLabel(); 076 clickDelayLbl = new JLabel(); 077 disallowedFramesLbl = new JLabel(); 078 jScrollPane1 = new JScrollPane(); 079 disallowedFrames = new EditableList<String>(); 080 disableFramesPnl = new JPanel(); 081 disableFrames = new JRadioButton(); 082 redirectToPanels = new JCheckBox(); 083 084 framesEnabled.add(enableFrames); 085 framesEnabled.add(disableFrames); 086 087 preferences.addPropertyChangeListener(new PropertyChangeListener() { 088 @Override 089 public void propertyChange(PropertyChangeEvent evt) { 090 preferencesPropertyChange(evt); 091 } 092 }); 093 094 enableFrames.setText(Bundle.getMessage("LabelEnableFrames")); // NOI18N 095 096 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, preferences, ELProperty.create("${!disableFrames}"), enableFrames, BeanProperty.create("selected"))); 097 098 clickDelay.setModel(new SpinnerNumberModel(1, 0, 999, 1)); 099 clickDelay.setToolTipText(Bundle.getMessage("ToolTipClickDelay")); // NOI18N 100 101 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${clickDelay}"), clickDelay, BeanProperty.create("value"))); 102 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), clickDelay, BeanProperty.create("enabled"))); 103 104 refreshDelay.setModel(new SpinnerNumberModel(5, 0, 999, 1)); 105 refreshDelay.setToolTipText(Bundle.getMessage("ToolTipRefreshDelay")); // NOI18N 106 107 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${refreshDelay}"), refreshDelay, BeanProperty.create("value"))); 108 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), refreshDelay, BeanProperty.create("enabled"))); 109 110 useAjax.setText(Bundle.getMessage("LabelUseAjax")); // NOI18N 111 useAjax.setToolTipText(Bundle.getMessage("ToolTipUseAjax")); // NOI18N 112 113 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${useAjax}"), useAjax, BeanProperty.create("selected"))); 114 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), useAjax, BeanProperty.create("enabled"))); 115 116 refreshDelayLbl.setText(Bundle.getMessage("LabelRefreshDelay")); // NOI18N 117 refreshDelayLbl.setToolTipText(Bundle.getMessage("ToolTipRefreshDelay")); // NOI18N 118 119 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), refreshDelayLbl, BeanProperty.create("enabled"))); 120 121 clickDelayLbl.setText(Bundle.getMessage("LabelClickDelay")); // NOI18N 122 clickDelayLbl.setToolTipText(Bundle.getMessage("ToolTipClickDelay")); // NOI18N 123 124 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), clickDelayLbl, BeanProperty.create("enabled"))); 125 126 disallowedFramesLbl.setText(Bundle.getMessage("LabelDisallowedFrames")); // NOI18N 127 disallowedFramesLbl.setToolTipText(Bundle.getMessage("ToolTipDisallowedFrames")); // NOI18N 128 129 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), disallowedFramesLbl, BeanProperty.create("enabled"))); 130 131 disallowedFrames.setModel(new DefaultEditableListModel<String>()); 132 disallowedFrames.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 133 disallowedFrames.setToolTipText(Bundle.getMessage("ToolTipDisallowedFrames")); // NOI18N 134 disallowedFrames.setListCellEditor(new DefaultListCellEditor<>(new JTextField())); 135 136 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), disallowedFrames, BeanProperty.create("enabled"))); 137 138 DefaultEditableListModel<String> model = (DefaultEditableListModel<String>) this.disallowedFrames.getModel(); 139 model.addListDataListener(this); 140 for (String frame : this.preferences.getDisallowedFrames()) { 141 model.addElement(frame); 142 } 143 model.addElement(" "); 144 jScrollPane1.setViewportView(disallowedFrames); 145 146 GroupLayout enableFramesPnlLayout = new GroupLayout(enableFramesPnl); 147 enableFramesPnl.setLayout(enableFramesPnlLayout); 148 enableFramesPnlLayout.setHorizontalGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 149 .addGroup(enableFramesPnlLayout.createSequentialGroup() 150 .addContainerGap() 151 .addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 152 .addGroup(enableFramesPnlLayout.createSequentialGroup() 153 .addGap(29, 29, 29) 154 .addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 155 .addGroup(enableFramesPnlLayout.createSequentialGroup() 156 .addComponent(clickDelay, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE) 157 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 158 .addComponent(clickDelayLbl, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)) 159 .addGroup(enableFramesPnlLayout.createSequentialGroup() 160 .addComponent(refreshDelay, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE) 161 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 162 .addComponent(refreshDelayLbl, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)) 163 .addComponent(useAjax, GroupLayout.PREFERRED_SIZE, 160, GroupLayout.PREFERRED_SIZE)) 164 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 165 .addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 166 .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) 167 .addComponent(disallowedFramesLbl, GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE))) 168 .addComponent(enableFrames, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 169 .addContainerGap()) 170 ); 171 enableFramesPnlLayout.setVerticalGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 172 .addGroup(enableFramesPnlLayout.createSequentialGroup() 173 .addContainerGap() 174 .addComponent(enableFrames) 175 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 176 .addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) 177 .addComponent(clickDelay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 178 .addComponent(clickDelayLbl) 179 .addComponent(disallowedFramesLbl)) 180 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 181 .addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 182 .addGroup(enableFramesPnlLayout.createSequentialGroup() 183 .addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) 184 .addComponent(refreshDelay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 185 .addComponent(refreshDelayLbl)) 186 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 187 .addComponent(useAjax) 188 .addContainerGap(108, Short.MAX_VALUE)) 189 .addComponent(jScrollPane1))) 190 ); 191 192 disableFrames.setText(Bundle.getMessage("LabelDisableFrames")); // NOI18N 193 disableFrames.setToolTipText(Bundle.getMessage("ToolTipDisableFrames")); // NOI18N 194 195 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${disableFrames}"), disableFrames, BeanProperty.create("selected"))); 196 197 redirectToPanels.setText(Bundle.getMessage("LabelRedirectFramesToPanels")); // NOI18N 198 redirectToPanels.setToolTipText(Bundle.getMessage("ToolTipRedirectFramesToPanels")); // NOI18N 199 200 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${redirectFramesToPanels}"), redirectToPanels, BeanProperty.create("selected"))); 201 bindingGroup.addBinding(Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, disableFrames, ELProperty.create("${selected}"), redirectToPanels, BeanProperty.create("enabled"))); 202 203 GroupLayout disableFramesPnlLayout = new GroupLayout(disableFramesPnl); 204 disableFramesPnl.setLayout(disableFramesPnlLayout); 205 disableFramesPnlLayout.setHorizontalGroup(disableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 206 .addGroup(disableFramesPnlLayout.createSequentialGroup() 207 .addGroup(disableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 208 .addGroup(disableFramesPnlLayout.createSequentialGroup() 209 .addContainerGap() 210 .addComponent(disableFrames, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 211 .addGroup(disableFramesPnlLayout.createSequentialGroup() 212 .addGap(35, 35, 35) 213 .addComponent(redirectToPanels, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 214 .addContainerGap()) 215 ); 216 disableFramesPnlLayout.setVerticalGroup(disableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING) 217 .addGroup(disableFramesPnlLayout.createSequentialGroup() 218 .addContainerGap() 219 .addComponent(disableFrames, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE) 220 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 221 .addComponent(redirectToPanels) 222 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 223 ); 224 225 GroupLayout layout = new GroupLayout(this); 226 this.setLayout(layout); 227 layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 228 .addComponent(enableFramesPnl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 229 .addComponent(disableFramesPnl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 230 ); 231 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 232 .addGroup(layout.createSequentialGroup() 233 .addComponent(enableFramesPnl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 234 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 235 .addComponent(disableFramesPnl, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) 236 ); 237 238 bindingGroup.bind(); 239 }// </editor-fold>//GEN-END:initComponents 240 241 private void preferencesPropertyChange(PropertyChangeEvent evt) {//GEN-FIRST:event_preferencesPropertyChange 242 if (evt.getPropertyName().equals(WebServerPreferences.DISALLOWED_FRAMES)) { 243 DefaultEditableListModel<String> model = (DefaultEditableListModel<String>) disallowedFrames.getModel(); 244 model.removeListDataListener(this); 245 model.removeAllElements(); 246 for (String frame : preferences.getDisallowedFrames()) { 247 model.addElement(frame); 248 } 249 model.addElement(" "); 250 model.addListDataListener(this); 251 } 252 }//GEN-LAST:event_preferencesPropertyChange 253 254 255 // Variables declaration - do not modify//GEN-BEGIN:variables 256 private JSpinner clickDelay; 257 private JLabel clickDelayLbl; 258 private JRadioButton disableFrames; 259 private JPanel disableFramesPnl; 260 private EditableList<String> disallowedFrames; 261 private JLabel disallowedFramesLbl; 262 private JRadioButton enableFrames; 263 private JPanel enableFramesPnl; 264 private ButtonGroup framesEnabled; 265 private JScrollPane jScrollPane1; 266 private WebServerPreferences preferences; 267 private JCheckBox redirectToPanels; 268 private JSpinner refreshDelay; 269 private JLabel refreshDelayLbl; 270 private JCheckBox useAjax; 271 private BindingGroup bindingGroup; 272 // End of variables declaration//GEN-END:variables 273 274 @Override 275 public String getPreferencesItem() { 276 return Bundle.getMessage("PreferencesItem"); 277 } 278 279 @Override 280 public String getPreferencesItemText() { 281 return Bundle.getMessage("PreferencesItemTitle"); 282 } 283 284 @Override 285 public String getTabbedPreferencesTitle() { 286 return Bundle.getMessage("TitleDelayPanel"); 287 } 288 289 @Override 290 public String getLabelKey() { 291 return null; 292 } 293 294 @Override 295 public JComponent getPreferencesComponent() { 296 return this; 297 } 298 299 @Override 300 public boolean isPersistant() { 301 return false; 302 } 303 304 @Override 305 public String getPreferencesTooltip() { 306 return null; 307 } 308 309 @Override 310 public void savePreferences() { 311 if (this.isDirty()) { 312 this.preferences.save(); 313 } 314 } 315 316 @Override 317 public boolean isDirty() { 318 return this.preferences.isDirty(); 319 } 320 321 @Override 322 public boolean isRestartRequired() { 323 return this.preferences.isRestartRequired(); 324 } 325 326 @Override 327 public boolean isPreferencesValid() { 328 return true; // no validity checking performed 329 330 } 331 332 @Override 333 public int getSortOrder() { 334 return 1110; 335 } 336 337 @Override 338 public void intervalAdded(ListDataEvent e) { 339 // do nothing 340 } 341 342 @Override 343 public void intervalRemoved(ListDataEvent e) { 344 // do nothing 345 } 346 347 @Override 348 public void contentsChanged(ListDataEvent e) { 349 DefaultEditableListModel<String> model = (DefaultEditableListModel<String>) disallowedFrames.getModel(); 350 if (!model.getElementAt(model.getSize() - 1).equals(" ")) { 351 model.addElement(" "); 352 } else if (model.getElementAt(e.getIndex0()).isEmpty()) { 353 model.removeElementAt(e.getIndex0()); 354 } 355 ArrayList<String> frames = new ArrayList<>(); 356 Enumeration<String> elements = model.elements(); 357 while (elements.hasMoreElements()) { 358 String frame = elements.nextElement().trim(); 359 if (!frame.isEmpty()) { 360 frames.add(frame); 361 } 362 } 363 this.preferences.setDisallowedFrames(frames.toArray(new String[frames.size()])); 364 } 365}