diff --git a/pom.xml b/pom.xml index 59d720c..293b777 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.unicenta unicentaopos - 5.0.1 + 5.0.2-SNAPSHOT jar UTF-8 diff --git a/src/main/java/com/unicenta/data/loader/PreparedSentence.java b/src/main/java/com/unicenta/data/loader/PreparedSentence.java index 4d870c1..3e56642 100644 --- a/src/main/java/com/unicenta/data/loader/PreparedSentence.java +++ b/src/main/java/com/unicenta/data/loader/PreparedSentence.java @@ -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); } /** diff --git a/src/main/java/com/unicenta/data/loader/SentenceExecTransaction.java b/src/main/java/com/unicenta/data/loader/SentenceExecTransaction.java index dfc164c..19c100f 100644 --- a/src/main/java/com/unicenta/data/loader/SentenceExecTransaction.java +++ b/src/main/java/com/unicenta/data/loader/SentenceExecTransaction.java @@ -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 t = new Transaction(m_s) { + Transaction t = new Transaction(session) { public Integer transact() throws BasicException{ return execInTransaction(params); } diff --git a/src/main/java/com/unicenta/pos/forms/JRootFrame.java b/src/main/java/com/unicenta/pos/forms/JRootFrame.java index c8fcf10..024cea8 100644 --- a/src/main/java/com/unicenta/pos/forms/JRootFrame.java +++ b/src/main/java/com/unicenta/pos/forms/JRootFrame.java @@ -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); } /** diff --git a/src/main/java/com/unicenta/pos/forms/StartPOS.java b/src/main/java/com/unicenta/pos/forms/StartPOS.java index e16cbe4..06c0e22 100644 --- a/src/main/java/com/unicenta/pos/forms/StartPOS.java +++ b/src/main/java/com/unicenta/pos/forms/StartPOS.java @@ -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(); } } \ No newline at end of file diff --git a/src/main/java/com/unicenta/pos/printer/ticket/BasicTicket.java b/src/main/java/com/unicenta/pos/printer/ticket/BasicTicket.java index aa4ab1b..bbad40b 100644 --- a/src/main/java/com/unicenta/pos/printer/ticket/BasicTicket.java +++ b/src/main/java/com/unicenta/pos/printer/ticket/BasicTicket.java @@ -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 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; - } - } - } \ No newline at end of file + if (pil != null) { + m_aCommands.add(pil); + m_iBodyHeight += pil.getHeight(); + pil = null; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/unicenta/pos/printer/ticket/PrintItemImage.java b/src/main/java/com/unicenta/pos/printer/ticket/PrintItemImage.java index 5201b1f..46b69d0 100644 --- a/src/main/java/com/unicenta/pos/printer/ticket/PrintItemImage.java +++ b/src/main/java/com/unicenta/pos/printer/ticket/PrintItemImage.java @@ -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; + } } diff --git a/src/main/java/com/unicenta/pos/ticket/TicketInfo.java b/src/main/java/com/unicenta/pos/ticket/TicketInfo.java index 9d1b984..7f82c28 100644 --- a/src/main/java/com/unicenta/pos/ticket/TicketInfo.java +++ b/src/main/java/com/unicenta/pos/ticket/TicketInfo.java @@ -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 */