KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > image > CustomZoomPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.image;
22
23
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.text.AttributeSet JavaDoc;
26 import javax.swing.text.BadLocationException JavaDoc;
27 import javax.swing.text.PlainDocument JavaDoc;
28
29 import org.openide.util.NbBundle;
30
31
32 /** This class define a panel for "Custom zoom" dialog.
33  *
34  * @author Lukas Tadial
35  */

36 public class CustomZoomPanel extends JPanel JavaDoc {
37
38     /** Creates new form CustomZoomPane */
39     public CustomZoomPanel() {
40         initComponents();
41         initAccessibility();
42     }
43
44
45     /** This method is called from within the constructor to
46      * initialize the form.
47      * WARNING: Do NOT modify this code. The content of this method is
48      * always regenerated by the Form Editor.
49      */

50     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
51
private void initComponents() {
52         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
53
54         enlargeLabel = new javax.swing.JLabel JavaDoc();
55         enlargeText = new javax.swing.JTextField JavaDoc();
56         decreasingLabel = new javax.swing.JLabel JavaDoc();
57         decreaseText = new javax.swing.JTextField JavaDoc();
58
59         setLayout(new java.awt.GridBagLayout JavaDoc());
60
61         enlargeLabel.setLabelFor(enlargeText);
62         org.openide.awt.Mnemonics.setLocalizedText(enlargeLabel, NbBundle.getBundle(CustomZoomPanel.class).getString("LBL_EnlargeFactor")); // NOI18N
63
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
64         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
65         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
66         add(enlargeLabel, gridBagConstraints);
67
68         enlargeText.setDocument(new WholeNumberDocument());
69         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
70         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
71         gridBagConstraints.weightx = 1.0;
72         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 11, 0, 11);
73         add(enlargeText, gridBagConstraints);
74
75         decreasingLabel.setLabelFor(decreaseText);
76         org.openide.awt.Mnemonics.setLocalizedText(decreasingLabel, NbBundle.getBundle(CustomZoomPanel.class).getString("LBL_DecreaseFactor")); // NOI18N
77
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
78         gridBagConstraints.gridx = 0;
79         gridBagConstraints.gridy = 1;
80         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
81         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 11, 0);
82         add(decreasingLabel, gridBagConstraints);
83
84         decreaseText.setDocument(new WholeNumberDocument());
85         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
86         gridBagConstraints.gridx = 1;
87         gridBagConstraints.gridy = 1;
88         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
89         gridBagConstraints.weightx = 1.0;
90         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 11, 11, 11);
91         add(decreaseText, gridBagConstraints);
92     }// </editor-fold>//GEN-END:initComponents
93

94     private void initAccessibility(){
95         getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(CustomZoomPanel.class).getString("ACSD_CustomZoomPanel"));
96         enlargeText.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(CustomZoomPanel.class).getString("ACS_EnlargeText"));
97         decreaseText.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(CustomZoomPanel.class).getString("ACS_DecreaseText"));
98         
99     }
100     
101     public int getEnlargeFactor() {
102         return Integer.parseInt(enlargeText.getText());
103     }
104     
105     public void setEnlargeFactor(int enlargeFactor) {
106         enlargeText.setText("" + enlargeFactor); // NOI18N
107
}
108     
109     public int getDecreaseFactor() {
110         return Integer.parseInt(decreaseText.getText());
111     }
112     
113     public void setDecreaseFactor(int decreaseFactor) {
114         decreaseText.setText("" + decreaseFactor); // NOI18N
115
}
116     
117     // Variables declaration - do not modify//GEN-BEGIN:variables
118
private javax.swing.JTextField JavaDoc decreaseText;
119     private javax.swing.JLabel JavaDoc decreasingLabel;
120     private javax.swing.JLabel JavaDoc enlargeLabel;
121     private javax.swing.JTextField JavaDoc enlargeText;
122     // End of variables declaration//GEN-END:variables
123

124
125     /** Documnet which accepts only digit chars. */
126     private static class WholeNumberDocument extends PlainDocument JavaDoc {
127
128         /** Overrides superclass method. */
129         public void insertString(int offs, String JavaDoc str, AttributeSet JavaDoc a)
130         throws BadLocationException JavaDoc {
131              char[] source = str.toCharArray();
132              StringBuffer JavaDoc result = new StringBuffer JavaDoc();
133              
134              for(int i=0; i<source.length; i++) {
135                  if(Character.isDigit(source[i])) {
136                      result.append(source[i]);
137                  } else {
138                      if(Boolean.getBoolean("netbeans.debug.excpetions")) // NOI18N
139
System.err.println("Image: Trying insert non-digit in custom zoom action."); // NOI18N
140
}
141              }
142              
143              // There has to be some number added.
144
if(result.length() == 0)
145                  return;
146              
147              super.insertString(offs, result.toString(), a);
148          }
149          
150      } // End of nested class WholeNumberDocument.
151

152     
153 }
154
Popular Tags