Advertisement
enjikaka

Untitled

Aug 16th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. package se.enji;
  2.  
  3. import javax.swing.*;
  4.  
  5. import java.awt.FlowLayout;
  6. import java.awt.Toolkit;
  7. import java.awt.datatransfer.Clipboard;
  8. import java.awt.datatransfer.ClipboardOwner;
  9. import java.awt.datatransfer.DataFlavor;
  10. import java.awt.datatransfer.StringSelection;
  11. import java.awt.datatransfer.Transferable;
  12. import java.awt.datatransfer.UnsupportedFlavorException;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.io.IOException;
  16. import java.util.HashMap;
  17.  
  18. public class Main extends JFrame implements ActionListener, ClipboardOwner {
  19.     private static final long serialVersionUID = -2536366832940097597L;
  20.  
  21.     public Main() {
  22.         super("SVT Play Downloader");
  23.         setSize(300, 300);
  24.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.         FlowLayout flow = new FlowLayout();
  26.         setLayout(flow);
  27.         JButton btn = new JButton("Klistra in debug kod.");
  28.         btn.addActionListener(this);
  29.         add(btn);
  30.         JTextPane jtxt = new JTextPane();
  31.         jtxt.setText("Klistra in kod ovan.");
  32.         add(jtxt);
  33.         setVisible(true);
  34.     }
  35.    
  36.     public static void main(String[] args) {
  37.         Main frame = new Main();
  38.     }
  39.    
  40.     public void actionPerformed(ActionEvent e) {
  41.         HashMap<String, String> hash = new HashMap<String, String>();
  42.         String cb = cbCopy();
  43.         String[] cbl = cb.split("\\r?\\n");
  44.         log("lines: " + cbl.length);
  45.         for (int i = 0; i < cbl.length; i++) {
  46.             String line = cbl[i];
  47.             if (line.contains(":")) {
  48.                 String[] co = line.split(":");
  49.                 String key = co[0].trim();
  50.                 String val = co[1].trim();
  51.                 if (key.isEmpty()) key = "_";
  52.                 if (val.isEmpty()) val = "_";
  53.                 hash.put(key, val);
  54.                 log(key + "=>" + co[1]);
  55.             }
  56.             else log(line);
  57.         }
  58.         //String out = hash.toString();
  59.         //cbPaste(out);
  60.         //log("Pasted");
  61.     }
  62.    
  63.     public void cbPaste(String s) {
  64.         StringSelection ss = new StringSelection(s);
  65.         Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
  66.         cb.setContents(ss, this);
  67.     }
  68.    
  69.     public String cbCopy() {
  70.         String result = "";
  71.         Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
  72.         Transferable contents = cb.getContents(null);
  73.         boolean notEmpty = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
  74.         if (notEmpty) {
  75.             try {
  76.                 result = (String)contents.getTransferData(DataFlavor.stringFlavor);
  77.             }
  78.             catch (UnsupportedFlavorException ex) {
  79.                 System.out.println(ex);
  80.                 ex.printStackTrace();
  81.             }
  82.             catch (IOException ex) {
  83.                 System.out.println(ex);
  84.                 ex.printStackTrace();
  85.             }
  86.         }
  87.         return result;
  88.     }
  89.    
  90.     public void log(String s) {
  91.         System.out.println(s);
  92.     }
  93.  
  94.     @Override
  95.     public void lostOwnership(Clipboard arg0, Transferable arg1) {
  96.         // TODO Auto-generated method stub
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement