Changeset 6748


Ignore:
Timestamp:
2004-02-09T15:55:22+13:00 (20 years ago)
Author:
kjdon
Message:

tidied up preview stuff. if windows and mac, just uses the start/open command and never prompts the user for a browser. if linux, prompts the user (should be changed to look for netscape and mozilla first). now use new prompt, PreviewCommandDialog, to get the browser, not the file association dialog which is really confusing

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileAssociationManager.java

    r6630 r6748  
    3232import org.greenstone.gatherer.Gatherer;
    3333import org.greenstone.gatherer.gui.FileAssociationDialog;
     34import org.greenstone.gatherer.gui.PreviewCommandDialog;
    3435import org.greenstone.gatherer.msm.MSMUtils;
    3536import org.greenstone.gatherer.util.StaticStrings;
     
    104105        return command;
    105106    }
    106     // Failing that we have to prompt the user for what they want to do, but we do our best to provide a sensible default (if available).
    107     // For windows we can have a pretty good guess
     107    command = null;
     108    // Failing that we have a guess at a sensible default
    108109    if(Utility.isWindows()) {
    109110        // we use cmd and start
     
    113114        command = StaticStrings.WIN_OPEN_COMMAND;//"cmd.exe /c start \"\" \""+url+"\"";
    114115        }
    115     }
    116 
    117     // Now prompt the user
    118     FileAssociationDialog dialog = new FileAssociationDialog(this);
    119     command = dialog.display(true, command);
    120     dialog.dispose();
    121     dialog = null;
     116    } else if (Utility.isMac()) {
     117        command = StaticStrings.MAC_OPEN_COMMAND; // "open %1"
     118    } else {
     119        // we try to look for a browser
     120    }
     121   
     122    // if we still haven't found something, prompt the user
     123    if (command == null) {
     124        PreviewCommandDialog dialog = new PreviewCommandDialog();
     125        command = dialog.display();
     126        dialog.dispose();
     127        dialog = null;
     128    }
    122129
    123130    // Store the result if any
    124     if(command != null) {
     131    if(command != null && !command.equals("")) {
    125132        Gatherer.config.setPreviewCommand(command);
    126     }
    127 
    128     // for now uder linux get the fileassoc thing. but eventually want a separate thing.
    129     // pretend we are trying to open an html file
    130     // Mmmoooo. - jmt12
    131 
     133        command = command.replaceAll(FILENAME_ARG, url);
     134        Gatherer.println("Result = " + command);
     135        return command;
     136    }
    132137    // if we haven't got a command by now, we'll never get one
    133     if (command == null) {
    134         Gatherer.println("Result = " + command);
    135         return null;
    136     }
    137     // Replace %1 with the url in quotes
    138     command = command.replaceAll(FILENAME_ARG, url);
    139     Gatherer.println("Result = " + command);
    140     return command;
     138    Gatherer.println("Result = null");
     139    return null;
     140   
    141141    }
    142142
  • trunk/gli/src/org/greenstone/gatherer/gui/FileAssociationDialog.java

    r6539 r6748  
    6464    extends ModalDialog {
    6565
    66     static final private String NORMAL = "normal";
    67     static final private String PREVIEW = "preview";
    68 
    6966    /** The default size of a label. */
    7067    static final private Dimension LABEL_SIZE = new Dimension(150, 25);
     
    7370
    7471    private boolean ignore = false;
    75     private boolean preview_type;
    76     private CardLayout card_layout;
    7772    private FileAssociationDialog self;
    7873    private FileAssociationManager file_association_manager;
     
    8277    private JButton remove_button;
    8378    private JButton replace_button;
    84     private JPanel swap_pane;
    8579    private JTable existing_associations_table;
    8680    private JTextField command_field;
     
    117111    existing_associations_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    118112    JPanel lower_pane = new JPanel();
    119    
    120113    JPanel details_pane = new JPanel();
    121 
    122     card_layout = new CardLayout();
    123     swap_pane = new JPanel(card_layout);
    124114
    125115    JPanel extension_pane = new JPanel();
     
    127117    extension_label.setPreferredSize(LABEL_SIZE);   
    128118    extension_field = new NonWhitespaceField();
    129 
    130     JLabel preview_label = new JLabel();
    131     Dictionary.setText(preview_label, "FileAssociationDialog.Preview");
    132119
    133120    JLabel command_label = new JLabel();
     
    192179    command_pane.add(browse_button, BorderLayout.EAST);
    193180
    194     swap_pane.add(extension_pane, NORMAL);
    195     swap_pane.add(preview_label, PREVIEW);
    196 
    197181    details_pane.setBorder(BorderFactory.createTitledBorder(Dictionary.get("FileAssociationDialog.Details")));
    198182    details_pane.setLayout(new GridLayout(3,1));
    199     details_pane.add(swap_pane);
     183    details_pane.add(extension_pane);
    200184    details_pane.add(command_label);
    201185    details_pane.add(command_pane);
     
    242226     */
    243227    public String display(String new_extension) {
    244     preview_type = false;
    245 
    246228    // Clear the current selection
    247229    existing_associations_table.clearSelection();
    248 
    249     // Now ensable the components that aren't important for the preview collection command
    250     existing_associations_table.setEnabled(true);
    251     Dictionary.setBoth(close_button, "FileAssociationDialog.Close", "FileAssociationDialog.Close_Tooltip");
    252     // And display the extension chooser
    253     card_layout.show(swap_pane, NORMAL);
    254     swap_pane.updateUI();
    255 
    256230    if(new_extension != null) {
    257231        extension_field.setText(new_extension);
    258232    }
    259 
    260233    setVisible(true);
    261 
    262234    if(new_extension != null) {
    263235        return file_association_manager.getCommandString(new_extension);
    264236    }
    265 
    266237    return null;
    267     }
    268 
    269     public String display(boolean is_preview_type, String command) {
    270     System.err.println("Preview type");
    271 
    272     preview_type = true;
    273 
    274     if(command != null) {
    275         command_field.setText(command);
    276     }
    277 
    278     // Clear the current selection
    279     existing_associations_table.clearSelection();
    280 
    281     // Now disable the components that aren't important for the preview collection command
    282     existing_associations_table.setEnabled(false);
    283 
    284     Dictionary.setBoth(close_button, "General.OK", "FileAssociationDialog.Close_Tooltip");
    285 
    286     // And display the preview collection message
    287     card_layout.show(swap_pane, PREVIEW);
    288     swap_pane.updateUI();
    289 
    290     setVisible(true);
    291     return command_field.getText();
    292238    }
    293239
     
    305251   
    306252    public void actionPerformed(ActionEvent event) {
    307         if(!preview_type) {
    308         String extension_str = extension_field.getText();
    309         file_association_manager.setCommand(extension_str, command_field.getText());
    310         // Select the appropriate entry in the table
    311         int index = -1;
    312         for(int i = 0; index == -1 && i < file_association_manager.size(); i++) {
    313             if(file_association_manager.getExtension(i).equals(extension_str)) {
    314             index = i;
    315             }
    316         }
    317         if(index > -1) {
    318             existing_associations_table.setRowSelectionInterval(index, index);
    319         }
    320         // And update buttons
    321         add_button.setEnabled(false);
    322         remove_button.setEnabled(true);
    323         }
     253        String extension_str = extension_field.getText();
     254        file_association_manager.setCommand(extension_str, command_field.getText());
     255        // Select the appropriate entry in the table
     256        int index = -1;
     257        for(int i = 0; index == -1 && i < file_association_manager.size(); i++) {
     258        if(file_association_manager.getExtension(i).equals(extension_str)) {
     259            index = i;
     260        }
     261        }
     262        if(index > -1) {
     263        existing_associations_table.setRowSelectionInterval(index, index);
     264        }
     265        // And update buttons
     266        add_button.setEnabled(false);
     267        remove_button.setEnabled(true);
    324268    }
    325269    }
Note: See TracChangeset for help on using the changeset viewer.