Merge branch 'main' into teya-integration

This commit is contained in:
hugh-unicenta
2023-11-10 17:56:41 +00:00
committed by GitHub
8 changed files with 134 additions and 72 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<groupId>com.unicenta</groupId>
<artifactId>unicentaopos</artifactId>
<version>5.0.1</version>
<version>5.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -67,12 +67,12 @@ public class PreparedSentence extends JDBCSentence {
/**
*
* @param s
* @param session
* @param sentence
* @param serwrite
*/
public PreparedSentence(Session s, String sentence, SerializerWrite serwrite) {
this(s, sentence, serwrite, null);
public PreparedSentence(Session session, String sentence, SerializerWrite serwrite) {
this(session, sentence, serwrite, null);
}
/**
@@ -29,14 +29,14 @@ import com.unicenta.basic.BasicException;
*/
public abstract class SentenceExecTransaction implements SentenceExec {
private Session m_s;
private Session session;
/**
*
* @param s
* @param session
*/
public SentenceExecTransaction(Session s) {
m_s = s;
public SentenceExecTransaction(Session session) {
this.session = session;
}
/**
@@ -66,7 +66,7 @@ public abstract class SentenceExecTransaction implements SentenceExec {
*/
public final int exec(final Object params) throws BasicException {
Transaction<Integer> t = new Transaction<Integer>(m_s) {
Transaction<Integer> t = new Transaction<Integer>(session) {
public Integer transact() throws BasicException{
return execInTransaction(params);
}
@@ -61,6 +61,14 @@ public class JRootFrame extends javax.swing.JFrame implements AppMessage {
initComponents();
}
public JRootApp getRootapp() {
return m_rootapp;
}
public void setRootapp(JRootApp m_rootapp) {
this.m_rootapp = m_rootapp;
}
/**
* @param props
*/
@@ -98,6 +106,7 @@ public class JRootFrame extends javax.swing.JFrame implements AppMessage {
new JFrmConfig(props).setVisible(true); // Show the configuration window.
}
setRootapp(m_rootapp);
}
/**
@@ -98,7 +98,6 @@ public class StartPOS {
String hostname = config.getProperty("machine.hostname");
TicketInfo.setHostname(hostname);
applicationStarted(hostname);
String screenmode = config.getProperty("machine.screenmode");
@@ -106,6 +105,8 @@ public class StartPOS {
JRootKiosk rootkiosk = new JRootKiosk();
try {
rootkiosk.initFrame(config);
applicationStarted(hostname, rootkiosk.getRootapp());
} catch (IOException ex) {
log.error(ex.getMessage());
}
@@ -113,18 +114,25 @@ public class StartPOS {
JRootFrame rootframe = new JRootFrame();
try {
rootframe.initFrame(config);
applicationStarted(hostname, rootframe.getRootapp());
} catch (Exception ex) {
log.error(ex.getMessage());
}
}
});
}
private static void applicationStarted(String host) {
private static void applicationStarted(String host, JRootApp jRootApp) {
new Thread(() -> {
Metrics metrics = new Metrics();
metrics.setDevice(host);
metrics.setUniCentaVersion(AppLocal.APP_VERSION);
new Application().postMetrics(metrics);
try {
Metrics metrics = new Metrics();
metrics.setDevice(host);
metrics.setUniCentaVersion(AppLocal.APP_VERSION);
Application application = new Application();
application.postMetrics(metrics);
application.startEventListener(host, jRootApp);
} catch (Exception e) {
log.error("Problem with starting the uniCenta plugin application:${}", e.getMessage());
}
}).start();
}
}
@@ -30,7 +30,6 @@ import java.util.ArrayList;
import java.util.Iterator;
/**
*
* @author JG uniCenta
*/
@Slf4j
@@ -50,120 +49,158 @@ public abstract class BasicTicket implements PrintItem {
*
*/
protected int m_iBodyHeight;
/** Creates a new instance of AbstractTicket */
public BasicTicket() {
// JG 16 May 12 use diamond inference
m_aCommands = new ArrayList<>();
pil = null;
m_iBodyHeight = 0;
}
/**
*
* Creates a new instance of AbstractTicket
*/
public BasicTicket() {
// JG 16 May 12 use diamond inference
m_aCommands = new ArrayList<>();
pil = null;
m_iBodyHeight = 0;
}
/**
* @return
*/
protected abstract Font getBaseFont();
/**
*
* @return
*/
protected abstract int getFontHeight();
/**
*
* @return
*/
protected abstract double getImageScale();
/**
*
* @return
*/
@Override
public int getHeight() {
return m_iBodyHeight;
}
public int getHeight() {
return m_iBodyHeight;
}
/**
*
* @param g2d
* @param x
* @param y
* @param width
*/
@Override
public void draw(Graphics2D g2d, int x, int y, int width) {
public void draw(Graphics2D g2d, int x, int y, int width) {
int currenty = y;
for (PrintItem pi : m_aCommands) {
pi.draw(g2d, x, currenty, width);
currenty += pi.getHeight();
}
}
int currenty = y;
for (PrintItem pi : m_aCommands) {
pi.draw(g2d, x, currenty, width);
currenty += pi.getHeight();
}
saveTicket(g2d, x, y, width);
}
private void saveTicket(Graphics2D g2d, int x, int y, int width) {
int receiptHeight = 5;
PrintItem pi;
for(Iterator i$ = m_aCommands.iterator(); i$.hasNext(); receiptHeight += pi.getHeight()) {
pi = (PrintItem)i$.next();
}
BufferedImage image = new BufferedImage(width + 10, receiptHeight, 1);
g2d = image.createGraphics();
int currenty = y;
for(Iterator i$ = this.m_aCommands.iterator(); i$.hasNext(); currenty += pi.getHeight()) {
pi = (PrintItem)i$.next();
if (pi instanceof PrintItemImage) {
((PrintItemImage) pi).setImage(negative(((PrintItemImage) pi).getImage()));
}
pi.draw(g2d, x, currenty, width);
}
try {
ImageIO.write(this.negative(image), "png", new File(System.getProperty("user.home") + "/receipt.png"));
}
catch (Exception e) {
System.out.println("Error serialising receipt image !!! : " + e);
}
}
public BufferedImage negative(BufferedImage img) {
for (int x = 0; x < img.getWidth(); ++x) {
for (int y = 0; y < img.getHeight(); ++y) {
int RGBA = img.getRGB(x, y);
Color col = new Color(RGBA, true);
col = new Color(Math.abs(col.getRed() - 255), Math.abs(col.getGreen() - 255), Math.abs(col.getBlue() - 255));
img.setRGB(x, y, col.getRGB());
}
}
return img;
}
/**
*
* @return
*/
public java.util.List<PrintItem> getCommands() {
return m_aCommands;
}
return m_aCommands;
}
// INTERFAZ PRINTER 2
// INTERFAZ PRINTER 2
/**
*
* @param image
*/
public void printImage(BufferedImage image) {
public void printImage(BufferedImage image) {
PrintItem pi = new PrintItemImage(image, getImageScale());
m_aCommands.add(pi);
m_iBodyHeight += pi.getHeight();
}
PrintItem pi = new PrintItemImage(image, getImageScale());
m_aCommands.add(pi);
m_iBodyHeight += pi.getHeight();
}
/**
*
* @param type
* @param position
* @param code
*/
public void printBarCode(String type, String position, String code) {
PrintItem pi = new PrintItemBarcode(type, position, code, getImageScale());
m_aCommands.add(pi);
m_iBodyHeight += pi.getHeight();
}
PrintItem pi = new PrintItemBarcode(type, position, code, getImageScale());
m_aCommands.add(pi);
m_iBodyHeight += pi.getHeight();
}
/**
*
* @param iTextSize
*/
public void beginLine(int iTextSize) {
pil = new PrintItemLine(iTextSize, getBaseFont(), getFontHeight());
}
pil = new PrintItemLine(iTextSize, getBaseFont(), getFontHeight());
}
/**
*
* @param iStyle
* @param sText
*/
public void printText(int iStyle, String sText) {
if (pil != null) {
pil.addText(iStyle, sText);
}
}
if (pil != null) {
pil.addText(iStyle, sText);
}
}
/**
*
*/
public void endLine() {
if (pil != null) {
m_aCommands.add(pil);
m_iBodyHeight += pil.getHeight();
pil = null;
}
}
}
if (pil != null) {
m_aCommands.add(pil);
m_iBodyHeight += pil.getHeight();
pil = null;
}
}
}
@@ -70,4 +70,12 @@ public class PrintItemImage implements PrintItem {
public int getHeight() {
return (int) (image.getHeight() * scale);
}
public BufferedImage getImage() {
return image;
}
public void setImage(BufferedImage image) {
this.image = image;
}
}
@@ -79,14 +79,14 @@ public final class TicketInfo implements SerializableRead, Externalizable {
private Double nsum;
private int ticketstatus;
private static String Hostname;
private static String hostname;
public static void setHostname(String name) {
Hostname=name;
hostname =name;
}
public static String getHostname() {
return Hostname;
return hostname;
}
/** Creates new TicketModel */