| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| package org.netbeans.modules.php.editor.options; |
| |
| import java.awt.event.ItemEvent; |
| import java.awt.event.ItemListener; |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.prefs.BackingStoreException; |
| import java.util.prefs.Preferences; |
| import javax.swing.JCheckBox; |
| import org.openide.util.Exceptions; |
| |
| /** |
| * |
| * @author Petr Hrebejk |
| */ |
| public class MarkOccurencesPanel extends javax.swing.JPanel { |
| |
| private static final boolean DEFAULT_VALUE = true; // May need to be splited if the defaunts ar not all on |
| private List<JCheckBox> boxes; |
| private MarkOccurencesOptionsPanelController controller; |
| |
| /* Creates new form MarkOccurencesPanel */ |
| public MarkOccurencesPanel(MarkOccurencesOptionsPanelController controller) { |
| initComponents(); |
| fillBoxes(); |
| addListeners(); |
| load(controller); |
| } |
| |
| public void load(MarkOccurencesOptionsPanelController controller) { |
| this.controller = controller; |
| |
| Preferences node = MarkOccurencesSettings.getCurrentNode(); |
| |
| for (JCheckBox box : boxes) { |
| box.setSelected(node.getBoolean(box.getActionCommand(), DEFAULT_VALUE)); |
| } |
| |
| componentsSetEnabled(); |
| |
| } |
| |
| public void store() { |
| Preferences node = MarkOccurencesSettings.getCurrentNode(); |
| for (javax.swing.JCheckBox box : boxes) { |
| boolean value = box.isSelected(); |
| boolean original = node.getBoolean(box.getActionCommand(), |
| DEFAULT_VALUE); |
| |
| if (value != original) { |
| node.putBoolean(box.getActionCommand(), value); |
| } |
| } |
| try { |
| node.flush(); |
| } catch (BackingStoreException ex) { |
| Exceptions.printStackTrace(ex); |
| } |
| } |
| |
| public boolean changed() { |
| Preferences node = MarkOccurencesSettings.getCurrentNode(); |
| for (JCheckBox box : boxes) { |
| boolean value = box.isSelected(); |
| boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); |
| if (value != original) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| |
| /** This method is called from within the constructor to |
| * initialize the form. |
| * WARNING: Do NOT modify this code. The content of this method is |
| * always regenerated by the Form Editor. |
| */ |
| // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
| private void initComponents() { |
| |
| onOffCheckBox = new javax.swing.JCheckBox(); |
| keepMarksCheckBox = new javax.swing.JCheckBox(); |
| |
| setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); |
| setFocusCycleRoot(true); |
| setFocusTraversalPolicy(new java.awt.FocusTraversalPolicy() { |
| public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){ |
| return onOffCheckBox; |
| }//end getDefaultComponent |
| |
| public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){ |
| return onOffCheckBox; |
| }//end getFirstComponent |
| |
| public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){ |
| return onOffCheckBox; |
| }//end getLastComponent |
| |
| public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ |
| return onOffCheckBox;//end getComponentAfter |
| } |
| public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){ |
| return onOffCheckBox;//end getComponentBefore |
| |
| }} |
| ); |
| |
| org.openide.awt.Mnemonics.setLocalizedText(onOffCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "CTL_OnOff_CheckBox")); // NOI18N |
| onOffCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
| |
| keepMarksCheckBox.setMnemonic('s'); |
| org.openide.awt.Mnemonics.setLocalizedText(keepMarksCheckBox, org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurencesPanel.keepMarksCheckBox.text")); // NOI18N |
| |
| javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); |
| this.setLayout(layout); |
| layout.setHorizontalGroup( |
| layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| .addGroup(layout.createSequentialGroup() |
| .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| .addGroup(layout.createSequentialGroup() |
| .addContainerGap() |
| .addComponent(onOffCheckBox)) |
| .addGroup(layout.createSequentialGroup() |
| .addGap(37, 37, 37) |
| .addComponent(keepMarksCheckBox))) |
| .addContainerGap(226, Short.MAX_VALUE)) |
| ); |
| layout.setVerticalGroup( |
| layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| .addGroup(layout.createSequentialGroup() |
| .addContainerGap() |
| .addComponent(onOffCheckBox) |
| .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) |
| .addComponent(keepMarksCheckBox) |
| .addContainerGap(237, Short.MAX_VALUE)) |
| ); |
| |
| onOffCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName")); // NOI18N |
| onOffCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "ACSD_OnOff_CB")); // NOI18N |
| |
| getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleName")); // NOI18N |
| getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MarkOccurencesPanel.class, "MarkOccurrencesPanel.AccessibleContext.accessibleDescription")); // NOI18N |
| }// </editor-fold>//GEN-END:initComponents |
| |
| |
| // Variables declaration - do not modify//GEN-BEGIN:variables |
| private javax.swing.JCheckBox keepMarksCheckBox; |
| private javax.swing.JCheckBox onOffCheckBox; |
| // End of variables declaration//GEN-END:variables |
| // End of variables declaration |
| |
| private void fillBoxes() { |
| boxes = new ArrayList<>(); |
| boxes.add(onOffCheckBox); |
| boxes.add(keepMarksCheckBox); |
| onOffCheckBox.setActionCommand(MarkOccurencesSettings.ON_OFF); |
| keepMarksCheckBox.setActionCommand(MarkOccurencesSettings.KEEP_MARKS); |
| } |
| |
| private void addListeners() { |
| ItemListener itemListener = new CheckItemListener(); |
| for (JCheckBox box : boxes) { |
| box.addItemListener(itemListener); |
| } |
| } |
| |
| private void componentsSetEnabled() { |
| for (int i = 1; i < boxes.size(); i++) { |
| boxes.get(i).setEnabled(onOffCheckBox.isSelected()); // Switch off the other boxes |
| } |
| } |
| |
| private class CheckItemListener implements ItemListener { |
| |
| @Override |
| public void itemStateChanged(ItemEvent evt) { |
| if (evt.getSource() == onOffCheckBox) { |
| componentsSetEnabled(); |
| } |
| controller.changed(); |
| } |
| |
| } |
| |
| } |