Package GUI

Source Code of GUI.ExportOnlineDialog$ExportThread

package GUI;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;

import com.pseuco.PseuCoShare;

public class ExportOnlineDialog extends JDialog {
  private static final long serialVersionUID = 1L;

  private final JPanel contentPanel = new JPanel();
 
  private final String filename;
  private final String code;
  private URI uri;

  /**
   * Create the dialog.
   */
  public ExportOnlineDialog(String filename, String code) {
    addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        close();
      }
    });
    this.filename = filename;
    this.code = code;
    setTitle("Export to pseuco.com");
    setBounds(100, 100, 349, 139);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
    {
      JLabel lblSubmittingYourFile = new JLabel("Submitting your file to pseuco.com ...");
      lblSubmittingYourFile.setFont(new Font("Tahoma", Font.PLAIN, 12));
      contentPanel.add(lblSubmittingYourFile);
    }
    {
      Component verticalStrut = Box.createVerticalStrut(20);
      verticalStrut.setMaximumSize(new Dimension(32767, 10));
      verticalStrut.setMinimumSize(new Dimension(0, 10));
      verticalStrut.setPreferredSize(new Dimension(0, 10));
      contentPanel.add(verticalStrut);
    }
    {
      JProgressBar progressBar = new JProgressBar();
      progressBar.setIndeterminate(true);
      contentPanel.add(progressBar);
    }
    {
      JPanel buttonPane = new JPanel();
      buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
      getContentPane().add(buttonPane, BorderLayout.SOUTH);
      {
        JButton cancelButton = new JButton("Cancel");
        cancelButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            close();
            dispose();
          }
        });
        cancelButton.setPreferredSize(new Dimension(80, 28));
        cancelButton.setFont(new Font("Tahoma", Font.PLAIN, 12));
        cancelButton.setActionCommand("Cancel");
        buttonPane.add(cancelButton);
      }
    }
  }
 
 
  private Thread exportThread;
 

  @SuppressWarnings("deprecation")
  private void close() {
    if (exportThread != null){
      exportThread.stop();
    }
  }
 
  /**
   * Should be called in EDT
   */
  public void startExport(){
    setVisible(true);
    exportThread = new ExportThread();
    exportThread.start();
  }

 
  private class ExportThread extends Thread{
   
    @Override
    public void run(){
      try{
        PseuCoShare pcs = new PseuCoShare();
        uri = pcs.submitFile("pseuco", filename, code, true);
        pcs.openInBrowser(uri);
        exportThread = null;
        dispose();
      }catch(Exception e){
        final Exception e2 = e;
        try {
          SwingUtilities.invokeAndWait(new Runnable() {
           
            @Override
            public void run() {
              JOptionPane.showMessageDialog(ExportOnlineDialog.this, "Error: "+e2.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);             
            }
          });
        } catch (InvocationTargetException | InterruptedException e1) {
        }
      }
    }
  }
}
TOP

Related Classes of GUI.ExportOnlineDialog$ExportThread

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.