Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Logger logger = Logger.getLogger(SignatureCapture.class);
- private JPanel signCanvas = new JPanel();
- private JPanel headerCanvas = new JPanel();
- private JPanel guestInfoCanvas = new JPanel();
- private JPanel container = new JPanel();
- private JPanel footerBtnCanvas = new JPanel();
- private int width;
- private int height;
- private int signCanvasWidth;
- private int signCanvasHeight;
- private GraphicsEnvironment enviroment;
- private GraphicsDevice[] devices;
- private GraphicsConfiguration configuration;
- private Graphics2D graphics;
- private JFrame frame;
- private Point lastPos = null;
- public BufferedImage image = null;
- private Graphics2D imageGraphics = null;
- private PassportScanInfo scanInfo;
- private ResortDetailBean resortInfo;
- private float guestCanvasWidthPer;
- private float headerCanvasHeightPer;
- private float footerBtnHeight;
- private ArrivalDepartureDao arrivalDepartureDao;
- public SignatureCapture() {
- initialize(null);
- }
- public SignatureCapture(String realPath) {
- initialize(realPath);
- }
- public SignatureCapture(String realPath, PassportScanInfo scanInfo,
- ResortDetailBean resortInfo, ArrivalDepartureDao arrivalDepartureDao) {
- this.scanInfo = scanInfo;
- this.resortInfo = resortInfo;
- this.arrivalDepartureDao = arrivalDepartureDao;
- initialize(realPath);
- }
- protected void initialize(String realPath) {
- guestCanvasWidthPer = 0.32f;
- headerCanvasHeightPer = 0.3f;
- footerBtnHeight = 75f;
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "What we do in life", "Echoes in eternity.");
- PrimeFaces.current().dialog().showMessageDynamic(message);
- enviroment = GraphicsEnvironment.getLocalGraphicsEnvironment();
- devices = enviroment.getScreenDevices();
- if (realPath == null || realPath.isEmpty()) {
- try {
- realPath = URLDecoder.decode(getClass().getResource("/")
- .getPath(), "UTF-8");
- // logger.info(realPath);
- } catch (UnsupportedEncodingException e1) {
- logger.error("Error while getting path from class");
- }
- }
- Border blackline = BorderFactory.createLineBorder(Color.black);
- guestInfoCanvas.setBorder(blackline);
- headerCanvas.setBorder(blackline);
- // signCanvas.setBorder(blackline);
- // footerBtnCanvas.setBorder(blackline);
- width = 500;
- height = 500;
- // take second or last one device
- for (int i = 0; i < devices.length; i++) {
- width = devices[i].getDisplayMode().getWidth();
- height = devices[i].getDisplayMode().getHeight();
- configuration = devices[i].getDefaultConfiguration();
- }
- if (configuration != null) {
- frame = new JFrame(configuration);
- frame.setSize(width, height);
- height = height - 20;// for frame size or task bar size
- guestInfoCanvas.setBounds(0, 0,
- Math.round(width * guestCanvasWidthPer), height);
- initializeGuestInfoLayout(Math.round(width * guestCanvasWidthPer),
- height);
- headerCanvas.setBounds(Math.round(width * guestCanvasWidthPer), 0,
- Math.round(width * (1f - guestCanvasWidthPer)),
- Math.round(height * headerCanvasHeightPer));
- initializeHeaderInfoLayout(
- Math.round(width * (1f - guestCanvasWidthPer)),
- Math.round(height * headerCanvasHeightPer));
- signCanvasWidth = Math.round(width * (1f - guestCanvasWidthPer));
- signCanvasHeight = Math
- .round((height * (1f - headerCanvasHeightPer))
- - footerBtnHeight);
- signCanvas.setBounds(Math.round(width * guestCanvasWidthPer),
- Math.round(height * headerCanvasHeightPer),
- signCanvasWidth, signCanvasHeight);
- footerBtnCanvas.setBounds(Math.round(width * guestCanvasWidthPer),
- Math.round(height - footerBtnHeight), signCanvasWidth,
- Math.round(footerBtnHeight));
- initializeSignFooterInfoLayout(realPath, signCanvasWidth,
- Math.round(footerBtnHeight));
- container.setSize(width, height);
- container.setLayout(null);
- container.add(guestInfoCanvas);
- container.add(headerCanvas);
- container.add(signCanvas);
- container.add(footerBtnCanvas);
- frame.setLayout(null);
- frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame.getContentPane().add(container);
- frame.setVisible(true);
- }
- graphics = (Graphics2D) signCanvas.getGraphics();
- signCanvas.setBackground(Color.WHITE);
- graphics.setColor(Color.GRAY);
- graphics.setStroke(new BasicStroke(4f));
- graphics.fillRect(0, 0, signCanvasWidth, signCanvasHeight);
- graphics.setColor(Color.BLUE);
- image = new BufferedImage(signCanvasWidth, signCanvasHeight,
- IndexColorModel.OPAQUE);
- imageGraphics = image.createGraphics();
- imageGraphics.setStroke(new BasicStroke(4f));
- imageGraphics.setBackground(Color.WHITE);
- imageGraphics.fillRect(0, 0, signCanvasWidth, signCanvasHeight);
- imageGraphics.setColor(Color.BLUE);
- signCanvas.addMouseMotionListener(new MouseMotionListener() {
- public void mouseDragged(MouseEvent m) {
- Point p = m.getPoint();
- if (lastPos == null)
- lastPos = p;
- graphics.drawLine(lastPos.x, lastPos.y, p.x, p.y);
- imageGraphics.drawLine(lastPos.x, lastPos.y, p.x, p.y);
- lastPos = p;
- }
- public void mouseMoved(MouseEvent m) {
- }
- });
- signCanvas.addMouseListener(new MouseListener() {
- public void mouseClicked(MouseEvent e) {
- }
- public void mousePressed(MouseEvent e) {
- lastPos = e.getPoint();
- }
- public void mouseReleased(MouseEvent e) {
- lastPos = null;
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void mouseExited(MouseEvent e) {
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement