Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.

Commit ab3bc19

Browse files
committed
Integration of the Java version
1 parent efbf6a4 commit ab3bc19

20 files changed

+2196
-35
lines changed

java/AppletBarcodeCoder.java

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* BarCode Coder Library (BCC Library)
3+
* BCCL Version 2.0.1
4+
* Porting : Barcode Java
5+
* HOUREZ Jonathan
6+
* Date : June 5, 2011
7+
*
8+
*
9+
* Author : DEMONTE Jean-Baptiste (firejocker)
10+
* HOUREZ Jonathan
11+
* Contact : jbdemonte @ gmail.com
12+
* Web site: http://barcode-coder.com/
13+
* dual licence : http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html
14+
* http://www.gnu.org/licenses/gpl.html
15+
*
16+
* Managed :
17+
*
18+
* standard 2 of 5 (std25)
19+
* interleaved 2 of 5 (int25)
20+
* ean 8 (ean8)
21+
* ean 13 (ean13)
22+
* code 11 (code11)
23+
* code 39 (code39)
24+
* code 93 (code93)
25+
* code 128 (code128)
26+
* codabar (codabar)
27+
* msi (msi)
28+
* datamatrix (datamatrix)
29+
*
30+
*/
31+
32+
33+
/*
34+
* This is an example of Applet
35+
*/
36+
37+
package com.barcode_coder.java_barcode;
38+
39+
import java.awt.*;
40+
import java.applet.*;
41+
import java.awt.event.*;
42+
import javax.swing.JPanel;
43+
44+
public class AppletBarcodeCoder extends Applet implements ActionListener
45+
{
46+
private static final long serialVersionUID = 1L;
47+
48+
private Button generateButton;
49+
private TextField codeField;
50+
private CheckboxGroup radioGroup;
51+
private Checkbox radioEAN8, radioEAN13;
52+
private Checkbox radioStandard2of5, radioInterleaved2of5;
53+
private Checkbox radioCode11, radioCode39, radioCode93, radioCode128;
54+
private Checkbox radioCodabar, radioMSI;
55+
private Checkbox radioDatamatrix;
56+
57+
private String hri = "", digit = "";
58+
private boolean barcode2D = true;
59+
private int width = 0;
60+
61+
public void init()
62+
{
63+
setLayout(new BorderLayout());
64+
65+
generateButton = new Button("Generate");
66+
codeField = new TextField("12345670",10);
67+
BorderLayout bl1 = new BorderLayout();
68+
JPanel jp1 = new JPanel();
69+
jp1.setLayout(bl1);
70+
jp1.add(new Label("Veuillez saisir le code : "), BorderLayout.WEST);
71+
jp1.add(codeField, BorderLayout.CENTER);
72+
jp1.add(generateButton, BorderLayout.EAST);
73+
add(jp1, BorderLayout.NORTH);
74+
75+
radioGroup = new CheckboxGroup();
76+
radioEAN8 = new BarcodeCheckBox("EAN8", radioGroup, true, BarcodeType.EAN8);
77+
radioEAN13 = new BarcodeCheckBox("EAN13", radioGroup, false, BarcodeType.EAN13);
78+
radioStandard2of5 = new BarcodeCheckBox("Standard 2 of 5", radioGroup, false, BarcodeType.Standard2of5);
79+
radioInterleaved2of5 = new BarcodeCheckBox("Interleaved 2 of 5", radioGroup, false, BarcodeType.Interleaved2of5);
80+
radioCode11 = new BarcodeCheckBox("Code 11", radioGroup, false, BarcodeType.Code11);
81+
radioCode39 = new BarcodeCheckBox("Code 39", radioGroup, false, BarcodeType.Code39);
82+
radioCode93 = new BarcodeCheckBox("Code 93", radioGroup, false, BarcodeType.Code93);
83+
radioCode128 = new BarcodeCheckBox("Code 128", radioGroup, false, BarcodeType.Code128);
84+
radioCodabar = new BarcodeCheckBox("Codabar", radioGroup, false, BarcodeType.Codabar);
85+
radioMSI = new BarcodeCheckBox("MSI", radioGroup, false, BarcodeType.MSI);
86+
radioDatamatrix = new BarcodeCheckBox("Datamatrix", radioGroup, false, BarcodeType.Datamatrix);
87+
GridLayout gl2 = new GridLayout(12,1);
88+
JPanel jp2 = new JPanel();
89+
jp2.setLayout(gl2);
90+
jp2.add(new Label("Type de code-barres :"));
91+
jp2.add(radioEAN8);
92+
jp2.add(radioEAN13);
93+
jp2.add(radioStandard2of5);
94+
jp2.add(radioInterleaved2of5);
95+
jp2.add(radioCode11);
96+
jp2.add(radioCode39);
97+
jp2.add(radioCode93);
98+
jp2.add(radioCode128);
99+
jp2.add(radioCodabar);
100+
jp2.add(radioMSI);
101+
jp2.add(radioDatamatrix);
102+
add(jp2, BorderLayout.SOUTH);
103+
104+
generateButton.addActionListener(this);
105+
}
106+
107+
public void paint(Graphics g)
108+
{
109+
System.out.println("Repaint");
110+
if (!barcode2D){
111+
for (int i = 0; i<this.digit.length(); i++){
112+
if (this.digit.charAt(i) == '1')
113+
g.fillRect(20+i, 100, 1, 50);
114+
g.drawString(this.hri,20,180);
115+
}
116+
}
117+
else{
118+
int i = 0;
119+
int j = 0;
120+
for (int k=0; k<this.digit.length(); k++){
121+
if (this.digit.charAt(k) == '1')
122+
g.fillRect(20+(i*5), 100+(j*5), 5, 5);
123+
System.out.println(i+" "+j);
124+
125+
i += 1;
126+
if (i == this.width){
127+
i = 0;
128+
j += 1;
129+
}
130+
}
131+
g.drawString(this.hri,20,100+(j*5)+20);
132+
}
133+
134+
}
135+
136+
137+
private void calculateBarcode(){
138+
Barcode barcode = BarcodeFactory.createBarcode(((BarcodeCheckBox)this.radioGroup.getSelectedCheckbox()).getType(),
139+
codeField.getText());
140+
141+
if (barcode == null){
142+
this.digit = "";
143+
this.hri = "";
144+
}
145+
else{
146+
this.digit = barcode.getDigit();
147+
this.hri = barcode.getComputedCode();
148+
this.barcode2D = barcode.is2D();
149+
this.width = barcode.getWidth();
150+
}
151+
}
152+
153+
public void actionPerformed(ActionEvent evt) {
154+
if (evt.getSource() == generateButton){
155+
calculateBarcode();
156+
repaint();
157+
}
158+
}
159+
160+
public class BarcodeCheckBox extends Checkbox{
161+
private static final long serialVersionUID = 1L;
162+
private BarcodeType type;
163+
public BarcodeCheckBox(String label, CheckboxGroup group, boolean state, BarcodeType type){
164+
super(label, group, state);
165+
this.type = type;
166+
}
167+
public BarcodeType getType(){
168+
return this.type;
169+
}
170+
}
171+
172+
}
173+

java/Bar.java

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* BarCode Coder Library (BCC Library)
3+
* BCCL Version 2.0.1
4+
* Porting : Barcode Java
5+
* HOUREZ Jonathan
6+
* Date : June 5, 2011
7+
*
8+
*
9+
* Author : DEMONTE Jean-Baptiste (firejocker)
10+
* HOUREZ Jonathan
11+
* Contact : jbdemonte @ gmail.com
12+
* Web site: http://barcode-coder.com/
13+
* dual licence : http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html
14+
* http://www.gnu.org/licenses/gpl.html
15+
*
16+
* Managed :
17+
*
18+
* standard 2 of 5 (std25)
19+
* interleaved 2 of 5 (int25)
20+
* ean 8 (ean8)
21+
* ean 13 (ean13)
22+
* code 11 (code11)
23+
* code 39 (code39)
24+
* code 93 (code93)
25+
* code 128 (code128)
26+
* codabar (codabar)
27+
* msi (msi)
28+
* datamatrix (datamatrix)
29+
*
30+
*/
31+
32+
package com.barcode_coder.java_barcode;
33+
34+
public class Bar {
35+
private int[] modules;
36+
37+
public Bar(int[] modules){
38+
this.modules = modules;
39+
}
40+
41+
public Bar(String modules){
42+
this.modules = new int[modules.length()];
43+
for (int i=0; i<modules.length(); i++){
44+
this.modules[i] = Integer.parseInt(String.valueOf(modules.charAt(i)));
45+
}
46+
}
47+
48+
public int[] getModules(){
49+
return this.modules;
50+
}
51+
52+
public void addModules(String modules){ // A vŽrifier
53+
if (this.modules != null){
54+
int[] modulesTemp = new int[modules.length() + this.modules.length];
55+
System.arraycopy(this.modules, 0, modulesTemp, 0, this.modules.length);
56+
for (int i=0; i<modules.length(); i++){
57+
modulesTemp[i+this.modules.length] = Integer.parseInt(String.valueOf(modules.charAt(i)));
58+
}
59+
this.modules = modulesTemp;
60+
}
61+
else{
62+
this.modules = new int[modules.length()];
63+
for (int i=0; i<modules.length(); i++){
64+
this.modules[i] = Integer.parseInt(String.valueOf(modules.charAt(i)));
65+
}
66+
}
67+
}
68+
69+
public void addModules(int[] modules){ // A vŽrifier
70+
if (this.modules != null){
71+
int[] modulesTemp = new int[modules.length + this.modules.length];
72+
System.arraycopy(this.modules, 0, modulesTemp, 0, this.modules.length);
73+
System.arraycopy(modules, 0, modulesTemp, this.modules.length, modules.length);
74+
this.modules = modulesTemp;
75+
}
76+
else{
77+
this.modules = new int[modules.length];
78+
System.arraycopy(modules, 0, this.modules, 0, this.modules.length);
79+
}
80+
}
81+
82+
public void setModules(int[] modules){
83+
this.modules = modules;
84+
}
85+
86+
public int getWidth(){
87+
return this.modules.length;
88+
}
89+
90+
public int getModule(int pos){
91+
return this.modules[pos];
92+
}
93+
94+
public void setModule(int pos, int value){
95+
this.modules[pos] = value;
96+
}
97+
}

0 commit comments

Comments
 (0)