source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/feedback/SelectPicture.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 21.7 KB
Line 
1package org.greenstone.gatherer.feedback;
2
3import java.awt.image.*;
4import javax.swing.BoxLayout;
5import javax.swing.ImageIcon;
6import javax.swing.JLabel;
7import javax.swing.*;
8import javax.swing.event.MouseInputAdapter;
9import java.awt.*;
10import java.awt.geom.*;
11import java.awt.geom.Line2D.*;
12import java.awt.geom.Line2D.Double;
13import java.awt.event.*;
14import java.awt.event.MouseEvent;
15import java.util.Locale;
16import java.util.ResourceBundle;
17import java.text.MessageFormat;
18import javax.swing.border.*;
19import javax.swing.BorderFactory;
20
21import org.greenstone.gatherer.util.JarTools;
22
23/**
24 * This class allows user to make scribble lines in the image.
25 * This class will display an image to a label and if the user drag inside the label
26 * then it will draw coloured line as the user drag the mouse.
27 * Image here is the screen shot of the whole screen size.
28 * @author Veronica Liesaputra
29 */
30public class SelectPicture extends WindowAdapter
31{
32 /**
33 * This is the images that stored all the images for the whole screen size image.
34 */
35 private BufferedImage[] screen;
36
37 /**
38 * This is the images that stored all the images for the window image.
39 */
40 private BufferedImage[] window;
41
42 /**
43 * This is the buffered image that contains the line that are drawn all
44 * over the screen image.
45 */
46 private BufferedImage bi;
47
48 /**
49 * This is the buffered image of the line that are drawn all over the screen image.
50 */
51 private BufferedImage bi2;
52
53 /**
54 * This is the buffered image of the screen image.
55 */
56 private BufferedImage bi3;
57
58 /**
59 * This is the buffered image that contains the line that are drawn all over the window image.
60 */
61 private BufferedImage bi4;
62
63 /**
64 * This is the buffered image of the line that are drawn all over the window image.
65 */
66 private BufferedImage bi5;
67
68 /**
69 * This is the buffered image of the window image.
70 */
71 private BufferedImage bi6;
72
73 /**
74 * This is the window's x-coord in the screen image.
75 */
76 private int xcoord;
77
78 /**
79 * This is the window's y-coord in the screen image.
80 */
81 private int ycoord;
82
83 /**
84 * This is the window's width in the screen image.
85 */
86 private int width;
87
88 /**
89 * This is the window's height in the screen image.
90 */
91 private int height;
92
93 /**
94 * This is to block all the input in this window while waiting.
95 */
96 private MouseListener mouse_blocker_listener = new MouseAdapter() {};
97
98 /**
99 * This variable will hold the resource of the words that is stored in Messages.properties file.
100 * The calling using messages.getString(someString) will caused someString to be translated
101 * into some other string that is hold in that file.usually it will caused it to be translated
102 * to the language that the user use or choose to have as stated in Locale.
103 */
104 private static ResourceBundle messages;
105
106 /**
107 * This variable hold the comments that user entered when they are drawing lines into the image.
108 */
109 private String details;
110
111 /**
112 * This variable is a flag to say whether or not user wants to send the feedback straight away.
113 */
114 private boolean sendNow;
115
116 /**
117 * This variable is a flag to say whether the user wants to draw the scribble lines or
118 * to erase the image.
119 */
120 private boolean drawNow;
121
122 /**
123 * This variable is a flag to say whether or not the image user wants to send is window
124 * or the whole screen image.
125 */
126 private boolean windowNow;
127
128 /**
129 * This method will make a modal-dialog that will allow user to draw a line all over the image.
130 * @param sh the buffered images of the screen image.
131 * @param wh the buffered images of the window image.
132 * @param iswindow the flag to say whether user wants to send window or whole screen image.
133 * @param screen_details the comments that user typed for this screenshot.
134 * @param msg hold the resource of the words that is stored in Messages.properties file.
135 */
136 public SelectPicture(BufferedImage[] sh,BufferedImage[] wh,boolean iswindow,String screen_details,ResourceBundle msg)
137 {
138 windowNow = iswindow;
139 drawNow = true;
140 details = screen_details;
141 messages = msg;
142 window = wh;
143 screen = sh;
144 }
145
146 /**
147 * This method setting up the window's bounds inside the screen image.
148 * @param x the window's x-coordinate in the screen image.
149 * @param y the window's y-coordniate in the screen image.
150 * @param w the window's width in the screen image.
151 * @param h the window's height in the screen image.
152 */
153 public void setWindowBounds (int x,int y,int w,int h)
154 {
155 xcoord = x;
156 ycoord = y;
157 width = w;
158 height = h;
159 makeNewWindow();
160 }
161
162 /**
163 * This method will get which one user wants to send the window or screen image.
164 * @return the flag whether user wants to send window or screen image.
165 */
166 public boolean getIsWindow()
167 {
168 return windowNow;
169 }
170
171 /**
172 * This method will get the screen image of the screenshot with the line drawn all over it.
173 * @return this is the screen image with the line drawn all over it.
174 */
175 public BufferedImage getImage()
176 {
177 return bi;
178 }
179
180 /**
181 * This method will get the screen image of the screenshot.
182 * @return this is the screen image.
183 */
184 public BufferedImage getImage3()
185 {
186 return bi5;
187 }
188
189 /**
190 * This method will get the screen image of only the line that drawn all over the image of
191 * the screenshot.
192 * @return this is the screen image of only the line.
193 */
194 public BufferedImage getImage2()
195 {
196 return bi2;
197 }
198
199 /**
200 * This method will get the window image of the screenshot with the line drawn all over it.
201 * @return this is the image with the line drawn all over it.
202 */
203 public BufferedImage getWindowImage()
204 {
205 return bi3;
206 }
207
208 /**
209 * This method will get the window image of the screenshot.
210 * @return this is the window image.
211 */
212 public BufferedImage getWindowImage3()
213 {
214 return bi6;
215 }
216
217 /**
218 * This method will get the window image of only the line that drawn all over the image of
219 * the screenshot.
220 * @return this is the window image of only the line.
221 */
222 public BufferedImage getWindowImage2()
223 {
224 return bi4;
225 }
226
227 /**
228 * This method will give the comments user made when they are drawing line over the picture.
229 * @return this is the comment user made.
230 */
231 public String getDetails ()
232 {
233 return details;
234 }
235
236 public boolean getSendNow()
237 {
238 return sendNow;
239 }
240
241 /**
242 * This method will make a modal-dialog that will have the image of the screen shot in the label,
243 * allow user to draw a line all over the image and comments it as well.
244 */
245 public void makeNewWindow()
246 {
247 JDialog f;
248 f = new Selecting(this);
249 f.setLocation(0,0);
250 }
251
252 /**
253 * This class will make a modal-dialog that will have the image of the screen shot in the label,
254 * allow user to draw a line all over the image and comments it as well.
255 */
256 class Selecting extends JDialog implements ActionListener
257 {
258 /**
259 * This is the modal-dialog.
260 */
261 private JDialog frame;
262
263 /**
264 * This is the special label that allows user to draw a line all over the icon set in the label.
265 */
266 private SelectionArea area;
267
268 /**
269 * This is the text area where user can enter the comments they want to add.
270 */
271 private JTextArea problem_details;
272
273 /**
274 * This is the owner of this modal-dialog.
275 */
276 private SelectPicture framework = null;
277
278 /**
279 * This is the graphs that will allow to draw the line all over the screen image in the label and getting
280 * the image of it.
281 */
282 private Graphs gp;
283
284 /**
285 * This is the graphs that will allow to draw the line all over the window image in the label and getting
286 * the image of it.
287 */
288 private Graphs gp2;
289
290 /**
291 * This constructor will make a modal-dialog that will have the image of the screen shot in the label,
292 * allow user to draw a line all over the image and comments it as well.
293 * @param controller this is the owner of the modal-dialog.
294 */
295 public Selecting(SelectPicture controller)
296 {
297 Container contentPane;
298
299 contentPane = getContentPane();
300
301 gp = new Graphs(screen);
302
303 window = gp.getWindowVersion(xcoord,ycoord,width,height);
304
305 gp2 = new Graphs(window);
306
307 buildUI(contentPane);
308
309 framework = controller;
310
311 setTitle(messages.getString("Showwhereistheproblem"));
312 setDefaultLookAndFeelDecorated(true);
313 setModal(true);
314
315 frame = this;
316 addWindowListener(framework);
317 setBackground(new Color(176,208,176));
318
319 setLocation(0,0);
320
321 pack();
322 setVisible(true);
323 }
324
325 /**
326 * This method will setup the contentpane of the modal-dialog.It will set the cursor for
327 * the label to be from the file pen.gif and set the image icon for the label.
328 * @param content this is the contentPane of the modal-dialog.
329 */
330 private void buildUI(Container content)
331 {
332 final JPanel container;
333 container = new JPanel();
334 container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
335 container.setBackground(new Color(176,208,176));
336 container.setBorder(new EmptyBorder(5,5,5,5));
337
338
339 ImageIcon image = createImageIcon(windowNow);
340 area = new SelectionArea(image, this);
341 area.setBackground(new Color(224,240,224));
342 area.setBorder(BorderFactory.createCompoundBorder
343 (BorderFactory.createLineBorder(Color.blue,4),
344 new EmptyBorder(10,10,10,10)));
345
346 ImageIcon imgicon,imgicon2;
347 Image img,img2;
348 imgicon = JarTools.getImage("pen.gif");
349 img = imgicon.getImage();
350 img = img.getScaledInstance(24,24,Image.SCALE_SMOOTH);
351 imgicon2 = JarTools.getImage("eraserpen.gif");
352 img2 = imgicon2.getImage();
353 final Cursor cursor;
354 final Cursor cursor2;
355 cursor = Toolkit.getDefaultToolkit().createCustomCursor(img,new Point(0,0),"crayon");
356 cursor2 = Toolkit.getDefaultToolkit().createCustomCursor(img2,new Point(0,0),"eraser");
357
358 area.setCursor(cursor);
359
360 Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
361 final JPanel iconarea = new JPanel();
362 iconarea.setBackground(new Color(176,208,176));
363 iconarea.add(area);
364 container.add(iconarea);
365
366 String screen_label;
367 screen_label = " " + messages.getString("ScreenShotLabel");
368 JLabel label;
369 label = new JLabel(screen_label);
370 label.setBackground(new Color(176,208,176));
371 container.add(label);
372
373 JPanel panes;
374 panes = new JPanel();
375 panes.setLayout(new GridLayout(0,2));
376 panes.setBackground(new Color(176,208,176));
377
378 problem_details = new JTextArea(details);
379 problem_details.setWrapStyleWord(true);
380 problem_details.setEditable(true);
381 problem_details.setBackground(new Color(224,240,224));
382 JScrollPane scroll;
383 scroll = new JScrollPane(problem_details);
384 scroll.setBackground(new Color(176,208,176));
385 scroll.setPreferredSize(new Dimension(50,100));
386 scroll.setBorder(BorderFactory.createTitledBorder(
387 new EmptyBorder(0,0,0,0),
388 "Screen shot " +
389 messages.getString("ProblemDetails")));
390
391 panes.add(scroll);
392
393 JPanel pane;
394 pane = new JPanel();
395 pane.setLayout(new GridLayout(2,3));
396 pane.setBackground(new Color(176,208,176));
397 pane.setBorder(new EmptyBorder(15,15,15,15));
398
399 if ((window == null) || (screen == null)) {System.out.println("How come!");}
400 else
401 {
402 final JButton toggle;
403
404 if (windowNow == false)
405 {
406 toggle = new JButton("GLI window.");
407 toggle.setToolTipText("Showing only GLI window.");
408 }
409 else
410 {
411 toggle = new JButton("Whole screen.");
412 toggle.setToolTipText("Showing whole screen.");
413 }
414 toggle.setActionCommand("Toggle");
415 toggle.addActionListener(new ActionListener ()
416 {
417 public void actionPerformed (ActionEvent e)
418 {
419 frame.addMouseListener(mouse_blocker_listener);
420 frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
421 if (windowNow == true)
422 {
423 windowNow = false;
424 toggle.setText("GLI window.");
425 toggle.setToolTipText("Showing only GLI window.");
426 window[0] = gp2.getScreenImage();
427 window[1] = gp2.getImage();
428 window[2] = gp2.getImage2();
429 gp.setScreenVersion(window,xcoord,ycoord,width,height);
430 area.setIcon(new ImageIcon(gp.getImage()));
431 }
432 else
433 {
434 windowNow = true;
435 toggle.setText("Whole screen.");
436 toggle.setToolTipText("Showing whole screen.");
437
438 window[0].flush();
439 window[0] = null;
440 window[1].flush();
441 window[1] = null;
442 window[2].flush();
443 window[2] = null;
444 window = null;
445 BufferedImage tmp;
446 gp2.getImage().flush();
447 tmp = gp2.getImage();
448 tmp.flush();
449 tmp = null;
450 gp2.getImage2().flush();
451 tmp = gp2.getImage2();
452 tmp.flush();
453 tmp = null;
454 gp2.flush();
455 gp2 = null;
456 System.gc();
457
458 window = gp.getWindowVersion(xcoord,ycoord,width,height);
459 gp2 = new Graphs(window);
460 area.setIcon(new ImageIcon(gp2.getImage()));
461 }
462
463 frame.pack();
464 frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
465 frame.removeMouseListener(mouse_blocker_listener);
466 }
467 });
468 toggle.setBackground(new Color(176,208,176));
469 pane.add(toggle);
470 }
471
472
473 JButton pen;
474 pen = new JButton(JarTools.getImage("penicon.gif"));
475 pen.setText("Pen");
476 pen.setPreferredSize(new Dimension(30,20));
477 pen.setActionCommand("Pen");
478 pen.setToolTipText("Draw.");
479 pen.addActionListener(new ActionListener ()
480 {
481 public void actionPerformed (ActionEvent e)
482 {
483 area.setCursor(cursor);
484 drawNow = true;
485 }
486 });
487 pen.setBackground(new Color(176,208,176));
488 pane.add(pen);
489
490 JButton eraser;
491 eraser = new JButton(JarTools.getImage("eraser.gif"));
492 eraser.setText("Eraser");
493 eraser.setActionCommand("Eraser");
494 eraser.setPreferredSize(new Dimension(30,20));
495 eraser.setToolTipText("Erase.");
496 eraser.addActionListener(new ActionListener ()
497 {
498 public void actionPerformed (ActionEvent e)
499 {
500 area.setCursor(cursor2);
501 drawNow = false;
502 }
503 });
504 eraser.setBackground(new Color(176,208,176));
505 pane.add(eraser);
506
507 if ((window == null) || (screen == null))
508 {
509 JLabel empty = new JLabel(" ");
510 empty.setBackground(new Color(176,208,176));
511 pane.add(empty);
512 }
513
514 JButton button;
515 button = new JButton("Clear Scribble");
516 button.setActionCommand("Clear");
517 button.setToolTipText("Clear all the scribble lines.");
518 button.addActionListener(this);
519 button.setBackground(new Color(176,208,176));
520 pane.add(button);
521
522 JButton button2;
523 button2 = new JButton("Finish Scribble");
524 button2.setActionCommand(messages.getString("Send"));
525 button2.setToolTipText("Back to Feedback form.");
526 button2.addActionListener(this);
527 button2.setBackground(new Color(176,208,176));
528 pane.add(button2);
529
530 JButton button3;
531 button3 = new JButton("Send");
532 button3.setActionCommand("SendNow");
533 button3.setToolTipText("Finish reporting feedback and send all information now.");
534 button3.addActionListener(this);
535 button3.setBackground(new Color(176,208,176));
536 pane.add(button3);
537
538 panes.add(pane);
539
540 container.add(panes);
541
542 panes.setAlignmentX(Component.LEFT_ALIGNMENT);
543 label.setAlignmentX(Component.LEFT_ALIGNMENT);
544 iconarea.setAlignmentX(Component.LEFT_ALIGNMENT);
545
546 container.setSize(container.getPreferredSize());
547 content.add(container);
548 }
549
550 /**
551 * This method will tell what the program should do when user click the buttons.
552 * @param e this is the event when user click button.
553 */
554 public void actionPerformed (ActionEvent e)
555 {
556 if(messages.getString("Send").equals(e.getActionCommand()))
557 {
558 frame.addMouseListener(mouse_blocker_listener);
559 frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
560 sendNow = false;
561 if (windowNow == false)
562 {
563 window = gp.getWindowVersion(xcoord,ycoord,width,height);
564 }
565 else
566 {
567 window[0] = gp2.getScreenImage();
568 window[1] = gp2.getImage();
569 window[2] = gp2.getImage2();
570 gp.setScreenVersion(window,xcoord,ycoord,width,height);
571 }
572
573 bi5 = gp.getScreenImage();
574 bi = gp.getImage();
575 bi2 = gp.getImage2();
576 bi3 = window[1];
577 bi4 = window[2];
578 bi6 = window[0];
579
580 details = problem_details.getText();
581 frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
582 frame.removeMouseListener(mouse_blocker_listener);
583 dispose();
584 }
585 if ("Clear".equals(e.getActionCommand()))
586 {
587 if (windowNow == false)
588 {
589 gp.reset();
590 area.setIcon(new ImageIcon(gp.getScreenImage()));
591 }
592 else
593 {
594 gp2.reset();
595 area.setIcon(new ImageIcon(gp2.getScreenImage()));
596 }
597 }
598
599 if ("SendNow".equals(e.getActionCommand()))
600 {
601 frame.addMouseListener(mouse_blocker_listener);
602 frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
603 sendNow = true;
604
605 if (windowNow == false)
606 {
607 window = gp.getWindowVersion(xcoord,ycoord,width,height);
608 }
609 else
610 {
611 window[0] = gp2.getScreenImage();
612 window[1] = gp2.getImage();
613 window[2] = gp2.getImage2();
614 gp.setScreenVersion(window,xcoord,ycoord,width,height);
615 }
616
617 bi5 = gp.getScreenImage();
618 bi = gp.getImage();
619 bi2 = gp.getImage2();
620 bi3 = window[1];
621 bi4 = window[2];
622 bi6 = window[0];
623
624 details = problem_details.getText();
625 frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
626 frame.removeMouseListener(mouse_blocker_listener);
627 dispose();
628 }
629 }
630
631 /**
632 * This method will create ImageIcon of the buffered image get from the screen shot instance.
633 * The image is screen shot whole screen size image.
634 * @return ImageIcon of the screen shot image.
635 */
636 protected ImageIcon createImageIcon(boolean iswindow)
637 {
638 if (iswindow == false)
639 {
640 if (screen[1] == null)
641 return new ImageIcon(screen[0]);
642 else
643 return new ImageIcon(screen[1]);
644 }
645 else
646 {
647 if (window[1] == null)
648 return new ImageIcon(window[0]);
649 else
650 return new ImageIcon(window[1]);
651 }
652 }
653
654 /**
655 * This is the special class, that will allows user to draw a line all over the label when
656 * user dragged the mouse inside the area.
657 */
658 private class SelectionArea extends JLabel
659 {
660 /**
661 * This is the owner of this label.
662 */
663 private Selecting controller;
664 /**
665 * This is the x coordinate of the first point.
666 */
667 private int x1;
668 /**
669 * This is the x coordinate of the second point.
670 */
671 private int x2;
672 /**
673 * This is the y coordinate of the first point.
674 */
675 private int y1;
676 /**
677 * This is the y coordinate of the second point.
678 */
679 private int y2;
680 /**
681 * This is the flag to say that user is over the label of the screen image
682 * and they are doing the mouse input from there.
683 */
684 private boolean ismouse;
685
686 /**
687 * This method will create a label with the specified image
688 * icon and it will added with mouse listener that will
689 * allow user to draw a line all over the image.
690 * @param image image icon to be added to the label.
691 * @param controller this is the owner of this label.
692 */
693 public SelectionArea(ImageIcon image, Selecting controller)
694 {
695 super(image);
696 this.controller = controller;
697 setOpaque(true);
698
699 MyListener myListener;
700 myListener = new MyListener();
701 addMouseListener(myListener);
702 addMouseMotionListener(myListener);
703 }
704
705 /**
706 * This is the modified mouse listener that will allow user to draw
707 * a line all over the label while user dragging the mouse.
708 */
709 private class MyListener extends MouseInputAdapter
710 {
711 /**
712 * This method will make a red dot in the place where user pressed the mouse.
713 * @param e the mouse event
714 */
715 public void mousePressed(MouseEvent e)
716 {
717 int x;
718 x = e.getX();
719 int y;
720 y = e.getY();
721
722 x2 = x;
723 y2 = y;
724
725 x1 = x2;
726 y1 = y2;
727 }
728
729 /**
730 * This method will make a red line from (x1,y1) to the coordinate where
731 * the mouse is located now.
732 * @param e the mouse event.
733 */
734 public void mouseDragged(MouseEvent e)
735 {
736 ismouse = true;
737 updateSize(e);
738 }
739
740
741 /**
742 * This method will make a red line from (x1,y1) to the coordinate where
743 * the mouse is located now.
744 * @param e the mouse event.
745 */
746 public void updateSize(MouseEvent e)
747 {
748 int x;
749 x = e.getX();
750 int y;
751 y = e.getY();
752
753 x2 = x;
754 y2 = y;
755
756 repaint();
757 }
758 }
759
760 /**
761 * This method will repaint all the component inside the dialog-window.
762 * It will draw a red line from (x1,y1) to (x2,y2) coordinates and
763 * updates the value of x1,y1 and the icon for the label.
764 * @param g the graphics of this dialog-window.
765 */
766 public void paintComponent(Graphics g)
767 {
768 super.paintComponent(g);
769
770 if (ismouse == true)
771 {
772 if (windowNow == false)
773 {
774 if (drawNow == true)
775 gp.drawLines(x1,y1,x2,y2);
776 else
777 gp.eraseLines(x1,y1,x2,y2);
778 }
779 else
780 {
781 if (drawNow == true)
782 gp2.drawLines(x1,y1,x2,y2);
783 else
784 gp2.eraseLines(x1,y1,x2,y2);
785 }
786
787 x1 = x2;
788 y1 = y2;
789
790 if (windowNow == false)
791 {
792 area.setIcon(new ImageIcon(gp.getImage()));
793 }
794 else
795 {
796 area.setIcon(new ImageIcon(gp2.getImage()));
797 }
798
799 ismouse = false;
800 }
801 }
802 }
803 }
804}
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
Note: See TracBrowser for help on using the repository browser.