greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 16335

Show
Ignore:
Timestamp:
2008-07-10 13:30:55 (4 months ago)
Author:
ak19
Message:

Value_field is now a JComponent rather than a JTextField, since URLField.java has changed to encompass JCombobox as well (it was previously a JTextField only)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gli/trunk/src/org/greenstone/gatherer/gui/WarningDialog.java

    r14568 r16335  
    4848    private JButton ok_button; 
    4949    private JCheckBox show_check; 
    50     private JTextField value_field; 
     50    private JComponent value_field; 
    5151    private JPanel value_panel; 
    5252    private String affected_property; 
    5353    private String full_property; 
    54  
    55  
    56     public WarningDialog(String warning_name, String warning_title, String warning_message, String affected_property, boolean can_cancel) 
     54    /** Whether or not to display the checkbox that will turn off this dialog in future */ 
     55    private final boolean showcheckbox; 
     56 
     57 
     58    public WarningDialog(String warning_name, String warning_title, String warning_message, String affected_property, boolean can_cancel)  
     59    { 
     60        this(warning_name, warning_title, warning_message, affected_property, can_cancel, true); // true for show checkbox 
     61    } 
     62 
     63 
     64    public WarningDialog(String warning_name, String warning_title, String warning_message, String affected_property, boolean can_cancel, 
     65                         boolean showcheckbox) 
    5766    { 
    5867        super(Gatherer.g_man, "Warning", true); 
     68 
     69        this.showcheckbox = showcheckbox;  
    5970 
    6071        // Determine the name of this prompt. 
     
    8899        value_field = new JTextField(); 
    89100        JPanel bottom_pane = new JPanel(); 
    90         show_check = new JCheckBox(Dictionary.get("WarningDialog.Dont_Show_Again")); 
    91101        JPanel control_pane = new JPanel(); 
    92102        ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip")); 
     
    129139        bottom_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 
    130140        bottom_pane.setLayout(new BorderLayout()); 
    131         bottom_pane.add(show_check, BorderLayout.CENTER); 
    132141        bottom_pane.add(control_pane, BorderLayout.EAST); 
     142        if(showcheckbox) { 
     143            show_check = new JCheckBox(Dictionary.get("WarningDialog.Dont_Show_Again")); 
     144            bottom_pane.add(show_check, BorderLayout.CENTER); 
     145        } 
    133146 
    134147        content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 
     
    150163 
    151164    public void actionPerformed(ActionEvent event) { 
    152         boolean bad_value = false; 
     165        boolean valid_value = true; 
    153166        if(event.getSource() == ok_button) { 
    154167            if(affected_property != null && Configuration.self != null) { 
    155                 String value = value_field.getText(); 
    156                 if(value.length() > 0) { 
    157                    if(value_field instanceof URLField) { 
    158                       bad_value = !((URLField)value_field).validateURL(); 
    159                    } 
    160                    if(!bad_value) { 
    161                       // Store the value of the property 
    162                       Configuration.setString(affected_property, true, value_field.getText()); 
    163                    } 
     168                valid_value = URLField.validateURL(value_field); 
     169                if(valid_value) { 
     170                    // Store the value of the property 
     171                    URLField.store(value_field, affected_property); //Configuration.setString(affected_property, true, value); 
    164172                } 
    165173            } 
    166             if(!bad_value) { 
     174            if(valid_value) { 
    167175                result = JOptionPane.OK_OPTION; 
    168176            } 
    169         } 
    170         if(!bad_value) { 
    171             if (Configuration.self != null) { 
     177        }  
     178 
     179        if(valid_value) { 
     180            if (Configuration.self != null && showcheckbox) { 
    172181                // Store the state of the show message checkbox. 
    173182                Configuration.set(full_property, true, !show_check.isSelected()); 
     
    182191 
    183192    /** Gives notification of key events on the buttons */ 
    184     public void keyPressed(KeyEvent e) { 
     193    public void keyPressed(KeyEvent e) {} 
     194 
     195    public void keyReleased(KeyEvent e) { 
    185196        if (e.getKeyCode() == KeyEvent.VK_ENTER) { 
    186197            // Enter: Click the button in focus 
     
    192203    } 
    193204 
    194     public void keyReleased(KeyEvent e) { } 
    195  
    196     public void keyTyped(KeyEvent e) { } 
     205    public void keyTyped(KeyEvent e) {} 
    197206 
    198207 
     
    216225     */ 
    217226    public void setMessageOnly(boolean message_only) { 
     227        if(!showcheckbox) { 
     228            return; 
     229        } 
     230 
    218231        // If this is a message then change the checkbox 
    219232        if(message_only) { 
     
    229242     * @param  control the JTextField subclass you want to use for the control 
    230243     */ 
    231     public void setValueField(JTextField control) { 
     244    public void setValueField(JComponent control) { 
    232245        // Remove the current control 
    233246        value_panel.remove(value_field); 
     
    253266 
    254267    public void setValueField(String field_value){ 
    255         this.value_field.setText(field_value); 
     268        URLField.setText(this.value_field, field_value); 
    256269    } 
    257270