Skip to content
This repository has been archived by the owner on Dec 22, 2019. It is now read-only.

Commit

Permalink
Internal refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cn committed Aug 26, 2012
1 parent 3bd5855 commit e5076c6
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions src/de/jcloudapp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,31 @@ public void run() {
icon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!working) { working = true; doScreen(); working = false; }
if(!working) { working = true; doScreenshot(); working = false; }
}
});

MenuItem screen = new MenuItem("Take screenshot");
MenuItem screen = new MenuItem("Take Screenshot");
screen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!working) { working = true; doScreen(); working = false; }
if(!working) { working = true; doScreenshot(); working = false; }
}
});

MenuItem uploadClip = new MenuItem("Upload from clipboard");
MenuItem uploadClip = new MenuItem("Upload from Clipboard");
uploadClip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!working) { working = true; doUploadClip(); working = false; }
if(!working) { working = true; doUploadClipboard(); working = false; }
}
});

MenuItem upload = new MenuItem("Upload...");
MenuItem upload = new MenuItem("Upload File...");
upload.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!working) { working = true; doUpload(); working = false; }
if(!working) { working = true; doUploadFile(); working = false; }
}
});

Expand Down Expand Up @@ -176,7 +176,7 @@ public void actionPerformed(ActionEvent e) {
}
}

public void doScreen() {
public void doScreenshot() {
System.out.println("Taking screenshot...");
BufferedImage bi = takeScreenshot();
try {
Expand All @@ -202,7 +202,7 @@ public void doScreen() {
}

@SuppressWarnings("unchecked")
public void doUploadClip() {
public void doUploadClipboard() {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable t = cb.getContents(null);

Expand Down Expand Up @@ -234,6 +234,46 @@ else if(t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
}
}

public void doUploadFile() {
FileDialog dlg = new FileDialog((Dialog)null, "Upload File...");
dlg.setVisible(true);
if(dlg.getDirectory() == null || dlg.getFile() == null) {
return;
}
File f = new File(dlg.getDirectory()+File.separator+dlg.getFile());
if(f.exists()) {
setImageWorking();
JSONObject drop = upload(f);
if(drop == null) { return; }
String url = getDropUrl(drop);
System.out.println("Upload complete, URL:\n"+url);
setClipboard(url);
setImageNormal();
icon.displayMessage("Upload finished", String.format("Item: %s", f.getName()), TrayIcon.MessageType.INFO);
}
}

public void doAbout() {
String msg = "JCloudApp (C) 2011 Christian Nicolai\n\n"
+ "Easy uploading of screenshots and files to CloudApp (tm) - cross-plattform.";
JOptionPane.showMessageDialog(null, msg, "About", JOptionPane.INFORMATION_MESSAGE);
}

public void doQuit() {
exit();
}

private BufferedImage takeScreenshot() {
try {
Robot robot = new Robot();
Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
return robot.createScreenCapture(captureSize);
} catch(AWTException ex) {
System.out.println(ex);
}
return null;
}

private void uploadFilesFromClipboard(List<File> data) {
if(data != null && data.size() > 0) {
setImageWorking();
Expand Down Expand Up @@ -270,7 +310,7 @@ private void uploadFilesFromClipboard(List<File> data) {
icon.displayMessage("Upload finished", msg, TrayIcon.MessageType.INFO);
}
}

private void uploadImageFromClipboard(BufferedImage bi) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -294,46 +334,6 @@ private void uploadImageFromClipboard(BufferedImage bi) {
}
}

public void doUpload() {
FileDialog dlg = new FileDialog((Dialog)null, "Upload...");
dlg.setVisible(true);
if(dlg.getDirectory() == null || dlg.getFile() == null) {
return;
}
File f = new File(dlg.getDirectory()+File.separator+dlg.getFile());
if(f.exists()) {
setImageWorking();
JSONObject drop = upload(f);
if(drop == null) { return; }
String url = getDropUrl(drop);
System.out.println("Upload complete, URL:\n"+url);
setClipboard(url);
setImageNormal();
icon.displayMessage("Upload finished", String.format("Item: %s", f.getName()), TrayIcon.MessageType.INFO);
}
}

public void doAbout() {
String msg = "JCloudApp (C) 2011 Christian Nicolai\n\n"
+ "Easy uploading of screenshots and files to CloudApp (tm) - cross-plattform.";
JOptionPane.showMessageDialog(null, msg, "About", JOptionPane.INFORMATION_MESSAGE);
}

public void doQuit() {
exit();
}

private BufferedImage takeScreenshot() {
try {
Robot robot = new Robot();
Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
return robot.createScreenCapture(captureSize);
} catch(AWTException ex) {
System.out.println(ex);
}
return null;
}

private JSONObject upload(File file) {
try {
return client.uploadFile(file);
Expand Down

0 comments on commit e5076c6

Please sign in to comment.