Changeset 5058


Ignore:
Timestamp:
2003-07-29T10:48:16+12:00 (21 years ago)
Author:
jmt12
Message:

Modified WarningDialog to allow it to display a text field if the name of the affected property is provided.

File:
1 edited

Legend:

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

    r4675 r5058  
    1515    implements ActionListener {
    1616
    17     static final private Dimension SIZE = new Dimension(400,160);
     17    static final private Dimension LABEL_SIZE = new Dimension(150, 25);
     18    static final private Dimension NORMAL_SIZE = new Dimension(400, 160);
     19    static final private Dimension SETTING_SIZE = new Dimension(400, 200);
    1820
     21    private Dictionary dictionary;
    1922    private int result = JOptionPane.CANCEL_OPTION;
    2023    private JButton cancel_button;
    2124    private JButton ok_button;
    2225    private JCheckBox show_check;
     26    private JTextField value_field;
     27    private String affected_property;
    2328    private String full_property;
    2429    private String warning_name;
    2530
     31    public WarningDialog(String full_property) {
     32    this(full_property, false, null, Gatherer.dictionary);
     33    }
     34
    2635    public WarningDialog(String full_property, boolean can_cancel) {
     36    this(full_property, can_cancel, null, Gatherer.dictionary);
     37    }
     38
     39    public WarningDialog(String full_property, String affected_property) {
     40    this(full_property, false, affected_property, Gatherer.dictionary);
     41    }
     42
     43    public WarningDialog(String full_property, boolean can_cancel, Dictionary dictionary) {
     44    this(full_property, can_cancel, null, dictionary);
     45    }
     46
     47    public WarningDialog(String full_property, String affected_feature, Dictionary dictionary) {
     48    this(full_property, false, affected_feature, dictionary);
     49    }
     50
     51    public WarningDialog(String full_property, boolean can_cancel, String affected_property) {
     52    this(full_property, can_cancel, affected_property, Gatherer.dictionary);
     53    }
     54   
     55    public WarningDialog(String full_property, boolean can_cancel, String affected_property, Dictionary dictionary) {
    2756    super(Gatherer.g_man, "Warning", true);
    2857    // Determine the name of this prompt.
     58    this.affected_property = affected_property;
     59    this.dictionary = dictionary;
    2960    this.full_property = full_property;
    3061    warning_name = full_property.substring(full_property.indexOf(".") + 1);
    3162    // Now build dialog.
    32     setSize(SIZE);
     63    if(affected_property != null) {
     64        setSize(SETTING_SIZE);
     65    }
     66    else {
     67        setSize(NORMAL_SIZE);
     68    }
    3369    setTitle(get("Title"));
    3470    // Creation
     
    4076    text_area.setLineWrap(true);
    4177    text_area.setWrapStyleWord(true);
     78    JPanel value_panel = new JPanel();
     79    JLabel value_label = new JLabel(get("WarningDialog.Value"));
     80    value_label.setPreferredSize(LABEL_SIZE);
     81    value_field = new JTextField();
    4282    JPanel bottom_pane = new JPanel();
    4383    show_check = new JCheckBox(get("WarningDialog.Dont_Show_Again"), false);
     
    5191    icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
    5292
     93    value_label.setBorder(BorderFactory.createEmptyBorder(0, icon_label.getPreferredSize().width, 0, 0));
     94
     95    value_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
     96    value_panel.setLayout(new BorderLayout());
     97    value_panel.add(value_label, BorderLayout.WEST);
     98    value_panel.add(value_field, BorderLayout.CENTER);
     99
    53100    text_pane.setLayout(new BorderLayout());
    54101    text_pane.add(icon_label, BorderLayout.WEST);
    55102    text_pane.add(new JScrollPane(text_area), BorderLayout.CENTER);
     103    if(affected_property != null) {
     104        text_pane.add(value_panel, BorderLayout.SOUTH);
     105    }
    56106         
    57107    if(can_cancel) {
     
    75125    content_pane.add(bottom_pane, BorderLayout.SOUTH);
    76126    // Position
     127    Dimension size = getSize();
    77128    if(Gatherer.g_man != null) {
    78129        Rectangle frame_bounds = Gatherer.g_man.getBounds();
    79         setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
     130        setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
    80131    }
    81132    else {
    82133        Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
    83         setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
     134        setLocation((screen_size.width - size.width) / 2, (screen_size.height - size.height) / 2);
    84135    }
    85136    }
     
    88139    if(event.getSource() == ok_button) {
    89140        result = JOptionPane.OK_OPTION;
     141        if(Gatherer.config != null) {
     142        // Store the value of the property
     143        Gatherer.config.setString(affected_property, true, value_field.getText());
     144        }
    90145    }
    91     // Store the state of the show message checkbox.
    92     Gatherer.config.set(full_property, true, !show_check.isSelected());
     146    if(Gatherer.config != null) {
     147        // Store the state of the show message checkbox.
     148        Gatherer.config.set(full_property, true, !show_check.isSelected());
     149    }
    93150    // Done.
    94151    dispose();
     
    97154    public int display() {
    98155    ///ystem.err.println("Show " + full_property + ": " + Gatherer.config.get(full_property, false));
    99     if(Gatherer.config.get(full_property, false)) {
     156    if(Gatherer.config == null || Gatherer.config.get(full_property, false)) {
    100157        // We only show if the warning has not been disabled.
    101158        show();
     
    112169        key = warning_name + "." + key;
    113170    }
    114     return Gatherer.dictionary.get(key);
     171    return dictionary.get(key);
    115172    }
    116173}
Note: See TracChangeset for help on using the changeset viewer.