Commits

Emilian Marius Bold  committed 5b2ba61

Importing patch from Ernie Rael which:

* bumps the version to 1.1
* sets the homepage to bitbucket site
* set spinner model: >= 0; step 50
* defines a custom spinner editor to workaround bugs when manually entering number (could miss persisting input). Also the editor only allows digits to be input.

  • Participants
  • Parent commits 8deb4d8
  • Tags 1.1

Comments (0)

Files changed (7)

 OpenIDE-Module: ro.emilianbold.javaeditor.blinkrate
 OpenIDE-Module-Layer: ro/emilianbold/javaeditor/blinkrate/layer.xml
 OpenIDE-Module-Localizing-Bundle: ro/emilianbold/javaeditor/blinkrate/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.0
+OpenIDE-Module-Specification-Version: 1.1
 

File nbproject/genfiles.properties

-build.xml.data.CRC32=5f839383
+build.xml.data.CRC32=8d295f9f
 build.xml.script.CRC32=683b782a
-build.xml.stylesheet.CRC32=79c3b980
+build.xml.stylesheet.CRC32=a56c6a5b@1.44.1
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=5f839383
+nbproject/build-impl.xml.data.CRC32=8d295f9f
 nbproject/build-impl.xml.script.CRC32=8c67bd34
-nbproject/build-impl.xml.stylesheet.CRC32=deb65f65
+nbproject/build-impl.xml.stylesheet.CRC32=68e521fc@1.44.1

File nbproject/project.properties

 javac.source=1.5
 javac.compilerargs=-Xlint -Xlint:-serial
-nbm.homepage=http://www.emilianbold.ro
+nbm.homepage=https://bitbucket.org/emilianbold/javaeditor-blinkrate
 nbm.module.author=Emilian Bold

File nbproject/project.xml

                     </run-dependency>
                 </dependency>
                 <dependency>
-                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
-                    <build-prerequisite/>
-                    <compile-dependency/>
-                    <run-dependency>
-                        <release-version>1</release-version>
-                        <specification-version>1.19.0.4.2</specification-version>
-                    </run-dependency>
-                </dependency>
-                <dependency>
                     <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.34.1</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     <code-name-base>org.netbeans.modules.options.api</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>

File src/ro/emilianbold/javaeditor/blinkrate/BlinkUtil.java

  */
 package ro.emilianbold.javaeditor.blinkrate;
 
-import javax.swing.text.EditorKit;
+import java.util.prefs.Preferences;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.mimelookup.MimePath;
-import org.netbeans.editor.Settings;
-import org.netbeans.editor.SettingsNames;
+import org.netbeans.api.editor.settings.SimpleValueNames;
 
 /**
  *
  */
 public class BlinkUtil {
 
+    private static Preferences prefs() {
+        return MimeLookup.getLookup(MimePath.get("text/x-java"))
+                .lookup(Preferences.class);
+    }
     public static void setBlink(int blinkMs) {
         if (blinkMs >= 0) {
-            Settings.setValue(MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(EditorKit.class).getClass(),
-                    SettingsNames.CARET_BLINK_RATE,
-                    blinkMs);
+            prefs().putInt(SimpleValueNames.CARET_BLINK_RATE, blinkMs);
         }
     }
     public static int getBlink() {
-            return (Integer)Settings.getValue(MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(EditorKit.class).getClass(),
-                    SettingsNames.CARET_BLINK_RATE);
+        int rv = prefs().getInt(SimpleValueNames.CARET_BLINK_RATE, -1);
+        return rv >= 0 ? rv : 300; // from editor.lib2.EditorPreferencesDefaults
+    }
+
+    private BlinkUtil()
+    {
     }
 }

File src/ro/emilianbold/javaeditor/blinkrate/option/BlinkratePanel.form

-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.1" encoding="UTF-8" ?>
 
 <Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
   <AuxValues>
     <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
     <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
     <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
     <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
     <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
                   <Group type="102" alignment="0" attributes="0">
                       <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
                       <EmptySpace max="-2" attributes="0"/>
-                      <Component id="spinner" pref="89" max="32767" attributes="0"/>
+                      <Component id="spinner" pref="139" max="32767" attributes="0"/>
                   </Group>
               </Group>
               <EmptySpace max="-2" attributes="0"/>

File src/ro/emilianbold/javaeditor/blinkrate/option/BlinkratePanel.java

 package ro.emilianbold.javaeditor.blinkrate.option;
 
+import javax.swing.JTextField;
+import javax.swing.SpinnerNumberModel;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DocumentFilter;
+import javax.swing.text.DocumentFilter.FilterBypass;
 import ro.emilianbold.javaeditor.blinkrate.BlinkUtil;
 
 final class BlinkratePanel extends javax.swing.JPanel {
     BlinkratePanel(BlinkrateOptionsPanelController controller) {
         this.controller = controller;
         initComponents();
+
+        // only positive values, and step of 50 milli-sec
+        SpinnerNumberModel m = (SpinnerNumberModel)spinner.getModel();
+        m.setMinimum(Integer.valueOf(0));
+        m.setStepSize(Integer.valueOf(50));
+
+        // This editor rejects non-digit characters
+        // and persists itself to the model as valid characters are input.
+        spinner.setEditor(new IntegerEditor());
+
         spinner.addChangeListener(new ChangeListener() {
-                    public void stateChanged(ChangeEvent arg0) {
-                        BlinkratePanel.this.controller.changed();
-                    }
-                });
+            public void stateChanged(ChangeEvent arg0) {
+                BlinkratePanel.this.controller.changed();
+            }
+        });
     }
 
     /** This method is called from within the constructor to
     }// </editor-fold>//GEN-END:initComponents
 
     void load() {
+        ((JTextField)spinner.getEditor()).setText("0");
         spinner.setValue(BlinkUtil.getBlink());
     }
 
         return ((Integer) spinner.getValue() >= 0);
     }
 
+    private class IntegerEditor extends JTextField {
+
+        @SuppressWarnings({"OverridableMethodCallInConstructor",
+                           "LeakingThisInConstructor"})
+        public IntegerEditor() {
+            setHorizontalAlignment(JTextField.RIGHT);
+            updateText();
+
+            String toolTipText = spinner.getToolTipText();
+            if (toolTipText != null) {
+                //JSpinner has tool tip text.  Use it.
+                if (!toolTipText.equals(getToolTipText())) {
+                    setToolTipText(toolTipText);
+                }
+            }
+
+            spinner.addChangeListener(new ChangeListener() {
+                public void stateChanged(ChangeEvent e)
+                {
+                    updateText();
+                }
+            });
+
+            // Only 0-9 allowed in string
+            ((AbstractDocument)getDocument())
+                    .setDocumentFilter(new DocumentFilter() {
+
+                private boolean digitsOnly(String s) {
+                    for(int i = 0; i < s.length(); i++) {
+                        char c = s.charAt(i);
+                        if(c < '0' || c > '9')
+                            return false;
+                    }
+                    return true;
+                }
+
+                @Override
+                public void insertString(FilterBypass fb, int offset,
+                                         String string, AttributeSet attr)
+                        throws BadLocationException
+                {
+                    if(digitsOnly(string)) {
+                        fb.insertString(offset, string, attr);
+                        updateModel();
+                    }
+                }
+
+                @Override
+                public void replace(FilterBypass fb, int offset, int length,
+                                    String text, AttributeSet attrs)
+                        throws BadLocationException
+                {
+                    if(digitsOnly(text)) {
+                        fb.replace(offset, length, text, attrs);
+                        updateModel();
+                    }
+                }
+
+                @Override
+                public void remove(FilterBypass fb, int offset, int length)
+                        throws BadLocationException
+                {
+                    fb.remove(offset, length);
+                    updateModel();
+                }
+            });
+        }
+
+        private int getValue() {
+            String s = getText();
+            int n = -1;
+            if(!s.isEmpty()) {
+                try {
+                    n = Integer.parseInt(s);
+                } catch(NumberFormatException ex) {
+                }
+            } else {
+                n = 0;
+            }
+            return n;
+        }
+
+        private void updateModel() {
+            int n = getValue();
+            if(n >= 0) {
+                if(n != (Integer)spinner.getValue())
+                    spinner.setValue(n);
+            } else
+                updateText();
+        }
+
+        private void updateText() {
+            int n = (Integer)spinner.getValue();
+            if(n != getValue())
+                setText("" + n);
+        }
+    }
+
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JLabel jLabel1;
     private javax.swing.JLabel jLabel2;