diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..d42ec40
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+ Builds, tests, and runs the project hexeditorcomponent.
+
+
+
diff --git a/manifest.mf b/manifest.mf
new file mode 100644
index 0000000..328e8e5
--- /dev/null
+++ b/manifest.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+X-COMMENT: Main-Class will be added automatically by build
+
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
new file mode 100644
index 0000000..af73351
--- /dev/null
+++ b/nbproject/build-impl.xml
@@ -0,0 +1,1771 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set src.dir
+ Must set test.src.dir
+ Must set build.dir
+ Must set dist.dir
+ Must set build.classes.dir
+ Must set dist.javadoc.dir
+ Must set build.test.classes.dir
+ Must set build.test.results.dir
+ Must set build.classes.excludes
+ Must set dist.jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No tests executed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set JVM to use for profiling in profiler.info.jvm
+ Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To run this application from the command line without Ant, try:
+
+ java -jar "${dist.jar.resolved}"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must set fix.includes
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set profile.class
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+ Some tests failed; see details above.
+
+
+
+ Must select some files in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+ Must select one file in the IDE or set test.class
+
+
+
+ Must select one file in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
new file mode 100644
index 0000000..acd31bd
--- /dev/null
+++ b/nbproject/genfiles.properties
@@ -0,0 +1,8 @@
+build.xml.data.CRC32=bf95bee6
+build.xml.script.CRC32=b5c25125
+build.xml.stylesheet.CRC32=f85dc8f2@1.117.0.48
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=bf95bee6
+nbproject/build-impl.xml.script.CRC32=2e76ecbc
+nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.117.0.48
diff --git a/nbproject/project.properties b/nbproject/project.properties
new file mode 100644
index 0000000..408a808
--- /dev/null
+++ b/nbproject/project.properties
@@ -0,0 +1,95 @@
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processor.options=
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.modulepath=\
+ ${run.modulepath}
+debug.test.classpath=\
+ ${run.test.classpath}
+debug.test.modulepath=\
+ ${run.test.modulepath}
+# Files in build.classes.dir which should be excluded from distribution jar
+dist.archive.excludes=
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/hexeditorcomponent.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+dist.jlink.dir=${dist.dir}/jlink
+dist.jlink.output=${dist.jlink.dir}/hexeditorcomponent
+excludes=
+includes=**
+jar.compress=false
+javac.classpath=
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.external.vm=true
+javac.modulepath=
+javac.processormodulepath=
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=21
+javac.target=21
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+javac.test.modulepath=\
+ ${javac.modulepath}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.html5=false
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+# The jlink additional root modules to resolve
+jlink.additionalmodules=
+# The jlink additional command line parameters
+jlink.additionalparam=
+jlink.launcher=true
+jlink.launcher.name=hexeditorcomponent
+main.class=hexeditorcomponent.Hexeditorcomponent
+manifest.file=manifest.mf
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=false
+platform.active=default_platform
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project.
+# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
+# To set system properties for unit tests define test-sys-prop.name=value:
+run.jvmargs=
+run.modulepath=\
+ ${javac.modulepath}
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+run.test.modulepath=\
+ ${javac.test.modulepath}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
diff --git a/nbproject/project.xml b/nbproject/project.xml
new file mode 100644
index 0000000..c5f9079
--- /dev/null
+++ b/nbproject/project.xml
@@ -0,0 +1,15 @@
+
+
+ org.netbeans.modules.java.j2seproject
+
+
+ hexeditorcomponent
+
+
+
+
+
+
+
+
+
diff --git a/src/hexeditorcomponent/HexTextBoxPanel.java b/src/hexeditorcomponent/HexTextBoxPanel.java
index 92d775e..f8c9aa3 100644
--- a/src/hexeditorcomponent/HexTextBoxPanel.java
+++ b/src/hexeditorcomponent/HexTextBoxPanel.java
@@ -22,12 +22,15 @@ public class HexTextBoxPanel extends JPanel {
private List hexFields = new ArrayList<>();
private JTextField asciiField;
+// private double fontSize = 12f; // dimensione di default
private int numBytes = 8;
private Color hexFieldBackground = Color.WHITE;
+ private byte[] xByte;
private boolean updatingFromAscii = false; // evita loop
- // ---------------- COSTRUTTORE ----------------
+ // ---------------- COSTRUTTORI ----------------
+
public HexTextBoxPanel() {
initComponent();
}
@@ -38,135 +41,253 @@ public class HexTextBoxPanel extends JPanel {
}
// ---------------- INIZIALIZZAZIONE COMPONENTI ----------------
- private void initComponent() {
- removeAll();
- hexFields.clear();
+ private void initComponent() {
+
+ removeAll();
+
+ if (xByte == null) {
+ xByte = new byte[numBytes];
+ } else if (xByte.length != numBytes) {
+ byte[] tmp = new byte[numBytes];
+ System.arraycopy(
+ xByte, 0,
+ tmp, 0,
+ Math.min(xByte.length, numBytes)
+ );
+ xByte = tmp;
+ }
+
+ hexFields.clear();
setLayout(new FlowLayout(FlowLayout.LEFT));
// Textbox per ogni byte
for (int i = 0; i < numBytes; i++) {
+
JTextField tf = new JTextField(2);
tf.setDocument(new HexDocument());
tf.setHorizontalAlignment(JTextField.CENTER);
tf.setBackground(hexFieldBackground);
+ tf.setText(String.format("%02X", xByte[i] & 0xFF));
- tf.setText("00");
tf.addFocusListener(new java.awt.event.FocusAdapter() {
+
@Override
public void focusLost(java.awt.event.FocusEvent e) {
String text = tf.getText();
+
if (text.length() == 1) {
tf.setText("0" + text.toUpperCase());
}
+
if (text.length() < 1) {
tf.setText("00");
}
}
+
@Override
- public void focusGained (java.awt.event.FocusEvent e) {
+ public void focusGained(java.awt.event.FocusEvent e) {
tf.selectAll();
}
});
- tf.getDocument().addDocumentListener(new SimpleDocumentListener() {
- @Override
- public void update() {
- if (!updatingFromAscii) {
- updateAsciiField();
+
+ tf.getDocument().addDocumentListener(
+ new SimpleDocumentListener() {
+ @Override
+ public void update() {
+ if (!updatingFromAscii) {
+ updateAsciiField();
+ }
+ }
}
- }
- });
+ );
+
hexFields.add(tf);
add(tf);
}
// Textbox ASCII bidirezionale
asciiField = new JTextField(numBytes);
- asciiField.setDocument(new FixedLengthDocument(numBytes));
- asciiField.setFont(new Font("Monospaced", Font.PLAIN, 12));
- asciiField.setEditable(true);
+asciiField.setDocument(new FixedLengthDocument(numBytes));
+asciiField.setEditable(true);
+asciiField.setHorizontalAlignment(JTextField.CENTER);
+asciiField.setMargin(new Insets(0,0,0,0));
- asciiField.getDocument().addDocumentListener(new SimpleDocumentListener() {
- @Override
- public void update() {
- updateHexFieldsFromAscii();
- }
- });
+//Font mono = new Font("Monospaced", Font.PLAIN, (int) Math.round(fontSize));
+//asciiField.setFont(mono);
- add(asciiField);
+//FontMetrics fm = asciiField.getFontMetrics(mono);
+//asciiField.setPreferredSize(new Dimension(fm.charWidth('M') * numBytes, fm.getHeight()));
+
+asciiField.getDocument().addDocumentListener(new SimpleDocumentListener() {
+ @Override
+ public void update() {
+ updateHexFieldsFromAscii();
+ }
+});
+
+add(asciiField);
updateAsciiField();
revalidate();
repaint();
}
- // ---------------- AGGIORNA ASCII DAI BYTE ----------------
- private void updateAsciiField() {
- StringBuilder sb = new StringBuilder();
+ // ---------------- FONT SIZE ----------------
- for (JTextField tf : hexFields) {
- String hex = tf.getText();
+// public double getFontSize() {
+// return fontSize;
+// }
+// ---------------- FONT ----------------
- if (hex.length() == 2) {
- try {
- int val = Integer.parseInt(hex, 16);
+@Override
+public void setFont(Font font) {
+ super.setFont(font);
- // ASCII stampabile
- if (val >= 32 && val <= 126) {
- sb.append((char) val);
- } else {
- sb.append('.');
- }
-
- } catch (NumberFormatException ignored) {
- sb.append('.');
- }
- } else {
- sb.append('.');
+ if (hexFields != null) {
+ for (JTextField tf : hexFields) {
+ tf.setFont(font);
}
}
- updatingFromAscii = true;
- asciiField.setText(sb.toString());
- updatingFromAscii = false;
+ if (asciiField != null) {
+ asciiField.setFont(font);
+ }
}
+@Override
+public void updateUI() {
+ super.updateUI();
+
+ Font font = getFont();
+ if (font == null || hexFields == null) return;
+
+ for (JTextField tf : hexFields) {
+ tf.setFont(font);
+ }
+
+ if (asciiField != null) {
+ asciiField.setFont(font);
+ }
+}
+
+// private void updateFontSize() {
+//
+// Font newFont = new Font(
+// "Monospaced",
+// Font.PLAIN,
+// (int) Math.round(fontSize)
+// );
+//
+// for (JTextField tf : hexFields) {
+// tf.setFont(newFont);
+// tf.setPreferredSize(null); // importantissimo
+// }
+//
+// if (asciiField != null) {
+// asciiField.setFont(newFont);
+// asciiField.setPreferredSize(null);
+// }
+//
+// revalidate();
+// repaint();
+// }
+
+ // ---------------- AGGIORNA ASCII DAI BYTE ----------------
+
+ private void updateAsciiField() {
+
+ StringBuilder sb = new StringBuilder();
+
+ for (JTextField tf : hexFields) {
+
+ String hex = tf.getText();
+
+ if (hex.length() == 2) {
+ try {
+ int val = Integer.parseInt(hex, 16);
+
+ if (val >= 32 && val <= 126) {
+ sb.append((char) val);
+ } else {
+ sb.append('.');
+ }
+
+ } catch (NumberFormatException ignored) {
+ sb.append('.');
+ }
+ } else {
+ sb.append('.');
+ }
+ }
+
+ updatingFromAscii = true;
+ asciiField.setText(sb.toString());
+ updatingFromAscii = false;
+ }
+
+ // ---------------- GET / SET BYTES ----------------
+
public byte[] getBytes() {
+
byte[] data = new byte[hexFields.size()];
for (int i = 0; i < hexFields.size(); i++) {
+
JTextField tf = hexFields.get(i);
String hex = tf.getText();
try {
data[i] = (byte) Integer.parseInt(hex, 16);
} catch (NumberFormatException e) {
- data[i] = 0; // se il campo non è valido, restituisci 0
+ data[i] = 0;
}
}
return data;
}
- public void setBytes(byte[] data) {
- int len = Math.min(data.length, hexFields.size());
- for (int i = 0; i < len; i++) {
- hexFields.get(i).setText(String.format("%02X", data[i]));
- }
- }
- public void clear(){
+ public void setBytes(byte[] data) {
+
+ if (data == null) return;
+
+ xByte = new byte[numBytes];
+
+ System.arraycopy(
+ data, 0,
+ xByte, 0,
+ Math.min(data.length, numBytes)
+ );
+
for (int i = 0; i < hexFields.size(); i++) {
- hexFields.get(i).setText("00");
+ hexFields.get(i)
+ .setText(String.format("%02X", xByte[i] & 0xFF));
+ }
+
+ updateAsciiField();
+ }
+
+ public void clear() {
+
+ for (int i = 0; i < hexFields.size(); i++) {
+ hexFields.get(i)
+ .setText(String.format("%02X", xByte[i]));
}
}
+
// ---------------- AGGIORNA BYTE DALL'ASCII ----------------
+
private void updateHexFieldsFromAscii() {
+
if (updatingFromAscii) return;
updatingFromAscii = true;
+
String text = asciiField.getText();
for (int i = 0; i < hexFields.size(); i++) {
+
JTextField tf = hexFields.get(i);
+
if (i < text.length()) {
int val = (int) text.charAt(i);
tf.setText(String.format("%02X", val));
@@ -174,16 +295,20 @@ public class HexTextBoxPanel extends JPanel {
tf.setText("00");
}
}
+
updatingFromAscii = false;
}
// ---------------- PROPRIETÀ GUI BUILDER ----------------
+
public int getNumBytes() {
return numBytes;
}
public void setNumBytes(int numBytes) {
+
if (numBytes <= 0) return;
+
this.numBytes = numBytes;
initComponent();
}
@@ -193,58 +318,88 @@ public class HexTextBoxPanel extends JPanel {
}
public void setHexFieldBackground(Color hexFieldBackground) {
+
this.hexFieldBackground = hexFieldBackground;
+
for (JTextField tf : hexFields) {
tf.setBackground(hexFieldBackground);
}
+
repaint();
}
-private static class FixedLengthDocument extends PlainDocument {
- private final int maxLength;
+ // ---------------- DOCUMENT ASCII LUNGHEZZA FISSA ----------------
- public FixedLengthDocument(int maxLength) {
- this.maxLength = maxLength;
- }
+ private static class FixedLengthDocument extends PlainDocument {
- @Override
- public void insertString(int offs, String str, AttributeSet a)
- throws BadLocationException {
+ private final int maxLength;
- if (str == null) return;
+ public FixedLengthDocument(int maxLength) {
+ this.maxLength = maxLength;
+ }
- if ((getLength() + str.length()) <= maxLength) {
- super.insertString(offs, str, a);
+ @Override
+ public void insertString(int offs, String str, AttributeSet a)
+ throws BadLocationException {
+
+ if (str == null) return;
+
+ if ((getLength() + str.length()) <= maxLength) {
+ super.insertString(offs, str, a);
+ }
}
}
-}
- // ---------------- DOCUMENT PER VALIDAZIONE HEX ----------------
+
+ // ---------------- DOCUMENT VALIDAZIONE HEX ----------------
+
private static class HexDocument extends PlainDocument {
+
@Override
- public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
+ public void insertString(int offs, String str, AttributeSet a)
+ throws BadLocationException {
+
if (str == null) return;
str = str.toUpperCase();
StringBuilder filtered = new StringBuilder();
+
for (char c : str.toCharArray()) {
- if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
+ if ((c >= '0' && c <= '9') ||
+ (c >= 'A' && c <= 'F')) {
filtered.append(c);
}
}
if ((getLength() + filtered.length()) <= 2) {
- super.insertString(offs, filtered.toString(), a);
+ super.insertString(
+ offs,
+ filtered.toString(),
+ a
+ );
}
}
}
// ---------------- DOCUMENT LISTENER SEMPLIFICATO ----------------
- private abstract static class SimpleDocumentListener implements javax.swing.event.DocumentListener {
- public abstract void update();
- @Override public void insertUpdate(javax.swing.event.DocumentEvent e) { update(); }
- @Override public void removeUpdate(javax.swing.event.DocumentEvent e) { update(); }
- @Override public void changedUpdate(javax.swing.event.DocumentEvent e) { update(); }
- }
-
+ private abstract static class SimpleDocumentListener
+ implements javax.swing.event.DocumentListener {
+
+ public abstract void update();
+
+ @Override
+ public void insertUpdate(javax.swing.event.DocumentEvent e) {
+ update();
+ }
+
+ @Override
+ public void removeUpdate(javax.swing.event.DocumentEvent e) {
+ update();
+ }
+
+ @Override
+ public void changedUpdate(javax.swing.event.DocumentEvent e) {
+ update();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/hexeditorcomponent/HexTextBoxPanelBeanInfo.java b/src/hexeditorcomponent/HexTextBoxPanelBeanInfo.java
new file mode 100644
index 0000000..7fd85bc
--- /dev/null
+++ b/src/hexeditorcomponent/HexTextBoxPanelBeanInfo.java
@@ -0,0 +1,34 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package hexeditorcomponent;
+
+/**
+ *
+ * @author mstc
+ */
+import java.awt.Image;
+import static java.beans.BeanInfo.ICON_COLOR_16x16;
+import static java.beans.BeanInfo.ICON_COLOR_32x32;
+import java.beans.SimpleBeanInfo;
+import javax.swing.ImageIcon;
+
+public class HexTextBoxPanelBeanInfo extends SimpleBeanInfo {
+
+ @Override
+ public Image getIcon(int iconKind) {
+ switch (iconKind) {
+ case ICON_COLOR_16x16:
+ return new ImageIcon(
+ getClass().getResource("hex16.png")
+ ).getImage();
+ case ICON_COLOR_32x32:
+ return new ImageIcon(
+ getClass().getResource("hex32.png")
+ ).getImage();
+ default:
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/hexeditorcomponent/hex16.png b/src/hexeditorcomponent/hex16.png
new file mode 100644
index 0000000..e44d41c
Binary files /dev/null and b/src/hexeditorcomponent/hex16.png differ
diff --git a/src/hexeditorcomponent/hex32.png b/src/hexeditorcomponent/hex32.png
new file mode 100644
index 0000000..4e5b429
Binary files /dev/null and b/src/hexeditorcomponent/hex32.png differ