Cambiados fields de efectivo por JFormattedtextfields y son formateados como numeros
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018-2019 Daniel Cortes
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.views.components;
|
||||
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.DocumentFilter;
|
||||
|
||||
public class LimitDocumentFilter extends DocumentFilter {
|
||||
|
||||
private int limit;
|
||||
|
||||
public LimitDocumentFilter(int limit) {
|
||||
if (limit <= 0) {
|
||||
throw new IllegalArgumentException("Limit can not be <= 0");
|
||||
}
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
|
||||
int currentLength = fb.getDocument().getLength();
|
||||
int overLimit = (currentLength + text.length()) - limit - length;
|
||||
if (overLimit > 0) {
|
||||
text = text.substring(0, text.length() - overLimit);
|
||||
}
|
||||
if (text.length() > 0) {
|
||||
super.replace(fb, offset, length, text, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018-2019 Daniel Cortes
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.views.components;
|
||||
|
||||
import javax.swing.text.DefaultFormatterFactory;
|
||||
import javax.swing.text.NumberFormatter;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class NumberFormatFactory extends DefaultFormatterFactory {
|
||||
public NumberFormatFactory() {
|
||||
super();
|
||||
NumberFormat pnDisplayFormat = NumberFormat.getIntegerInstance();
|
||||
pnDisplayFormat.setMinimumIntegerDigits(1);
|
||||
pnDisplayFormat.setMaximumIntegerDigits(9);
|
||||
NumberFormatter displayFormatter = new NumberFormatter(pnDisplayFormat);
|
||||
displayFormatter.setValueClass(Integer.class);
|
||||
|
||||
NumberFormat pnEditFormat = NumberFormat.getIntegerInstance();
|
||||
pnEditFormat.setMinimumIntegerDigits(1);
|
||||
pnEditFormat.setMaximumIntegerDigits(9);
|
||||
|
||||
NumberFormatter editFormatter = new NumberFormatter(pnEditFormat);
|
||||
editFormatter.setValueClass(Integer.class);
|
||||
|
||||
this.setDefaultFormatter(displayFormatter);
|
||||
this.setDisplayFormatter(displayFormatter);
|
||||
this.setEditFormatter(editFormatter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user