diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f069337..863c43f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,62 +6,19 @@
-
+
-
-
-
-
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
@@ -117,12 +74,96 @@
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -140,11 +181,6 @@
- addRow
- set
- print
- "
- fec
System
[2018] [Daniel Cortes]
id
@@ -170,6 +206,11 @@
editar
toggleSortOrder
Copyright (c) 2018 Daniel Cortes
+ JFormattedTextField(NumberFormat.getCurrencyInstance())
+ NumberFormat.getCurrencyInstance(Locale.forLanguageTag("CL"))
+ new JFormattedTextField()
+ DosMil
+ document
2018 Daniel Cortes
@@ -179,6 +220,8 @@
text
integer primary key
Copyright (c) 2018-2019 Daniel Cortes
+ JFormattedTextField(NumberFormat.getCurrencyInstance(Locale.forLanguageTag("CL")))
+ new JFormattedTextField(formatter)
$PROJECT_DIR$/src
@@ -190,9 +233,6 @@
@@ -295,6 +338,8 @@
+
+
@@ -305,14 +350,40 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
@@ -326,7 +397,7 @@
-
+
@@ -506,7 +577,12 @@
-
+
+
+
+
+
+
1545280618093
@@ -690,11 +766,25 @@
1546536860193
-
+
+ 1546540174373
+
+
+
+ 1546540174373
+
+
+ 1546540666662
+
+
+
+ 1546540666662
+
+
-
+
@@ -707,8 +797,9 @@
+
-
+
@@ -717,7 +808,7 @@
-
+
@@ -730,7 +821,7 @@
-
+
@@ -797,7 +888,6 @@
-
@@ -821,33 +911,22 @@
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -875,13 +954,6 @@
-
-
-
-
-
-
-
@@ -918,66 +990,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1006,16 +1024,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1026,134 +1034,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1209,36 +1089,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1297,8 +1147,315 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dist/caja.jar b/dist/caja.jar
index 2c225db..f07f07a 100644
Binary files a/dist/caja.jar and b/dist/caja.jar differ
diff --git a/dist/database.sqlite b/dist/database.sqlite
index f3a435e..4c5d85d 100644
Binary files a/dist/database.sqlite and b/dist/database.sqlite differ
diff --git a/src/danielcortes/xyz/controllers/ArqueoController.java b/src/danielcortes/xyz/controllers/ArqueoController.java
index 77f1f16..97feebb 100644
--- a/src/danielcortes/xyz/controllers/ArqueoController.java
+++ b/src/danielcortes/xyz/controllers/ArqueoController.java
@@ -90,15 +90,15 @@ public class ArqueoController {
*/
private void fillEfectivo() {
this.efectivo = this.efectivoDAO.findByCaja(this.caja);
- this.view.getVeinteMilField().setText(String.valueOf(efectivo.getVeinteMil()));
- this.view.getDiezMilField().setText(String.valueOf(efectivo.getDiezMil()));
- this.view.getCincoMilField().setText(String.valueOf(efectivo.getCincoMil()));
- this.view.getDosMilField().setText(String.valueOf(efectivo.getDosMil()));
- this.view.getMilField().setText(String.valueOf(efectivo.getMil()));
- this.view.getQuinientosField().setText(String.valueOf(efectivo.getQuinientos()));
- this.view.getCienField().setText(String.valueOf(efectivo.getCien()));
- this.view.getCincuentaField().setText(String.valueOf(efectivo.getCincuenta()));
- this.view.getDiezField().setText(String.valueOf(efectivo.getDiez()));
+ this.view.getVeinteMilField().setValue(efectivo.getVeinteMil());
+ this.view.getDiezMilField().setValue(efectivo.getDiezMil());
+ this.view.getCincoMilField().setValue(efectivo.getCincoMil());
+ this.view.getDosMilField().setValue(efectivo.getDosMil());
+ this.view.getMilField().setValue(efectivo.getMil());
+ this.view.getQuinientosField().setValue(efectivo.getQuinientos());
+ this.view.getCienField().setValue(efectivo.getCien());
+ this.view.getCincuentaField().setValue(efectivo.getCincuenta());
+ this.view.getDiezField().setValue(efectivo.getDiez());
}
/**
@@ -252,31 +252,31 @@ public class ArqueoController {
* llama a updateResumenEfectivo y updateResumenArqueo para actualizar los datos en efectivoField y arqueoField
*/
private void guardarEfectivo() {
- String diez = this.view.getDiezField().getText();
- String cincuenta = this.view.getCincuentaField().getText();
- String cien = this.view.getCienField().getText();
- String quinientos = this.view.getQuinientosField().getText();
- String mil = this.view.getMilField().getText();
- String dosMil = this.view.getDosMilField().getText();
- String cincoMil = this.view.getCincoMilField().getText();
- String diezMil = this.view.getDiezMilField().getText();
- String veinteMil = this.view.getVeinteMilField().getText();
+ int diez = (Integer) this.view.getDiezField().getValue();
+ int cincuenta = (Integer) this.view.getCincuentaField().getValue();
+ int cien = (Integer) this.view.getCienField().getValue();
+ int quinientos = (Integer) this.view.getQuinientosField().getValue();
+ int mil = (Integer) this.view.getMilField().getValue();
+ int dosMil = (Integer) this.view.getDosMilField().getValue();
+ int cincoMil = (Integer) this.view.getCincoMilField().getValue();
+ int diezMil = (Integer) this.view.getDiezMilField().getValue();
+ int veinteMil = (Integer) this.view.getVeinteMilField().getValue();
- if (this.validateEfectivoInput(diez, cincuenta, cien, quinientos, mil, dosMil, cincoMil, diezMil, veinteMil)) {
- this.efectivo.setDiez(Integer.valueOf(diez));
- this.efectivo.setCincuenta(Integer.valueOf(cincuenta));
- this.efectivo.setCien(Integer.valueOf(cien));
- this.efectivo.setQuinientos(Integer.valueOf(quinientos));
- this.efectivo.setMil(Integer.valueOf(mil));
- this.efectivo.setDosMil(Integer.valueOf(dosMil));
- this.efectivo.setCincoMil(Integer.valueOf(cincoMil));
- this.efectivo.setDiezMil(Integer.valueOf(diezMil));
- this.efectivo.setVeinteMil(Integer.valueOf(veinteMil));
+ //if (this.validateEfectivoInput(diez, cincuenta, cien, quinientos, mil, dosMil, cincoMil, diezMil, veinteMil)) {
+ this.efectivo.setDiez(diez);
+ this.efectivo.setCincuenta(cincuenta);
+ this.efectivo.setCien(cien);
+ this.efectivo.setQuinientos(quinientos);
+ this.efectivo.setMil(mil);
+ this.efectivo.setDosMil(dosMil);
+ this.efectivo.setCincoMil(cincoMil);
+ this.efectivo.setDiezMil(diezMil);
+ this.efectivo.setVeinteMil(veinteMil);
this.efectivoDAO.updateEfectivo(efectivo);
this.updateResumenEfectivo();
this.updateResumenArqueo();
- }
+ //}
}
/**
diff --git a/src/danielcortes/xyz/views/ArqueoView.form b/src/danielcortes/xyz/views/ArqueoView.form
index 25e8ce3..11281ed 100644
--- a/src/danielcortes/xyz/views/ArqueoView.form
+++ b/src/danielcortes/xyz/views/ArqueoView.form
@@ -188,14 +188,14 @@
-
+
-
+
@@ -206,24 +206,24 @@
-
+
-
+
-
+
-
+
@@ -242,24 +242,24 @@
-
+
-
+
-
+
-
+
@@ -278,14 +278,14 @@
-
+
-
+
@@ -296,14 +296,14 @@
-
+
-
+
@@ -314,14 +314,14 @@
-
+
-
+
@@ -332,14 +332,14 @@
-
+
-
+
diff --git a/src/danielcortes/xyz/views/ArqueoView.java b/src/danielcortes/xyz/views/ArqueoView.java
index 9dd3f96..c995afb 100644
--- a/src/danielcortes/xyz/views/ArqueoView.java
+++ b/src/danielcortes/xyz/views/ArqueoView.java
@@ -28,22 +28,26 @@ package danielcortes.xyz.views;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
+import danielcortes.xyz.views.components.LimitDocumentFilter;
+import danielcortes.xyz.views.components.NumberFormatFactory;
import javax.swing.*;
import javax.swing.border.TitledBorder;
+import javax.swing.text.AbstractDocument;
import java.awt.*;
+import java.util.ArrayList;
public class ArqueoView {
private JPanel contentPanel;
- private JTextField veinteMilField;
- private JTextField diezMilField;
- private JTextField cincoMilField;
- private JTextField dosMilField;
- private JTextField milField;
- private JTextField quinientosField;
- private JTextField cienField;
- private JTextField cincuentaField;
- private JTextField diezField;
+ private JFormattedTextField veinteMilField;
+ private JFormattedTextField diezMilField;
+ private JFormattedTextField cincoMilField;
+ private JFormattedTextField dosMilField;
+ private JFormattedTextField milField;
+ private JFormattedTextField quinientosField;
+ private JFormattedTextField cienField;
+ private JFormattedTextField cincuentaField;
+ private JFormattedTextField diezField;
private JTextField chequesField;
private JTextField tarjetasField;
private JTextField efectivoField;
@@ -67,43 +71,62 @@ public class ArqueoView {
private JTextField diferenciaField;
private JTextField debeRendirField;
+ private ArrayList efectivoFieldList;
+
+ public ArqueoView() {
+ $$$setupUI$$$();
+
+ this.efectivoFieldList = new ArrayList<>();
+ this.efectivoFieldList.add(this.veinteMilField);
+ this.efectivoFieldList.add(this.diezMilField);
+ this.efectivoFieldList.add(this.cincoMilField);
+ this.efectivoFieldList.add(this.dosMilField);
+ this.efectivoFieldList.add(this.milField);
+ this.efectivoFieldList.add(this.quinientosField);
+ this.efectivoFieldList.add(this.cienField);
+ this.efectivoFieldList.add(this.cincuentaField);
+ this.efectivoFieldList.add(this.diezField);
+
+ this.setupFields();
+ }
+
public JPanel getContentPanel() {
return contentPanel;
}
- public JTextField getVeinteMilField() {
+ public JFormattedTextField getVeinteMilField() {
return veinteMilField;
}
- public JTextField getDiezMilField() {
+ public JFormattedTextField getDiezMilField() {
return diezMilField;
}
- public JTextField getCincoMilField() {
+ public JFormattedTextField getCincoMilField() {
return cincoMilField;
}
- public JTextField getDosMilField() {
+ public JFormattedTextField getDosMilField() {
return dosMilField;
}
- public JTextField getMilField() {
+ public JFormattedTextField getMilField() {
return milField;
}
- public JTextField getQuinientosField() {
+ public JFormattedTextField getQuinientosField() {
return quinientosField;
}
- public JTextField getCienField() {
+ public JFormattedTextField getCienField() {
return cienField;
}
- public JTextField getCincuentaField() {
+ public JFormattedTextField getCincuentaField() {
return cincuentaField;
}
- public JTextField getDiezField() {
+ public JFormattedTextField getDiezField() {
return diezField;
}
@@ -195,13 +218,6 @@ public class ArqueoView {
return errorTarjetas;
}
- {
-// GUI initializer generated by IntelliJ IDEA GUI Designer
-// >>> IMPORTANT!! <<<
-// DO NOT EDIT OR ADD ANY CODE HERE!
- $$$setupUI$$$();
- }
-
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
@@ -283,17 +299,17 @@ public class ArqueoView {
final JLabel label8 = new JLabel();
label8.setText("$20000");
panel3.add(label8, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- veinteMilField = new JTextField();
- veinteMilField.setText("0");
+ veinteMilField = new JFormattedTextField();
+ veinteMilField.setText("");
panel3.add(veinteMilField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
final JLabel label9 = new JLabel();
label9.setText("$10000");
panel3.add(label9, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- diezMilField = new JTextField();
- diezMilField.setText("0");
+ diezMilField = new JFormattedTextField();
+ diezMilField.setText("");
panel3.add(diezMilField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
- cincoMilField = new JTextField();
- cincoMilField.setText("0");
+ cincoMilField = new JFormattedTextField();
+ cincoMilField.setText("");
panel3.add(cincoMilField, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
final JLabel label10 = new JLabel();
label10.setText("$5000");
@@ -301,11 +317,11 @@ public class ArqueoView {
final JLabel label11 = new JLabel();
label11.setText("$2000");
panel3.add(label11, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- dosMilField = new JTextField();
- dosMilField.setText("0");
+ dosMilField = new JFormattedTextField();
+ dosMilField.setText("");
panel3.add(dosMilField, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
- milField = new JTextField();
- milField.setText("0");
+ milField = new JFormattedTextField();
+ milField.setText("");
panel3.add(milField, new GridConstraints(8, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
final JLabel label12 = new JLabel();
label12.setText("$1000");
@@ -313,26 +329,26 @@ public class ArqueoView {
final JLabel label13 = new JLabel();
label13.setText("$500");
panel3.add(label13, new GridConstraints(10, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- quinientosField = new JTextField();
- quinientosField.setText("0");
+ quinientosField = new JFormattedTextField();
+ quinientosField.setText("");
panel3.add(quinientosField, new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
final JLabel label14 = new JLabel();
label14.setText("$100");
panel3.add(label14, new GridConstraints(12, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- cienField = new JTextField();
- cienField.setText("0");
+ cienField = new JFormattedTextField();
+ cienField.setText("");
panel3.add(cienField, new GridConstraints(12, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
final JLabel label15 = new JLabel();
label15.setText("$50");
panel3.add(label15, new GridConstraints(14, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- cincuentaField = new JTextField();
- cincuentaField.setText("0");
+ cincuentaField = new JFormattedTextField();
+ cincuentaField.setText("");
panel3.add(cincuentaField, new GridConstraints(14, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
final JLabel label16 = new JLabel();
label16.setText("$10");
panel3.add(label16, new GridConstraints(16, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- diezField = new JTextField();
- diezField.setText("0");
+ diezField = new JFormattedTextField();
+ diezField.setText("");
panel3.add(diezField, new GridConstraints(16, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
guardarEfectivoButton = new JButton();
guardarEfectivoButton.setText("Guardar");
@@ -441,4 +457,10 @@ public class ArqueoView {
return contentPanel;
}
+ private void setupFields() {
+ for (JFormattedTextField formattedTextField : this.efectivoFieldList) {
+ formattedTextField.setFormatterFactory(new NumberFormatFactory());
+ ((AbstractDocument) formattedTextField.getDocument()).setDocumentFilter(new LimitDocumentFilter(9));
+ }
+ }
}
diff --git a/src/danielcortes/xyz/views/components/LimitDocumentFilter.java b/src/danielcortes/xyz/views/components/LimitDocumentFilter.java
new file mode 100644
index 0000000..4752e18
--- /dev/null
+++ b/src/danielcortes/xyz/views/components/LimitDocumentFilter.java
@@ -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);
+ }
+ }
+
+}
diff --git a/src/danielcortes/xyz/views/components/NumberFormatFactory.java b/src/danielcortes/xyz/views/components/NumberFormatFactory.java
new file mode 100644
index 0000000..4c4098b
--- /dev/null
+++ b/src/danielcortes/xyz/views/components/NumberFormatFactory.java
@@ -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);
+ }
+}