Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. private static Logger logger = Logger.getLogger(SignatureCapture.class);
  2. private JPanel signCanvas = new JPanel();
  3. private JPanel headerCanvas = new JPanel();
  4. private JPanel guestInfoCanvas = new JPanel();
  5. private JPanel container = new JPanel();
  6. private JPanel footerBtnCanvas = new JPanel();
  7. private int width;
  8. private int height;
  9. private int signCanvasWidth;
  10. private int signCanvasHeight;
  11. private GraphicsEnvironment enviroment;
  12. private GraphicsDevice[] devices;
  13. private GraphicsConfiguration configuration;
  14. private Graphics2D graphics;
  15. private JFrame frame;
  16. private Point lastPos = null;
  17. public BufferedImage image = null;
  18. private Graphics2D imageGraphics = null;
  19. private PassportScanInfo scanInfo;
  20. private ResortDetailBean resortInfo;
  21. private float guestCanvasWidthPer;
  22. private float headerCanvasHeightPer;
  23. private float footerBtnHeight;
  24.  
  25. private ArrivalDepartureDao arrivalDepartureDao;
  26.  
  27. public SignatureCapture() {
  28. initialize(null);
  29. }
  30.  
  31. public SignatureCapture(String realPath) {
  32. initialize(realPath);
  33. }
  34.  
  35. public SignatureCapture(String realPath, PassportScanInfo scanInfo,
  36. ResortDetailBean resortInfo, ArrivalDepartureDao arrivalDepartureDao) {
  37. this.scanInfo = scanInfo;
  38. this.resortInfo = resortInfo;
  39. this.arrivalDepartureDao = arrivalDepartureDao;
  40. initialize(realPath);
  41. }
  42.  
  43. protected void initialize(String realPath) {
  44. guestCanvasWidthPer = 0.32f;
  45. headerCanvasHeightPer = 0.3f;
  46. footerBtnHeight = 75f;
  47. FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "What we do in life", "Echoes in eternity.");
  48.  
  49. PrimeFaces.current().dialog().showMessageDynamic(message);
  50. enviroment = GraphicsEnvironment.getLocalGraphicsEnvironment();
  51. devices = enviroment.getScreenDevices();
  52.  
  53. if (realPath == null || realPath.isEmpty()) {
  54. try {
  55. realPath = URLDecoder.decode(getClass().getResource("/")
  56. .getPath(), "UTF-8");
  57. // logger.info(realPath);
  58. } catch (UnsupportedEncodingException e1) {
  59. logger.error("Error while getting path from class");
  60. }
  61. }
  62.  
  63. Border blackline = BorderFactory.createLineBorder(Color.black);
  64. guestInfoCanvas.setBorder(blackline);
  65. headerCanvas.setBorder(blackline);
  66. // signCanvas.setBorder(blackline);
  67. // footerBtnCanvas.setBorder(blackline);
  68. width = 500;
  69. height = 500;
  70. // take second or last one device
  71. for (int i = 0; i < devices.length; i++) {
  72. width = devices[i].getDisplayMode().getWidth();
  73. height = devices[i].getDisplayMode().getHeight();
  74. configuration = devices[i].getDefaultConfiguration();
  75. }
  76.  
  77. if (configuration != null) {
  78. frame = new JFrame(configuration);
  79. frame.setSize(width, height);
  80. height = height - 20;// for frame size or task bar size
  81. guestInfoCanvas.setBounds(0, 0,
  82. Math.round(width * guestCanvasWidthPer), height);
  83.  
  84. initializeGuestInfoLayout(Math.round(width * guestCanvasWidthPer),
  85. height);
  86.  
  87. headerCanvas.setBounds(Math.round(width * guestCanvasWidthPer), 0,
  88. Math.round(width * (1f - guestCanvasWidthPer)),
  89. Math.round(height * headerCanvasHeightPer));
  90.  
  91. initializeHeaderInfoLayout(
  92. Math.round(width * (1f - guestCanvasWidthPer)),
  93. Math.round(height * headerCanvasHeightPer));
  94.  
  95. signCanvasWidth = Math.round(width * (1f - guestCanvasWidthPer));
  96. signCanvasHeight = Math
  97. .round((height * (1f - headerCanvasHeightPer))
  98. - footerBtnHeight);
  99.  
  100. signCanvas.setBounds(Math.round(width * guestCanvasWidthPer),
  101. Math.round(height * headerCanvasHeightPer),
  102. signCanvasWidth, signCanvasHeight);
  103.  
  104. footerBtnCanvas.setBounds(Math.round(width * guestCanvasWidthPer),
  105. Math.round(height - footerBtnHeight), signCanvasWidth,
  106. Math.round(footerBtnHeight));
  107.  
  108. initializeSignFooterInfoLayout(realPath, signCanvasWidth,
  109. Math.round(footerBtnHeight));
  110.  
  111. container.setSize(width, height);
  112. container.setLayout(null);
  113. container.add(guestInfoCanvas);
  114. container.add(headerCanvas);
  115. container.add(signCanvas);
  116. container.add(footerBtnCanvas);
  117. frame.setLayout(null);
  118. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  119. frame.getContentPane().add(container);
  120. frame.setVisible(true);
  121. }
  122.  
  123. graphics = (Graphics2D) signCanvas.getGraphics();
  124. signCanvas.setBackground(Color.WHITE);
  125. graphics.setColor(Color.GRAY);
  126. graphics.setStroke(new BasicStroke(4f));
  127. graphics.fillRect(0, 0, signCanvasWidth, signCanvasHeight);
  128. graphics.setColor(Color.BLUE);
  129.  
  130. image = new BufferedImage(signCanvasWidth, signCanvasHeight,
  131. IndexColorModel.OPAQUE);
  132. imageGraphics = image.createGraphics();
  133. imageGraphics.setStroke(new BasicStroke(4f));
  134. imageGraphics.setBackground(Color.WHITE);
  135. imageGraphics.fillRect(0, 0, signCanvasWidth, signCanvasHeight);
  136. imageGraphics.setColor(Color.BLUE);
  137.  
  138. signCanvas.addMouseMotionListener(new MouseMotionListener() {
  139. public void mouseDragged(MouseEvent m) {
  140.  
  141. Point p = m.getPoint();
  142. if (lastPos == null)
  143. lastPos = p;
  144. graphics.drawLine(lastPos.x, lastPos.y, p.x, p.y);
  145. imageGraphics.drawLine(lastPos.x, lastPos.y, p.x, p.y);
  146. lastPos = p;
  147. }
  148.  
  149. public void mouseMoved(MouseEvent m) {
  150. }
  151. });
  152.  
  153. signCanvas.addMouseListener(new MouseListener() {
  154. public void mouseClicked(MouseEvent e) {
  155.  
  156. }
  157.  
  158. public void mousePressed(MouseEvent e) {
  159. lastPos = e.getPoint();
  160. }
  161.  
  162. public void mouseReleased(MouseEvent e) {
  163. lastPos = null;
  164. }
  165.  
  166. public void mouseEntered(MouseEvent e) {
  167. }
  168.  
  169. public void mouseExited(MouseEvent e) {
  170. }
  171. });
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement