Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * BlueJPastebin
- * Connects BlueJ to the Pastebin service
- * @author revoked
- * @version Alpha 0.1
- * Code adapted from BlueJ source code
- import bluej.extensions.*;
- import bluej.extensions.event.*;
- import bluej.extensions.editor.*;
- import java.net.URL;
- import javax.swing.*;
- import java.awt.event.*;
- import java.net.*;
- import java.io.*;
- import java.util.Scanner;
- public class SimpleExtension2 extends Extension implements PackageListener {
- public void startup (BlueJ bluej) {
- bluej.setMenuGenerator(new MenuBuilder());
- bluej.addPackageListener(this);
- }
- public void packageOpened ( PackageEvent ev ) {
- try {
- System.out.println ("Project " + ev.getPackage().getProject().getName() + " opened.");
- } catch (ExtensionException e) {
- System.out.println("Project closed by BlueJ");
- }
- }
- public void packageClosing ( PackageEvent ev ) {
- }
- public boolean isCompatible () {
- return true;
- }
- public String getVersion () {
- return ("0.1");
- }
- public String getName () {
- return ("BlueJPastebin");
- }
- public void terminate() {
- System.out.println ("BlueJPastebin exiting");
- }
- public String getDescription () {
- return ("Allows users to directly upload code from BlueJ to the Pastebin service");
- }
- public URL getURL () {
- try {
- return new URL("http://www.bluej.org/doc/writingextensions.html");
- } catch ( Exception eee ) {
- System.out.println ("BlueJPasebin: getURL: Exception="+eee.getMessage());
- return null;
- }
- }
- }
- class MenuBuilder extends MenuGenerator {
- private BPackage curPackage;
- private BClass curClass;
- private BObject curObject;
- public JMenuItem getClassMenuItem(BClass aClass) {
- JMenu jm = new JMenu("Pastebin");
- jm.add(new JMenuItem(new EditAction()));
- return jm;
- }
- public void notifyPostClassMenu(BClass bc, JMenuItem jmi) {
- System.out.println("Post on Class menu by BlueJPastebin");
- curPackage = null ; curClass = bc ; curObject = null;
- }
- public void addCode() {
- Editor classEditor = null;
- try {
- classEditor = curClass.getEditor();
- } catch (Exception e) { }
- if(classEditor == null) {
- System.out.println("Can't create Editor for " + curClass);
- return;
- }
- int textLen = classEditor.getTextLength();
- TextLocation beginningLocation = classEditor.getSelectionBegin();
- TextLocation endingLocation = classEditor.getSelectionEnd();
- TextLocation lastLine = classEditor.getTextLocationFromOffset(textLen);
- try {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter your pastebin code:");
- String urlParameters = "api_option=paste&api_paste_code="ha"&api_dev_key="revokedforso";
- URL myURL = new URL("http://pastebin.com/api/api_post.php");
- URLConnection myURLConnection = myURL.openConnection();
- myURLConnection.setDoOutput(true);
- myURLConnection.connect();
- OutputStreamWriter writer = new OutputStreamWriter(myURLConnection.getOutputStream());
- writer.write(urlParameters);
- writer.flush();
- String line;
- BufferedReader reader = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
- while ((line = reader.readLine()) != null) {
- JOptionPane.showMessageDialog(null, line);
- }
- writer.close();
- reader.close();
- }
- catch (MalformedURLException e) {
- // new URL() failed
- // ...
- System.out.println("Enter a valid URL");
- }
- catch (IOException e) {
- // openConnection() failed
- // ...
- System.out.println("INPUT OUTPUT ERROR");
- }
- }
- class EditAction extends AbstractAction {
- public EditAction() {
- putValue(AbstractAction.NAME, "Upload to Patebin");
- }
- public void actionPerformed(ActionEvent e) {
- addCode();
- }
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement