libsimple-validation-java-.orig/0000755000175000017500000000000012234612336015667 5ustar tonytonylibsimple-validation-java-.orig/org/0000755000175000017500000000000011654612134016457 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/0000755000175000017500000000000011654612134020256 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/validation/0000755000175000017500000000000011654612134022410 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/validation/spi/0000755000175000017500000000000011654612134023203 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/validation/spi/accessibility/0000755000175000017500000000000011654612134026032 5ustar tonytony././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/spi/accessibility/GlobalValidationCallback.javalibsimple-validation-java-.orig/org/netbeans/validation/spi/accessibility/GlobalValidationCallback.j0000644000175000017500000000414311654612134033037 0ustar tonytony/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.netbeans.validation.spi.accessibility; import java.util.Collection; import org.netbeans.validation.api.Problem; import org.openide.util.Exceptions; import org.openide.util.Lookup; /** * * @author Tim Boudreau */ public abstract class GlobalValidationCallback { private static final Object LOCK = new Object(); private static GlobalValidationCallback INSTANCE; static GlobalValidationCallback getDefault() { synchronized (LOCK) { if (INSTANCE == null) { INSTANCE = new ProxyGlobalCallback(); } } return INSTANCE; } public void onValidationTrigger (Object source, Object triggeringEvent) { } public void onValidationFinished (Object source, Object triggeringEvent) { } public abstract void onProblem (Object component, Problem problem); public abstract void onProblemCleared (Object component, Problem problem); private static final class ProxyGlobalCallback extends GlobalValidationCallback { private ProxyGlobalCallback() { } Collection registered() { return Lookup.getDefault().lookupAll(GlobalValidationCallback.class); } @Override public void onProblem(Object component, Problem problem) { for (GlobalValidationCallback cb : registered()) { try { cb.onProblem(component, problem); } catch (Exception e) { Exceptions.printStackTrace(e); } } } @Override public void onProblemCleared(Object component, Problem problem) { for (GlobalValidationCallback cb : registered()) { try { cb.onProblemCleared(component, problem); } catch (Exception e) { Exceptions.printStackTrace(e); } } } } } libsimple-validation-java-.orig/org/netbeans/validation/api/0000755000175000017500000000000011654612134023161 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/validation/api/Bundle.properties0000644000175000017500000000450511654612134026514 0ustar tonytony# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common # Development and Distribution License("CDDL") (collectively, the # "License"). You may not use this file except in compliance with the # License. You can obtain a copy of the License at # http://www.netbeans.org/cddl-gplv2.html # or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the # specific language governing permissions and limitations under the # License. When distributing the software, include this License Header # Notice in each file and include the License file at # nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this # particular file as subject to the "Classpath" exception as provided # by Sun in the GPL Version 2 section of the License file that # accompanied this code. If applicable, add the following below the # License Header, with the fields enclosed by brackets [] replaced by # your own identifying information: # "Portions Copyrighted [year] [name of copyright owner]" # # Contributor(s): # # The Original Software is NetBeans. The Initial Developer of the Original # Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun # Microsystems, Inc. All Rights Reserved. # # If you wish your version of this file to be governed by only the CDDL # or only the GPL Version 2, indicate your decision by adding # "[Contributor] elects to include this software in this distribution # under the [CDDL or GPL Version 2] license." If you do not indicate a # single choice of license, a recipient has the option to distribute # your version of this file under either the CDDL, the GPL Version 2 or # to extend the choice of license to its licensees as provided above. # However, if you add GPL Version 2 code and therefore, elected the GPL # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. OpenIDE-Module-Name=Validation Ui Api GENERIC_EMPTY_TEXTFIELD_ERROR={0} not set INFO=Informational Message WARNING=Warning Message FATAL=Fatal Error INFO.annotation=Informational Message: {0} WARNING.annotation=Warning Message: {0} FATAL.annotation=Fatal Error: {0} libsimple-validation-java-.orig/org/netbeans/validation/api/ui/0000755000175000017500000000000011661314136023575 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/validation/api/ui/ValidationListener.java0000644000175000017500000001351211654612134030243 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.Problems; /** * Abstract base class for UI component listeners that can trigger validation when an interesting * event occurs, and when requested perform validation of the UI component using a {@link org.netbeans.validation.api.Validator}. *

* Implement whatever UI component listener interface * is necessary, add it as a listener to the UI component(s) it should listen to, and * then pass the listener to {@code ValidationGroup.add()}. *

* When an event that should * trigger validation occurs, let the listener (the subclass of {@code ValidationListener}) call the * {@link #performValidation() } method to notfify the simplevalidation infrastructure * what's going on. The infrastrure will then usually call the {@link #performValidation(org.netbeans.validation.api.Problems) } * method, in which the the listener (the subclass of {@code ValidationItem}) * should validate the UI-component using a suitable {@link org.netbeans.validation.api.Validator}. *

* Note that one validation listener may not belong to more than one ValidationGroup. *

* * @author Tim Boudreau * @author Hugo Heden */ public abstract class ValidationListener extends ValidationItem implements java.util.EventListener { private TargetType target; private final Class targetType; protected ValidationListener(Class targetType, ValidationUI ui, TargetType component){ super(ui); this.targetType = targetType; this.target = component; } /** * Called by subclasses to indicate to the simple-validation infrastructure * that user has interacted with the UI-component in a way that makes revalidation * needed. *

* This will initiate the validation logic (unless the validation is suspended, see * {@link ValidationItem#runWithValidationSuspended(java.lang.Runnable)}: * A call to {@link ValidationListener#performValidation(org.netbeans.validation.api.Problems)} * will occur. *

* If this results in a {@link Problem}, the {@link ValidationUI} * managed by this {@code ValidationListener} (such as an error icon * decorating the UI-component) will be activated, indicating the {@code Problem} * to the user. *

* If this ValidationListener is added to a {@link ValidationGroup}, * the latter will update its {@code ValidationUI}:s as well (unless there happens * to be a more severe {@code Problem} somewhere else within that {@code ValidationGroup}) */ // protected final void performValidation() { // Intended to be called by subclasses // super.performValidation(); // } @Override final void subtreeRevalidation(){ // Intended to be called by parent ValidationGroup if (isSuspended()) { return; } Problems ps = new Problems(); this.performValidation(ps); Problem lead = ps.getLeadProblem(); super.setCurrentLeadProblem(lead); } /** * Called by the simplevalidation infrastructure when it is time to * perform the validation. The instance of the class subclassing ValidationListener * should have access to the UI-component to validate, and to a validator, and simply call * the validator's validate() method with the appropriate arguments. *

* If the component to be validated is disabled (it is greyed out and can't * be interacted with) it is usually considered to have no problems. */ protected abstract void performValidation(Problems problems); protected final TargetType getTarget() { return target; } Class targetType() { return targetType; } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/ValidationListenerFactory.java0000644000175000017500000002606711715053270031602 0ustar tonytony/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.netbeans.validation.api.ui; import java.util.Collection; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.ComboBoxModel; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JList; import javax.swing.ListSelectionModel; import javax.swing.text.Document; import javax.swing.text.JTextComponent; import org.netbeans.validation.api.Validator; import org.netbeans.validation.api.ValidatorUtils; import org.openide.util.Lookup; /** * Factory for listeners on a particular type of component with a particular * type of model. Creates listeners which can be attached to one * component and run validators for the specified model type. * For example, a validator for the Document of a JTextArea would most likely * be a Validator<JTextComponent, Document>. *

* Instances of ValidationListenerFactory for specific component types may * be declaratively registered in META-INF/services in your JAR (i.e. * findable via JDK 6's ServiceLoader or NetBeans default Lookup). *

* The library contains built-in listeners for Swing components, including * JList, JTextComponent, JComboBox and arrays of AbstractButton. These * will be found in preference to any registered factories. * * @author Tim Boudreau */ public abstract class ValidationListenerFactory { private final Class componentType; private final Class modelType; protected ValidationListenerFactory(Class componentType, Class modelType) { this.componentType = componentType; this.modelType = modelType; } final Class componentType() { return componentType; } final Class modelType() { return modelType; } /** * Create a ValidationListener for a specific type of component, which accepts * Validators of a given type. By default, the following combinations are * supported: *

* To register validation listeners for additional types, subclass * SwingValidationListenerFactory and register it * in JDK 6's ServiceLoader/NetBeans default Lookup by placing flat * files in META-INF/services in a JAR on the classpath. Each such * registered type must also have an annotation of type * ListenerFor, so that it can be located correctly. * Example:
@SwingValidationListenerFactory.ListenerFor(componentType=JColorChooser.class, modelObjectType=Color.class)
public class ColorChooserValidationListenerFactory extends SwingValidationListenerFactory {

    @Override
    protected  ValidationListener createListener(
        JColorChooser component, ValidationStrategy strategy,
        ValidationUI validationUI, Validator validator) {
        //This cast is safe - this method will never be called unless
        //the type has first been checked
        return new ColorChooserListener(component, validationUI,
            (Validator) validator);
    }

    static final class ColorChooserListener
                    extends AbstractValidationListener
                    implements PropertyChangeListener {
        ColorChooserListener (JColorChooser comp, ValidationUI ui,
                              Validator validator) {
            super (comp, ui, color);
            comp.addPropertyChangeListener("color", this);
        }

        @Override
        protected Color getModelObject(JColorChooser comp) {
            return comp.getColor();
        }

        public void propertyChange(PropertyChangeEvent evt) {
            performValidation();
        }
    }
}
* * @param The component type. * @param The type of object the Validator accepts * @param component A component of CType or a subclass * @param strategy The validation strategy to use * @param validationUI A validation UI, typically the component decorator * @param validator A validator that accepts ModelType arguments * @return a listener */ public static ValidationListener createValidationListener(final CType component, final ValidationStrategy strategy, ValidationUI validationUI, final Validator validator) { Class modelType = validator.modelType(); ValidationListener result = null; //If we're really using some other toolkit, avoid loading more Swing //classes than JComponent if (component instanceof JComponent || (component.getClass().isArray() && JComponent.class.isAssignableFrom(component.getClass().getComponentType()))) { result = findBuiltInValidationListener(component, strategy, validationUI, validator); } if (result == null) { @SuppressWarnings("rawtypes") Collection registered = Lookup.getDefault().lookupAll(ValidationListenerFactory.class); if (Object.class.equals(modelType)) { Logger.getLogger(ValidationListenerFactory.class.getName()).log( Level.WARNING, "Bad form to create a Validator: {0}", validator.getClass().getName()); } @SuppressWarnings("unchecked") // XXX this code is probably wrong, but have not yet figured out why; probably should accept Class param Class compType = (Class) component.getClass(); for (ValidationListenerFactory f : registered) { if (f.componentType().isAssignableFrom(compType)) { ValidationListenerFactory cast = f.as(compType, modelType, component); if (cast != null) { return cast.createListener(component, strategy, validationUI, validator); } } } } if (result == null) { throw new IllegalArgumentException("No registered validator for " + "components of type " + component.getClass().getName() + " and validators for objects of type " + modelType); } return result; } // XXX unchecked warnings: need cast method for ValidationListener @SuppressWarnings("unchecked") static ValidationListener findBuiltInValidationListener(final CType component, final ValidationStrategy strategy, ValidationUI validationUI, final Validator validator) { Class modelType = validator.modelType(); if (component instanceof JList && Integer[].class.equals(modelType)) { return (ValidationListener) SwingValidationListenerFactories.createJListValidationListenerConverted((JList) component, strategy, validationUI, ValidatorUtils.cast(Integer[].class, validator)); } else if (component instanceof JList && ListSelectionModel.class.isAssignableFrom(modelType)) { return SwingValidationListenerFactories.createJListValidationListener(JList.class.cast(component), strategy, validationUI, (Validator) validator); } else if (component instanceof JTextComponent && String.class.equals(modelType)) { return SwingValidationListenerFactories.createJTextComponentValidationListener(JTextComponent.class.cast(component), strategy, validationUI, (Validator) validator); } else if (component instanceof JTextComponent && Document.class.isAssignableFrom(modelType)) { return SwingValidationListenerFactories.createJTextComponentValidationListener(JTextComponent.class.cast(component), strategy, validationUI, (Validator) validator); } else if (component instanceof JComboBox && String.class.equals(modelType)) { return SwingValidationListenerFactories.createJComboBoxValidationListener(JComboBox.class.cast(component), strategy, validationUI, (Validator) validator); } else if (component instanceof JComboBox && ComboBoxModel.class.isAssignableFrom(modelType)) { return SwingValidationListenerFactories.createJComboBoxValidationListener(JComboBox.class.cast(component), strategy, validationUI, (Validator) validator); } else if (ButtonModel[].class.equals(modelType) && component.getClass().isArray() && component.getClass().getComponentType().isAssignableFrom(AbstractButton.class)) { return SwingValidationListenerFactories.createButtonsValidationListener(AbstractButton[].class.cast(component), validationUI, (Validator) validator); } else if (Integer[].class.equals(modelType) && component.getClass().isArray() && component.getClass().getComponentType().isAssignableFrom(AbstractButton.class)) { return SwingValidationListenerFactories.createButtonsValidationListener(AbstractButton[].class.cast(component), validationUI, (Validator) validator); } return null; } protected abstract ValidationListener createListener (final CompType component, final ValidationStrategy strategy, ValidationUI validationUI, final Validator validator); ValidationListenerFactory as (Class actualCompType, Class actualModelType, T comp) { return new Cast (actualCompType, actualModelType, comp, this); } private static final class Cast extends ValidationListenerFactory { private final ValidationListenerFactory other; Cast(Class compType, Class model, CompType comp, ValidationListenerFactory other) { super (compType, model); this.other = other; } @Override @SuppressWarnings("unchecked") protected ValidationListener createListener(CompType component, ValidationStrategy strategy, ValidationUI validationUI, Validator validator) { T t = other.componentType.cast(component); Validator v = ValidatorUtils.cast(other.modelType(), validator); ValidationListener real = other.createListener(t, strategy, validationUI, v); return (ValidationListener) real; } } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/ValidationStrategy.java0000644000175000017500000000554511654612134030267 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; /** * Determines what event on the component will trigger running validation. * For example, if validation of a text component's content involves expensive * calculation which could slow down the UI, you may want to use ON_FOCUS_LOSS; * however ON_CHANGE_OR_ACTION (reacting every time a key is typed) provides * more satisfactory user experience. * * @author Tim Boudreau */ public enum ValidationStrategy { /** Use whatever is generally most appropriate for this component */ DEFAULT, /** Validate when focus is lost */ ON_FOCUS_LOSS, /** Validate on a document change or action performed or change event */ ON_CHANGE_OR_ACTION, /** Validate using JComponent.setInputVerifier */ INPUT_VERIFIER, } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/ButtonsValidationListenerImpl.java0000644000175000017500000001035211654612134032443 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import java.awt.Color; import org.netbeans.validation.api.Validator; import org.netbeans.validation.api.ui.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.List; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.JColorChooser; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.validation.api.Problems; /** * THIS CLASS AND EVERYTHING ELSE IN THIS PACKAGE IS NOT API. DO NOT CALL * OR INSTANTIATE DIRECTLY. * * @author Hugo Heden */ class ButtonsValidationListenerImpl extends ValidationListener implements ItemListener, ChangeListener{ private final Validator validator; private final AbstractButton[] buttons; public ButtonsValidationListenerImpl(AbstractButton[] buttons, ValidationUI validationUI, Validator validator) { super(AbstractButton[].class, validationUI, buttons); this.validator = validator; this.buttons = buttons; for (int i = 0; i < buttons.length; i++) { buttons[i].getModel().addChangeListener(this); buttons[i].getModel().addItemListener(this); } performValidation(); // Make sure any initial errors are discovered immediately. } @Override public void itemStateChanged(ItemEvent e) { performValidation(); } @Override public void stateChanged(ChangeEvent pce) { performValidation(); } @Override protected void performValidation(Problems ps) { boolean theyreAllDisabled = true; List selectedButtons = new ArrayList(); for (AbstractButton button : buttons) { if (button.getModel().isEnabled()) { theyreAllDisabled = false; if (button.getModel().isSelected()) { selectedButtons.add(button.getModel()); } } } if (!theyreAllDisabled) { validator.validate(ps, null, selectedButtons.toArray(new ButtonModel[selectedButtons.size()])); } } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/SwingValidationListenerFactories.java0000644000175000017500000003751711654612134033126 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import java.awt.EventQueue; import javax.swing.ComboBoxModel; import javax.swing.JComboBox; import javax.swing.JList; import javax.swing.ListSelectionModel; import javax.swing.text.Document; import javax.swing.text.JTextComponent; import org.netbeans.validation.api.Validator; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import org.netbeans.validation.api.ValidatorUtils; import org.netbeans.validation.api.conversion.Converter; import org.netbeans.validation.api.ui.swing.SwingValidationGroup; /** * A number of factory methods for creating ValidationListeners handling validation of Swing components. *

* Note that there are also some convenience methods for creating a ValidationListener * and directly adding it to a ValidationGroup, see the {@code add} methods in class {@link SwingValidationGroup}, * so the using the methods in this class should often not be necessary. * * Note that the factory methods here could be moved to ValidationGroup, however, * this would cause ValidationGroup to trigger heavier classloading (at least * if -Xverify:none is not set for the VM). * * @author Tim Boudreau * @author Hugo Heden */ final class SwingValidationListenerFactories { private SwingValidationListenerFactories(){} /** * Create a ValidationListener for a JList. The JList will be validated * with the passed ValidationStrategy * using the passed Validator * showing any problems in the passed ValidationUI *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.JList, org.netbeans.validation.api.Validator[]) } * * */ static ValidationListener createJListValidationListener(final JList component, final ValidationStrategy strategy, ValidationUI validationUI, final Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new JListValidationListenerImpl(component, strategy, validationUI, validator); } /** * Create a ValidationListener for a JList. The JList will be validated * with the passed ValidationStrategy * using the passed chain of Validator * showing any problems in the passed ValidationUI *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.JList, org.netbeans.validation.api.Validator[]) } * */ static ValidationListener createJListValidationListenerConverted(final JList component, final ValidationStrategy strategy, ValidationUI validationUI, final Validator orig) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; final Validator validator = Converter.find(Integer[].class, ListSelectionModel.class).convert(orig); return new JListValidationListenerImpl(component, strategy, validationUI, validator); } /** * Create a ValidationListener for a JTextComponent (such as JTextField or JTextArea). The JTextComponent will be validated * with the passed ValidationStrategy * using the passed Validator * showing any problems in the passed ValidationUI * *

Swing {@code Document}s (the model used by JTextComponent) * are thread-safe, and can be modified from other threads. In * the case that a text component validator receives an event on * another thread, validation will be scheduled for later, * on the event thread. *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.text.JTextComponent, org.netbeans.validation.api.Validator[]) } * */ static ValidationListener createJTextComponentValidationListener(final JTextComponent comp, final ValidationStrategy strategy, final ValidationUI validationUI, final Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new JTextComponentValidationListenerImpl(comp, strategy, validationUI, validator); } /** * Create a ValidationListener for a JTextComponent (such as JTextField or JTextArea). The JTextComponent will be validated * (with ValidationStrategy.DEFAULT) * using the passed Validator * showing any problems in the passed ValidationUI * *

Swing {@code Document}s (the model used by JTextComponent) * are thread-safe, and can be modified from other threads. In * the case that a text component validator receives an event on * another thread, validation will be scheduled for later, * on the event thread. *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.text.JTextComponent, org.netbeans.validation.api.Validator[]) } * */ static ValidationListener createJTextComponentValidationListener(final JTextComponent comp, final ValidationUI validationUI, final Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new JTextComponentValidationListenerImpl(comp, ValidationStrategy.DEFAULT, validationUI, validator); } /** * Create a ValidationListener for a JTextComponent (such as JTextField or JTextArea). The JTextComponent will be validated * with the passed ValidationStrategy * using the passed chain of Validator * showing any problems in the passed ValidationUI * *

Swing {@code Document}s (the model used by JTextComponent) * are thread-safe, and can be modified from other threads. In * the case that a text component validator receives an event on * another thread, validation will be scheduled for later, * on the event thread. *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.text.JTextComponent, org.netbeans.validation.api.Validator[]) } * */ static ValidationListener createJTextComponentValidationListener(final JTextComponent comp, final ValidationStrategy strategy, final ValidationUI validationUI, final Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; final Validator merged = ValidatorUtils.merge(validators); final Validator validator = Converter.find(String.class, Document.class).convert(merged); return new JTextComponentValidationListenerImpl(comp, strategy, validationUI, validator); } /** * Create a ValidationListener for a JTextComponent (such as JTextField or JTextArea). The JTextComponent will be validated * (with ValidationStrategy.DEFAULT) * using the passed chain of Validator * showing any problems in the passed ValidationUI * *

Swing {@code Document}s (the model used by JTextComponent) * are thread-safe, and can be modified from other threads. In * the case that a text component validator receives an event on * another thread, validation will be scheduled for later, * on the event thread. *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.text.JTextComponent, org.netbeans.validation.api.Validator[]) } * */ static ValidationListener createJTextComponentValidationListener(final JTextComponent comp, final ValidationUI validationUI, final Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return createJTextComponentValidationListener(comp, ValidationStrategy.DEFAULT, validationUI, validators); } /** * Create a ValidationListener for a JComboBox. The JComboBox will be validated * with the passed ValidationStrategy * using the passed Validator * showing any problems in the passed ValidationUI *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.JComboBox, org.netbeans.validation.api.Validator[]) } */ static ValidationListener createJComboBoxValidationListener(final JComboBox component, final ValidationStrategy strategy, ValidationUI validationUI, final Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new JComboBoxValidationListenerImpl(component, strategy, validationUI, validator); } /** * Create a ValidationListener for a JComboBox. The JComboBox will be validated * (with ValidationStrategy.DEFAULT) * using the passed Validator * showing any problems in the passed ValidationUI *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.JComboBox, org.netbeans.validation.api.Validator[]) } */ static ValidationListener createJComboBoxValidationListener(final JComboBox component, ValidationUI validationUI, final Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new JComboBoxValidationListenerImpl(component, ValidationStrategy.DEFAULT, validationUI, validator); } /** * Create a ValidationListener for a JComboBox. The JComboBox will be validated * with the passed ValidationStrategy * using the passed chain of Validator * showing any problems in the passed ValidationUI *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.JComboBox, org.netbeans.validation.api.Validator[]) } */ static ValidationListener createJComboBoxValidationListener(final JComboBox component, final ValidationStrategy strategy, ValidationUI validationUI, final Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; final Validator merged = ValidatorUtils.merge(validators); final Validator validator = Converter.find(String.class, ComboBoxModel.class).convert(merged); return new JComboBoxValidationListenerImpl(component, strategy, validationUI, validator); } /** * Create a ValidationListener for a JComboBox. The JComboBox will be validated * (with ValidationStrategy.DEFAULT) * using the passed chain of Validator * showing any problems in the passed ValidationUI *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.JComboBox, org.netbeans.validation.api.Validator[]) } */ static ValidationListener createJComboBoxValidationListener(final JComboBox component, ValidationUI validationUI, final Validator... validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return createJComboBoxValidationListener(component, ValidationStrategy.DEFAULT, validationUI, validator); } /** * Create a ValidationListener for a AbstractButton[] (such as a number of JCheckBoxes and JRadioButtons). The AbstractButton[] will be validated * using the passed Validator * showing any problems in the passed ValidationUI * *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.AbstractButton[], org.netbeans.validation.api.Validator[]) } */ static ValidationListener createButtonsValidationListener(final AbstractButton[] buttons, ValidationUI validationUI, final Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new ButtonsValidationListenerImpl(buttons, validationUI, validator); } /** * Create a ValidationListener for a AbstractButton[] (such as a number of JCheckBoxes and JRadioButtons). The AbstractButton[] will be validated * using the passed chain of Validator * showing any problems in the passed ValidationUI *

* Note that there is also a convenience method for creating a ValidationListener * and directly adding it to a ValidationGroup, see * {@link SwingValidationGroup#add(javax.swing.AbstractButton[], org.netbeans.validation.api.Validator[]) } * */ static ValidationListener createButtonsValidationListener(final AbstractButton[] buttons, ValidationUI validationUI, final Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; final Validator merged = ValidatorUtils.merge(validators); final Validator validator = Converter.find(Integer[].class, ButtonModel[].class).convert(merged); return new ButtonsValidationListenerImpl(buttons, validationUI, validator); } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/ValidationUI.java0000644000175000017500000000776211654612134027005 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import org.netbeans.validation.api.Problem; /** * User interface controller which can show the user one problem. This * could involve showing an icon and some textual info in a status * bar, and/or disabling some OK-button (if the problem is of {@code * Severity.FATAL}) etc. * *

For one {@link ValidationGroup} (a group of UI-components * validated together), typically one or a few {@code ValidationUI} * instances might be used, but one instance of {@code ValidationUI} * should only be used with at most one {@code ValidationGroup} - * otherwise a new {@code Problem} in one {@code ValidationGroup} will * hide any {@code Problem}s in others. * *

Also, typically a {@code ValidationUI} instance is also used * for decorating each separate GUI-component that has a Problem. The * {@link org.netbeans.validation.api.ui.swing.SwingComponentDecorationFactory} is * a factory class creating such {@code ValidationUI} instances for decorating * Swing components when there is a validation problem in them. * * @author Tim Boudreau */ public interface ValidationUI { /** * Sets the {@link Problem} to be displayed to the user. Depending on the * severity of the problem, the user interface may want to block the * user from continuing until it is fixed (for example, disabling the * Next button in a wizard or the OK button in a dialog). * @param problem A problem that the user should be shown, which may * affect the state of the UI as a whole. Should never be null. */ public void showProblem(final Problem problem); /** * Clear the problem shown in this UI. */ public void clearProblem(); /** * Access a ValidationUI instance that does nothing. */ public static final ValidationUI NO_OP = new ValidationUI(){ @Override public void showProblem(Problem problem) {} public void clearProblem() {} }; } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/0000755000175000017500000000000011661314136024724 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/ValidationPanel.java0000644000175000017500000002715611654612134030655 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui.swing; import org.netbeans.validation.api.ui.ValidationGroupProvider; import org.netbeans.validation.api.ui.*; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dialog; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.KeyboardFocusManager; import java.awt.LayoutManager; import java.awt.Rectangle; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Collections; import java.util.LinkedList; import java.util.List; import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.KeyStroke; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.validation.api.Problem; import org.openide.util.NbBundle; /** * A simple panel which can display a problem, fire changes when the problem * changes. To use, create your own panel and call setInnerComponent() with it. * Call getValidationGroup() to add other components to the validation group. * * @author Tim Boudreau */ public final class ValidationPanel extends JPanel implements ValidationGroupProvider { private final JComponent problemLabel; private boolean initialized; private Problem problem = null; private final List listeners = Collections.synchronizedList( new LinkedList()); protected final SwingValidationGroup group; private final VUI vui = new VUI(); public ValidationPanel (SwingValidationGroup group) { super(new BorderLayout()); if (group == null) { group = SwingValidationGroup.create(vui); } else { group.addUI(vui); } this.group = group; problemLabel = group.createProblemLabel(); problemLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); add(problemLabel, BorderLayout.SOUTH); initialized = true; int b = System.getProperty("mrj.version") != null ? 12 : 5; setBorder(BorderFactory.createEmptyBorder(b,b,b,b)); } public ValidationPanel() { this(null); } public void setDelegateValidationUI(ValidationUI ui) { group.addUI(ui); } public void removeDelegateValidationUI (ValidationUI ui) { group.removeUI(ui); } private JDialog createDialog() { Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (w == null) { Frame[] f = Frame.getFrames(); w = f == null || f.length == 0 ? null : f[0]; } JDialog result; if (w instanceof Frame) { result = new JDialog ((Frame) w); } else if (w instanceof Dialog) { result = new JDialog ((Dialog) w); } else { result = new JDialog(); } if (w != null) { result.setLocationRelativeTo(w); } return result; } public boolean showOkCancelDialog(String title) { final JDialog dlg = createDialog(); dlg.setModal(true); dlg.setTitle (title); JPanel content = new JPanel(new BorderLayout()); content.add(this, BorderLayout.CENTER); dlg.setContentPane(content); JPanel buttons = new JPanel(new FlowLayout(FlowLayout.TRAILING)); final JButton ok = new JButton(NbBundle.getMessage(ValidationPanel.class, "OK")); //NOI18N final JButton cancel = new JButton(NbBundle.getMessage(ValidationPanel.class, "Cancel")); boolean mac = System.getProperty("mrj.version") != null; buttons.add(mac ? cancel : ok); buttons.add(mac ? ok : cancel); final ValidationUI okButtonEnabler = new ValidationUI(){ public void showProblem(Problem problem) { if(problem == null || !problem.isFatal()){ ok.setEnabled(true); } else { ok.setEnabled(false); } } public void clearProblem() { showProblem(null); } }; group.addUI(okButtonEnabler); content.add(buttons, BorderLayout.SOUTH); dlg.getRootPane().getActionMap().put("esc", new AbstractAction(){ //NOI18N @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); dlg.getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "esc"); //NOI18N final boolean[] result = new boolean[1]; ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { group.removeUI(okButtonEnabler); result[0] = true; dlg.setVisible(false); dlg.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { group.removeUI(okButtonEnabler); result[0] = false; dlg.setVisible(false); dlg.dispose(); } }); dlg.getRootPane().setDefaultButton(ok); dlg.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { centerScreen (e.getWindow()); } public void centerScreen(Window w) { if (w.getOwner() == null) { Dimension dim = getToolkit().getScreenSize(); Rectangle abounds = w.getBounds(); w.setLocation((dim.width - abounds.width) / 2, (dim.height - abounds.height) / 2); } } @Override public void windowClosing(WindowEvent e) { cancel.doClick(); } }); dlg.pack(); dlg.setVisible(true); return result[0]; } /** * Get this panel's built-in validation group, which drives its display * of error messages. Add an inner panel by calling setInnerComponent(), * then add your components to that, and add them to the validation group * using whatever validators you want * @return The validation group */ @Override public final ValidationGroup getValidationGroup() { return group; } /** * Overridden to disallow setting the layout manager. Use * setInnerComponent(). * @param mgr */ @Override public final void setLayout(LayoutManager mgr) { if (initialized) { throw new IllegalStateException("Use setInnerComponent, do not set" + //NOI18N " the layout"); //NOI18N } super.setLayout(mgr); } /** * Set the inner component which will be displayed above the * problem label * @param c The component */ public final void setInnerComponent(Component c) { removeAll(); add(problemLabel, BorderLayout.SOUTH); add(c, BorderLayout.CENTER); if (isDisplayable()) { invalidate(); revalidate(); repaint(); } } @Override protected void addImpl(Component comp, Object constraints, int index) { super.addImpl(comp, constraints, index); if (comp instanceof ValidationGroupProvider) { ValidationGroup g = ((ValidationGroupProvider) comp).getValidationGroup(); group.addItem(g, false); } if (comp instanceof ValidationUI) { ValidationUI theUI = (ValidationUI) comp; group.addUI(theUI); } } private class VUI implements ValidationUI { @Override public final void showProblem(Problem problem){ Problem old = ValidationPanel.this.problem; ValidationPanel.this.problem = problem; if ( (old != null && !old.equals(problem)) || (old == null && problem != null) ) { fireChange(); } } public void clearProblem() { showProblem(null); } } /** * Get the last reported problem * @return the problem, or null if there is none */ public final Problem getProblem() { return problem; } /** * Determine if there currently is a fatal problem * @return true if there is a problem */ public final boolean isFatalProblem() { return problem != null && problem.isFatal(); } /** * Add a change listener which will be notified when the problem * returned by getProblem changes * @param cl a change listener */ public final void addChangeListener(ChangeListener cl) { listeners.add(cl); } /** * Add a change listener which will be notified when the problem * returned by getProblem changes * @param cl a change listener */ public final void removeChangeListener(ChangeListener cl) { listeners.remove(cl); } private void fireChange() { ChangeListener[] cl = listeners.toArray(new ChangeListener[0]); if (cl.length > 0) { ChangeEvent e = new ChangeEvent(this); for (ChangeListener l : cl) { l.stateChanged(e); } } // doLayout(); } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/Bundle.properties0000644000175000017500000000407311654612134030260 0ustar tonytony# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common # Development and Distribution License("CDDL") (collectively, the # "License"). You may not use this file except in compliance with the # License. You can obtain a copy of the License at # http://www.netbeans.org/cddl-gplv2.html # or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the # specific language governing permissions and limitations under the # License. When distributing the software, include this License Header # Notice in each file and include the License file at # nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this # particular file as subject to the "Classpath" exception as provided # by Sun in the GPL Version 2 section of the License file that # accompanied this code. If applicable, add the following below the # License Header, with the fields enclosed by brackets [] replaced by # your own identifying information: # "Portions Copyrighted [year] [name of copyright owner]" # # Contributor(s): # # The Original Software is NetBeans. The Initial Developer of the Original # Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun # Microsystems, Inc. All Rights Reserved. # # If you wish your version of this file to be governed by only the CDDL # or only the GPL Version 2, indicate your decision by adding # "[Contributor] elects to include this software in this distribution # under the [CDDL or GPL Version 2] license." If you do not indicate a # single choice of license, a recipient has the option to distribute # your version of this file under either the CDDL, the GPL Version 2 or # to extend the choice of license to its licensees as provided above. # However, if you add GPL Version 2 code and therefore, elected the GPL # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. WARNING_LABEL=Warning Label OK=Ok Cancel=Cancel libsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/SwingValidationGroup.java0000644000175000017500000004400611654612134031713 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui.swing; import java.awt.Component; import org.netbeans.validation.api.ui.*; import java.awt.EventQueue; import java.awt.Point; import javax.swing.AbstractButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JList; import javax.swing.Popup; import javax.swing.text.JTextComponent; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.Validator; import org.netbeans.validation.api.ValidatorUtils; /** * {@link ValidationGroup} subclass specialized for handling Swing * components. This subclass has {@code add}-methods for adding * GUI-components for common Swing cases. There are also a method for * getting the {@link SwingComponentDecorationFactory} used by this * SwingValidationGroup to create decorations for the separate * GUI-components added to the group. A custom {@code SwingComponentDecorationFactory} * can be specified when creating the {@code SwingValidationGroup}. * *

For components this library supports out-of-the-box such as * JTextFields or JComboBoxes, simply call * one of the add() methods with your component and * validators. For validating your own components or ones this class * doesn't have methods for, you implement {@link ValidationListener}s, and add them * to the {@code ValidationGroup} using the the method * {@link ValidationGroup#addItem(org.netbeans.validation.api.ui.ValidationItem, boolean) } */ public final class SwingValidationGroup extends ValidationGroup { private final SwingComponentDecorationFactory decorator; private SwingValidationGroup(GroupValidator additionalGroupValidation, SwingComponentDecorationFactory decorator, ValidationUI... ui) { super(additionalGroupValidation, ui); if (ui == null) { throw new NullPointerException(); } this.decorator = ( decorator!=null ? decorator : SwingComponentDecorationFactory.getDefault() ); } public static SwingValidationGroup create(ValidationUI... ui) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new SwingValidationGroup(null, null, ui); } /** * Creates a {@code SwingValidationGroup}. * * Will use a {@code SwingComponentDecorationFactory} returned by {@link SwingComponentDecorationFactory#getDefault() } to modify the appearance of * subsequently added components (to show that there is a problem with a * component's content). To instead use a custom {@code SwingComponentDecorationFactory}, call * {@link #create(org.netbeans.validation.api.ui.GroupValidator, org.netbeans.validation.api.ui.swing.SwingComponentDecorationFactory, org.netbeans.validation.api.ui.ValidationUI[]) } * * @param ui Zero or more {@code ValidationUI}:s. Will be used by the {@code SwingValidationGroup} to show the leading problem (if any) */ public static SwingValidationGroup create(GroupValidator additionalGroupValidation, ValidationUI... ui) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new SwingValidationGroup(additionalGroupValidation, null, ui); } /** * Creates a {@code SwingValidationGroup}. * @param additionalGroupValidation may be null * @param ui Zero or more {@code ValidationUI}:s. Will all be used by the * {@code SwingValidationGroup} to show the leading problem (if any) * @param decorator A decorator to be used to modify the appearance of * subsequently added components (to show that there is a problem with a * component's content). */ public static SwingValidationGroup create(GroupValidator additionalGroupValidation, SwingComponentDecorationFactory decorator, ValidationUI... ui) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; return new SwingValidationGroup(additionalGroupValidation, decorator, ui); } /** * Gets the currently set component decorator used to modify * components appearance (to show that there is a problem with a * component's content). * @return decorator A decorator. May not be null. */ final SwingComponentDecorationFactory getComponentDecorationFactory() { return decorator; } @Override protected final ValidationUI decorationFor (T comp) { ValidationUI dec = comp instanceof JComponent ? this.getComponentDecorationFactory().decorationFor((JComponent) comp) : ValidationUI.NO_OP; return dec; } /** * Add a text component to be validated using the passed validators. * *

When a problem occurs, the created ValidationListener will * use a {@link ValidationUI} created by this {@code ValidationGroup} to decorate * the component. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. * *

Swing {@code Document}s (the model used by JTextComponent) * are thread-safe, and can be modified from other threads. In * the case that a text component validator receives an event on * another thread, validation will be scheduled for later, * on the event thread. * * @param comp A text component such as a JTextField * @param validators One or more Validators */ public final void add(JTextComponent comp, Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; assert validators.length > 0 : "Empty validator array"; Validator merged = ValidatorUtils.merge(validators); ValidationListener vl = ValidationListenerFactory.createValidationListener(comp, ValidationStrategy.DEFAULT, this.getComponentDecorationFactory().decorationFor(comp), merged); this.addItem (vl, false); } /** * Add a text component to be validated using the passed validator. * *

When a problem occurs, the created ValidationListener will * use a {@link ValidationUI} created by this {@code ValidationGroup} to decorate * the component. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. * *

Swing {@code Document}s (the model used by JTextComponent) * are thread-safe, and can be modified from other threads. In * the case that a text component validator receives an event on * another thread, validation will be scheduled for later, * on the event thread. *

Unlike {@link #add(JTextComponent,Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to add more than one validator, simply add the result of {@link ValidatorUtils#merge(Validator,Validator)}. * @param comp A text component such as a JTextField * @param validator a validator */ public final void add(JTextComponent comp, Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; ValidationListener vl = ValidationListenerFactory.createValidationListener(comp, ValidationStrategy.DEFAULT, this.getComponentDecorationFactory().decorationFor(comp), validator); this.addItem (vl, false); } /** * Add a combo box to be validated using the passed validators * *

When a problem occurs, the created {@link ValidationListener} will * use a {@link ValidationUI} created by this {@code ValidationGroup} to decorate * the component. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. * * @param box A combo box component * @param validators One or more Validators */ public final void add(JComboBox box, Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; this.addItem(ValidationListenerFactory.createValidationListener(box, ValidationStrategy.DEFAULT, ValidationUI.NO_OP, ValidatorUtils.merge(validators)), false); } /** * Add a combo box to be validated using the passed validator. * *

When a problem occurs, the created {@link ValidationListener} will * use a {@link ValidationUI} created by this {@code ValidationGroup} to decorate * the component. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. *

Unlike {@link #add(JComboBox,Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to add more than one validator, simply add the result of {@link ValidatorUtils#merge(Validator,Validator)}. * @param box A combo box component * @param validator a validator */ public final void add(JComboBox box, Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; this.addItem(ValidationListenerFactory.createValidationListener(box, ValidationStrategy.DEFAULT, ValidationUI.NO_OP, validator), false); } /** * Add a JList to be validated using the passed validators * *

When a problem occurs, the created {@link ValidationListener} will * use a {@link ValidationUI} created by this {@code ValidationGroup} to decorate * the component. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. * * @param list A JList component * @param validators One or more Validators */ public final void add(JList list, Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; this.addItem(ValidationListenerFactory.createValidationListener(list, ValidationStrategy.DEFAULT, this.getComponentDecorationFactory().decorationFor(list), ValidatorUtils.merge(validators)), false); } /** * Add a JList to be validated using the passed validator. * *

When a problem occurs, the created {@link ValidationListener} will * use a {@link ValidationUI} created by this {@code ValidationGroup} to decorate * the component. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. *

Unlike {@link #add(JList,Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to add more than one validator, simply add the result of {@link ValidatorUtils#merge(Validator,Validator)}. * @param list A JList component * @param validator a validator */ public final void add(JList list, Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; this.addItem(ValidationListenerFactory.createValidationListener(list, ValidationStrategy.DEFAULT, this.getComponentDecorationFactory().decorationFor(list), validator), false); } /** * Add a validator of button models - typically to see if any are selected. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. * * @param buttons The buttons * @param validators A number of Validators */ public final void add(final AbstractButton[] buttons, Validator... validators) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; this.addItem(ValidationListenerFactory.createValidationListener(buttons, ValidationStrategy.DEFAULT, ValidationUI.NO_OP, ValidatorUtils.merge(validators)), false); } /** * Add a validator of button models - typically to see if any are selected. * *

Note: All methods in this class must be called from * the AWT Event Dispatch thread, or assertion errors will be * thrown. Manipulating components on other threads is not safe. *

Unlike {@link #add(AbstractButton[],Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to add more than one validator, simply add the result of {@link ValidatorUtils#merge(Validator,Validator)}. * @param buttons The buttons * @param validator a validator */ public final void add(final AbstractButton[] buttons, Validator validator) { assert EventQueue.isDispatchThread() : "Must be called on event thread"; this.addItem(ValidationListenerFactory.createValidationListener(buttons, ValidationStrategy.DEFAULT, ValidationUI.NO_OP, validator), false); } /** * Create a label which will show the current problem if any, which * can be added to a panel that uses validation * * @return A JLabel */ public final JComponent createProblemLabel() { assert EventQueue.isDispatchThread() : "Must be called on event thread"; final MultilineLabel result = new MultilineLabel(); addUI(result.createUI()); return result; } /** * Create a Popup which can be shown over a component to display what the * problem is. The resulting popup will be word-wrapped and effort will be * made to ensure it fits on-screen in the case of lengthy error messages. * * @param problem The problem to show * @param target The target component * @param relativeLocation The coordinates where the popup should appear, * in the coordinate space of the target component, not the screen. * @return A popup. Generally, use the returned popup once and get a new * one if you want to show a message again. The returned popup will take * care of hiding itself on component hierarchy changes. */ static Popup createProblemPopup (Problem problem, Component target, Point relativeLocation) { return MultilineLabelUI.showPopup(problem, target, relativeLocation.x, relativeLocation.y); } /** * Client property which can be set to provide a component's name * for use in validation messages. If not set, the component's * getName() method is used. */ private static final String CLIENT_PROP_NAME = "_name"; /** * Get a string name for a component using the following strategy: *

    *
  1. Check jc.getClientProperty(CLIENT_PROP_NAME)
  2. *
  3. If that returned null, call jc.getName() *
* @param jc The component * @return its name, if any, or null */ public static String nameForComponent(JComponent jc) { String result = (String) jc.getClientProperty(CLIENT_PROP_NAME); if (result == null) { result = jc.getName(); } return result; } public static void setComponentName(JComponent comp, String localizedName) { comp.putClientProperty (CLIENT_PROP_NAME, localizedName); } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/MultilineLabel.java0000644000175000017500000001435511654612134030502 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui.swing; import java.awt.Dimension; import java.lang.ref.WeakReference; import javax.swing.JLabel; import javax.swing.ToolTipManager; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.ui.ValidationUI; import org.openide.util.NbBundle; /** * Label which uses a fixed height based on its icon and text. Uses * multiline label UI to render multi-line text * * @author Tim Boudreau */ final class MultilineLabel extends JLabel { private final boolean isPopup; MultilineLabel() { this(false); } MultilineLabel(boolean isPopup) { this.isPopup = isPopup; } boolean isPopup() { return isPopup; } @Override public void updateUI() { setUI (new MultilineLabelUI()); } private int tallest = Integer.MIN_VALUE; @Override public Dimension getPreferredSize() { Dimension result = super.getPreferredSize(); if (!isPopup && !isPreferredSizeSet()) { if (tallest < result.height) { tallest = result.height; } result.height = tallest; } return result; } private int knownWidth = -1; @Override @SuppressWarnings("deprecation") public void reshape(int x, int y, int w, int h) { //May be deprecated, but AWT will call it internally - this is the //place to intercept size changes other than a listener if (!isPopup) { if (w != knownWidth) { knownWidth = w; tallest = Integer.MIN_VALUE; } } super.reshape(x, y, w, h); } @Override public void addNotify() { super.addNotify(); if (!isPopup) { ToolTipManager.sharedInstance().registerComponent(this); } } @Override public void removeNotify() { super.removeNotify(); if (!isPopup) { ToolTipManager.sharedInstance().unregisterComponent(this); } } @Override public String getToolTipText() { String s = getText(); if (s != null && !"".equals(s.trim())) { return htmlize(s); } return super.getToolTipText(); } private static String htmlize(String s) { StringBuilder res = new StringBuilder(""); String[] words = s.split(" "); boolean newline = false; int ct = 0; for (String word : words) { ct += word.length(); newline = ct > 80; if(newline) { res.append ("
"); ct = 0; } res.append(word); res.append(' '); } return res.toString(); } ValidationUI createUI() { return new LblUI(this); } private static final class LblUI implements ValidationUI { //Don't allow the group to hold a reference to the label permanetly private final WeakReference label; LblUI(JLabel lbl) { assert lbl != null; this.label = new WeakReference(lbl); } @Override public void showProblem(Problem problem) { JLabel lbl = label.get(); if (lbl != null) { if (problem == null) { lbl.setText(" "); lbl.setIcon(null); lbl.getAccessibleContext().setAccessibleName( NbBundle.getMessage(MultilineLabel.class, "WARNING_LABEL")); lbl.getAccessibleContext().setAccessibleDescription(""); } else { lbl.setText(problem.getMessage()); lbl.setIcon(problem.severity().icon()); lbl.setForeground(problem.severity().color()); lbl.getAccessibleContext().setAccessibleName( problem.severity().toString()); lbl.getAccessibleContext().setAccessibleDescription( problem.severity().describeError(problem.getMessage())); } } } public void clearProblem() { showProblem(null); } } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/SwingComponentDecorationFactory.javalibsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/SwingComponentDecorationFactory0000644000175000017500000001573711654612134033177 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui.swing; import org.netbeans.validation.api.ui.*; import org.openide.util.Lookup; import javax.swing.JComponent; /** * Factory class for creating {@link ValidationUI} instances that can decorate * a Swing GUI-component when it has a Problem. * *

By default, one instance of a class implementing this interface * is used to create a * ValidationUI for all components handled by the simplevalidation * framework. This instance can be replaced with a custom one, as * described below. *

* For custom decoration, simply pass a different * decorator factory in ValidationGroup.add() (and if necessary, proxy the * default decorator factory for all but some specific kind of component). * * A rudimentary example of writing a component decorator: The code and * description below show how to replace the default * SwingComponentDecorationFactory with one that will create {@code ValidationUI} * instances that draws a thick colored border around the component * when there is an error. *

*

{@code
 * package com.foo.myapp;
 * public class MySwingComponentDecorationFactory extends SwingComponentDecorationFactory {
 *      public ValidationUI decorationFor(final JComponent c) {
 *         return new ValidationUI() {
 *             private javax.swing.border.Border origBorder = c.getBorder();
 *             public void showProblem(Problem problem) {
 *                if( problem == null ) {
 *                    c.setBorder(origBorder);
 *                } else {
 *                    c.setBorder(javax.swing.BorderFactory.createLineBorder(problem.severity().color(), 3));
 *                }
 *             }
 *        };
 *     }
 *  };
 * }
* * Our MySwingComponentDecorationFactory is then registered so that * it can be found using JDK 6's ServiceLoader (or NetBeans' * Lookup): Create a file named org.netbeans.validation.api.ui.swing.SwingComponentDecorationFactory * in the folder META-INF/services in your source root (so that * it will be included in the JAR file). Add one line of text to this file - * the fully qualified name of your class, e.g. *
 * com.foo.myapp.MySwingComponentDecorationFactory
 * 
* * @author Tim Boudreau * @author Hugo Heden */ public abstract class SwingComponentDecorationFactory { private static SwingComponentDecorationFactory componentDecorator = new SimpleDefaultDecorator(); private static final SwingComponentDecorationFactory noOpDecorationFactory = new SwingComponentDecorationFactory() { @Override public ValidationUI decorationFor(JComponent c) { return ValidationUI.NO_OP; } }; /** * * Special decorator that does not decorate at all -- even if * there is a problem -- a "null" decorator. This is useful if no * component decorations are desired. For example application * wide: * *
{@code
     * SwingComponentDecorationFactory.set(SwingComponentDecorationFactory.getNoOpDecorationFactory());
     * }
* Or just for one specific group of components, here a SwingValidationGroup: *
{@code
     * SwingValidationGroup group = SwingValidationGroup.create(SwingComponentDecorationFactory.getNoOpDecorationFactory());
     * }
* * */ public static final SwingComponentDecorationFactory getNoOpDecorationFactory() { return noOpDecorationFactory; } /** * Factory method that creates a {@code ValidationUI} visually attached to * the Swing GUI-component when there is a {@code Problem}. When a * {@code Problem} occurs in a component, this {@code ValidationUI} needs to be * updated using {@link ValidationUI#showProblem} (this is * typically done from within a {@code ValidationListener}) and * will then apply some visual mark to the component. When the * problem disappears, {@code ValidationListener} will pass {@code * null} to {@code ValidationUI#showProblem}, * which makes sure that the visual cue is removed, so that the * components is restored to its original visual state. * * @param c The component * @return A ValidationUI, visually attached to the component. */ public abstract ValidationUI decorationFor(JComponent c); /** * * Get the current application wide component decorator */ public static final SwingComponentDecorationFactory getDefault() { SwingComponentDecorationFactory result = Lookup.getDefault().lookup(SwingComponentDecorationFactory.class); if (result == null) { result = componentDecorator; } return result; } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/AbstractValidationListener.java0000644000175000017500000001141011654612134033051 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui.swing; import javax.swing.JComponent; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.netbeans.validation.api.ui.ValidationListener; import org.netbeans.validation.api.ui.ValidationUI; /** * Base class for ValidationListeners. * * @author Tim Boudreau */ public abstract class AbstractValidationListener extends ValidationListener { private final Validator validator; /** * Create a new AbstractValidationListener for the single component * passed here as an argument. If the component is not expected to * live after the validator is detached, you can add this object as a * listener to the component in the constructor (but remember that * this means the component will reference this validator forever). * @param comp */ public AbstractValidationListener(Class type, CompType comp, ValidationUI ui, Validator validator) { super(type, ui, comp); this.validator = validator; } /** * Get the name of the component which should be passed to * validate. The default implementation delegates to * nameForComponent which will either return the * client-property based name or the result of getName() on * the component. * * @param comp The component * @return A localized name */ protected String findComponentName (CompType comp) { return SwingValidationGroup.nameForComponent(comp); } /** * Get the model object that will be passed to validate * @param comp The component * @return The model object */ protected abstract T getModelObject(CompType comp); /** * Called when validation runs. The default implementation does nothing; * some validators may want to change the visual appearance of the component * to indicate an error. * * @param component The component * @param validationResult The result of validation */ protected void onValidate(CompType component, Problem validationResult){} @Override protected final void performValidation(Problems ps) { CompType comp = getTarget(); if (!comp.isEnabled()) { return; } Problems problems = new Problems(); validator.validate(problems, SwingValidationGroup.nameForComponent(comp), getModelObject(comp)); //XXX generics quirk onValidate(getTarget(), problems.getLeadProblem()); } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/SimpleDefaultDecorator.java0000644000175000017500000007216411654612134032203 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui.swing; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.HierarchyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JToolTip; import javax.swing.SwingUtilities; import javax.swing.border.Border; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Point; import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.event.HierarchyListener; import java.awt.image.BufferedImage; import java.awt.image.FilteredImageSource; import java.awt.image.ImageFilter; import java.awt.image.RGBImageFilter; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.UIManager; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.Severity; import org.netbeans.validation.api.ui.ValidationUI; /** * Default decorator class provided by simplevalidation. * *

By default, one instance of this class is used to decorate all * components validated by simplevalidation in the application. This * instance can be replaced with a custom one, see {@link * SwingComponentDecorationFactory}. Either a completely different {@code * SwingComponentDecorationFactory} class or an instance of a class deriving * from {@code SimpleDefaultDecorator}, overriding one or more of * the protected methods. * *

{@code SimpleDefaultDecorator} adds an problem icon to the * decorated component when there is a problem in it. The icon is * added using the {@code JLayeredPane} mechanism in Swing, so that * ends up "over" the decorated component (it partly covers the * decorated component). {@code JLayeredPane} gives us the freedom to * place the icon outside of the bounding rectangle of the decorated * component. The exakt location of the icon can be customized by * deriving from this class and overriding the {@code * getDecorationLocation} method. * *

{@code SimpleDefaultDecorator} also provides with some toolTip * management: The toolTip owned by the decoration icon is updated * live if it happens to be visible when the problem changes (and the * tooltip disappears if the problem disappears). The content of the * tooltip is a JLabel, by default showing the {@code icon()} of the * {@link Severity} of the current problem together with the problem * message, in suitable colors. This can be overridden by deriving * classes. * *

A customization example would be the following, which makes the * icons a little bit bigger than the default, and the colors a little * bit stronger. * *

{@code
 *  SwingComponentDecorationFactory.set(new SimpleDefaultDecorator(){
 *   protected Color getComponentOverlayColor(Severity s, JComponent decoratedComponent){
 *       if(s == Severity.INFO) {
 *           return null; // Skip the gray background for INFO 
 *       }
 *       int alpha = 26; // Corresponds to 0.10f -- rather strong actually
 *       return new Color(s.color().getRed(), s.color().getGreen(), s.color().getBlue(), alpha);
 *   }
 *   
 *   protected Point getDecorationLocation(Severity s, JComponent decoratedComponent, Dimension decorationIconSize) {
 *       return new Point( decoratedComponent.getWidth() - (int)(0.6*decorationIconSize.width), -2);
 *   }
 *
 *   protected Image getDecorationImage(Severity severity, JComponent decoratedComponent) {
 *       return severity.image(); // bigger than the small severity.badge() -- a bit too big actually, will need to be scaled down 
 *   }
 *
 *   protected Double getDecorationImageScaling(Severity s, JComponent decoratedComponent) {
 *        if (s == Severity.FATAL) {
 *            // Scale down the FATAL image a bit more
 *            return 0.75;
 *        }
 *        return 0.85;
 *    }
 *
 *    protected Integer getDecorationOverlapTransparency(Severity s, JComponent decoratedComponent) {
 *        if (s == Severity.WARNING) {
 *            // Not much transparency for warning icon, which has a light color.
 *            return 0xAA;
 *        }
 *        return 0x77;
 *    }
 *});
 * }
* * @author Tim Boudreau * @author Hugo Heden */ final class SimpleDefaultDecorator extends SwingComponentDecorationFactory { private Icon fatalIconTransp = null; private Icon warningIconTransp = null; private Icon infoIconTransp = null; @Override public ValidationUI decorationFor(JComponent c) { return new ToolTippedIconLabel(c, this); } /** * A problem has occured in a component, and this method the a way * to specify what the tooltip owned by the decoration icon * should contain from now on (until another problem occurs in * this component) * *

If no toolTip is desired, this method should just return * false. * *

Otherwise, the toolTip will contain the JLabel passed to * this method. An example implementation would be the following. * *

{@code
     * ttLabel.setText(problem.getMessage());
     * return true;
     * }
* * or perhaps (adjusting the ttLabel configured by the super * class): * *
{@code
     * super.configureToolTipLabel(problem, decoratedComponent, ttLabel);
     * ttLabel.setIcon(null);
     * return true;
     * }
* * * @param problem The problem that has occured. * @param decoratedComponent The component in which the problem has occured. * @param ttLabel label that will be contained within the tooltip * @return false if no toolTip is to be shown at all, true otherwise */ protected boolean configureToolTipLabel(Problem problem, JComponent decoratedComponent, JLabel ttLabel){ // No good: color transparent, stuff "under" toolTip may leak through (the color chooser in ValidationDemo does so) // ttLabel.setBackground(this.getComponentOverlayColor(problem.severity(), decoratedComponent)); //TDB: Try for JDK default theme if available Color bg = UIManager.getColor("white"); //But may not be available on, e.g., GTK look and feel ttLabel.setBackground(bg == null ? Color.WHITE : bg); // The following works well, but creates garbage -- a new Border for every new Problem that occurs: // ttLabel.setBorder(new ColorizingBorder(decoratedComponent, this)); ttLabel.setOpaque(true); ttLabel.setIcon(problem.severity().icon()); ttLabel.setForeground(problem.severity().color()); Border b = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(problem.severity().color(), 1), BorderFactory.createMatteBorder(3, 3, 3, 3, bg)); ttLabel.setBorder(b); ttLabel.setText(problem.getMessage()); return true; } /** * A {@code Color} with which to paint over the decorated * component -- a color overlay. The whole bounding rectangle of * the component will be filled. It is recommended to make this * color transparent to a high degree, or else the content of the * decorated component will be hidden by the painted color. If * the returned Color is null, the component will not get any * color overlay. * * * @param s The {@code Severity} of the problem the component is to be decorated for. * @param decoratedComponent The component to be decorated * @return A {@code Color} to be painted over the bounding rectangle over the component, * or null if nothing is to be painted. */ protected Color getComponentOverlayColor(Severity s, JComponent decoratedComponent) { int alpha = 13; // Corresponds to alpha of 0.05f [(int)(0.05*255+0.5) == 13] return new Color(s.color().getRed(), s.color().getGreen(), s.color().getBlue(), alpha); } /** * Specifies where the decorative icon is to be drawn, expressed * in the coordinate system of the decoratedComponent. The * decoration does not need to be drawn inside of the component * bounds -- for example negative numbers are ok. * *

For example, to have the top left corner of the icon * located at the top left corner of the decorated component: * {@code return new Point(0, 0); } * *

Or, to have the bottom right corner of the icon located at * the top right corner of the decoratedComponent: {@code return * new * Point(decoratedComponent.getWidth()-decorationIconSize.width, * -decorationIconSize.height); } * * * @param s The Severity for which the returned decoration location is intended * @param decorationIconSize Size of the decoration icon * @param decoratedComponent Component to be decorated * @return Location of the upper left corner of the icon, expressed in the decoratedComponent * coordinate system. */ protected Point getDecorationLocation(Severity s, JComponent decoratedComponent, Dimension decorationIconSize) { return new Point(decoratedComponent.getWidth() - decorationIconSize.width + 2, -2); } /** * Specifies an {@code Image} to be used for the decorative icon. Would * typically return {@code severity.image()} or {@code severity.badge()}, * but any custom image would of course be possible to use. The methods * {@code getDecorationImageScaling} and * {@code getDecorationOverlapTransparency} are used to process this image * somewhat before rendering, * @param severity The {@code Severity} for which this image is to be used. * @param decoratedComponent {@code Component} to be decorated * @return An {@code Image} with which to decorate the component, or null * if no Icon is to be shown for this severity and/or decoratedComponent * */ protected Image getDecorationImage(Severity severity, JComponent decoratedComponent) { return severity.badge(); } /** * Specifies a scaling to apply to the icon returned by {@code * getDecorationImage} before rendering it. * * @param s The severity for which this scaling will apply * @param decoratedComponent The component being decorated * @return A Double representing a positive number, or null if no scaling should be applied. */ protected Double getDecorationImageScaling(Severity s, JComponent decoratedComponent) { return null; } /** * Specifies a transparency to apply to the icon returned by * {@code getDecorationImage} before rendering it. This * transparency will only be applied to the part of the icon that * overlaps/covers the decorated component. * *

The alpha value defines the transparency of a color and can * be represented 0 - 255. An alpha value of 255 means that the * color is completely opaque and an alpha value of 0 means that * the color is completely transparent. * * @param s The severity for which this transparency will apply * @param decoratedComponent The component being decorated * @return An Integer representing a positive number between 0 and 255, or null if no transparency should be applied. */ protected Integer getDecorationOverlapTransparency(Severity s, JComponent decoratedComponent) { return null; } /** * Creates/gets a version of the Icon returned by {@code * getDecorationImage} (for this severity and decoratedComponent) * that has been scaled and made transparent according to what is * returned by {@code getDecorationImageScaling} and {@code * getDecorationOverlapTransparency} * *

Method is intended to be called internally from the {@code * SimpleDefaultDecorator} infrastructure. * * @param severity The {@code Severity} for which this icon is to be applied * @param decoratedComponent * @return */ Icon getDecorationIcon(Severity severity, final JComponent decoratedComponent) { // "singletons", only created once. if (severity.equals(Severity.FATAL) && fatalIconTransp != null) { return fatalIconTransp; } if (severity.equals(Severity.WARNING) && warningIconTransp != null) { return warningIconTransp; } if (severity.equals(Severity.INFO) && infoIconTransp != null) { return infoIconTransp; } Image image = getDecorationImage(severity, decoratedComponent); if (image == null) { return null; } ImageIcon icon = new ImageIcon(image); Double scaling = getDecorationImageScaling(severity, decoratedComponent); if (scaling != null) { int scaledWidth = (int) (scaling * icon.getIconWidth()); int scaledHeight = (int) (scaling * icon.getIconHeight()); BufferedImage scaledImg = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = scaledImg.createGraphics(); // TODO: Better rescaling if downscaling? See code example on // http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); // Slowest but with highest quality g2.drawImage(image, 0, 0, scaledWidth, scaledHeight, null); g2.dispose(); image = scaledImg; icon = new ImageIcon(image); } final Integer alpha = getDecorationOverlapTransparency(severity, decoratedComponent); if (alpha != null) { final Point translate = this.getDecorationLocation(null, decoratedComponent, new Dimension(icon.getIconWidth(), icon.getIconWidth())); final int dcW = decoratedComponent.getWidth(); final int dcH = decoratedComponent.getHeight(); ImageFilter filter = new RGBImageFilter() { @Override public int filterRGB(int x, int y, int rgb) { // If this x,y-coordinate covers the decorated component, make some transparency. // The trailing FFFFFF means to keep all *colors* as is. x += translate.x; y += translate.y; if (x > 0 && x < dcW && y > 0 && y < dcH) { return (alpha << 24 | 0xFFFFFF) & rgb; } return rgb; } }; image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), filter)); icon = new ImageIcon(image); } if (severity.equals(Severity.FATAL)) { return fatalIconTransp = icon; } if (severity.equals(Severity.WARNING)) { return warningIconTransp = icon; } assert severity.equals(Severity.INFO); return infoIconTransp = icon; } /** * A border to apply to the component which shows an error. A useful * way to create custom borders is to wrap the original border and * paint it, then paint over it. If the insets of the border returned * by this method are different than the insets of the original * border, then the UI layout will "jump".

Severity.color() and * Severity.image() are handy here. */ static final class ColorizingBorder implements Border, ValidationUI { private SimpleDefaultDecorator decorator; private final JComponent decoratedComponent; private final Border real; private Severity severity = null; public ColorizingBorder(JComponent c, SimpleDefaultDecorator decorator) { this.decorator = decorator; this.decoratedComponent = c; this.real = (c.getBorder() != null ? c.getBorder() : BorderFactory.createEmptyBorder()); c.setBorder(this); } @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { real.paintBorder(c, g, x, y, width, height); if (severity == null) { return; } Color niceTransparentColorForRectangle = decorator.getComponentOverlayColor(severity, decoratedComponent); if (niceTransparentColorForRectangle == null) { return; } g.setColor(niceTransparentColorForRectangle); g.fillRect(x, y, width, height); // Graphics2D gg = (Graphics2D) g; // Composite composite = gg.getComposite(); // AlphaComposite alpha = // AlphaComposite.getInstance(AlphaComposite.SRC_OVER, // decorator.decorationBackgroundAlpha(severity, decoratedComponent)); // try { // gg.setComposite(alpha); // gg.fillRect(x, y, width, height); // } finally { // gg.setComposite(composite); // } // Insets ins = getBorderInsets(c); // BufferedImage badge = severity.image(); // int by = (c.getHeight() / 2) - (badge.getHeight() / 2); // int w = Math.max (2, ins.left); // int bx = x + width - (badge.getHeight() + (w * 2)); // gg.drawRenderedImage(badge, AffineTransform.getTranslateInstance(bx, by)); } @Override public Insets getBorderInsets(Component c) { return real.getBorderInsets(c); } @Override public boolean isBorderOpaque() { return false; } @Override public void showProblem(Problem problem) { if ( problem == null) { severity = null; } else { severity = problem.severity(); //c.repaint(); } } public void clearProblem() { severity = null; } } /** * A JLabel with a decorative icon (that will update when a new {@code * Problem} appears) and that displays an informative tooltip. * @author heden */ static final class ToolTippedIconLabel extends JLabel implements ValidationUI { final private JToolTip tt = new JToolTip(); final private JLabel ttLabel = new JLabel(); final private JComponent decoratedComponent; final private ValidationUI colorizingBorder; private Problem currentProblem = null; private MouseEvent lastMouseEvent = null; private boolean hasAddedToPane = false; private SimpleDefaultDecorator decorator; ToolTippedIconLabel(final JComponent component, SimpleDefaultDecorator decorator) { this.decorator = decorator; this.decoratedComponent = component; this.colorizingBorder = new ColorizingBorder(component, decorator); this.setOpaque(false); // Using HierarchyListener instead of ComponentListener.componentShown() // and ComponentListener.componentHidden() to handle JTabbedPane, see // issue 32 decoratedComponent.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { if((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0){ tryDecorationIcon(); ToolTippedIconLabel.this.setVisible( decoratedComponent.isShowing() && currentProblem != null ); } } }); decoratedComponent.addComponentListener(new ComponentAdapter() { @Override public void componentMoved(ComponentEvent evt) { tryDecorationIcon(); } @Override public void componentResized(ComponentEvent evt) { tryDecorationIcon(); } }); this.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { lastMouseEvent = e; } @Override public void mouseExited(MouseEvent e) { lastMouseEvent = null; } }); this.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { lastMouseEvent = e; } }); ////////////////////////////////////////// // Fiddle with tooltip tt.setLayout(new BorderLayout()); tt.add(ttLabel); tt.setBorder(null); } @Override public JToolTip createToolTip() { assert SwingUtilities.isEventDispatchThread() : "Not on EventDispatchThread"; assert tt != null; return tt; } @Override public void setVisible(boolean visible) { super.setVisible(visible); if (visible && currentProblem != null) { colorizingBorder.showProblem(currentProblem); } else { colorizingBorder.clearProblem(); } } @Override public void showProblem(final Problem problem) { // JComponent has been newly validated. assert SwingUtilities.isEventDispatchThread() : "Not on EventDispatchThread"; if (problem != null && problem.equals(currentProblem)) { return; } colorizingBorder.showProblem(problem); currentProblem = problem; if (currentProblem == null) { if (this.isVisible()) { this.setVisible(false); } if (tt.isShowing()) { // Bring down tooltip if it isShowing final MouseEvent theEvent = lastMouseEvent; // lastEvent will be set to null in mouseExited, so hold a local reference here. this.dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_EXITED, System.currentTimeMillis(), 0, 0, 0, 0, false)); lastMouseEvent = theEvent; } return; } //////////////////////////////////////////////////// // Fiddle with tooltip. We do not do this within tryDecorationIcon(), // because it is only necessary to do this in updateProblem(). Also, we do // this *before* calling tryDecorationIcon(), because that method can // return false in cases when we still want to prepare the tooltip. problemUpdateTooltip(problem); if (!this.tryDecorationIcon()) { return; } this.setVisible(true); } private void problemUpdateTooltip(Problem problem) { if (decorator.getDecorationImage(problem.severity(), decoratedComponent) == null || !decorator.configureToolTipLabel(problem, decoratedComponent, ttLabel)) { // No tooltip if no decoration, and also no toolTip if configureToolTipLabel // returned false tt.setVisible(false); if(this.getToolTipText() != null) { this.setToolTipText(null); // "Unregister" from ToolTipManager.. } return; } tt.setVisible(true); if(this.getToolTipText() == null) { this.setToolTipText(""); // "Register" with ToolTipManager.. } tt.setPreferredSize(ttLabel.getPreferredSize()); if (lastMouseEvent != null) { // * If the tooltip is showing: "adapt" the *size* of the tooltip by bringing // it down and up again -- by emulating some mouse movements. // * If the tooltip is not showing but the mouse pointer seems to be // above icon, fire up tooltip. final MouseEvent theEvent = lastMouseEvent; // lastEvent will be set to null in mouseExited, so hold a local reference here. this.dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_EXITED, System.currentTimeMillis() - 100, theEvent.getModifiers(), theEvent.getX(), theEvent.getY(), 0, false)); assert lastMouseEvent == null; this.dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_ENTERED, System.currentTimeMillis() - 50, theEvent.getModifiers(), theEvent.getX(), theEvent.getY(), 0, false)); this.dispatchEvent(new MouseEvent(this, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), theEvent.getModifiers(), theEvent.getX(), theEvent.getY(), 0, false)); assert lastMouseEvent != null; } //////////////////////////////////////////////////// } /** * Set/Update the location of the icon so that it follows the * component at resize etc. * * @return true if there is an icon and the state of the UI is * such that it is ready to be set visible. * * @return false otherwise: If there is currently no problem, * or if the UI has not finished laying out * (so that the location of the decoration icon can not yet be * calculated), or if the decorator has been configured in a way * that there should be no Icon visible at all for the current * severity (only the ColorizingBorder is to be used) */ private boolean tryDecorationIcon() { assert SwingUtilities.isEventDispatchThread() : "Not on EventDispatchThread"; if (!decoratedComponent.isShowing()) { // This is before UI has finished being laid out. Can't do // anything now, wait until component listener gets notified. // (problemUpdate() has been called during initialization -- // the UI has errors from the start.) return false; } assert JLayeredPane.getLayeredPaneAbove(decoratedComponent) != null : "JLayeredPane.getLayeredPaneAbove(decoratedComponent) unexpectedly returned null"; // Actually this is not so unexpected if we're not in a JFrame, JDialog, JApplet or JInternalFrame. // See http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html . // Should we account for this possibility somehow? if (!hasAddedToPane) { JLayeredPane.getLayeredPaneAbove(decoratedComponent).add(ToolTippedIconLabel.this, new Integer(JLayeredPane.getLayer(decoratedComponent) + 10)); hasAddedToPane = true; } if (currentProblem == null) { // No point in calculating location now, we don't know our size yet. // (We have not encountered a problem yet so there's no icon. We're // here because the ComponentListener has been notified about a resize or a move.) return false; } Icon icon = decorator.getDecorationIcon(currentProblem.severity(), decoratedComponent); if (icon == null) { return false; } this.setIcon(icon); this.setSize(new Dimension(getIcon().getIconWidth(), getIcon().getIconHeight())); Point p = decoratedComponent.getLocationOnScreen(); SwingUtilities.convertPointFromScreen(p, this.getParent()); Point transl = decorator.getDecorationLocation(null, decoratedComponent, new Dimension(this.getIcon().getIconWidth(), this.getIcon().getIconHeight())); p.translate(transl.x, transl.y); this.setLocation(p); return true; } public void clearProblem() { showProblem(null); } } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/swing/MultilineLabelUI.java0000644000175000017500000004747311661314136030746 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui.swing; import java.awt.Color; import java.awt.Component; import java.awt.Component.BaselineResizeBehavior; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Point; import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.event.HierarchyBoundsListener; import java.awt.event.HierarchyEvent; import java.awt.event.HierarchyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JViewport; import javax.swing.Popup; import javax.swing.PopupFactory; import javax.swing.UIManager; import javax.swing.WindowConstants; import javax.swing.border.Border; import javax.swing.plaf.LabelUI; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.Severity; /** * Label UI which renders multiline text * * @author Tim Boudreau */ final class MultilineLabelUI extends LabelUI { private static Graphics2D createOffscreenGraphics(JComponent c) { if (c == null || c.getGraphicsConfiguration() == null) { return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(1, 1).createGraphics(); } return c.getGraphicsConfiguration().createCompatibleImage(1, 1).createGraphics(); } @Override public int getBaseline(JComponent c, int width, int height) { return c.getInsets().top + createOffscreenGraphics(null).getFontMetrics(c.getFont()).getMaxAscent(); } @Override public BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) { return BaselineResizeBehavior.CONSTANT_DESCENT; } @Override public void installUI(JComponent c) { super.installUI(c); ((JLabel) c).setIconTextGap(5); ((JLabel) c).setOpaque(false); } @Override public void update(Graphics g, JComponent c) { if (c.isOpaque()) { g.setColor (c.getBackground()); g.fillRect(0, 0, c.getWidth(), c.getHeight()); } paint (g, c); } @Override public Dimension getMaximumSize(JComponent c) { GraphicsConfiguration gc = c.getGraphicsConfiguration(); if (gc == null) { return super.getMaximumSize(c); } int maxw = gc.getDevice().getDisplayMode().getWidth(); String s = ((JLabel) c).getText(); Insets ins = c.getInsets(); Graphics2D g = createOffscreenGraphics(c); int txtWidth = ins.left + g.getFontMetrics(c.getFont()).stringWidth(s); int parentWidth = (c.getParent() == null ? maxw - (maxw / 4) : c.getParent().getWidth() - (c.getParent().getWidth() / 4)) - ins.right; Dimension result; if (txtWidth > parentWidth) { int ht = renderPlainString(c, s, g, ins.left, ins.top, parentWidth, c.getFont(), Color.BLACK, false).requiredHeight; result = new Dimension (parentWidth, ht); } else { result = new Dimension (txtWidth, g.getFontMetrics(c.getFont()).getHeight()); } Icon icon = ((JLabel) c).getIcon(); if (icon != null) { result.width += icon.getIconWidth(); result.height += icon.getIconHeight(); } result.width += ins.left + ins.right; result.height += ins.top + ins.bottom; return result; } @Override public Dimension getMinimumSize(JComponent c) { JLabel lbl = (JLabel) c; char[] dummy = new char[80]; Arrays.fill(dummy, 'X'); Graphics2D g = createOffscreenGraphics(c); int testWidth = g.getFontMetrics(c.getFont()).stringWidth(new String(dummy)); GraphicsConfiguration gc = c.getGraphicsConfiguration(); if (gc == null) { return super.getMinimumSize(c); } int maxw = gc.getDevice().getDisplayMode().getWidth(); Insets ins = c.getInsets(); int parentWidth = c.getWidth(); if (parentWidth == 0 && c.getParent() != null) { Component parent = c.getParent(); while (parentWidth == 0 && parent != null) { parentWidth = parent.getWidth(); if (parent instanceof JScrollPane) { JScrollPane pane = (JScrollPane) parent; JViewport port = pane.getViewport(); parentWidth = port.getWidth(); Insets paneInsets = pane.getInsets(); Insets portInsets = port.getInsets(); parentWidth -= paneInsets.left + paneInsets.right + portInsets.left + portInsets.right; } parent = parent.getParent(); } } if (parentWidth == 0) { parentWidth = maxw + (maxw / 4); } parentWidth -= ins.left + ins.right; boolean needWrap = parentWidth < testWidth; int ht = Math.max(16, g.getFontMetrics(c.getFont()).getHeight()); if (!needWrap) { //Always provide for 2 lines ht *= 2; } int w = g.getFontMetrics(c.getFont()).stringWidth(lbl.getText()); Dimension result = new Dimension (ins.left + ins.right + w, ins.bottom + ins.top + ht); return result; } private static final int MIN_CHARS = 100; @Override public Dimension getPreferredSize(JComponent c) { JLabel lbl = (JLabel) c; String s = lbl.getText(); boolean popup = c instanceof MultilineLabel && ((MultilineLabel) c).isPopup(); if (!popup) { if (s == null || s.length() < MIN_CHARS) { char[] dummy = new char[MIN_CHARS]; Arrays.fill(dummy, 'X'); s = new String(dummy); } } int maxw = c.getGraphicsConfiguration() == null ? Toolkit.getDefaultToolkit().getScreenSize().width : c.getGraphicsConfiguration().getDevice().getDisplayMode().getWidth(); Insets ins = c.getInsets(); int parentWidth = c.getWidth(); if (parentWidth == 0 && c.getParent() != null) { Component parent = c.getParent(); while (parentWidth == 0 && parent != null) { parentWidth = parent.getWidth(); parent = parent.getParent(); } } if (parentWidth <= 0) { parentWidth = maxw + (maxw / 4); } parentWidth -= ins.left + ins.right; return getPreferredSize(lbl, parentWidth).dim; } static Metrics getPreferredSize (JLabel lbl, int parentWidth) { Icon icon = lbl.getIcon(); if (icon != null) { parentWidth -= icon.getIconWidth(); } Insets ins = lbl.getInsets(); int iconW = icon == null ? 0 : icon.getIconWidth() + lbl.getIconTextGap(); Graphics2D g = createOffscreenGraphics(lbl); Metrics metrics = renderPlainString(lbl, lbl.getText(), g, ins.left, ins.top, parentWidth, lbl.getFont(), Color.BLACK, false, iconW); int ht = metrics.requiredHeight; Dimension result = new Dimension(); if (icon != null) { result.height = Math.max (metrics.lineheight * metrics.linecount, icon.getIconHeight()); } else { result.height = metrics.lineheight * metrics.linecount; } result.width = metrics.widestLine; result.width += ins.left + ins.right; result.height += ins.top + ins.bottom; metrics.dim = result; return metrics; } @Override public void paint(Graphics g, JComponent c) { Insets ins = c.getInsets(); Graphics2D gg = (Graphics2D) g; JLabel lbl = (JLabel) c; Icon icon = lbl.getIcon(); int gap = lbl.getIconTextGap(); int startX = ins.left + gap; int startY = ins.top; if (icon != null) { icon.paintIcon(c, g, ins.top, ins.left); startX = icon.getIconWidth() + gap; boolean popup = c instanceof MultilineLabel && ((MultilineLabel) c).isPopup(); int yHeight = popup ? g.getFontMetrics(c.getFont()).getHeight() : g.getFontMetrics(c.getFont()).getMaxAscent(); startY += (icon.getIconHeight() / 2) - (yHeight / 2); } String txt = ((JLabel) c).getText(); if (txt != null) { renderPlainString(c, txt, gg, ins.left, startY, c.getWidth() - (ins.left + ins.right), c.getFont(), c.getForeground(), true, startX); } } private static Metrics renderPlainString (JComponent c, String s, Graphics2D g, int x, int y, int w, Font f, Color foreground, boolean paint) { return renderPlainString(c, s, g, x, y, w, f, foreground, paint, 0); } private static Metrics renderPlainString (JComponent comp, String s, Graphics2D g, int x, int y, int w, Font f, Color foreground, boolean paint, int startX) { if (g == null) { g = createOffscreenGraphics(comp); } if (f == null) { f = UIManager.getFont("controlFont"); if (f == null) { int fs = 11; Object cfs = UIManager.get("customFontSize"); //NOI18N if (cfs instanceof Integer) { fs = ((Integer) cfs).intValue(); } f = new Font("Dialog", Font.PLAIN, fs); //NOI18N } } if (paint) { g.setRenderingHints(getHints()); g.setFont(f); g.setColor(foreground); } FontMetrics fm = g.getFontMetrics(f); int baseline = y + fm.getMaxAscent(); int ht = fm.getHeight(); Metrics result = new Metrics(ht); int dx = x + startX; result.lineLength(dx); String[] words = s.split(" "); int spaceWidth = fm.stringWidth(" "); wordloop: for (int i=0; i < words.length; i++) { String word = words[i]; int wordWidth = fm.stringWidth(word); boolean wrap = dx + wordWidth > w && i > 0; boolean brutalWrap = wordWidth > w; if (brutalWrap) { char[] chars = word.toCharArray(); for (int j = 0; j < chars.length; j++) { char c = chars[j]; int cwidth = fm.charWidth(c); if (dx + cwidth > w) { result.lineLength(dx); dx = x; baseline += ht; result.wrap(); } if (paint) { g.drawChars(chars, j, 1, dx, baseline); } dx += cwidth; result.lineLength(dx); if (j == chars.length - 1) { dx += spaceWidth; result.lineLength(dx); continue wordloop; } } } if (wrap) { result.lineLength(dx); result.wrap(); dx = x; baseline += ht; } if (paint) { g.drawString(word, dx, baseline); } dx += spaceWidth + wordWidth; result.lineLength(dx); } // result.finished(baseline + fm.getMaxDescent() + y); result.finished(baseline + y); return result; } private static final boolean antialias = Boolean.getBoolean("nb.cellrenderer.antialiasing") // NOI18N ||Boolean.getBoolean("swing.aatext") // NOI18N ||(isGTK() && gtkShouldAntialias()) // NOI18N || isAqua(); static Map hintsMap; @SuppressWarnings("unchecked") static final Map getHints() { //XXX We REALLY need to put this in a graphics utils lib if (hintsMap == null) { //Thanks to Phil Race for making this possible hintsMap = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N if (hintsMap == null) { hintsMap = new HashMap(); if (antialias) { hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } } } Map ret = hintsMap; assert ret != null; // does this method need to be synchronized? return ret; } static boolean isAqua () { return "Aqua".equals(UIManager.getLookAndFeel().getID()); } static boolean isGTK () { return "GTK".equals(UIManager.getLookAndFeel().getID()); } static boolean isNimbus () { return "Nimbus".equals(UIManager.getLookAndFeel().getID()); } private static Boolean gtkAA; static final boolean gtkShouldAntialias() { if (gtkAA == null) { Object o = Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/Antialias"); //NOI18N gtkAA = new Integer(1).equals(o) ? Boolean.TRUE : Boolean.FALSE; } return gtkAA.booleanValue(); } static Popup showPopup(Problem problem, Component parent, int x, int y) { Severity severity = problem.severity(); Color bg = UIManager.getColor("white") == null ? Color.WHITE : UIManager.getColor("white"); Border b = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(severity.color(), 1), BorderFactory.createEmptyBorder(3, 3, 3, 3)); final MultilineLabel lbl = new MultilineLabel(true); lbl.createUI().showProblem(problem); lbl.setBorder(b); lbl.setForeground(severity.color()); lbl.setBackground(bg); Point screenLoc = parent.getLocationOnScreen(); int screenWidth = parent.getGraphicsConfiguration().getDevice().getDisplayMode().getWidth(); int screenX = screenLoc.x + x; int screenY = screenLoc.y + y; int availWidth = screenWidth - screenX; Popup popup = PopupFactory.getSharedInstance().getPopup(parent, lbl, screenX, screenY); Insets ins = b.getBorderInsets(lbl); Metrics mm = getPreferredSize(lbl, availWidth); System.err.println("METRICS:\n" + mm); Dimension d = mm.dim; d.width = mm.widestLine + ins.left + ins.right + severity.icon().getIconWidth() + lbl.getIconTextGap(); lbl.setPreferredSize(d); return new WrapPopup(parent, popup); } private static final class WrapPopup extends Popup implements HierarchyListener, HierarchyBoundsListener { private final Popup realPopup; private final Component target; WrapPopup(Component target, Popup realPopup) { this.realPopup = realPopup; this.target = target; } @Override public void hide() { realPopup.hide(); detach(); } @Override public void show() { attach(); realPopup.show(); } private void attach() { target.addHierarchyListener(this); target.addHierarchyBoundsListener(this); } private void detach() { target.removeHierarchyListener(this); target.removeHierarchyBoundsListener(this); } @Override public void ancestorMoved(HierarchyEvent e) { hide(); } @Override public void ancestorResized(HierarchyEvent e) { hide(); } @Override public void hierarchyChanged(HierarchyEvent e) { hide(); } } public static void main(String[] args) throws Exception { JFrame jf = new JFrame(); final JLabel lbl = new JLabel("Hello"); jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jf.setContentPane(lbl); final String err = "This is a big honkin long error message, in fact its so long it will probably have to be wrapped to multiple lines whether " + "we want it to or not - otherwise there will be much trouble."; lbl.addMouseListener(new MouseAdapter() { Popup popup; @Override public void mouseEntered(MouseEvent e) { if (popup != null) { popup.hide(); } popup = MultilineLabelUI.showPopup(new Problem(err, Severity.FATAL), lbl, e.getX(), e.getY()); popup.show(); } @Override public void mouseExited(MouseEvent e) { if (popup != null) popup.hide(); } @Override public void mouseMoved(MouseEvent e) { mouseEntered(e); } }); jf.pack(); jf.setVisible(true); } private static final class Metrics { int linecount = 1; int widestLine; int requiredHeight; final int lineheight; Dimension dim; Metrics(int lineheight) { this.lineheight = lineheight; } void wrap() { linecount++; } void finished(int bottom) { this.requiredHeight = bottom; } void lineLength(int pixels) { widestLine = Math.max(pixels, widestLine); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append ("Line Count: " + linecount); sb.append("\nWidest Line: " + widestLine); sb.append("\nRequired Height " + requiredHeight); sb.append("\nLine Height: " + lineheight); return sb.toString(); } } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/JListValidationListenerImpl.java0000644000175000017500000001174211654612134032036 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import javax.swing.event.ListSelectionEvent; import org.netbeans.validation.api.Validator; import org.netbeans.validation.api.ui.*; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.EventListener; import javax.swing.InputVerifier; import javax.swing.JComponent; import javax.swing.JList; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionListener; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.ui.swing.SwingValidationGroup; import org.netbeans.validation.api.ui.swing.SwingValidationGroup; /** * * @author Hugo Heden */ class JListValidationListenerImpl extends ValidationListener implements EventListener, ListSelectionListener, FocusListener { private Validator validator; private boolean hasFatalProblem = false; public JListValidationListenerImpl(JList component, ValidationStrategy strategy, ValidationUI validationUI, Validator validator ) { super(JList.class, validationUI, component); this.validator = validator; if (strategy == null) { throw new NullPointerException("strategy null"); } getTarget().addPropertyChangeListener("enabled", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { performValidation(); } }); switch (strategy) { case DEFAULT: case ON_CHANGE_OR_ACTION: component.addListSelectionListener(this); break; case ON_FOCUS_LOSS: component.addFocusListener(this); break; case INPUT_VERIFIER: component.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { performValidation(); return !hasFatalProblem; } }); break; default: throw new AssertionError(); } performValidation(); // Make sure any initial errors are discovered immediately. } @Override protected void performValidation(Problems ps){ JList component = getTarget(); if (!getTarget().isEnabled()) { return; } validator.validate(ps, SwingValidationGroup.nameForComponent(component), component.getSelectionModel()); hasFatalProblem = ps.hasFatal(); } @Override public void focusLost(FocusEvent e) { performValidation(); } public void valueChanged(ListSelectionEvent lse) { performValidation(); } @Override public void focusGained(FocusEvent e) { } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/ValidationGroupProvider.java0000644000175000017500000000530411654612134031265 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import org.netbeans.validation.api.ui.ValidationGroup; /** * Optional interface which can be implemented on a component to * indicate that it supplies validation. *

* Useful for composing together panels that have validation groups - * for example, if a panel implementing this interface is added to * a ValidationPanel, then its SwingValidationGroup will tranparently * be merged into that of the ValidationPanel. * * @author Tim Boudreau */ public interface ValidationGroupProvider { public ValidationGroup getValidationGroup(); } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/JComboBoxValidationListenerImpl.java0000644000175000017500000001152511654612134032632 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import javax.swing.ComboBoxModel; import org.netbeans.validation.api.Validator; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.InputVerifier; import javax.swing.JComponent; import java.util.EventListener; import javax.swing.JComboBox; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.ui.swing.SwingValidationGroup; /** * * @author Tim Boudreau */ class JComboBoxValidationListenerImpl extends ValidationListener implements EventListener, ItemListener, FocusListener { private Validator validator; private boolean hasFatalProblem = false; public JComboBoxValidationListenerImpl(JComboBox component, ValidationStrategy strategy, ValidationUI validationUI, Validator validator ) { super(JComboBox.class, validationUI, component); this.validator = validator; if (strategy == null) { throw new NullPointerException("strategy null"); } component.addPropertyChangeListener("enabled", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { performValidation(); } }); switch (strategy) { case DEFAULT: case ON_CHANGE_OR_ACTION: component.addItemListener(this); break; case ON_FOCUS_LOSS: component.addFocusListener(this); break; case INPUT_VERIFIER: component.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { performValidation(); return !hasFatalProblem; } }); break; default: throw new AssertionError(); } performValidation(); // Make sure any initial errors are discovered immediately. } @Override protected void performValidation(Problems ps){ JComboBox component = getTarget(); if (!component.isEnabled()) { return; } validator.validate(ps, SwingValidationGroup.nameForComponent(component), component.getModel()); hasFatalProblem = ps.hasFatal(); } @Override public void focusLost(FocusEvent e) { performValidation(); } @Override public void itemStateChanged(ItemEvent e) { performValidation(); } @Override public void focusGained(FocusEvent e) { } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/MulticastValidationUI.java0000644000175000017500000001014011654612134030653 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import org.netbeans.validation.api.Problem; /** * * @author Tim Boudreau */ final class MulticastValidationUI implements ValidationUI { private final Set real; MulticastValidationUI(ValidationUI... real) { this.real = new HashSet(Arrays.asList(real)); assert validUIs(real); } public void add(ValidationUI ui) { if (ui == null) { throw new NullPointerException(); } assert !contains(ui) : "Already a member: " + ui; real.add (ui); } public void remove(ValidationUI ui) { if (ui == null) { throw new NullPointerException(); } assert contains(ui) : "Not a member: " + ui; real.remove(ui); } public boolean contains(ValidationUI check) { boolean result = real.contains(check); if (!result) { for (ValidationUI ui : real) { if (ui instanceof MulticastValidationUI) { if (result = ((MulticastValidationUI) ui).contains(check)) { break; } } } } return result; } @Override public void showProblem(Problem problem) { assert real != null; for (ValidationUI ui : real) { ui.showProblem(problem); } } public boolean validUIs(ValidationUI[] uis) { for (int i = 0; i < uis.length; i++) { ValidationUI ui = uis[i]; if (ui == null) { throw new NullPointerException("Element " + i + " of ui " + "array is null"); } } return true; } public void clearProblem() { assert real != null; for (ValidationUI ui : real) { ui.clearProblem(); } } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/ValidationItem.java0000644000175000017500000002477311654612134027367 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import org.netbeans.validation.api.Problem; /** * Common superclass for {@code ValidationGroup} and {@code ValidationListener}, providing a common API * for forcing revalidation of the managed UI component or components, see {@link #performValidation()}, * and for temporarily suspending validation, see * {@link #runWithValidationSuspended(java.lang.Runnable)} * *

{@code ValidationItem}s can be added to a ValidationGroup using * {@link ValidationGroup#addItem(org.netbeans.validation.api.ui.ValidationItem, boolean) }. * * @author Tim Boudreau * @author Hugo Heden */ public abstract class ValidationItem { private Problem currentLeadProblem = null; private Problem currentProblemInUI = null; private ValidationGroup parentValidationGroup = null; private int suspendCount = 0; private boolean uiEnabled = true; private final MulticastValidationUI multicastValidationUI = new MulticastValidationUI(); ValidationItem(ValidationUI... uis) { // Package visibility to make class "final" outside of package for (ValidationUI ui : uis) { // Dont call addUI. This is superclass constructor, the subclass is not finished with creation yet, so this is too early. // Instead, subclass is responsible for updating UI:s multicastValidationUI.add(ui); } } void addUI(ValidationUI ui) { if (!containsUI(ui)) { multicastValidationUI.add(ui); if(uiEnabled){ if (currentProblemInUI == null) { ui.clearProblem(); } else { ui.showProblem(currentProblemInUI); } } } } void removeUI(ValidationUI ui) { if (containsUI(ui)) { this.multicastValidationUI.remove(ui); ui.clearProblem(); } } final void showIfUIEnabled( Problem problem ){ if( uiEnabled && ( (currentProblemInUI != null && !currentProblemInUI.equals(problem) ) || ( currentProblemInUI == null && problem != null ) ) ){ currentProblemInUI = problem; if ( problem == null) { multicastValidationUI.clearProblem(); } else { multicastValidationUI.showProblem( problem ); } } } private boolean containsUI(ValidationUI ui) { return this.multicastValidationUI.contains(ui); } /** *

A request (to the simple-validation infrastructure) for revalidation of * the component(s) managed by this ValidationListener/ValidationGroup, updating * the {@code ValidationUI} as necessary. * *

This method can be called by client code (i.e non-subclasses), to manually * request revalidation -- a "refresh". This can be useful if custom ValidationListeners are used that rely * not only on the state of the managed component, but also on outside state * that the listener does not know about * *

More typically, this method is called by {@code ValidationListener} subclasses * to let the simple-validation infrastructure know * that the user has interacted with the UI-component in a way that makes revalidation * needed. * *

This will initiate the validation logic (unless the validation is suspended, see * {@link ValidationItem#runWithValidationSuspended(java.lang.Runnable)}: * A call to {@link ValidationListener#performValidation(org.netbeans.validation.api.Problems)} * will occur. * *

If this results in a {@link Problem}, the {@link ValidationUI} * managed by this {@code ValidationListener} (such as an error icon * decorating the UI-component) will be activated, indicating the {@code Problem} * to the user. * *

If this ValidationListener has been added to a {@link ValidationGroup}, * the latter will update its {@code ValidationUI}:s as well (unless there happens * to be a more severe {@code Problem} somewhere else within that {@code ValidationGroup}) * * @return The lead problem of the ValidationItem, null if there is no Problem * * */ public final Problem performValidation() { if (isSuspended()) { return this.getCurrentLeadProblem(); } subtreeRevalidation(); if( getParentValidationGroup() != null ) { getParentValidationGroup().validationTriggered(this); } else { showIfUIEnabled(getCurrentLeadProblem()); } return getCurrentLeadProblem(); } // Package private method. Intented to be a helper method for implementing performValidation(). // If the latter is called on a ValidationGroup, the whole subtree should revalidate // recursively down to the leafs, with help from this method. // So, if this is a ValidationGroup, this // method should pass the call recursively down the tree of ValidationItem:s to // the leafs (typically ValidationListener:s). A ValidationListener should // perform revalidation, store the new lead problem (if any) and then // just return -- i.e they should not call validationTriggered or update // the UI. The calling parent ValidationGroup should then perform GroupValidation // (if any) and then update the UI of each child as appropriate, and then // return -- i.e it should not update its own UI. abstract void subtreeRevalidation(); /** * The current problem leading problem (if any) with this ValidationItem * @return The current problem * @return null if there currently is no problem. */ final Problem getCurrentLeadProblem() { return this.currentLeadProblem; } final void setCurrentLeadProblem(Problem problem){ this.currentLeadProblem = problem; } /** * Indicates whether this ValidationGroup is currently suspended. * @see #runWithValidationSuspended(java.lang.Runnable) * @return true if this ValidationGroup is currently suspended, false otherwise */ final boolean isSuspended() { return suspendCount > 0 || (getParentValidationGroup() != null && ((ValidationItem)getParentValidationGroup()).isSuspended()); } /** * Disable validation and invoke a runnable. This method is useful * in UIs where a change in one component can trigger changes in * another component, and you do not want validation to be triggered * because a component was programmatically updated. *

* For example, say you have a dialog that lets you create a new * Servlet source file. As the user types the servlet name, web.xml * entries are updated to match, and these are also in fields in the same * dialog. Since the updated web.xml entries are being programmatically * (and presumably correctly) generated, those changes should not * trigger a useless validation run. Wrap such generation code in * a Runnable and pass it to this method when making programmatic * changes to the contents of the UI. *

* The runnable is run synchronously, but no changes made to components * while the runnable is running will trigger validation. *

* When the last runnable exits, * validateAll(null) will be called to run validation * against the entire newly updated UI. *

* This method is reentrant - a call to updateComponents can trigger * another call to updateComponents without triggering multiple * calls to validateAll() on each Runnable's exit. * * @param run A runnable which makes changes to the contents of one * or more components in the UI which should not trigger validation */ public final void runWithValidationSuspended(Runnable run) { suspendCount++; try { run.run(); } finally { suspendCount--; if (!isSuspended()) { performValidation(); } } } /** * @return null if this ValidationItem is not added to a ValidationGroup */ final ValidationGroup getParentValidationGroup() { return parentValidationGroup; } /** * @param parentGroup null allowed */ final void setParentValidationGroup(ValidationGroup parentGroup, boolean setUIEnabled) { this.parentValidationGroup = parentGroup; this.uiEnabled = setUIEnabled; } } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/GroupValidator.java0000644000175000017500000002562211654612134027412 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import org.netbeans.validation.api.Problems; /** * Encapsulates validation of the combination of several UI * components within a {@link ValidationGroup}. * *

UI-components whose validity depends not only on their own state * but on the state of each other as well, can be said to have * validity interdependencies. In such cases not only the state of * each component needs to be validated as a singular, but the * combination of components needs to be validated as well. * *

The following items outline what needs to be done to achieve this. * *

    * *
  • The UI components with interdependencies need to be added to * the same {@code ValidationGroup} * *
  • This {@code ValidationGroup} needs to be prepared at creation time * with an instance of {@code GroupValidator}. * *
  • In this {@code GroupValidator}, the method {@link * #performGroupValidation(org.netbeans.validation.api.Problems) } * needs to be overridden to perform the custom interdependency * validation. * *
* *

When a UI component is changed (either programmatically or by * having been interacted with by the user) the following will happen: * *

    * *
  • As usual, the UI component will be revalidated using its * connected validators. * *
  • Now, only if there is no fatal {@link org.netbeans.validation.api.Problem} * in any of the UI components within the {@code ValidationGroup}, the validation in * the {@code GroupValidator} will be invoked as well. * *
  • If it turns out that the latter yields a {@code Problem} more * severe (i.e strictly worse) than any other {@code Problem} in the * {@code ValidationGroup}, then this {@code Problem} will become the * lead problem in the group. * *
  • The lead problem of the group (whichever it may be) is shown * as usual in the {@link ValidationUI}(s) of the {@code ValidationGroup}. * *
  • If the lead {@code Problem} happens to be the one caused by the * {@code GroupValidator}, then the default behavior is that this * {@code Problem} will cause all UI components within the * ValidationGroup to be decorated. This behavior can however be * disabled by passing {@code false} to the constructor {@link * #GroupValidator(boolean) } * *
* *

The following code example illustrates how this class can be * used. *

        // Given three text fields, aField, bField and cField, this class validates
        // that the sum of the numbers in them equals a number given in a combo box.
        class SumValidation extends GroupValidator {
            SumValidation() {
                // The boolean specifies whether a Problem generated by the
                // GroupValidator should cause the UI-components in the
                // ValidationGroup to be decorated or not
                super(true);
            }
            @Override
            protected void performGroupValidation(Problems problems) {
                try {
                    int desiredSum = Integer.parseInt(sumComboBox.getModel().getSelectedItem().toString());
                    int val1 = Integer.parseInt(aField.getText());
                    int val2 = Integer.parseInt(bField.getText());
                    int val3 = Integer.parseInt(cField.getText());
                    int sum = val1 + val2 + val3;
                    if (sum != desiredSum) {
                        problems.add( new Problem (val1 + "+" + val2 + "+" + val3 +
                                " equals " + sum + ", not " + desiredSum, Severity.FATAL));
                    } else if (val1 == desiredSum || val2 == desiredSum || val3 == desiredSum) {
                        problems.add( new Problem ("Hey...that's cheating!",
                                Severity.WARNING) );
                    }
                } catch (NumberFormatException e) {
                    //do nothing, the other validators would have taken care of the bad entry
                }
            }
        }

        // The GroupValidator can be used as follows:

        // Create ValidationGroup that will contain UI component with validity
        // interdependencies. Pass a GroupValidator -- SumValidation -- to the
        // ValidationGroup creator.
        SwingValidationGroup bunch = SwingValidationGroup.create(new SumValidation());

        // Create a Validator that can be reused for individual validation of
        // the three text fields
        Validator<String> fieldValidator =
                StringValidators.trimString(StringValidators.REQUIRE_NON_EMPTY_STRING,
                StringValidators.NO_WHITESPACE,
                StringValidators.REQUIRE_VALID_NUMBER,
                StringValidators.REQUIRE_VALID_INTEGER,
                StringValidators.REQUIRE_NON_NEGATIVE_NUMBER);

        bunch.add(aField, fieldValidator);
        bunch.add(bField, fieldValidator);
        bunch.add(cField, fieldValidator);

        // Add the combo box as well so that the additional group
        // validation is triggered whenever the combo box is interacted with. Note
        // that there are no validators added for the combo box alone. Also, ValidationUI.NoOp.get()
        // is passed, so that the combo box will not be decorated when there's a problem.
        bunch.add(SwingValidationListenerFactory.createJComboBoxValidationListener(sumComboBox, ValidationUI.NoOp.get()));
 *
 *
 * 
* @author Hugo Heden */ public abstract class GroupValidator { private final boolean shallShowProblemInChildrenUIs; private boolean isCurrentlyLeadingProblem = false; /** * Default constructor, calls {@code this(true)} */ protected GroupValidator() { this( true ); } /** * @param shallShowProblemInChildrenUIs specifies whether a * Problem generated by the {@code GroupValidator} (if it happens * to be the lead {@code Problem}) should cause the UI-components * in the {@code ValidationGroup} to be decorated (showing the * {@code Problem}) or not */ protected GroupValidator(boolean shallShowProblemInChildrenUIs ) { this.shallShowProblemInChildrenUIs = shallShowProblemInChildrenUIs; } final boolean isCurrentlyLeadingProblem() { return isCurrentlyLeadingProblem; } final void setIsCurrentlyLeadingProblem(boolean isCurrentlyLeadingProblem) { this.isCurrentlyLeadingProblem = isCurrentlyLeadingProblem; } final boolean shallShowProblemInChildrenUIs() { return shallShowProblemInChildrenUIs; } /** * Validate the state of the combination of the UI components * within the ValidationGroup. If invalid * this method shall add one or more {@code Problem}s to * the passed list. * * @param problems A list of problems. */ protected abstract void performGroupValidation(Problems problems); } libsimple-validation-java-.orig/org/netbeans/validation/api/ui/ValidationGroup.java0000644000175000017500000005101111654612134027546 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import java.util.LinkedList; import java.util.List; import org.netbeans.validation.api.Problem; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.netbeans.validation.api.ValidatorUtils; import org.netbeans.validation.api.builtin.stringvalidation.StringValidators; /** * A {@code ValidationGroup} logically groups a set of GUI-components, * such as text fields, lists, tables, comboboxes etc, each validated * by one or more validators (such as the built-in ones provided by * the framework in {@link StringValidators}). * *

Note: If you are validating Swing components, you will probably * want to use {@link * org.netbeans.validation.api.ui.swing.SwingValidationGroup} which contains * convenience add methods for common Swing components, and performs * Swing-specific threading correctness checks. * *

A {@code ValidationGroup} is typically associated with a panel * containing GUI-components (such as a {@code JPanel} or {@code * JDialog} in Swing). The idea with logically grouping GUI-components * (as opposed to treating them completely separately) is to to * indicate the most severe {@link Problem} in the panel (graded * by {@link org.netbeans.validation.api.Severity}) -- the "lead * problem" of the group -- to the user in various ways. Even if the * user happens to currently be interacting with another GUI component * that has no error in it, the lead problem of the panel/group will * be visible to the user. * *

If there is more than one Problem that is the most severe (they * have equal Severity) in the group of UI-components, then the one in * the UI-component that has been most recently interacted with will * be the lead problem. * *

The way for the {@code ValidationGroup} to show the lead * problem in the UI is by using one or more instances of the {@link * ValidationUI} interface. {@code ValidationUI} instances can be * added by client code using the {@link * #addUI(org.netbeans.validation.api.ui.ValidationUI) } method. * One {@code ValidationUI} instance could indicate the lead * problem for example by showing a message in some status * bar. Another one could disable some OK-button (which could be * suitable if the lead problems has {@code Severity.FATAL}) etc. All * these {@code ValidationUI}s are updated whenever the lead problem * of the group changes. * * If the ValidationGroup contains UI-components whose validity * depends not only on their own state but on the state of each other * as well, they can be said to have validity interdependencies. In * such cases not only the state of each component needs to be * validated, but the combination of components as well. This is done * by passing a {@code GroupValidator} object when creating the * ValidationGroup. For more on that, see {@link GroupValidator}. * *

Now, to add a GUI-component to the {@code ValidationGroup}, * client code would wrap it (together with the desired Validators) * into a {@link ValidationListener} that is then added to the {@code * ValidationGroup} using the {@link * #addItem(org.netbeans.validation.api.ui.ValidationItem, boolean) } method. Note * that this is the generic but perhaps inconvenient case -- the * subclass {@link * org.netbeans.validation.api.ui.swing.SwingValidationGroup} contains * a number of {@code add}-methods for convenience, to simplify this * procedure for common Swing components. * *

Each {@code ValidationListener} listens to suitable GUI-events * (often key-press events or mouse-events). When such an event occurs * the {@code ValidationListener} will perform revalidation and then * notify its parent {@code ValidationGroup} so that it can reevaluate * its lead problem. * *

Not only ValidationListener:s can be added to ValidationGroup, * but so can other ValdiationGroups as well. (This is the reason why * ValidationListener and ValidationGroup share a common superclass, * {@link ValidationItem}, and that this is the type of the argument * of {@code ValidationGroup#add}.) This is useful when there are two * separate panels with their own {@code ValidationGroup}s, and one of * the panels is (perhaps temporarily) to be embedded into the other. * Whenever there is a change in one of the added child * ValidationGroup's components, it will drive the UI(s) belonging to * the parent group, as well as (optionally) its own. (The latter can * be disabled by passing {@code true} as second parameter to {@link * #addItem(org.netbeans.validation.api.ui.ValidationItem, boolean) } * instead of {@code false} * * *

The core functionality of the {@code ValidationGroup} with * added {@code ValidationItem}:s works as follows: * *

    * *
  • When an appropriate change in a UI component occurs, a {@code * ValidationListener} will observe that and make sure the component * is validated (by invoking the {@code Validator}(s)) and then * decorate the UI component if there is a Problem in it. This is * unless the ValidationListener is suspended, in which case nothing * at all will happen, see {@link * ValidationItem#runWithValidationSuspended }
  • * *
  • The ValidationListener will notify its parent ValidationGroup * about the validation. If there was a fatal {@code Problem} in that * UI component, then this will also become the lead problem of the * whole group because it is the most recent of the most severe * problems in the groups.
  • * *
  • If not, the most recent of the most severe of the problems of * the UI components in the ValidationGroup will be the lead * problem. (This does not involve actual revalidation of these * components, the problem that occured when the component last * triggered validation is assumed to still be there).
  • * *
  • When the lead problem of the ValidationGroup has been * determined, the showProblem method of the * ValidationUI:s of the group will be called. This may * for example involve disabling an OK-button if the lead problem is * fatal (and enabling it if not) and showing an error message. This * is unless this ValidationGroup has been added "with disabled UI" to * another ValidationGroup, in which case the Problem will not be * shown in the ValidationUI.
  • * *
  • If this ValidationGroup has been added to another one then the * parent is notified. The parent ValidationGroup will then check if * its lead problem needs to be updated, update its ValidationUI:s * accordingly (unless it has a disabled UI) and notify its parent if * there is one -- and so on. * *
* * @author Tim Boudreau */ public class ValidationGroup extends ValidationItem { private final GroupValidator additionalGroupValidation; private final List validationItems = new LinkedList(); private boolean isAncestorToSelf = false; protected ValidationGroup(GroupValidator additionalGroupValidation, ValidationUI... ui) { super(ui); this.additionalGroupValidation = additionalGroupValidation; if (ui == null) { throw new NullPointerException ("UI null"); } } protected ValidationGroup(ValidationUI... ui) { this(null, ui); } /** * Create a new validation group * @param ui Zero or more initial UIs which will display errors * @return A validation group */ public static ValidationGroup create (ValidationUI... ui) { return new ValidationGroup(ui); } /** * Create a new validation group * @param additionalGroupValidation * @param ui Zero or more initial UIs which will display errors * @return A validation group */ public static ValidationGroup create(GroupValidator additionalGroupValidation, ValidationUI... ui) { return new ValidationGroup(additionalGroupValidation, ui); } /** * * @param * @param * @param comp * @param validators */ public final void add (ComponentType comp, Validator... validators) { this.addItem (ValidationListenerFactory.createValidationListener(comp, ValidationStrategy.DEFAULT, decorationFor(comp), ValidatorUtils.merge(validators)), false); } /** * * @param * @param * @param comp * @param validator */ public final void add (ComponentType comp, Validator validator) { this.addItem (ValidationListenerFactory.createValidationListener(comp, ValidationStrategy.DEFAULT, decorationFor(comp), validator), false); } protected ValidationUI decorationFor(T component) { return ValidationUI.NO_OP; } /** * Add a UI which should be called on validation of this group or * any components within it. * *

This is useful in the case that you have multiple * components which are provided separately and each want to * respond to validation problems (for example, one UI controlling * a dialog's OK button, another controlling display of error * text). * * @param ui An implementation of ValidationUI */ @Override public final void addUI(ValidationUI ui) { super.addUI(ui); } /** * Remove a delegate UI which is being controlled by this * validation item. Will clear the UI from any Problem as well. * * @param ui The UI */ @Override public final void removeUI(ValidationUI ui) { super.removeUI(ui); } /** * Adds a ValidationItem (i.e a ValidationListener or another * ValidationGroup) to this ValidationGroup. * *

The purpose of being able to disable a ValidationUI is so * you can compose together reusable panels which have their own * ValidationUI, but only let the outer ValidationUI show the lead * problem when one is inside another. Typically, without the * ability to turn off the inner panel's ValidationUI, when * there's a problem in the inner panel the error message is going * to be shown twice -- once at the bottom of the dialog and one * in the middle of the screen inside the inner panel -- which would look bad. * *

Note that the subclass {@link * org.netbeans.validation.api.ui.swing.SwingValidationGroup} * contains a number of {@code add}-methods for convenience, to * simplify this procedure for common Swing components * @param validationItem item to add * @param disableUI indicates that the validation UI of the parent panel * should not be notified * */ public final void addItem(ValidationItem validationItem, boolean disableUI){ if( validationItem.getParentValidationGroup() != null ){ throw new IllegalArgumentException("Added item already has parent group"); //NOI18N } validationItem.setParentValidationGroup(this, !disableUI); // Add first in list to make this the most recent one, // as if the user would have interacted with it.. (not sure about this, // but shouldn't be a big deal..?) validationItems.add(0, validationItem); // A check to make sure a child validation group cannot have an // ancestor of itself added to itself - i.e. preemptively avoid endless loops: if( this.detectAncestryToSelf() ){ validationItems.remove(0); validationItem.setParentValidationGroup(null, true); throw new IllegalArgumentException("Ancestry to self"); //NOI18N } // This is like validationTriggered just happened for the added child. // This is probably reasonable, because when a child that has a problem is added to a group, // and this problem happens to be the worst problem in the group, the group UI should be updated. if (!isSuspended()) { /* Don't pass the child to update, because we do not want to update its UI (it has problably already done so itself)*/ update(false, null); if (getParentValidationGroup() != null) { getParentValidationGroup().validationTriggered(this); } else { showIfUIEnabled(this.getCurrentLeadProblem()); } } } /** * Intended to be used by {@link ValidationGroup#add(org.netbeans.validation.api.ui.ValidationItem) } * to detect self-ancestry (fail-fast-detection of infinite loop problems) * @return true if detected ancestry to self -- i.e bad news. * @return false if good news */ boolean detectAncestryToSelf() { if( isAncestorToSelf ) { return true; } isAncestorToSelf = true; boolean badNews = false; if(getParentValidationGroup() != null){ badNews = getParentValidationGroup().detectAncestryToSelf(); } isAncestorToSelf = false; return badNews; } /** * Removes a previously added ValidationItem (i.e a * ValidationListener or another ValidationGroup) to this * ValidationGroup. * *

If the ValidationItem to be removed has the current lead * problem of the ValidationGroup, the ValidationGroup will remove * that and evaluate a new lead problem * * @param validationItem item to remove */ public final void remove(ValidationItem validationItem) { if( validationItems.remove(validationItem) ) { validationItem.setParentValidationGroup(null, true); if( this.getCurrentLeadProblem() != null && this.getCurrentLeadProblem() == validationItem.getCurrentLeadProblem() ){ if( !isSuspended() ) { this.update( false, null ); if( getParentValidationGroup() != null ) { getParentValidationGroup().validationTriggered(this); } else { showIfUIEnabled(this.getCurrentLeadProblem()); } } } } } @Override final void subtreeRevalidation(){ if (isSuspended()) { return ; } update( true, null ); } // Intended to be called from child ValidationItem that has triggered validation. final void validationTriggered(final ValidationItem triggeringChild) { // Never "touch" the trigger (do not call performValidation on it). The trigger takes care of itself. assert triggeringChild != null; assert !isSuspended(); // child should have noticed. // Put trigger first in list, because it's the most recent trigger. // This way, if there are more than one problem with // equal severity, we ensure that the lead problem of this // ValidationGroup (see update()) is always the more recent one (rather than an arbitary // one) validationItems.remove(triggeringChild); validationItems.add(0, triggeringChild); update( false, triggeringChild ); if( getParentValidationGroup() != null ) { getParentValidationGroup().validationTriggered(this); } else { showIfUIEnabled(this.getCurrentLeadProblem()); } } private void update(final boolean childrenShallPerformValidation, final ValidationItem triggerThatHasAlreadyPerformedValidation) { assert !isSuspended(); assert ! ( childrenShallPerformValidation && triggerThatHasAlreadyPerformedValidation!=null ); // This would be unexpected final Problems ps = new Problems(); // Iterate from first to last, so that the most recent problems will be // added first to the Problems. Problems.getLeadProblem() will return: // (1) the most severe problem, // (2) the problem *added* first (the one triggered most recently) if (childrenShallPerformValidation) { for (ValidationItem vi : validationItems) { if (vi != triggerThatHasAlreadyPerformedValidation) { vi.subtreeRevalidation(); } ps.add(vi.getCurrentLeadProblem()); } } else { for (ValidationItem vi : validationItems) { final Problem p = vi.getCurrentLeadProblem(); ps.add(p); if( p != null && p.isFatal() ){ break; // Optimization: We already found a fatal problem, no need to keep looking. } } } Problem leadProblem = ps.getLeadProblem(); boolean haveUpdatedRelevantChildrenUI = false; if (additionalGroupValidation != null) { boolean theAdditionalProblemIsLeading = false; if (leadProblem == null || !leadProblem.isFatal()) { additionalGroupValidation.performGroupValidation(ps); final Problem nue = ps.getLeadProblem(); if (nue != null && !nue.equals(leadProblem)) { theAdditionalProblemIsLeading = true; leadProblem = nue; } } if (additionalGroupValidation.shallShowProblemInChildrenUIs()) { if (theAdditionalProblemIsLeading) { for (ValidationItem vi : validationItems) { vi.showIfUIEnabled(leadProblem); } haveUpdatedRelevantChildrenUI = true; } else if(additionalGroupValidation.isCurrentlyLeadingProblem()) { // The "additional" problem of this group has been showing // in the children UI:s (and it's time to overwrite it with // each childs own respective Problem) for (ValidationItem vi : validationItems) { vi.showIfUIEnabled(vi.getCurrentLeadProblem()); } haveUpdatedRelevantChildrenUI = true; } additionalGroupValidation.setIsCurrentlyLeadingProblem(theAdditionalProblemIsLeading); } } if ( !haveUpdatedRelevantChildrenUI ){ if( triggerThatHasAlreadyPerformedValidation != null ) { triggerThatHasAlreadyPerformedValidation.showIfUIEnabled(triggerThatHasAlreadyPerformedValidation.getCurrentLeadProblem()); } else if (childrenShallPerformValidation) { for (ValidationItem vi : validationItems) { vi.showIfUIEnabled(vi.getCurrentLeadProblem()); } } } super.setCurrentLeadProblem(leadProblem); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/ui/JTextComponentValidationListenerImpl.javalibsimple-validation-java-.orig/org/netbeans/validation/api/ui/JTextComponentValidationListenerImpl.0000644000175000017500000001271711654612134033073 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.ui; import org.netbeans.validation.api.ui.*; import java.awt.EventQueue; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.InputVerifier; import javax.swing.JComponent; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.Document; import javax.swing.text.JTextComponent; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.netbeans.validation.api.ui.swing.SwingValidationGroup; import org.netbeans.validation.api.ui.swing.SwingValidationGroup; /** * * @author Tim Boudreau */ class JTextComponentValidationListenerImpl extends ValidationListener implements DocumentListener, FocusListener, Runnable { private Validator validator; private boolean hasFatalProblem = false; public JTextComponentValidationListenerImpl(JTextComponent component, ValidationStrategy strategy, ValidationUI validationUI, Validator validator ) { super(JTextComponent.class, validationUI, component); this.validator = validator; if (strategy == null) { throw new NullPointerException("strategy null"); } component.addPropertyChangeListener("enabled", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { performValidation(); } }); switch (strategy) { case DEFAULT: case ON_CHANGE_OR_ACTION: component.getDocument().addDocumentListener(this); break; case INPUT_VERIFIER: component.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { performValidation(); return !hasFatalProblem; } }); break; case ON_FOCUS_LOSS: component.addFocusListener(this); break; } performValidation(); // Make sure any initial errors are discovered immediately. } @Override protected final void performValidation(Problems ps){ JTextComponent component = getTarget(); if (!component.isEnabled()) { return; } validator.validate(ps, SwingValidationGroup.nameForComponent(component), component.getDocument()); hasFatalProblem = ps.hasFatal(); } @Override public void focusLost(FocusEvent e) { performValidation(); } @Override public void focusGained(FocusEvent e) { } @Override public void insertUpdate(DocumentEvent e) { removeUpdate(e); } @Override public void removeUpdate(DocumentEvent e) { //Documents can be legally updated from another thread, //but we will not run validation outside the EDT if (!EventQueue.isDispatchThread()) { EventQueue.invokeLater(this); } else { performValidation(); } } @Override public void changedUpdate(DocumentEvent e) { removeUpdate(e); } // See removeUpdate.. @Override public void run() { performValidation(); } } libsimple-validation-java-.orig/org/netbeans/validation/api/warning.png0000644000175000017500000000113311654612134025332 0ustar tonytonyPNG  IHDRagAMA7tEXtSoftwareAdobe ImageReadyqe<IDATxb?###6s* F? sDN{Дj6O<)W)iNel2g`DXM@a5`}/C"?_ ` >H]-@1aANńa 4GW @,kc(PVt/>~ A|8HY=@aC?4# 2h8~uh$ ~fhPR0Pdc` ab y:0@G_QdL#ԁԃ܀_xTA 70D] }<%&J ȸ{c=>it9z>b UP"MHȁ= ν *ڊ( 9OŚ\@ܘ)-P@"x d@տv|,QIENDB`libsimple-validation-java-.orig/org/netbeans/validation/api/Validator.java0000644000175000017500000000663311654612134025761 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api; import org.netbeans.validation.api.builtin.stringvalidation.StringValidators; /** * Validator that can validate some aspect of a component's model, and * indicate problems to the user. * *

Note that the enum {@link StringValidators} provides many * built-in validators to perform common tasks. * * @author Tim Boudreau */ public interface Validator { /** * Validate the passed model. If the component is invalid, this * method shall add problems to the passed list. * * @param problems A list of problems. * @param compName The name of the component in question (may be null in some cases) * @param model The model in question */ void validate (Problems problems, String compName, T model); /** * The type of the model object which can be validated. Necessary due * to limitations of the Java implementation of generics, so that * model conversions can be done at runtime, and declaratively registered * ValidationListeners can be matched with Validator types. *

* The return value of this method is expected to remain constant * throughout the life of this validator. * * @return The type of the model object expected. Note that a validator * may be passed a subclass of this type. */ Class modelType(); } libsimple-validation-java-.orig/org/netbeans/validation/api/Problem.java0000644000175000017500000001203711654612134025427 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api; /** * Represents a problem produced by a validator. * * @author Tim Boudreau */ public final class Problem implements Comparable { private final String message; private final Severity severity; /** * Create a new problem with the given message and severity * @param message A localized, human readable message * @param severity The severity */ public Problem(String message, Severity severity) { if (message == null) { throw new NullPointerException ("Null message"); //NOI18N } if (severity == null) { throw new NullPointerException ("Null severity"); //NOI18N } this.message = message; this.severity = severity; } /** * Get the {@code Severity} of this Problem. The severity indicates whether * the user should be blocked from further action until the problem * is corrected, or if continuing with a warning is reasonable. * It also determines the warning icon which can be displayed to the * user. * @return The severity of the Problem */ public Severity severity() { return severity; } /** * Determine which Problem is more severe. Uses compareTo(). * @param p1 p2 the two Problems to compare. Any of them (or both) may be null. * @return p1 if p1 is worse * @return p2 if p2 is worse * @return p1 (the first argument) if p1 and p2 are equally severe. * @return null if both problems to compare are null */ public static Problem worst(Problem p1, Problem p2){ if( p1==null ) { return p2; } if( p2==null ) { return p1; } return p2.compareTo(p1)<0 ? p2 : p1; } /** * Convenience method to determine if this problem is of Severity.FATAL * severity * @return true if severity() == Severity.FATAL */ public boolean isFatal() { return severity == Severity.FATAL; } /** * Get the localized, human-readable description of the problem * @return The message */ public String getMessage() { return message; } /** * Compare, such that most severe Problems will appear first, least last * @param o * @return the difference in severity as an integer */ @Override public int compareTo(Problem o) { int ix = severity.ordinal(); int oid = o == null ? -1 : o.severity.ordinal(); // return ix - oid; return oid - ix; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null || o.getClass() != Problem.class ) { return false; } Problem p = (Problem) o; return p.severity == severity && p.getMessage().equals(getMessage()); } @Override public String toString() { return getMessage() + " (" + severity() + ")"; } @Override public int hashCode() { return message.hashCode() * (severity.hashCode() + 1); } } libsimple-validation-java-.orig/org/netbeans/validation/api/warning-badge.png0000644000175000017500000000056611654612134026403 0ustar tonytonyPNG  IHDR pHYs  gAMA|Q cHRMz%u0`:o_FIDATxb5 bdfxf1024V b8S`7fbyiu ל[`Ӣ\23Hsp0< /~2,WMf`-gB@r5-3⎿>à @   a8@, 3r?W-bpRWAFFP ~ 7S 4IENDB`libsimple-validation-java-.orig/org/netbeans/validation/api/CustomLevelValidator.java0000644000175000017500000000644511654612134030145 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; /** * Allows limiting the severity produced by other validators. * * @author Tim Boudreau */ final class CustomLevelValidator extends AbstractValidator { private final Validator other; private final Severity customSeverity; CustomLevelValidator(Severity customSeverity, Validator other) { super (other.modelType()); this.customSeverity = customSeverity; this.other = other; if (customSeverity == Severity.FATAL) { Logger.getLogger(CustomLevelValidator.class.getName()).log(Level.INFO, "Pointless to filter to Severity.FATAL", new IllegalArgumentException()); } } @Override public void validate(Problems problems, String compName, T model) { Problems nue = new Problems(); other.validate(nue, compName, model); List l = nue.allProblems(); for (Problem p : l) { if (p.severity().compareTo(customSeverity) > 0) { p = new Problem (p.getMessage(), customSeverity); } problems.add(p); } } } libsimple-validation-java-.orig/org/netbeans/validation/api/conversion/0000755000175000017500000000000011654612134025346 5ustar tonytony././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/StringToDocumentConverter.javalibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/StringToDocumentConverter.jav0000644000175000017500000000660511654612134033217 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.conversion; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import org.netbeans.validation.api.AbstractValidator; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * * @author Tim Boudreau */ final class StringToDocumentConverter extends Converter { StringToDocumentConverter() { super (String.class, Document.class); } @Override public Validator convert(Validator from) { return new DocValidator (from); } private static class DocValidator extends AbstractValidator { private Validator wrapped; private DocValidator(Validator from) { super (Document.class); this.wrapped = from; } @Override public void validate(Problems problems, String compName, Document model) { try { String text = model.getText(0, model.getLength()); wrapped.validate(problems, compName, text); } catch (BadLocationException ex) { throw new IllegalStateException (ex); } } @Override public String toString() { return "DocValidator for [" + wrapped + "]"; } } } libsimple-validation-java-.orig/org/netbeans/validation/api/conversion/Converter.java0000644000175000017500000002025611654612134030165 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.conversion; import java.util.Collection; import org.netbeans.validation.api.*; import java.util.HashSet; import java.util.Set; import org.netbeans.validation.api.ValidatorUtils; import org.openide.util.Lookup; /** * Converts validators. Can convert a {@link Validator} working on one type (such as {@code String}) * to a {@code Validator} of a different type, such as javax.swing.text.Document. * In this way, it is possible to write only validators * for {@code String}s, but use them against javax.swing.text.Documents (for validating * {@code JTextField} and {@code JTextArea} components), etc. * * @author Tim Boudreau */ public abstract class Converter { private static Set > registry = new HashSet>(); private final Class from; private final Class to; protected Converter (Class from, Class to) { this.from = from; this.to = to; } public final Class from() { return from; } public final Class to() { return to; } /** * Create a {@link Validator} for type {@code To} from a validator for type * {@code From}. For example, a converter that is a factory for Validators * of {@code javax.swing.text.Document}s from a validator * that only handles Strings may be created. (Convert would simply return a * Validator that wraps the Validator. At validation time * it will first call Document.getText(), and then pass the result to * the wrapped Validator). * @param from The original validator. * @return A validator of the type requested */ public abstract Validator convert (Validator from); /** * Will merge the chain of passed validators to one, and then convert it to * the requested type. See {@link #convert(org.netbeans.validation.api.Validator) } * * @param froms A chain of validator to convert. * @return A validator of the type requested */ public final Validator convert (Validator... froms) { return (convert(ValidatorUtils.merge(froms))); } /** * Register a converter * @param * @param * @param from * @param to * @param converter */ public static void register (Converter converter) { registry.add (converter); } static { Converter.register (new StringToDocumentConverter()); Converter.register (new StringToComboBoxModelConverter()); Converter.register (new SelectedIndicesToListSelectionModelConverter()); Converter.register (new SelectedIndicesToButtonModelArrayConverter()); } /** * Find a converter to create validators for one type from validators for * another type. * @param The type of object we get from a component, such as a * javax.swing.text.Document * @param The type of object we want to process, such as a * java.lang.String * @param from A class, such as Document.class * @param to A class such as String.class * @return An object which can take validators for type From * and produce validators for type To */ public static Converter find (Class from, Class to) { Collection converters = Lookup.getDefault().lookupAll(Converter.class); for (Converter c : converters) { if (c.match(from,to)) { return c.as(from, to); } } for (Converter c : registry) { if (c.match(from, to)) { return c.as(from, to); } } throw new IllegalArgumentException ("No registered converter from " + from.getName() + " to " + to.getName()); } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Converter other = (Converter) obj; if (this.from != other.from && (this.from == null || !this.from.equals(other.from))) { return false; } if (this.to != other.to && (this.to == null || !this.to.equals(other.to))) { return false; } return true; } @Override public int hashCode() { int hash = 7; hash = 23 * hash + (this.from != null ? this.from.hashCode() : 0); hash = 11 * hash + (this.to != null ? this.to.hashCode() : 0); return hash; } private boolean match (Class from, Class to) { // return from().isAssignableFrom(from) && to().isAssignableFrom(to); return from().equals(from) && to().equals(to); } Converter as (Class t, Class r) { return new Wrap(t, r, this); } static final class Wrap extends Converter { final Converter other; private final Exception ex; Wrap (Class a, Class b, Converter other) { super (a,b); this.other = other; ex = new Exception(); } @Override public Validator convert(Validator from) { Validator tv = ValidatorUtils.cast (other.from, from); Validator cvt = other.convert(tv); return ValidatorUtils.cast(to(), cvt); } } // private static final class DepthComparator implements Comparator> { // int classDepth(Class type) { // int depth = 0; // Set> set = new HashSet>(); // for (;type != null; type = type.getSuperclass()) { // set.addAll(Arrays.asList(type.getInterfaces())); // depth++; // } // return depth + set.size(); // } // // public int compare(Converter o1, Converter o2) { // return classDepth(o1.from()) - classDepth(o2.from()); // } // } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/SelectedIndicesToButtonModelArrayConverter.javalibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/SelectedIndicesToButtonModelA0000644000175000017500000000675511654612134033116 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.conversion; import java.util.ArrayList; import java.util.List; import javax.swing.ButtonModel; import org.netbeans.validation.api.AbstractValidator; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * * @author Hugo Heden */ class SelectedIndicesToButtonModelArrayConverter extends Converter { SelectedIndicesToButtonModelArrayConverter() { super (Integer[].class, ButtonModel[].class); } @Override public Validator convert(Validator from) { return new V(from); } private static final class V extends AbstractValidator { private final Validator wrapped; public V(Validator wrapped) { super (ButtonModel[].class); this.wrapped = wrapped; } @Override public void validate(Problems problems, String compName, ButtonModel[] buttonModels) { List selectedElements = new ArrayList(buttonModels.length); int index = 0; for( ButtonModel m : buttonModels ){ if(m.isSelected()){ selectedElements.add(index); } ++index; } wrapped.validate(problems, compName, selectedElements.toArray(new Integer[selectedElements.size()])); } } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/StringToComboBoxModelConverter.javalibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/StringToComboBoxModelConverte0000644000175000017500000000620511654612134033165 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.conversion; import javax.swing.ComboBoxModel; import org.netbeans.validation.api.AbstractValidator; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * * @author Tim Boudreau */ class StringToComboBoxModelConverter extends Converter { StringToComboBoxModelConverter() { super (String.class, ComboBoxModel.class); } @Override public Validator convert(Validator from) { return new V(from); } private static final class V extends AbstractValidator { private final Validator wrapped; public V(Validator wrapped) { super (ComboBoxModel.class); this.wrapped = wrapped; } @Override public void validate(Problems problems, String compName, ComboBoxModel model) { Object o = model.getSelectedItem(); String s = o == null ? "" : o.toString(); wrapped.validate(problems, compName, s); } } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/SelectedIndicesToListSelectionModelConverter.javalibsimple-validation-java-.orig/org/netbeans/validation/api/conversion/SelectedIndicesToListSelectio0000644000175000017500000000727411654612134033161 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.conversion; import java.util.ArrayList; import java.util.List; import javax.swing.ListSelectionModel; import org.netbeans.validation.api.AbstractValidator; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * * @author Hugo Heden */ class SelectedIndicesToListSelectionModelConverter extends Converter { SelectedIndicesToListSelectionModelConverter() { super (Integer[].class, ListSelectionModel.class); } @Override public Validator convert(Validator from) { return new V(from); } private static final class V extends AbstractValidator { private final Validator wrapped; public V(Validator wrapped) { super (ListSelectionModel.class); this.wrapped = wrapped; } @Override public void validate(Problems problems, String compName, ListSelectionModel model) { if(model.isSelectionEmpty()){ wrapped.validate(problems, compName, new Integer[0]); } else { List list = new ArrayList(model.getMaxSelectionIndex()+1 - model.getMinSelectionIndex()); for ( int i = model.getMinSelectionIndex(); i <= model.getMaxSelectionIndex(); ++i ){ if( model.isSelectedIndex(i)){ list.add(i); } } wrapped.validate(problems, compName, list.toArray(new Integer[list.size()])); } } } } libsimple-validation-java-.orig/org/netbeans/validation/api/error-badge.png0000644000175000017500000000060711654612134026063 0ustar tonytonyPNG  IHDR pHYs  gAMA|Q cHRMz%u0`:o_FIDATxb/ji>񢟿~- &6lI'IL± y3pr{o@1ױ2?~OUAlH X]_2/ ?yH(xw@1]:ۿ 0] 6H $@ ҥb~6aӧ߿ F?#9G; d`xǏ?0QdIENDB`libsimple-validation-java-.orig/org/netbeans/validation/api/AndValidator.java0000644000175000017500000000625711654612134026406 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api; import java.util.List; /** * * @author Tim Boudreau */ final class AndValidator extends AbstractValidator { private final List> validators; AndValidator(Class type, List> initial) { super (type); validators = initial; assert validatorTypesMatch (initial) : "Validator type mismatch: " //NOI18N + validators; } @Override public void validate(Problems problems, String compName, T model) { for (Validator v : validators) { v.validate(problems, compName, model); } } @Override public String toString() { return "AndValidator for " + validators; } private boolean validatorTypesMatch(List> validators) { Class type = null; for (Validator v : validators) { if (type == null) { type = v.modelType(); } else { if (!type.equals(v.modelType())) { return false; } } } return true; } } libsimple-validation-java-.orig/org/netbeans/validation/api/Problems.java0000644000175000017500000001334211715053030025602 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * A collection of problems, to which a Validator can add additional problems. * * @author Tim Boudreau */ public final class Problems { private final List problems = new ArrayList(); private boolean hasFatal; /** * Convenience method to add a problem with the specified message and * Severity.FATAL * @param problem */ public final void add (String problem) { add (problem, Severity.FATAL); } /** * Add a problem with the specified severity * @param problem the message * @param severity the severity */ public final void add (String problem, Severity severity) { problems.add (new Problem (problem, severity)); hasFatal |= severity == Severity.FATAL; } /** * Add a problem * @param problem The problem (may be null) */ public final void add (Problem problem) { if( problem == null ) { return; } problems.add (problem); hasFatal |= (problem.severity() == Severity.FATAL); } /** * Dump all problems in another instance of Problems into this one. * @param problems The other problems. */ public final void putAll (Problems problems) { if (problems == this) throw new IllegalArgumentException ( "putAll to self"); //NOI18N this.problems.addAll (problems.problems); hasFatal |= (problems.hasFatal()); } /** * Determine if this set of problems includes any that are fatal. * @return true if a fatal problem has been encountered */ public final boolean hasFatal() { return hasFatal; } /** * Create a new Problems with the initial (fatal) problem. * @param message A localized message * @return A Problems */ public static Problems create (String message) { Problems result = new Problems(); result.add(message); return result; } /** * Get the {@code Problem} with the highest severity. * * If there is more than one problem with equal severity, the * one first added will be considered more severe. * * @return The most severe {@code Problem} in this set * @return null if there was no {@code Problem} */ public final Problem getLeadProblem() { // Note that Collections.sort() is *stable*, a fact we use to guarantee // this: of problems with equal severity, the problems added first will // remain before the later ones, and will thusly be considered "more leading". // (This may be helpful if the problems added first // have *occured* more *recently* and thusly can be regarded as leading // -- more natural to indicate to a user). Collections.sort (problems); return problems.isEmpty() ? null : problems.get(0); } /** * Get the entire set of problems, sorted by severity first, order of * addition second. * @return A list of Problems */ public final List allProblems() { List result = new ArrayList(problems.size()); result.addAll(problems); Collections.sort(result); return result; } @Override public String toString() { StringBuilder sb = new StringBuilder(); for (Iterator it = problems.iterator(); it.hasNext();) { Problem p = it.next(); sb.append (p); if (it.hasNext()) { sb.append (", "); } } return sb.toString(); } } libsimple-validation-java-.orig/org/netbeans/validation/api/info-badge.png0000644000175000017500000000063511654612134025666 0ustar tonytonyPNG  IHDR pHYs  gAMA|Q cHRMz%u0`:o_FIDATxbd6V[YXOUЂ.~ݷL vNf [;Ȩ|c,2[YIZ_ V{paAn7o#3խ'.}`%p[20˧Dm!3˧/C+~Š"Jb ?fz bf)YI*<}މ.J F&QZsI;/sg]wIENDB`libsimple-validation-java-.orig/org/netbeans/validation/api/AbstractValidator.java0000644000175000017500000000116611654612134027441 0ustar tonytony/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.netbeans.validation.api; /** * Convenience base class for validators. * * @author Tim Boudreau */ public abstract class AbstractValidator implements Validator { private final Class type; protected AbstractValidator(Class type) { this.type = type; } /** * Model type for this validator - the type of argument it validates. * @return The model type */ @Override public final Class modelType() { return type; } } libsimple-validation-java-.orig/org/netbeans/validation/api/Severity.java0000644000175000017500000001347011654612134025643 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.UIManager; import org.openide.util.NbBundle; /** * enum indicating {@code Severity}, used for classifying {@link Problem} instances. * * @author Tim Boudreau */ public enum Severity { /** * An information message for the user, which should not block * them from proceeding but may provide advice */ INFO, /** * A warning to the user that they should change a value, but * which does not block them from proceeding */ WARNING, /** * A fatal problem with user input which must be corrected */ FATAL; private BufferedImage image; /** * Get a warning icon as an image * @return An image */ public synchronized BufferedImage image() { if (image == null) { String name; switch (this) { case INFO: name = "info.png"; //NOI18N break; case WARNING: name = "warning.png"; //NOI18N break; case FATAL: name = "error.png"; //NOI18N break; default: throw new AssertionError(); } try { image = ImageIO.read(Severity.class.getResourceAsStream(name)); } catch (IOException ex) { throw new IllegalArgumentException(ex); } } return image; } /** * Get an icon version of the warning image * @return An icon */ public Icon icon() { return new ImageIcon(image()); } /** * Get a suitable color for displaying problem text * @return A color */ public Color color() { switch (this) { case FATAL: { Color c = UIManager.getColor("nb.errorForeground"); //NOI18N if (c == null) { c = Color.RED.darker(); } return c; } case WARNING: return Color.BLUE.darker(); case INFO: return UIManager.getColor("textText"); default: throw new AssertionError(); } } BufferedImage badge; public BufferedImage badge() { if (badge == null) { String name; switch (this) { case INFO: name = "info-badge.png"; //NOI18N break; case WARNING: name = "warning-badge.png"; //NOI18N break; case FATAL: name = "error-badge.png"; //NOI18N break; default: throw new AssertionError(); } try { badge = ImageIO.read(Severity.class.getResourceAsStream(name)); } catch (IOException ex) { throw new IllegalArgumentException(ex); } } return badge; } /** * Annotate an error description with the severity. Used for providing * accessible descriptions for error components. * * @param toDescribe * @return */ public String describeError (String toDescribe) { return NbBundle.getMessage(Severity.class, name() + ".annotation", toDescribe); } /** * Returns a localized name for this enum constant * @return A localized name */ @Override public String toString() { return NbBundle.getMessage(Severity.class, name()); } } libsimple-validation-java-.orig/org/netbeans/validation/api/builtin/0000755000175000017500000000000011654612134024627 5ustar tonytonylibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/0000755000175000017500000000000011654612134030210 5ustar tonytony././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle.propertieslibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle.properti0000644000175000017500000001131411715047572033215 0ustar tonytony# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common # Development and Distribution License("CDDL") (collectively, the # "License"). You may not use this file except in compliance with the # License. You can obtain a copy of the License at # http://www.netbeans.org/cddl-gplv2.html # or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the # specific language governing permissions and limitations under the # License. When distributing the software, include this License Header # Notice in each file and include the License file at # nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this # particular file as subject to the "Classpath" exception as provided # by Sun in the GPL Version 2 section of the License file that # accompanied this code. If applicable, add the following below the # License Header, with the fields enclosed by brackets [] replaced by # your own identifying information: # "Portions Copyrighted [year] [name of copyright owner]" # # Contributor(s): # # The Original Software is NetBeans. The Initial Developer of the Original # Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun # Microsystems, Inc. All Rights Reserved. # # If you wish your version of this file to be governed by only the CDDL # or only the GPL Version 2, indicate your decision by adding # "[Contributor] elects to include this software in this distribution # under the [CDDL or GPL Version 2] license." If you do not indicate a # single choice of license, a recipient has the option to distribute # your version of this file under either the CDDL, the GPL Version 2 or # to extend the choice of license to its licensees as provided above. # However, if you add GPL Version 2 code and therefore, elected the GPL # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. ERR_TEXTFIELD_EMPTY={0} must be set ERR_JAVA_IDENTIFIER={0} is not a legal Java variable/class name ERR_INVALID_FILE_NAME={0} ''{1}'' contains illegal file name characters ERR_NOT_INTEGER=''{0}'' is not an integer ERR_NEGATIVE_NUMBER={0} may not be a negative number NOT_A_NUMBER="{0}" is not a number on {1} DISALLOWED_CHARS=The characters {0} are not allowed in {1} ODD_LENGTH_HEX=Hexadecimal numbers must have an even number of characters INVALID_HEX=Invalid hexadecimal character ''{0}'' in {1} URL_NOT_VALID=''{0}'' is not a valid URL FILE_DOES_NOT_EXIST=''{0}'' does not exist FILE_IS_NOT_A_DIRECTORY=''{0}'' is not a directory FILE_IS_NOT_A_FILE=''{0}'' is not a file MAY_NOT_CONTAIN_WHITESPACE=''{0}'' may not contain whitespace characters MSG_MAY_NOT_BE_EMPTY={0} may not be empty ADDR_PART_BAD=''{0}'' is not an integer ADDR_PART_HIGH=IP components must be 0-256 - {0} too high ADDR_PART_NEGATIVE=IP components may not be negative numbers ({0}) NEGATIVE_PORT=Negative port number {0} not allowed PORT_TOO_HIGH=Port number too high INVALID_PORT=''{1}'' is not a valid port number LABEL_TOO_LONG=''{0}'' is too long a host name label NUMBER_PART_IN_HOSTNAME=Host names may not contain numbers: {0} BAD_CHAR_IN_HOSTNAME=Illegal character ''{0}'' in hostname TOO_MANY_LABELS=Too many parts in host name or IP address ''{0}'' MAY_NOT_START_WITH_DIGIT={0} may not start with a digit MSG_DOES_NOT_MATCH_NUMBER_FORMAT=Invalid value for {0}: ''{1}'' MSG_PORT_NOT_ALLOWED={0} may not specify a port INVALID_HOST_NAME=Invalid host ''{1}'' ILLEGAL_CHARSET_NAME=Illegal character set ''{1}'' UNSUPPORTED_CHARSET_NAME=Unsupported character set ''{1}'' INVALID_CHARACTER=The character ''{1}'' in {0} is not encodable in {2} NOT_AN_EMAIL_ADDRESS=''{1}'' is not a valid email address EMAIL_MISSING_HOST={0} does not specify a destination host LABEL_EMPTY=Empty address part in {0} EMAIL_HAS_>1_@={0} contains more than one @ character HOST_STARTS_OR_ENDS_WITH_PERIOD=Host may not begin or end with a . ADDRESS_CONTAINS_INT_AND_NON_INT_LABELS=Illegal host {0} - mixes numbers and labels TOO_MANY_COLONS=Too many :''s in {0}: ''{1}'' INVALID_HOST_OR_IP={0} is not a valid host or IP address: ''{1}'' EMAIL_MISSING_NAME=Name missing from email address IP_ADDRESS_CONTAINS_WHITESPACE=IP address {0} may not contain whitespace HOST_MAY_NOT_CONTAIN_WHITESPACE=Host name {0} may not contain whitespace ADDRESS_MAY_BE_TOO_LONG=Name part of {0} is more than 64 characters long and \ will not work on most mail severs VALUE_OUT_OF_RANGE={0} must be between {2} and {3}: {1} STRING_TOO_LONG={0} too long: {1} STRING_TOO_SHORT={0} must be at least {2} characters long: {0} FILE_EXISTS={0} exists MAY_NOT_END_WITH={0} may not end with ''{1}'' NO_AT_SYMBOL=No @ symbol ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/FormatValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/FormatValidator0000644000175000017500000000550511654612134033236 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.text.Format; import java.text.ParseException; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class FormatValidator extends StringValidator { private final Format fmt; FormatValidator(Format fmt) { this.fmt = fmt; } @Override public void validate(Problems problems, String compName, String model) { try { fmt.parseObject(model); } catch (ParseException ex) { problems.add(NbBundle.getMessage(FormatValidator.class, "MSG_DOES_NOT_MATCH_NUMBER_FORMAT", compName, model)); //NOI18N } } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/EmptyStringIllegalValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/EmptyStringIlle0000644000175000017500000000523111654612134033227 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class EmptyStringIllegalValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String model) { if (model.isEmpty()) { String message = NbBundle.getMessage(EmptyStringIllegalValidator.class, "MSG_MAY_NOT_BE_EMPTY", compName); //NOI18N problems.add (message); } } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/StringValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/StringValidator0000644000175000017500000000046111654612134033250 0ustar tonytonypackage org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.AbstractValidator; /** * * @author Tim Boudreau */ abstract class StringValidator extends AbstractValidator { protected StringValidator() { super (String.class); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/DisallowCharactersValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/DisallowCharact0000644000175000017500000000607311654612134033205 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class DisallowCharactersValidator extends StringValidator { private char[] chars; public DisallowCharactersValidator(char[] chars) { this.chars = chars; } private String asString() { return "'" + new String(chars) + "' "; //NOI18N } @Override public void validate(Problems problems, String compName, String model) { for (char c : chars) { for (char cc : model.toCharArray()) { if (cc == c) { problems.add (NbBundle.getMessage(DisallowCharactersValidator.class, "DISALLOWED_CHARS", asString(), compName)); //NOI18N return; } } } } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/EncodableInCharsetValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/EncodableInChar0000644000175000017500000000712411654612134033100 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class EncodableInCharsetValidator extends StringValidator { private final String charsetName; EncodableInCharsetValidator(String charsetName) { this.charsetName = charsetName; //Be fail-fast with respect to exceptions Charset.forName(charsetName); } EncodableInCharsetValidator() { this(Charset.defaultCharset().name()); } @Override public void validate(Problems problems, String compName, String model) { char[] c = model.toCharArray(); boolean result = true; String curr; for (int i = 0; i < c.length; i++) { curr = new String(new char[]{c[i]}); try { String nue = new String(curr.getBytes(charsetName)); result = c[i] == nue.charAt(0); if (!result) { problems.add(NbBundle.getMessage( EncodableInCharsetValidator.class, "INVALID_CHARACTER", compName, curr, charsetName)); //NOI18N break; } } catch (UnsupportedEncodingException ex) { //Already tested in constructor throw new AssertionError(ex); } } } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MayNotContainSpacesValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MayNotContainSp0000644000175000017500000000541011654612134033161 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class MayNotContainSpacesValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String model) { char[] chars = model.toCharArray(); for (char c : chars) { if (Character.isWhitespace(c)) { problems.add(NbBundle.getMessage( MayNotContainSpacesValidator.class, "MAY_NOT_CONTAIN_WHITESPACE", compName)); //NOI18N } } } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MayNotStartWithDigit.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MayNotStartWith0000644000175000017500000000532611654612134033222 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class MayNotStartWithDigit extends StringValidator { @Override public void validate(Problems problems, String compName, String model) { if (model.length() > 0) { char c = model.charAt(0); if (Character.isDigit(c)) { problems.add(NbBundle.getMessage(MayNotStartWithDigit.class, "MAY_NOT_START_WITH_DIGIT", compName)); //NOI18N } } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/NumberRange.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/NumberRange.jav0000644000175000017500000000626711654612134033132 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class NumberRange extends StringValidator { private Number max; private Number min; NumberRange (Number min, Number max) { this.min = min; this.max = max; } @Override public void validate(Problems problems, String compName, String model) { try { double val = Double.parseDouble(model); double minn = min.doubleValue(); double maxx = max.doubleValue(); boolean result = val >= minn && val <= maxx; if (!result) { problems.add (NbBundle.getMessage(NumberRange.class, "VALUE_OUT_OF_RANGE", new Object[] { //NOI18N compName, model, min, max})); } } catch (NumberFormatException e) { //should be handled by another validator } } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MinimumLength.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MinimumLength.j0000644000175000017500000000540711654612134033146 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class MinimumLength extends StringValidator { private final int len; MinimumLength (int len) { this.len = len; } @Override public void validate(Problems problems, String compName, String model) { if (model.length() < len) { problems.add(NbBundle.getMessage(MaximumLength.class, "STRING_TOO_SHORT", compName, model, "" + len)); //NOI18N } } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/RegexpValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/RegexpValidator0000644000175000017500000000615711654612134033244 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.text.MessageFormat; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * * @author Tim Boudreau */ final class RegexpValidator extends StringValidator { private final Pattern pattern; private final String message; private boolean acceptPartialMatches; RegexpValidator(String pattern, String message, boolean acceptPartialMatches) { this.pattern = Pattern.compile(pattern); this.message = message; this.acceptPartialMatches = acceptPartialMatches; } @Override public void validate(Problems problems, String compName, String model) { Matcher m = pattern.matcher(model); boolean result = acceptPartialMatches ? m.lookingAt() : m.matches(); if (!result) { String prb = message; prb = MessageFormat.format(prb, new Object[] { compName, model }); problems.add(prb); } } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/TrimStringValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/TrimStringValid0000644000175000017500000000553411654612134033224 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * Validator which wraps another String validator and simply calls trim() * on the value before passing it to the other validator. * * @author Tim Boudreau */ final class TrimStringValidator extends StringValidator { private final Validator other; TrimStringValidator (Validator other) { this.other = other; } @Override public void validate(Problems problems, String compName, String model) { other.validate(problems, compName, model == null ? null : model.trim()); } @Override public String toString() { return "TrimStringValidator for " + other; //NOI18N } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/SplitStringValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/SplitStringVali0000644000175000017500000000605611654612134033240 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * A validator of strings that first splits the string in question using the * passed regular expression, and then runs another validator over each * component string. * * @author Tim Boudreau */ final class SplitStringValidator extends StringValidator { private final String regexp; private final Validator other; public SplitStringValidator(String regexp, Validator other) { this.regexp = regexp; this.other = other; } @Override public void validate(Problems problems, String compName, String model) { String[] components = model.split (regexp); for (String component : components) { other.validate (problems, compName, component); } } @Override public String toString() { return "SplitStringValidator for " + other; //NOI18N } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MayNotEndWithValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MayNotEndWithVa0000644000175000017500000000157011654612134033117 0ustar tonytony/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * Does not allow a string to terminate with a particular character * * @author Tim Boudreau */ final class MayNotEndWithValidator extends StringValidator { private final char c; public MayNotEndWithValidator(char c) { this.c = c; } @Override public void validate(Problems problems, String compName, String model) { if (model != null && model.charAt(model.length() - 1) == c) { problems.add(NbBundle.getMessage(MayNotEndWithValidator.class, "MAY_NOT_END_WITH", compName, new String(new char[] { c }))); } } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IllegalCharactersInFileNameValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IllegalCharacte0000644000175000017500000000561011654612134033141 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.io.File; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; import org.openide.util.Utilities; /** * * @author Tim Boudreau */ final class IllegalCharactersInFileNameValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String text) { boolean invalid = text.contains(File.separator) || text.contains(File.pathSeparator); if (!invalid && Utilities.isWindows()) { invalid = text.contains(":"); } if( invalid ) { problems.add( NbBundle.getMessage (IllegalCharactersInFileNameValidator.class, "ERR_INVALID_FILE_NAME", compName, text)) ; //NOI18N } } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/ValidHexadecimalNumberValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/ValidHexadecima0000644000175000017500000000612311654612134033145 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class ValidHexadecimalNumberValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String model) { if (model.length() % 2 != 0) { problems.add(NbBundle.getMessage(ValidHexadecimalNumberValidator.class, "ODD_LENGTH_HEX", compName)); //NOI18N return; } for (char c : model.toCharArray()) { boolean good = (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9'); if (!good) { problems.add (NbBundle.getMessage(ValidHexadecimalNumberValidator.class, "INVALID_HEX", //NOI18N new String(new char[] { c }), compName)); return; } } } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/NonNegativeNumberValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/NonNegativeNumb0000644000175000017500000000567211654612134033204 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ class NonNegativeNumberValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String text) { try { double d = Double.parseDouble(text); if (d < 0D) { String problem = NbBundle.getMessage( NonNegativeNumberValidator.class, "ERR_NEGATIVE_NUMBER", compName); //NOI18N problems.add (problem); } } catch (NumberFormatException e) { //do nothing - if someone wants not-a-number validation, they should //chain an IntegerDocumentValidator or similar } } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/StringValidators.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/StringValidator0000644000175000017500000004270411654612134033256 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.ValidatorUtils; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; import java.text.Format; import java.util.Locale; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * An enumeration of validator factories for commonly needed forms of * validation such as non-empty strings, valid file names and URLs and * so forth. *

* Also contains static factory methods for validators which do things * like match regexp's and split strings and run another validator over * the components. * * @author Tim Boudreau */ public enum StringValidators implements Validator { /** * Factory for validators which require non-zero length text. */ REQUIRE_NON_EMPTY_STRING, /** * Factory for validators which require a legal filename */ REQUIRE_VALID_FILENAME, /** * Factory for validators which require a valid integer */ REQUIRE_VALID_INTEGER, /** * Factory for validators which require a non-negative number (may * be floating point or int) */ REQUIRE_NON_NEGATIVE_NUMBER, /** * Factory for validators which require a valid number of some sort */ REQUIRE_VALID_NUMBER, /** * Factory for validators which require that strings not be a * Java keyword */ REQUIRE_JAVA_IDENTIFIER, /** * Factory for validators that require that strings be a valid * hexadecimal number */ VALID_HEXADECIMAL_NUMBER, /** * Factory for validators that require that strings not contain whitespace */ NO_WHITESPACE, /** * Factory for validators that require that a string represent a file * which exists on disk */ FILE_MUST_EXIST, /** * Factory for validators that require that a string represent a file * which is a file, not a directory */ FILE_MUST_BE_FILE, /** * Factory for validators that require that a string represent a file * which is a directory, not a data file */ FILE_MUST_BE_DIRECTORY, /** * Factory for validators that require that a string represent a valid URL */ URL_MUST_BE_VALID, /** * Factory for validators that check the validity of an IP address (may * contain port info) */ IP_ADDRESS, /** * Factory for validators that check the validity of an host name (may * contain port info) */ HOST_NAME, /** * Factory for validators that check the validity of an IP address or * host name (may contain port info) */ HOST_NAME_OR_IP_ADDRESS, /** * Factory for validators that do not allow strings which start with * a digit */ MAY_NOT_START_WITH_DIGIT, /** * Factory for validators that validate standard internet email addresses * (name + @ + valid hostname or ip). *

* Note: This validator is not useful for all legal email addresses - * for example, "root" with is a legal email address on a * Unix machine. Do not use this validator where users * might legitimately expect to be able to enter such unqualified email * addresses. */ EMAIL_ADDRESS, /** * Factory for validators that require the passed string to be a valid * character set name according to the specification of * java.nio.Charset.forName(String). */ CHARACTER_SET_NAME, /** * Factory for validators that validate a java package name. Note that * this does not mean the package name actually exists anywhere, just * that it does not contain java keywords. */ JAVA_PACKAGE_NAME, /** * Validator which only passes non-existent file names */ FILE_MUST_NOT_EXIST, /** * Validator which fails any string that ends with a . */ MAY_NOT_END_WITH_PERIOD, ; /** * Get a validator of strings. * @param trim If true, String.trim() is called before passing the value * to the actual validator * @return A validator for strings */ private Validator instantiate(boolean trim) { Validator result; switch (this) { case REQUIRE_JAVA_IDENTIFIER : result = new NotJavaIdentifierValidator(); break; case REQUIRE_NON_EMPTY_STRING : result = new EmptyStringIllegalValidator(); break; case REQUIRE_NON_NEGATIVE_NUMBER : result = new NonNegativeNumberValidator(); break; case REQUIRE_VALID_FILENAME : result = new IllegalCharactersInFileNameValidator(); break; case REQUIRE_VALID_INTEGER : result = new IsAnIntegerValidator(); break; case REQUIRE_VALID_NUMBER : result = new IsANumberValidator(); break; case VALID_HEXADECIMAL_NUMBER : result = new ValidHexadecimalNumberValidator(); break; case NO_WHITESPACE : result = new MayNotContainSpacesValidator(); break; case FILE_MUST_BE_DIRECTORY : result = new FileValidator (FileValidator.Type.MUST_BE_DIRECTORY); break; case FILE_MUST_BE_FILE : result = new FileValidator (FileValidator.Type.MUST_BE_FILE); break; case FILE_MUST_EXIST : result = new FileValidator (FileValidator.Type.MUST_EXIST); break; case FILE_MUST_NOT_EXIST : result = new FileValidator (FileValidator.Type.MUST_NOT_EXIST); break; case URL_MUST_BE_VALID : result = new UrlValidator(); break; case IP_ADDRESS : result = new IpAddressValidator(); break; case HOST_NAME : result = new HostNameValidator(true); break; case HOST_NAME_OR_IP_ADDRESS : result = new ValidHostNameOrIPValidator(); break; case MAY_NOT_START_WITH_DIGIT : result = new MayNotStartWithDigit(); break; case EMAIL_ADDRESS : result = new EmailAddressValidator(); return result; case JAVA_PACKAGE_NAME : result = StringValidators.splitString("\\.", StringValidators.REQUIRE_JAVA_IDENTIFIER); // NOI18N return result; case MAY_NOT_END_WITH_PERIOD : result = new MayNotEndWithValidator('.'); return result; default : throw new AssertionError(); } if (trim) { return new TrimStringValidator(result); } else { return result; } } @Override public void validate (Problems problems, String compName, String model) { instantiate(false).validate(problems, compName, model); } /** * Returns a Validator that will first call {@code trim()} on the {@code String} to be validated, * and then passes the resulting (trimmed) {@code String} to this instance of {@code StringValidators}. * *

See also the static {@link #trimString(org.netbeans.validation.api.Validator[]) } * that does a similar thing for any {@code Validator} (or a chain thereof) * that need not be an instance of the {@code StringValidators} enum */ public Validator trim() { return instantiate(true); } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /** * Creates a {@code Validator} that will first call {@code trim()} on the {@code String} to be validated, * and then passes the resulting (trimmed) {@code String} to the passed {@code Validator} (or chain thereof). * *

See also {@link ValidatorUtils#merge(org.netbeans.validation.api.Validator[]) } * which merges validators (any {@code Validator}, not just {@code * Validator}) without wrapping the result in one * that does String trimming. * * @param validators a chain of String validators */ public static Validator trimString(Validator... validators) { return new TrimStringValidator( ValidatorUtils.merge(validators) ); } /** * Creates a {@code Validator} that will first call {@code trim()} on the {@code String} to be validated, * and then passes the resulting (trimmed) {@code String} to the passed {@code Validator}. *

Unlike {@link #trimString(Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to trim more than one validator, simply trim the result of {@link ValidatorUtils#merge(Validator,Validator)}. * @param validator a String validator */ public static Validator trimString(Validator validator) { return new TrimStringValidator(validator); } /** * Returns a validator which first splits the string to be evaluated according * to the passed regexp, then passes each component of the split string to * the passed validator. * * @param regexp The regular expression pattern to use to split the string * @param validators the validator (or chain of validators) that the returned one * should delegate to validate each component of the split string * @return A validator which evaluates each of component of the split string * using the passed Validator (or chain of validators) */ public static Validator splitString(String regexp, Validator... validators) { return new SplitStringValidator(regexp, ValidatorUtils.merge(validators) ); } /** * Returns a validator which first splits the string to be evaluated according * to the passed regexp, then passes each component of the split string to * the passed validator. *

Unlike {@link #splitString(String,Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to split more than one validator, simply split the result of {@link ValidatorUtils#merge(Validator,Validator)}. * @param regexp The regular expression pattern to use to split the string * @param validator the validator that the returned one * should delegate to validate each component of the split string * @return A validator which evaluates each of component of the split string * using the passed Validator */ public static Validator splitString(String regexp, Validator validator) { return new SplitStringValidator(regexp, validator); } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /** * Create a validator which does not allow you to terminate a string * with a particular character * @param ch The character * @return A validator */ public static Validator mayNotEndWith(char ch) { return new MayNotEndWithValidator(ch); } /** * Get a validator which fails if any of the characters in the * passed char array are contained in the evaluated text * @param chars The array of illegal characters * @return A validator which will show an error if any of the passed * characters are in the String it encounters */ public static Validator disallowChars(char[] chars) { return new DisallowCharactersValidator(chars); } /** * Get a validator which fails if the text to validate does not match a * passed regular expression. * @param regexp The regular expression * @param message The output message if there is a problem. The message * may refer to the component name as {0} and the text that has not matched * as {1} if desired * @param acceptPartialMatches if true, will use Matcher.lookingAt() rather * than Matcher.matches() * @return A validator */ public static Validator regexp (String regexp, String message, boolean acceptPartialMatches) { return new RegexpValidator(regexp, message, acceptPartialMatches); } /** * Create a number validator that uses a specific locale. For the default * locale, use StringValidators.REQUIRE_VALID_NUMBER. Use this if you specifically * want validation for another locale. * @param l The locale to use * @return A string validator for numbers */ public static Validator validNumber (Locale l) { return new IsANumberValidator(l); } /** * Get a validator that uses a specific Format (e.g. * NumberFormat) instance and fails * if fmt.parseObject() throws a ParseException * @param fmt A java.text.Format * @return A string validator that uses the provided NumberFormat */ public static Validator forFormat(Format fmt) { return new FormatValidator(fmt); } /** * Get a validator which determines if the passed string can be encoded * in the specified encoding. Useful, for example, for validating * strings that are specified to be in a particular encoding (e.g. * email addresses and US-ASCII) * * @param charsetName The name of a character set recognized by * java.nio.Charset * @return A validator of character set names * @throws UnsupportedCharsetException if the character set is unsupported * @throws IllegalCharsetNameException if the character set is illegal */ public static Validator encodableInCharset(String charsetName) { return new EncodableInCharsetValidator(charsetName); } /** * Get a validator that guarantees that a number is within a certain * range (inclusive) * @param min The minimum value * @param max The maximum value * @return A validator for number ranges */ public static Validator numberRange (Number min, Number max) { return new NumberRange(min, max); } /** * Validator that enforces minimum input length * @param length * @return A validator for string lengths */ public static Validator minLength (int length) { return new MinimumLength(length); } /** * Validator that enforces maximum input length * @param length * @return A validator for string lengths */ public static Validator maxLength (int length) { return new MaximumLength(length); } public Class modelType() { return String.class; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/UrlValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/UrlValidator.ja0000644000175000017500000000674011654612134033143 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.net.MalformedURLException; import java.net.URL; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ class UrlValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String model) { try { URL url = new URL (model); //java.net.url does not require US-ASCII host names, //but the spec does String host = url.getHost(); if (!"".equals(host)) { //NOI18N new ValidHostNameOrIPValidator(true).validate(problems, compName, host); return; } String protocol = url.getProtocol(); if ("mailto".equals(protocol)) { //NOI18N String emailAddress = url.toString().substring("mailto:".length()); //NOI18N emailAddress = emailAddress == null ? "" : emailAddress; new EmailAddressValidator().validate(problems, compName, emailAddress); return; } } catch (MalformedURLException e) { String problem = NbBundle.getMessage(UrlValidator.class, "URL_NOT_VALID", model); //NOI18N problems.add(problem); } } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/HostNameValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/HostNameValidat0000644000175000017500000001664211654612134033167 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class HostNameValidator extends StringValidator { private final boolean allowPort; HostNameValidator(boolean allowPort) { this.allowPort = allowPort; } @Override public void validate(Problems problems, String compName, String model) { if (model.length() == 0) { problems.add(NbBundle.getMessage(HostNameValidator.class, "INVALID_HOST_NAME", compName, model)); //NOI18N return; } if (model.startsWith(".") || model.endsWith(".")) { //NOI18N problems.add(NbBundle.getMessage(IpAddressValidator.class, "HOST_STARTS_OR_ENDS_WITH_PERIOD", model)); //NOI18N return; } String[] parts = model.split("\\."); if (parts.length > 4) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "TOO_MANY_LABELS", model)); //NOI18N return; } if (!allowPort && model.contains(":")) { //NOI18N problems.add(NbBundle.getMessage(HostNameValidator.class, "MSG_PORT_NOT_ALLOWED", compName, model)); //NOI18N return; } new MayNotContainSpacesValidator().validate(problems, compName, model); if (model.endsWith("-") || model.startsWith("-")) { problems.add(NbBundle.getMessage(HostNameValidator.class, "INVALID_HOST_NAME", compName, model)); //NOI18N return; } for (int i = 0; i < parts.length; i++) { String label = parts[i]; if (label.length() > 63) { problems.add(NbBundle.getMessage(HostNameValidator.class, "LABEL_TOO_LONG", label)); //NOI18N return; } if (i == parts.length - 1 && label.indexOf(":") > 0) { String[] labelAndPort = label.split(":"); if (labelAndPort.length > 2) { problems.add(NbBundle.getMessage(HostNameValidator.class, "INVALID_PORT", compName, label)); //NOI18N return; } if (labelAndPort.length == 1) { problems.add(NbBundle.getMessage(HostNameValidator.class, "INVALID_PORT", compName, "''")); //NOI18N return; } if (label.endsWith(":")) { problems.add(NbBundle.getMessage(HostNameValidator.class, "TOO_MANY_COLONS", compName, label)); //NOI18N return; } try { int port = Integer.parseInt(labelAndPort[1]); if (port < 0) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "NEGATIVE_PORT", port)); //NOI18N return; } else if (port >= 65536) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "PORT_TOO_HIGH", port)); //NOI18N return; } } catch (NumberFormatException e) { problems.add(NbBundle.getMessage(HostNameValidator.class, "INVALID_PORT", compName, labelAndPort[1])); //NOI18N return; } if(!checkHostPart(labelAndPort[0], problems, compName)){ return; } } else { checkHostPart(label, problems, compName); } } // for } private boolean checkHostPart(String label, Problems problems, String compName) { if (label.length() > 63) { problems.add(NbBundle.getMessage(HostNameValidator.class, "LABEL_TOO_LONG", label)); //NOI18N return false; } if (label.length() == 0) { problems.add(NbBundle.getMessage(HostNameValidator.class, "LABEL_EMPTY", compName, label)); //NOI18N return false; } try { Integer.parseInt(label); problems.add(NbBundle.getMessage(HostNameValidator.class, "NUMBER_PART_IN_HOSTNAME", label)); //NOI18N return false; } catch (NumberFormatException e) { //do nothing } Problems tmp = new Problems(); new EncodableInCharsetValidator().validate(tmp, compName, label); problems.putAll(tmp); if (!tmp.hasFatal()) { for (char c : label.toLowerCase().toCharArray()) { if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9' || c == '-')) { //NOI18N continue; } problems.add(NbBundle.getMessage(HostNameValidator.class, "BAD_CHAR_IN_HOSTNAME", new String(new char[]{c}))); //NOI18N return false; } } return true; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IsAnIntegerValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IsAnIntegerVali0000644000175000017500000000524511654612134033125 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class IsAnIntegerValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String model) { try { Integer.parseInt(model); } catch (NumberFormatException e) { problems.add(NbBundle.getMessage (IsAnIntegerValidator.class, "ERR_NOT_INTEGER", model)); //NOI18N } } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle_it.propertieslibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle_it.prope0000644000175000017500000001171511654612134033171 0ustar tonytony# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common # Development and Distribution License("CDDL") (collectively, the # "License"). You may not use this file except in compliance with the # License. You can obtain a copy of the License at # http://www.netbeans.org/cddl-gplv2.html # or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the # specific language governing permissions and limitations under the # License. When distributing the software, include this License Header # Notice in each file and include the License file at # nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this # particular file as subject to the "Classpath" exception as provided # by Sun in the GPL Version 2 section of the License file that # accompanied this code. If applicable, add the following below the # License Header, with the fields enclosed by brackets [] replaced by # your own identifying information: # "Portions Copyrighted [year] [name of copyright owner]" # # Contributor(s): # # The Original Software is NetBeans. The Initial Developer of the Original # Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun # Microsystems, Inc. All Rights Reserved. # # If you wish your version of this file to be governed by only the CDDL # or only the GPL Version 2, indicate your decision by adding # "[Contributor] elects to include this software in this distribution # under the [CDDL or GPL Version 2] license." If you do not indicate a # single choice of license, a recipient has the option to distribute # your version of this file under either the CDDL, the GPL Version 2 or # to extend the choice of license to its licensees as provided above. # However, if you add GPL Version 2 code and therefore, elected the GPL # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. ERR_TEXTFIELD_EMPTY={0} deve essere impostato ERR_JAVA_IDENTIFIER={0} non \u00E8 un identificatore Java ERR_INVALID_FILE_NAME={0} ''{1}'' contiene caratteri illegali per un nome di file ERR_NOT_INTEGER=''{0}'' non \u00E8 un intero ERR_NEGATIVE_NUMBER={0} non deve essere un numero negativo NOT_A_NUMBER="{0}" non \u00E8 un numero in {1} DISALLOWED_CHARS=I caratteri {0} non sono permessi in {1} ODD_LENGTH_HEX=I numeri esadecimali devono avere un numero pari di caratteri INVALID_HEX=Carattere esadecimale ''{0}'' non valido in {1} URL_NOT_VALID=''{0}'' non \u00E8 un URL valido FILE_DOES_NOT_EXIST=''{0}'' non esiste FILE_IS_NOT_A_DIRECTORY=''{0}'' non \u00E8 una directory FILE_IS_NOT_A_FILE=''{0}'' non \u00E8 un file MAY_NOT_CONTAIN_WHITESPACE=''{0}'' non deve contenere spazi MSG_MAY_NOT_BE_EMPTY={0} non deve essere vuoto ADDR_PART_BAD=''{0}'' non \u00E8 un intero ADDR_PART_HIGH=Gli elementi dell''IP devono essere 0-256 - {0} \u00E8 troppo grande ADDR_PART_NEGATIVE=Gli elementi dell''IP non devono essere numeri negativi ({0}) NEGATIVE_PORT=Numero di porta negativo {0} non permesso PORT_TOO_HIGH=Numero di porta troppo grande INVALID_PORT=''{1}'' non \u00E8 un numero di porta valido LABEL_TOO_LONG=''{0}'' \u00E8 troppo lungo per essere un elemento di hostname NUMBER_PART_IN_HOSTNAME=Gli hostname non devono contenere numeri: {0} BAD_CHAR_IN_HOSTNAME=Carattere illegale ''{0}'' nell''hostname TOO_MANY_LABELS=Troppi elementi nell''hostname o indirizzo IP ''{0}'' MAY_NOT_START_WITH_DIGIT={0} non deve cominciare con una cifra MSG_DOES_NOT_MATCH_NUMBER_FORMAT=Valore non valido per {0}: ''{1}'' MSG_PORT_NOT_ALLOWED={0} non deve specificare una porta INVALID_HOST_NAME=Hostname non valido ''{1}'' ILLEGAL_CHARSET_NAME=Codifica di caratteri non valida ''{1}'' UNSUPPORTED_CHARSET_NAME=Codifica di caratteri non supportata ''{1}'' INVALID_CHARACTER=Il carattere ''{1}'' in {0} non \u00E8 codificabile in {2} NOT_AN_EMAIL_ADDRESS=''{1}'' non \u00E8 un indirizzo email valido EMAIL_MISSING_HOST={0} non specifica un host LABEL_EMPTY=Elemento vuoto nell''indirizzo {0} EMAIL_HAS_>1_@={0} contiene pi\u00F9 di un carattere @ HOST_STARTS_OR_ENDS_WITH_PERIOD=L''hostname non deve iniziare o finire con . ADDRESS_CONTAINS_INT_AND_NON_INT_LABELS=Hostname illegale {0} - mescola numeri e stringhe TOO_MANY_COLONS=Troppi : in {0}: ''{1}'' INVALID_HOST_OR_IP={0} non \u00E8 un hostname o indirizzo IP valido: ''{1}'' EMAIL_MISSING_NAME=La prima parte dell''indirizzo email \u00E8 mancante IP_ADDRESS_CONTAINS_WHITESPACE=L''indirizzo IP {0} non deve contenere spazi HOST_MAY_NOT_CONTAIN_WHITESPACE=L''hostname {0} non deve contenere spazi ADDRESS_MAY_BE_TOO_LONG=La prima parte di {0} \u00E8 pi\u00F9 lunga di 64 caratteri e \ potrebbe non funzionare su molti server email VALUE_OUT_OF_RANGE={0} deve essere tra {2} e {3}: {1} STRING_TOO_LONG={0} \u00E8 troppo lungo: {1} STRING_TOO_SHORT={0} deve essere lungo almeno {2} caratteri: {1} FILE_EXISTS={0} esiste MAY_NOT_END_WITH={0} non deve finire con ''{1}'' ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MaximumLength.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/MaximumLength.j0000644000175000017500000000545211654612134033150 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class MaximumLength extends StringValidator { private final int len; MaximumLength (int len) { this.len = len; } @Override public void validate(Problems problems, String compName, String model) { boolean result = model.length() <= len; if (!result) { problems.add(NbBundle.getMessage(MaximumLength.class, "STRING_TOO_LONG", compName, model, "" + len)); //NOI18N } } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/ValidHostNameOrIPValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/ValidHostNameOr0000644000175000017500000001244711654612134033142 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class ValidHostNameOrIPValidator extends StringValidator { private final HostNameValidator hostVal; private final IpAddressValidator ipVal = new IpAddressValidator(); ValidHostNameOrIPValidator(boolean allowPort) { hostVal = new HostNameValidator(allowPort); } ValidHostNameOrIPValidator() { this(true); } @Override public void validate(Problems problems, String compName, String model) { String[] parts = model.split ("\\."); boolean hasIntParts = false; boolean hasNonIntParts = false; if (model.indexOf(" ") > 0 || model.indexOf ("\t") > 0) { problems.add (NbBundle.getMessage(ValidHostNameOrIPValidator.class, "HOST_MAY_NOT_CONTAIN_WHITESPACE", compName, model)); //NOI18N return; } if (parts.length == 0) { //the string "." problems.add (NbBundle.getMessage(ValidHostNameOrIPValidator.class, "INVALID_HOST_OR_IP", compName, model)); //NOI18N return; } for (int i = 0; i < parts.length; i++) { String s = parts[i]; if (i == parts.length - 1 && s.contains(":")) { //NOI18N String[] partAndPort = s.split(":"); //NOI18N if (partAndPort.length > 2) { problems.add (NbBundle.getMessage(ValidHostNameOrIPValidator.class, "TOO_MANY_COLONS", compName, model)); //NOI18N return; } if (partAndPort.length == 0) { //the string ":" problems.add (NbBundle.getMessage(ValidHostNameOrIPValidator.class, "INVALID_HOST_OR_IP", compName, model)); //NOI18N return; } s = partAndPort[0]; if (partAndPort.length == 2) { try { Integer.parseInt (partAndPort[1]); } catch (NumberFormatException nfe) { problems.add (NbBundle.getMessage(ValidHostNameOrIPValidator.class, "INVALID_PORT", compName, partAndPort[1])); //NOI18N return; } } } try { Integer.parseInt (s); hasIntParts = true; } catch (NumberFormatException nfe) { hasNonIntParts = true; } if (hasIntParts && hasNonIntParts) { problems.add(NbBundle.getMessage (ValidHostNameOrIPValidator.class, "ADDRESS_CONTAINS_INT_AND_NON_INT_LABELS", compName, model)); //NOI18N return; } } if(hasNonIntParts){ hostVal.validate(problems, compName, model); } else { assert hasIntParts; ipVal.validate(problems, compName, model); } } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/CharsetValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/CharsetValidato0000644000175000017500000000601111654612134033206 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class CharsetValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String model) { try { Charset.forName(model); } catch (IllegalCharsetNameException badName) { problems.add (NbBundle.getMessage(CharsetValidator.class, "ILLEGAL_CHARSET_NAME", compName, model)); //NOI18N } catch (UnsupportedCharsetException unsup) { problems.add (NbBundle.getMessage(CharsetValidator.class, "UNSUPPORTED_CHARSET_NAME", compName, model)); //NOI18N } } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/NotJavaIdentifierValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/NotJavaIdentifi0000644000175000017500000000541711654612134033160 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; import org.openide.util.Utilities; /** * * @author Tim Boudreau */ final class NotJavaIdentifierValidator extends StringValidator { public NotJavaIdentifierValidator() { } @Override public void validate(Problems problems, String compName, String text) { if (text.trim().length() == 0) { return; } if (!Utilities.isJavaIdentifier(text)) { problems.add(NbBundle.getMessage(NotJavaIdentifierValidator.class, "ERR_JAVA_IDENTIFIER", text)); } } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IsANumberValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IsANumberValida0000644000175000017500000000645711654612134033115 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.text.NumberFormat; import java.text.ParseException; import java.text.ParsePosition; import java.util.Locale; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class IsANumberValidator extends StringValidator { private Locale locale; IsANumberValidator() { this (null); } IsANumberValidator(Locale l) { this.locale = l; } @Override public void validate(Problems problems, String compName, String model) { ParsePosition p = new ParsePosition(0); NumberFormat.getNumberInstance(locale == null ? Locale.getDefault() : locale).parse(model, p); if (model.length() != p.getIndex() || p.getErrorIndex() != -1) { try { Double.valueOf(model); if (model.length() != model.trim().length()) { throw new NumberFormatException(); } } catch (NumberFormatException e) { problems.add(NbBundle.getMessage(IsANumberValidator.class, "NOT_A_NUMBER", model, compName)); //NOI18N } } } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle_de.propertieslibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle_de.prope0000644000175000017500000001177411654612134033152 0ustar tonytony# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common # Development and Distribution License("CDDL") (collectively, the # "License"). You may not use this file except in compliance with the # License. You can obtain a copy of the License at # http://www.netbeans.org/cddl-gplv2.html # or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the # specific language governing permissions and limitations under the # License. When distributing the software, include this License Header # Notice in each file and include the License file at # nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this # particular file as subject to the "Classpath" exception as provided # by Sun in the GPL Version 2 section of the License file that # accompanied this code. If applicable, add the following below the # License Header, with the fields enclosed by brackets [] replaced by # your own identifying information: # "Portions Copyrighted [year] [name of copyright owner]" # # Contributor(s): # # The Original Software is NetBeans. The Initial Developer of the Original # Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun # Microsystems, Inc. All Rights Reserved. # # If you wish your version of this file to be governed by only the CDDL # or only the GPL Version 2, indicate your decision by adding # "[Contributor] elects to include this software in this distribution # under the [CDDL or GPL Version 2] license." If you do not indicate a # single choice of license, a recipient has the option to distribute # your version of this file under either the CDDL, the GPL Version 2 or # to extend the choice of license to its licensees as provided above. # However, if you add GPL Version 2 code and therefore, elected the GPL # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. ERR_TEXTFIELD_EMPTY={0} darf nicht leer sein ERR_JAVA_IDENTIFIER={0} ist kein g\u00FCltiger Java Bezeichner ERR_INVALID_FILE_NAME={0} "{1}" enth\u00E4lt ung\u00FCltige Zeichen f\u00FCr einen Dateinamen ERR_NOT_INTEGER="{0}" ist keine g\u00FCltige ganze Zahl ERR_NEGATIVE_NUMBER={0} darf nicht negativ sein NOT_A_NUMBER="{0}" ist keine Zahl f\u00FCr {1} DISALLOWED_CHARS=Die Zeichen {0} sind nicht zul\u00E4ssig f\u00FCr {1} ODD_LENGTH_HEX=Hexadezimale Zahlen m\u00FCssen eine gerade Anzahl von Zeichen haben INVALID_HEX=Ung\u00FCltiges hexadezimales Zeichen "{0}" f\u00FCr {1} URL_NOT_VALID={0} ist keine g\u00FCltige URL FILE_DOES_NOT_EXIST={0} existiert nicht FILE_IS_NOT_A_DIRECTORY={0} ist kein Verzeichnis FILE_IS_NOT_A_FILE={0} ist keine Datei MAY_NOT_CONTAIN_WHITESPACE={0} Darf keine Leerzeichen enthalten MSG_MAY_NOT_BE_EMPTY={0} darf nicht leer sein ADDR_PART_BAD={0} ist keine ganze Zahl ADDR_PART_HIGH=IP-Bestandteile m\u00FCssen zwischen 0 und 256 liegen - {0} ist zu hoch ADDR_PART_NEGATIVE=IP Addressbestandteile d\u00FCrfen nicht negativ sein ({0}) NEGATIVE_PORT=Negative Portnummer {0} nicht zul\u00E4ssig PORT_TOO_HIGH=Portnummer ist zu hoch INVALID_PORT="{1}" ist keine g\u00FCltige Portnummer LABEL_TOO_LONG="{0}" ist ein zu langer Hostname NUMBER_PART_IN_HOSTNAME=Hostnamen d\u00FCrfen keine Zahlen enthalten: {0} BAD_CHAR_IN_HOSTNAME=Ung\u00FCltiges Zeichen {0} im Hostnamen (a-z,0-9 allowed) TOO_MANY_LABELS=Zu viele Teile in IP Addresse {0} MSG_DOES_NOT_MATCH_NUMBER_FORMAT=Ung\u00FCltiger Wert f\u00FCr {0}: ''{1}'' MSG_PORT_NOT_ALLOWED={0} darf keinen Port enthalten INVALID_HOST_NAME=Ung\u00FCltiger Hostname ''{1}'' ILLEGAL_CHARSET_NAME=Ung\u00FCltige Zeichenkodierung ''{1}'' UNSUPPORTED_CHARSET_NAME=Zeichenkodierung ''{1}'' wird nicht unterst\u00FCtzt INVALID_CHARACTER=Das Zeichen ''{1}'' in {0} ist nicht mit {2} kodierbar NOT_AN_EMAIL_ADDRESS=''{1}'' ist keine g\u00FCltige E-Mail Adresse EMAIL_MISSING_HOST=In {0} ist kein Zielrechner angegeben LABEL_EMPTY=Leerer Adressteil in {0} EMAIL_HAS_>1_@={0} enth\u00E4lt mehr als ein @ Zeichen HOST_STARTS_OR_ENDS_WITH_PERIOD=Hostname darf nicht mit einem . beginnen oder enden ADDRESS_CONTAINS_INT_AND_NON_INT_LABELS=Hostname ung\u00FCltig: {0} - Vermischung von Zahlen und Labels TOO_MANY_COLONS=Zu viele : in "{1}" INVALID_HOST_OR_IP={0} ist kein g\u00FCltiger Wert f\u00FCr einen Hostnamen oder eine IP Adresse: ''{1}'' EMAIL_MISSING_NAME=E-Mail Adresse enth\u00E4lt keinen Namen IP_ADDRESS_CONTAINS_WHITESPACE=IP Adresse {0} darf kein Leerzeichen enthalten HOST_MAY_NOT_CONTAIN_WHITESPACE=Hostname {0} darf kein Leerzeichen enthalten ADDRESS_MAY_BE_TOO_LONG=Namensanteil von {0} ist l\u00E4nger als 64 Zeichen - die meisten Mailserver akzeptieren dies nicht #Check - compliments of google translate VALUE_OUT_OF_RANGE={0} wird nicht zwischen {2} und {3}: {1} STRING_TOO_LONG={0} ist zu lang: {1} STRING_TOO_SHORT={0} muss mindestens {2} Zeichen lang sein: {1} FILE_EXISTS={0} vorhanden ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/EmailAddressValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/EmailAddressVal0000644000175000017500000001126411715053216033135 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Severity; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ class EmailAddressValidator extends StringValidator { private final Validator hv = new ValidHostNameOrIPValidator(false); private final Validator spv = new MayNotContainSpacesValidator(); private final Validator encv = new EncodableInCharsetValidator("US-ASCII"); static final Pattern ADDRESS_PATTERN = Pattern.compile("(.*?)<(.*)>$"); //NOI18N @Override public void validate(Problems problems, String compName, String model) { Matcher m = ADDRESS_PATTERN.matcher(model); String address; if (m.lookingAt()) { if (m.groupCount() == 2) { address = m.group(2); } else { address = m.group(1); } } else { address = model; } String[] nameAndHost = address.split("@"); if (nameAndHost.length == 0) { problems.add (NbBundle.getMessage(EmailAddressValidator.class, "NO_AT_SYMBOL", compName, address)); return; } if (nameAndHost.length == 1 && nameAndHost[0].contains("@")) { problems.add(NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_MISSING_HOST", compName, nameAndHost[0])); return; } if (nameAndHost.length > 2) { problems.add(NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_HAS_>1_@", compName, address)); return; } String name = nameAndHost[0]; if (name.length() == 0) { problems.add(NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_MISSING_NAME", compName, name)); return; } if (name.length() > 64) { problems.add(NbBundle.getMessage(EmailAddressValidator.class, "ADDRESS_MAY_BE_TOO_LONG", compName, name), Severity.WARNING); } String host = nameAndHost.length >= 2 ? nameAndHost[1] : null; if(host == null) { problems.add(NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_MISSING_HOST", compName, nameAndHost[0])); return; } hv.validate(problems, compName, host); spv.validate(problems, compName, name); encv.validate(problems, compName, address); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle_fr.propertieslibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/Bundle_fr.prope0000644000175000017500000001232011654612134033155 0ustar tonytony# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common # Development and Distribution License("CDDL") (collectively, the # "License"). You may not use this file except in compliance with the # License. You can obtain a copy of the License at # http://www.netbeans.org/cddl-gplv2.html # or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the # specific language governing permissions and limitations under the # License. When distributing the software, include this License Header # Notice in each file and include the License file at # nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this # particular file as subject to the "Classpath" exception as provided # by Sun in the GPL Version 2 section of the License file that # accompanied this code. If applicable, add the following below the # License Header, with the fields enclosed by brackets [] replaced by # your own identifying information: # "Portions Copyrighted [year] [name of copyright owner]" # # Contributor(s): Vergereau J\u00E9r\u00F4me # # The Original Software is NetBeans. The Initial Developer of the Original # Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun # Microsystems, Inc. All Rights Reserved. # # If you wish your version of this file to be governed by only the CDDL # or only the GPL Version 2, indicate your decision by adding # "[Contributor] elects to include this software in this distribution # under the [CDDL or GPL Version 2] license." If you do not indicate a # single choice of license, a recipient has the option to distribute # your version of this file under either the CDDL, the GPL Version 2 or # to extend the choice of license to its licensees as provided above. # However, if you add GPL Version 2 code and therefore, elected the GPL # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. ERR_TEXTFIELD_EMPTY={0} doit \u00EAtre rempli ERR_JAVA_IDENTIFIER={0} N''est pas un identifier Java ERR_INVALID_FILE_NAME={0} ''{1}'' contient des caract\u00E9res interdit pour un fichier ERR_NOT_INTEGER=''{0}'' n''est pas un entier ERR_NEGATIVE_NUMBER={0} ne doit pas \u00EAtre une valeur n\u00E9gative NOT_A_NUMBER="{0}" n''est pas un chiffre de {1} DISALLOWED_CHARS=Ce caract\u00E9re {0} n''est pas autoris\u00E9 dans {1} ODD_LENGTH_HEX=Les chiffres hexadecimal doivent avoir un certains nombre de caract\u00E9res INVALID_HEX=Caract\u00E9re hexadecimal non valide ''{0}'' in {1} URL_NOT_VALID=''{0}'' n'est pas une URL valide FILE_DOES_NOT_EXIST=''{0}'' n''existe pas FILE_IS_NOT_A_DIRECTORY=''{0}'' n''est pas un r\u00E9pertoire FILE_IS_NOT_A_FILE=''{0}'' n''est pas un fichier MAY_NOT_CONTAIN_WHITESPACE=''{0}'' ne doit pas contenir de caract\u00E9res espace MSG_MAY_NOT_BE_EMPTY={0} ne doit pas \u00EAtre vide ADDR_PART_BAD=''{0}'' n''est pas un entier ADDR_PART_HIGH=IP components doit \u00EAtre entre 0-256 - {0} trop grand ADDR_PART_NEGATIVE=IP components ne peut pas \u00EAtre une valeur n\u00E9gative ({0}) NEGATIVE_PORT=Num\u00E9ro de port n\u00E9gatif {0} non autoris\u00E9 PORT_TOO_HIGH=Num\u00E9ro de Port trop grand INVALID_PORT=''{1}'' n''est pas un num\u00E9ro de port valide LABEL_TOO_LONG=''{0}'' est trop long pour un intitul\u00E9 d''h\u00F4te NUMBER_PART_IN_HOSTNAME=Les noms d''h\u00F4te (hostnames) ne doivent pas contenir de chiffre: {0} BAD_CHAR_IN_HOSTNAME=Caract\u00E8re ill\u00E9gale ''{0}'' sur le nom d''h\u00F4te (hostname) TOO_MANY_LABELS=Trop de partie dans l''adresse IP ''{0}'' MAY_NOT_START_WITH_DIGIT={0} ne doit pas commencer par un digit MSG_DOES_NOT_MATCH_NUMBER_FORMAT=Valeur non valide pour {0}: ''{1}'' MSG_PORT_NOT_ALLOWED={0} ne doit pas sp\u00E9cifier de port INVALID_HOST_NAME=H\u00F4te(Host) non valide''{1}'' ILLEGAL_CHARSET_NAME=Caract\u00E9re d\u00E9finit non valide ''{1}'' UNSUPPORTED_CHARSET_NAME=Caract\u00E9re d\u00E9finit non support\u00E9 ''{1}'' INVALID_CHARACTER=Le caract\u00E8re ''{1}'' pour {0} n''est pas encodable en {2} NOT_AN_EMAIL_ADDRESS=''{1}'' n''est pas une adresse mail valide EMAIL_MISSING_HOST={0} ne sp\u00E9cifie pas un destinataire@@2 LABEL_EMPTY=Partie d''adresse vide pour {0} EMAIL_HAS_>1_@={0} contient plus d''un caract\u00E9re @ HOST_STARTS_OR_ENDS_WITH_PERIOD=L''h\u00F4te(host) ne doit pas commencer ou finir par . ADDRESS_CONTAINS_INT_AND_NON_INT_LABELS=H\u00F4te(host) ill\u00E9gale {0} - contient des chiffres et des lettres TOO_MANY_COLONS=Trop de :''s pour {0}: ''{1}'' INVALID_HOST_OR_IP={0} n''est pas une adresse IP ou un h\u00F4te(host) valide: ''{1}'' EMAIL_MISSING_NAME=La premi\u00E9re partie est manquante pour l''adresse mail IP_ADDRESS_CONTAINS_WHITESPACE=L''adresse IP {0} ne doit pas contenir d''espace HOST_MAY_NOT_CONTAIN_WHITESPACE=Le nom d''h\u00F4te(hostname) {0} ne doit pas contenir d''espace ADDRESS_MAY_BE_TOO_LONG=La premi\u00E9re partie de {0} est plus grand que 64 caract\u00E9res et \ ne fonctionnera pas sur la pluspart des serveurs mail VALUE_OUT_OF_RANGE={0} doit \u00EAtre entre {2} et {3}: {1} STRING_TOO_LONG={0} trop long: {1} STRING_TOO_SHORT={0} doit avoir au moins {2} caract\u00E9res : {0} FILE_EXISTS={0} existes ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IpAddressValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/IpAddressValida0000644000175000017500000001565411654612134033145 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class IpAddressValidator extends StringValidator { @Override public void validate(Problems problems, String compName, String s) { if (s.startsWith(".") || s.endsWith(".")) { //NOI18N problems.add(NbBundle.getMessage(IpAddressValidator.class, "HOST_STARTS_OR_ENDS_WITH_PERIOD", s)); //NOI18N return; } if (s.indexOf(" ") >= 0 || s.indexOf ("\t") >= 0) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "IP_ADDRESS_CONTAINS_WHITESPACE", compName, s)); //NOI18N return; } String[] parts = s.split("\\."); if (parts.length > 4) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "TOO_MANY_LABELS", s)); //NOI18N return; } if( parts.length < 3) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "ADDR_PART_BAD", s)); //NOI18N return; } for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (i == parts.length - 1 && part.indexOf(":") > 0) { //NOI18N if (part.endsWith(":")) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "TOO_MANY_COLONS", compName, s)); //NOI18N return; } String[] pts = part.split(":"); //NOI18N try { int addr = Integer.parseInt(pts[0]); if (addr < 0) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "ADDR_PART_NEGATIVE", pts[1])); //NOI18N return; } if (addr > 256) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "ADDR_PART_HIGH", pts[1])); //NOI18N return; } } catch (NumberFormatException e) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "ADDR_PART_BAD", pts.length >= 2 ? pts[1] : "''")); //NOI18N return; } if (pts.length == 2 && pts[1].length() == 0) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "INVALID_PORT", compName, "")); //NOI18N return; } if (pts.length == 1 ) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "INVALID_PORT", compName, "")); //NOI18N return; } if (pts.length > 1) { try { int port = Integer.parseInt(pts[1]); if (port < 0) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "NEGATIVE_PORT", pts[1])); //NOI18N return; } else if (port >= 65536) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "PORT_TOO_HIGH", pts[1])); //NOI18N return; } } catch (NumberFormatException e) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "INVALID_PORT", compName, pts[1])); //NOI18N return; } } } else { try { int addr = Integer.parseInt(part); if (addr < 0) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "ADDR_PART_NEGATIVE", part)); //NOI18N return; } if (addr > 256) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "ADDR_PART_HIGH", part)); //NOI18N return; } } catch (NumberFormatException e) { problems.add(NbBundle.getMessage(IpAddressValidator.class, "ADDR_PART_BAD", part)); //NOI18N return; } } } //for } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/FileValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/stringvalidation/FileValidator.j0000644000175000017500000000720311654612134033112 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.stringvalidation; import java.io.File; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Severity; import org.netbeans.validation.api.Validator; import org.openide.util.NbBundle; /** * * @author Tim Boudreau */ final class FileValidator extends StringValidator { private final Type type; FileValidator(Type type) { this.type = type; } @Override public void validate(Problems problems, String compName, String model) { File file = new File (model); String key; boolean ok; switch (type) { case MUST_EXIST : key = "FILE_DOES_NOT_EXIST"; //NOI18N ok = file.exists(); break; case MUST_BE_DIRECTORY : key = "FILE_IS_NOT_A_DIRECTORY"; //NOI18N ok = file.isDirectory(); break; case MUST_BE_FILE : key = "FILE_IS_NOT_A_FILE"; //NOI18N ok = file.isFile(); break; case MUST_NOT_EXIST : key = "FILE_EXISTS"; //NOI18N ok = !file.exists(); break; default : throw new AssertionError(); } if (!ok) { String problem = NbBundle.getMessage(FileValidator.class, key, file.getName()); problems.add(problem, Severity.FATAL); } } enum Type { MUST_EXIST, MUST_NOT_EXIST, MUST_BE_DIRECTORY, MUST_BE_FILE, } } libsimple-validation-java-.orig/org/netbeans/validation/api/builtin/indexvalidation/0000755000175000017500000000000011654612134030011 5ustar tonytony././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/indexvalidation/SelectionMustBeNonEmptyValidator.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/indexvalidation/SelectionMustBeN0000644000175000017500000000532511654612134033124 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.indexvalidation; import org.netbeans.validation.api.AbstractValidator; import org.netbeans.validation.api.Severity; import org.netbeans.validation.api.Problems; /** * * @author Hugo Heden */ final class SelectionMustBeNonEmptyValidator extends AbstractValidator { SelectionMustBeNonEmptyValidator() { super (Integer[].class); } @Override public void validate(Problems problems, String compName, Integer[] selectedItems) { if (selectedItems.length == 0) { String str = "Something must be selected"; problems.add(str, Severity.FATAL); } } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/indexvalidation/IndexValidators.javalibsimple-validation-java-.orig/org/netbeans/validation/api/builtin/indexvalidation/IndexValidators.0000644000175000017500000000621211654612134033113 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api.builtin.indexvalidation; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; /** * An enumeration of validator factories for commonly needed forms of * selection validaton. This is useful for validating the user selection in components * such as a {@code JList} or a number of {@code AbstractButtons}. * * @author Tim Boudreau, Hugo Heden */ public enum IndexValidators implements Validator { REQUIRE_SELECTION ; private Validator instantiate() { Validator result; switch (this) { case REQUIRE_SELECTION : result = new SelectionMustBeNonEmptyValidator(); break; default : throw new AssertionError(); } return result; } @Override public void validate (Problems problems, String compName, Integer[] model) { instantiate().validate(problems, compName, model); } public Class modelType() { return Integer[].class; } } libsimple-validation-java-.orig/org/netbeans/validation/api/error.png0000644000175000017500000000133211654612134025017 0ustar tonytonyPNG  IHDRagAMA7tEXtSoftwareAdobe ImageReadyqe<lIDATxb?2#$3.-qـ]P& ?b\Li)7!7`;LsC÷7o =g1pqp0p0 4 @͂1_lXX-_1~EXdA y:z>hqb"+W~~zm A@Ado7n0F_\od|oϟl+ `sD<<4÷o( @? a|,'4ϟ @p/`Ŀw-' << @L0/=`GW@L08P }&v0@Xgϯ_;XXXNc#/4Ƀԁԃ8%222rٱ-g Ph|O _^^@5os@@ h:,N(0s]c8wVf>bA3O^37j #zvyHiaA t_/*xHIENDB`libsimple-validation-java-.orig/org/netbeans/validation/api/ValidatorUtils.java0000644000175000017500000002432611654612134027001 0ustar tonytony/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.validation.api; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.netbeans.validation.api.conversion.Converter; /** * Some utilities for manipulating and creating new Validators, useful in many situations. * * @author Tim Boudreau */ public class ValidatorUtils { /** * Merge together a chain of validators (all working which work against the same * type), using logical {@code AND}. The resulting validator reports success if all the merged validators * report success. (If one or more of the merged validators report failure, the resulting * merged validator reports failure.) * * @param The type of model (Document, String, etc.) you want to * work with * @param validators A chain of validators which should be logically * AND'd together, merged into a single validator * @return a single validator which delegates to all of the passed ones */ public static Validator merge (Validator... validators) { if (validators == null) { throw new NullPointerException(); } if (validators.length == 1) { return validators[0]; } if (validators.length == 0) { throw new IllegalArgumentException ("Merging empty array of " + "validators"); } return new AndValidator(validators[0].modelType(), Arrays.asList(validators)); } /** * Merge together two validators (both of which work against the same type), using logical {@code AND}. * The resulting validator reports success if both the merged validators * report success. (If one or both of the merged validators report failure, the resulting * merged validator reports failure.) *

Unlike {@link #merge(Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to merge more than two validators, simply merge the result of merging two with the next one. * @param The type of model (Document, String, etc.) you want to * work with * @param validator1 one validator * @param validator2 another validator of the same type * @return a single validator which delegates to both of the passed ones */ public static Validator merge(Validator validator1, Validator validator2) { // XXX could check if one or both are instanceof AndValidator and unpack them, but probably overkill List> validators = new ArrayList>(2); validators.add(validator1); validators.add(validator2); return new AndValidator(validator1.modelType(), validators); } /** * Wrapper one or more validators in a validator which imposes a limit on * the severity of the validators in use. This means that while the * validators you pass in here will work normally, all Problems encountered * which are of greater severity than the maximum passed here will be reset * to the level you pass here. *

* This makes it possible to use validators from the StringValidators enum, which * mostly produce FATAL errors, for cases where only a warning or info message * is actually to be displayed. * @param The type * @param maximum * @param validators */ public static Validator limitSeverity (Severity maximum, Validator... validators) { assert maximum != null : "Maximum null"; assert validators != null : "Validators null"; assert validators.length > 0 : "Empty validators array"; return new CustomLevelValidator(maximum, merge(validators)); } /** * Wraps a validator in a validator which imposes a limit on the severity of the validator in use. * This means that while the * validator you pass in here will work normally, all Problems encountered * which are of greater severity than the maximum passed here will be reset * to the level you pass here. *

* This makes it possible to use validators from the StringValidators enum, which * mostly produce FATAL errors, for cases where only a warning or info message * is actually to be displayed. *

Unlike {@link #limitSeverity(Severity,Validator...)}, calling this method does not trigger warnings under {@code -Xlint:unchecked}. * If you wish to limit more than one validator, simply limit the result of {@link #merge(Validator,Validator)}. * @param The type * @param maximum * @param validator */ public static Validator limitSeverity(Severity maximum, Validator validator) { assert maximum != null : "Maximum null"; assert validator != null : "Validator null"; return new CustomLevelValidator(maximum, validator); } /** * Get a validator for a validator of a possibly unknown type. The resulting * validator simply uses other.modelType().cast(model) and passes it on; * this will result in a ClassCastException if the passed type argument is * not the same as or a subtype of the passed Validator's * modelType(). *

* This method exists principally to avoid compile-time warnings for cases * where a validator type is not actually known at compile time. Most * client code will use a specific type; this technique is mainly * used for cases of factories for validators against multiple types, * whose types cannot be determined at compile-time. *

* * @param The type parameter of the desired validator * @param The type of the actual validator * @param type The model type of the desired validator * @param other A validator whose type should be a supertype or the same as * the passed type argument * @return A validator of the desired type */ public static Validator cast (Class type, Validator other) { return new CastValidator (type, other); } /** * Will do the following: *