Advertisement
Guest User

Untitled

a guest
May 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. package kolokvij;
  2.  
  3. import java.awt.Image;
  4. import java.awt.List;
  5. import java.io.BufferedInputStream;
  6. import java.io.BufferedOutputStream;
  7. import java.io.File;
  8. import java.io.FileInputStream;
  9. import java.io.FileOutputStream;
  10. import java.io.IOException;
  11. import java.io.LineNumberInputStream;
  12. import java.nio.file.DirectoryStream;
  13. import java.nio.file.FileSystems;
  14. import java.nio.file.Files;
  15. import java.nio.file.Path;
  16. import java.nio.file.Paths;
  17. import java.util.ArrayList;
  18.  
  19. import javax.swing.plaf.FileChooserUI;
  20.  
  21. import org.eclipse.swt.SWT;
  22. import org.eclipse.swt.widgets.Display;
  23. import org.eclipse.swt.widgets.Shell;
  24. import org.eclipse.swt.widgets.Label;
  25. import org.eclipse.swt.widgets.Button;
  26. import org.eclipse.swt.events.SelectionAdapter;
  27. import org.eclipse.swt.events.SelectionEvent;
  28. import org.eclipse.swt.widgets.Text;
  29. import org.eclipse.swt.widgets.Combo;
  30.  
  31. public class app {
  32.  
  33. protected Shell shlAplikacija;
  34. private Text txtPoddirektorij;
  35. private Text txtDirektorij;
  36. private Text txtPopisSlika;
  37. private Text txtStatus;
  38.  
  39. private String podDirektorij;
  40. private String izabranaSlika;
  41. private int index;
  42.  
  43. /**
  44. * Launch the application.
  45. * @param args
  46. */
  47. public static void main(String[] args) {
  48. try {
  49. app window = new app();
  50. window.open();
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. }
  54. }
  55.  
  56. /**
  57. * Open the window.
  58. */
  59. public void open() {
  60. Display display = Display.getDefault();
  61. createContents();
  62. shlAplikacija.open();
  63. shlAplikacija.layout();
  64. while (!shlAplikacija.isDisposed()) {
  65. if (!display.readAndDispatch()) {
  66. display.sleep();
  67. }
  68. }
  69. }
  70.  
  71. /**
  72. * Create contents of the window.
  73. */
  74. protected void createContents() {
  75. shlAplikacija = new Shell();
  76. shlAplikacija.setSize(450, 501);
  77. shlAplikacija.setText("Aplikacija");
  78.  
  79. Label lblOdaberite = new Label(shlAplikacija, SWT.NONE);
  80. lblOdaberite.setBounds(10, 33, 129, 15);
  81. lblOdaberite.setText("Kreiranje poddirektorija");
  82.  
  83. Button btnKreiranjePoddirektorija = new Button(shlAplikacija, SWT.NONE);
  84. btnKreiranjePoddirektorija.addSelectionListener(new SelectionAdapter() {
  85. @Override
  86. public void widgetSelected(SelectionEvent e) {
  87. podDirektorij=(txtPoddirektorij.getText());
  88. try{
  89. Path testDirectoryPath = Paths.get("C:\\SLIKE");
  90. Path newPath = Paths.get(testDirectoryPath+"\\"+podDirektorij);
  91. Files.createDirectory(newPath);
  92. txtStatus.setText("Poddirektorij uspješno kreiran!");
  93. txtDirektorij.setText("C:\\SLIKE\\"+podDirektorij);
  94. }
  95. catch (IOException ex){
  96. ex.printStackTrace();
  97. }
  98. }
  99. });
  100. btnKreiranjePoddirektorija.setBounds(251, 57, 129, 25);
  101. btnKreiranjePoddirektorija.setText("Kreiraj poddirektorij");
  102.  
  103. txtPoddirektorij = new Text(shlAplikacija, SWT.BORDER);
  104. txtPoddirektorij.setBounds(10, 59, 221, 21);
  105.  
  106. Label lblNewLabel = new Label(shlAplikacija, SWT.NONE);
  107. lblNewLabel.setBounds(10, 106, 129, 15);
  108. lblNewLabel.setText("Odabir slika za kopiranje");
  109.  
  110. Combo cmbOdabirSlike = new Combo(shlAplikacija, SWT.READ_ONLY);
  111. cmbOdabirSlike.addSelectionListener(new SelectionAdapter() {
  112. @Override
  113. public void widgetSelected(SelectionEvent e) {
  114. index= cmbOdabirSlike.getSelectionIndex();
  115. izabranaSlika=cmbOdabirSlike.getItem(index);
  116. }
  117. });
  118. cmbOdabirSlike.setBounds(10, 138, 109, 23);
  119. try {
  120.  
  121.  
  122. Path originalDirectory = FileSystems.getDefault().
  123. getPath("C:\\Users\\Marin\\Desktop\\Slike s mobitela");
  124.  
  125. DirectoryStream<Path> stream =
  126. Files.newDirectoryStream(originalDirectory, "*.PNG"); {
  127. for (Path entry : stream) {
  128. cmbOdabirSlike.add(entry.getFileName().toString());
  129.  
  130. }
  131. }
  132. stream.close();
  133. } catch (IOException e1) {
  134. // TODO Auto-generated catch block
  135. e1.printStackTrace();
  136. }
  137.  
  138.  
  139. txtDirektorij = new Text(shlAplikacija, SWT.BORDER);
  140. txtDirektorij.setBounds(147, 138, 129, 21);
  141.  
  142.  
  143. Button btnKopiraj = new Button(shlAplikacija, SWT.NONE);
  144. btnKopiraj.addSelectionListener(new SelectionAdapter() {
  145. @Override
  146. public void widgetSelected(SelectionEvent e1) {
  147. System.out.println(izabranaSlika);
  148. try {
  149. FileInputStream in= new FileInputStream("C:\\Users\\Marin\\Desktop\\Slike s mobitela\\"+izabranaSlika);
  150. FileOutputStream out = new FileOutputStream("C:\\SLIKE\\"+podDirektorij+"\\"+izabranaSlika);
  151. BufferedInputStream bin = new BufferedInputStream(in);
  152. BufferedOutputStream bout = new BufferedOutputStream(out);
  153. int b = 0;
  154. while(b!=-1) {
  155. b=bin.read();
  156. bout.write(b);
  157. }
  158. bin.close();
  159. bout.close();
  160. }
  161. catch (IOException e){
  162. System.out.println("Posao nije obavljen.");
  163.  
  164. }
  165. }
  166. });
  167. btnKopiraj.setBounds(315, 132, 88, 32);
  168. btnKopiraj.setText("Kopiraj");
  169.  
  170. txtPopisSlika = new Text(shlAplikacija, SWT.BORDER);
  171. txtPopisSlika.setBounds(10, 232, 109, 94);
  172.  
  173. Label lblPopisKopiranihSlika = new Label(shlAplikacija, SWT.NONE);
  174. lblPopisKopiranihSlika.setBounds(10, 194, 129, 15);
  175. lblPopisKopiranihSlika.setText("Popis kopiranih slika");
  176.  
  177. Button btnPopisSlika = new Button(shlAplikacija, SWT.NONE);
  178. btnPopisSlika.addSelectionListener(new SelectionAdapter() {
  179. @Override
  180. public void widgetSelected(SelectionEvent e) {
  181. }
  182. });
  183. btnPopisSlika.setBounds(147, 259, 109, 39);
  184. btnPopisSlika.setText("Prikazi popis slika");
  185.  
  186. Label lblStatus = new Label(shlAplikacija, SWT.NONE);
  187. lblStatus.setBounds(10, 374, 39, 15);
  188. lblStatus.setText("Status");
  189.  
  190. txtStatus = new Text(shlAplikacija, SWT.BORDER);
  191. txtStatus.setBounds(62, 371, 341, 21);
  192.  
  193. Button btnIzlaz = new Button(shlAplikacija, SWT.NONE);
  194. btnIzlaz.setBounds(349, 427, 75, 25);
  195. btnIzlaz.setText("Izlaz");
  196.  
  197. }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement