001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.image;
043:
044: import javax.swing.JPanel;
045: import javax.swing.text.AttributeSet;
046: import javax.swing.text.BadLocationException;
047: import javax.swing.text.PlainDocument;
048:
049: import org.openide.util.NbBundle;
050:
051: /** This class define a panel for "Custom zoom" dialog.
052: *
053: * @author Lukas Tadial
054: */
055: public class CustomZoomPanel extends JPanel {
056:
057: /** Creates new form CustomZoomPane */
058: public CustomZoomPanel() {
059: initComponents();
060: initAccessibility();
061: }
062:
063: /** This method is called from within the constructor to
064: * initialize the form.
065: * WARNING: Do NOT modify this code. The content of this method is
066: * always regenerated by the Form Editor.
067: */
068: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
069: private void initComponents() {
070: java.awt.GridBagConstraints gridBagConstraints;
071:
072: enlargeLabel = new javax.swing.JLabel();
073: enlargeText = new javax.swing.JTextField();
074: decreasingLabel = new javax.swing.JLabel();
075: decreaseText = new javax.swing.JTextField();
076:
077: setLayout(new java.awt.GridBagLayout());
078:
079: enlargeLabel.setLabelFor(enlargeText);
080: org.openide.awt.Mnemonics.setLocalizedText(enlargeLabel,
081: NbBundle.getBundle(CustomZoomPanel.class).getString(
082: "LBL_EnlargeFactor")); // NOI18N
083: gridBagConstraints = new java.awt.GridBagConstraints();
084: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
085: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
086: add(enlargeLabel, gridBagConstraints);
087:
088: enlargeText.setDocument(new WholeNumberDocument());
089: gridBagConstraints = new java.awt.GridBagConstraints();
090: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
091: gridBagConstraints.weightx = 1.0;
092: gridBagConstraints.insets = new java.awt.Insets(12, 11, 0, 11);
093: add(enlargeText, gridBagConstraints);
094:
095: decreasingLabel.setLabelFor(decreaseText);
096: org.openide.awt.Mnemonics.setLocalizedText(decreasingLabel,
097: NbBundle.getBundle(CustomZoomPanel.class).getString(
098: "LBL_DecreaseFactor")); // NOI18N
099: gridBagConstraints = new java.awt.GridBagConstraints();
100: gridBagConstraints.gridx = 0;
101: gridBagConstraints.gridy = 1;
102: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
103: gridBagConstraints.insets = new java.awt.Insets(5, 12, 11, 0);
104: add(decreasingLabel, gridBagConstraints);
105:
106: decreaseText.setDocument(new WholeNumberDocument());
107: gridBagConstraints = new java.awt.GridBagConstraints();
108: gridBagConstraints.gridx = 1;
109: gridBagConstraints.gridy = 1;
110: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
111: gridBagConstraints.weightx = 1.0;
112: gridBagConstraints.insets = new java.awt.Insets(5, 11, 11, 11);
113: add(decreaseText, gridBagConstraints);
114: }// </editor-fold>//GEN-END:initComponents
115:
116: private void initAccessibility() {
117: getAccessibleContext().setAccessibleDescription(
118: NbBundle.getBundle(CustomZoomPanel.class).getString(
119: "ACSD_CustomZoomPanel"));
120: enlargeText.getAccessibleContext().setAccessibleDescription(
121: NbBundle.getBundle(CustomZoomPanel.class).getString(
122: "ACS_EnlargeText"));
123: decreaseText.getAccessibleContext().setAccessibleDescription(
124: NbBundle.getBundle(CustomZoomPanel.class).getString(
125: "ACS_DecreaseText"));
126:
127: }
128:
129: public int getEnlargeFactor() {
130: return Integer.parseInt(enlargeText.getText());
131: }
132:
133: public void setEnlargeFactor(int enlargeFactor) {
134: enlargeText.setText("" + enlargeFactor); // NOI18N
135: }
136:
137: public int getDecreaseFactor() {
138: return Integer.parseInt(decreaseText.getText());
139: }
140:
141: public void setDecreaseFactor(int decreaseFactor) {
142: decreaseText.setText("" + decreaseFactor); // NOI18N
143: }
144:
145: // Variables declaration - do not modify//GEN-BEGIN:variables
146: private javax.swing.JTextField decreaseText;
147: private javax.swing.JLabel decreasingLabel;
148: private javax.swing.JLabel enlargeLabel;
149: private javax.swing.JTextField enlargeText;
150:
151: // End of variables declaration//GEN-END:variables
152:
153: /** Documnet which accepts only digit chars. */
154: private static class WholeNumberDocument extends PlainDocument {
155:
156: /** Overrides superclass method. */
157: public void insertString(int offs, String str, AttributeSet a)
158: throws BadLocationException {
159: char[] source = str.toCharArray();
160: StringBuffer result = new StringBuffer();
161:
162: for (int i = 0; i < source.length; i++) {
163: if (Character.isDigit(source[i])) {
164: result.append(source[i]);
165: } else {
166: if (Boolean.getBoolean("netbeans.debug.excpetions")) // NOI18N
167: System.err
168: .println("Image: Trying insert non-digit in custom zoom action."); // NOI18N
169: }
170: }
171:
172: // There has to be some number added.
173: if (result.length() == 0)
174: return;
175:
176: super .insertString(offs, result.toString(), a);
177: }
178:
179: } // End of nested class WholeNumberDocument.
180:
181: }
|