Changeset 6089


Ignore:
Timestamp:
2003-12-02T17:21:46+13:00 (20 years ago)
Author:
jmt12
Message:

Added indeterminate progress bar while exporting. There was a lot of hassle involving interaction between javas modal dialogs are our better version - which inevitably lead to the AWTEvent thread remaining blocked. By writing my own dialog to replace JOptionPane this problem went away, but there is still something strange happening as the export dialog itself loses its modality immediately after a message dialog is shown on screen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/ExportCollectionPrompt.java

    r6061 r6089  
    6767    extends ModalDialog
    6868    implements GShellListener {
     69   
     70    private OKButtonListener ok_button_listener;
    6971    private ArrayList all_collections = null;
    7072    private ArrayList selected_collections = null;
     
    111113     */
    112114    public ExportCollectionPrompt() {
    113     super(Gatherer.g_man);
     115    super(Gatherer.g_man, true);
    114116    cancel_button = new JButton();
    115117    cancel_button.setMnemonic(KeyEvent.VK_C);
     
    149151
    150152    prompt = this;
    151     setModal(true);
    152153    setSize(SIZE);
    153154    Dictionary.setText(this, "ExportCollectionPrompt.Title");
     
    158159    list.clearSelection();
    159160    list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    160     ok_button.addActionListener(new OKButtonListener());
     161    ok_button_listener = new OKButtonListener();
     162    ok_button.addActionListener(ok_button_listener);
    161163    ok_button.setEnabled(false);
    162164    //title.getDocument().addDocumentListener(new DocumentListener());
     
    290292    Gatherer.println("");
    291293    GShell process = new GShell(args, GShell.EXPORT, 3, this, null, GShell.GSHELL_EXPORT);
    292     //process.addGShellListener(this); - already added as listener
    293     process.run(); // Don't bother threading this... yet
     294    process.start();
     295    //process.run();
    294296    Gatherer.println("ExportCollectionPrompt.exportCollection().return");
    295297    }
     
    316318        args[1] += "exported_"+cd_title.replaceAll("\\s","");
    317319    }
     320    ResultDialog result_dialog = new ResultDialog(success, extra);
     321    result_dialog.setVisible(true); // Blocks
     322    result_dialog.dispose();
     323    result_dialog = null;
     324    /*
    318325    if (success) {
    319326        JOptionPane.showMessageDialog(prompt,Dictionary.get("ExportCollectionPrompt.Successful_Export", args)+"\n\n"+Dictionary.get("ExportCollectionPrompt.Output")+"\n"+extra, Dictionary.get("ExportCollectionPrompt.Successful_Title"),JOptionPane.INFORMATION_MESSAGE);
     
    322329        JOptionPane.showMessageDialog(prompt,Dictionary.get("ExportCollectionPrompt.Failed_Export", args)+"\n\n"+Dictionary.get("ExportCollectionPrompt.Output")+"\n"+extra, Dictionary.get("ExportCollectionPrompt.Failed_Title"),JOptionPane.WARNING_MESSAGE);
    323330    }
     331    */
    324332    }
    325333
     
    381389     */
    382390    public synchronized void processComplete(GShellEvent event) {
     391    successful = false;
    383392    if(event.getStatus() == GShell.OK) {
    384393        if(event.getType() == GShell.EXPORT) {
     
    386395        }
    387396    }
    388     else {
    389         successful = false;
    390     }
     397    ok_button_listener.processComplete();
    391398    }
    392399
     
    433440    private class OKButtonListener
    434441    implements ActionListener {
     442    private Component glass_pane;
     443    private MouseListener mouse_blocker_listener;
     444    private ProgressDialog progress_dialog;
     445
    435446    /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
    436447     * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
     
    440451     */
    441452    public void actionPerformed(ActionEvent event) {
    442         // make sure there are some colls specified
     453        ///ystem.err.println("OK Clicked");
     454        // Make sure there are some colls specified
    443455        selected_collections = list.getSelected();
    444456        error_message = new StringBuffer();
    445457       
    446         // set the cursor to hourglass
    447         Component glass_pane = getGlassPane();
    448         MouseListener mouse_blocker_listener = new MouseAdapter() {};
     458        // Set the cursor to hourglass
     459        glass_pane = getGlassPane();
     460        mouse_blocker_listener = new MouseAdapter() {};
    449461        glass_pane.addMouseListener(mouse_blocker_listener);
    450462        glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     
    452464
    453465        // Export the selected collection.
     466        ///ystem.err.println("Export collections");
    454467        exportCollections();
    455        
     468
     469        // Show progress dialog
     470        ///ystem.err.println("Showing progress dialog");
     471        progress_dialog = new ProgressDialog();
     472        progress_dialog.setVisible(true);
     473    }
     474
     475    public void processComplete() {
     476        ///ystem.err.println("Process complete");
     477        // Dispose of progress dialog
     478        progress_dialog.setVisible(false);
     479        progress_dialog.dispose();
     480        progress_dialog = null;
     481
    456482        // unset the cursor
    457483        glass_pane.setVisible(false);
     
    460486        glass_pane = null;
    461487        mouse_blocker_listener= null;
    462 
     488       
    463489        if (successful) {
    464490        resultPrompt(true, error_message.toString());
     
    468494        error_message = null;
    469495    }
     496
     497    private class ProgressDialog
     498        extends ModalDialog {
     499       
     500        private Dimension size = new Dimension(400,65);
     501       
     502        public ProgressDialog() {
     503        super(Gatherer.g_man, Dictionary.get("ExportCollectionPrompt.Title"), true);
     504        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
     505        setSize(size);
     506        JPanel content_pane = (JPanel) getContentPane();
     507        JLabel progress_label = new JLabel();
     508        Dictionary.setText(progress_label, "ExportCollectionPrompt.Progress_Label");
     509        JProgressBar progress_bar = new JProgressBar();
     510        progress_bar.setIndeterminate(true);
     511        content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     512        content_pane.setLayout(new BorderLayout());
     513        content_pane.add(progress_label, BorderLayout.NORTH);
     514        content_pane.add(progress_bar, BorderLayout.CENTER);
     515        // Position
     516        Rectangle frame_bounds = Gatherer.g_man.getBounds();
     517        setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
     518        }
     519    }
    470520    }
    471521
     
    504554    }
    505555    }
     556
     557    private class ResultDialog
     558    extends ModalDialog {
     559   
     560    private Dimension size = new Dimension(400,300);
     561    private ResultDialog self;
     562
     563    public ResultDialog(boolean success, String extra) {
     564        super(Gatherer.g_man, Dictionary.get("ExportCollectionPrompt.Successful_Title"), true);
     565
     566        this.self = this;
     567
     568        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
     569        setSize(size);
     570       
     571        JPanel content_pane = (JPanel) getContentPane();
     572        JLabel result_label = new JLabel();
     573        if(success) {
     574        Dictionary.registerText(result_label, "ExportCollectionPrompt.Successful_Export");
     575        }
     576        else {
     577        Dictionary.registerText(result_label, "ExportCollectionPrompt.Failed_Export");
     578        }
     579
     580        JPanel button_pane = new JPanel();
     581        JButton close_button = new JButton("Close");
     582        close_button.addActionListener(new CloseButtonListener());
     583
     584        JPanel output_pane = new JPanel();
     585        JLabel output_label = new JLabel();
     586        Dictionary.registerText(output_label, "ExportCollectionPrompt.Output");
     587
     588        JTextArea output_textarea = new JTextArea(extra);
     589        output_textarea.setCaretPosition(0);
     590        output_textarea.setEditable(false);
     591        output_textarea.setLineWrap(true);
     592        output_textarea.setWrapStyleWord(true);
     593       
     594        button_pane.setLayout(new BorderLayout());
     595        button_pane.add(close_button, BorderLayout.EAST);
     596
     597        output_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
     598        output_pane.setLayout(new BorderLayout());
     599        output_pane.add(output_label, BorderLayout.NORTH);
     600        output_pane.add(new JScrollPane(output_textarea), BorderLayout.CENTER);
     601
     602        content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     603        content_pane.setLayout(new BorderLayout());
     604        content_pane.add(result_label, BorderLayout.NORTH);
     605        content_pane.add(output_pane, BorderLayout.CENTER);
     606        content_pane.add(button_pane, BorderLayout.SOUTH);
     607
     608        // Position
     609        Rectangle frame_bounds = Gatherer.g_man.getBounds();
     610        setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
     611    }
     612
     613    private class CloseButtonListener
     614        implements ActionListener {
     615        public void actionPerformed(ActionEvent event) {
     616        self.setVisible(false);
     617        }
     618    }
     619    }
    506620}
     621
     622
     623
     624
Note: See TracChangeset for help on using the changeset viewer.