Changeset 4310


Ignore:
Timestamp:
2003-05-23T16:33:44+12:00 (21 years ago)
Author:
jmt12
Message:

redesign

File:
1 edited

Legend:

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

    r4293 r4310  
    2828import java.awt.*;
    2929import java.awt.event.*;
     30import java.io.File;
    3031import javax.swing.*;
     32import org.greenstone.gatherer.Configuration;
    3133import org.greenstone.gatherer.Gatherer;
    32 import org.greenstone.gatherer.Configuration;
     34import org.greenstone.gatherer.gui.TextFieldLabel;
     35import org.greenstone.gatherer.util.Utility;
    3336/** Displays a dynamic prompt to allow the user to choose how metadata is to be added, updated or removed from target FileNodes. The prompt changes depending on the action requested, the file nodes encountered and the number of file nodes in the selection. */
    3437public class MetaEditPrompt
     
    3639     implements ActionListener {
    3740
    38      private boolean multiple_selection = false;
    39 
    40      private int type;
    4141     private int value;
    42 
    43      private JButton accumulate_b;
    44      private JButton accumulate_all_b;
    45      private JButton cancel_b;
    46      private JButton skip_b;
    47      private JButton overwrite_b;
    48      private JButton overwrite_all_b;
    49      private JButton remove_b;
    50      private JButton remove_all_b;
    51      private JButton update_b;
    52      private JButton update_all_b;
    53 
    54      private JLabel title;
    55 
    56      private JTextArea text;
    57 
    58      private JPanel button_row;
    59      private JPanel content_pane;
    60 
    61      static private Dimension SIZE    = new Dimension(400, 280);
    62 
    63      // Prompt Types
    64      static public int ADD_PROMPT      =  0;
    65      static public int REMOVE_PROMPT   =  1;
    66      static public int UPDATE_PROMPT   =  2;
    67 
     42     private JButton accumulate;
     43     private JButton accumulate_all;
     44     private JButton cancel;
     45     private JButton skip;
     46     private JButton overwrite;
     47     private JButton overwrite_all;
     48     private JButton remove;
     49     private JButton remove_all;
     50     private JButton update;
     51     private JButton update_all;
     52     static private Dimension LABEL_SIZE = new Dimension(100, 25);
     53     static private Dimension SIZE = new Dimension(400, 280);
    6854     // Generic prompt values.
    6955     static public int CONFIRM         =  0;
    7056     static public int CANCEL          =  1;
    7157     static public int SKIP            =  2;
    72 
    73      // Values for the different add action prompts.
     58     // Values for the different add and update action prompts.
    7459     static public int ACCUMULATE      =  3;
    7560     static public int ACCUMULATE_ALL  =  4;
    7661     static public int OVERWRITE       =  5;
    7762     static public int OVERWRITE_ALL   =  6;
    78 
    79      // Values for the different update action prompts.
    80      static public int UPDATE          =  7;
    81      static public int UPDATE_ALL      =  8;
    82      static public int UPDATE_ONCE     =  9;
    83 
     63     static public int UPDATE_ONCE     =  7; // Caused by SARM
    8464     // Values for the different remove action prompts.
    85      static public int REMOVE          = 10;
    86      static public int REMOVE_ALL      = 11;
    87 
    88      public MetaEditPrompt(int type, boolean multiple_selection) {
    89           super(Gatherer.g_man); // Needed for modal response!
    90           this.multiple_selection = multiple_selection;
    91           this.setFont(Gatherer.config.getFont("general.font", false));
    92           this.setModal(true);
     65     static public int REMOVE          =  8;
     66     static public int REMOVE_ALL      =  9;
     67     // Prompt Types
     68     static public String ADD_PROMPT    = "Add_Prompt";
     69     static public String REMOVE_PROMPT = "Remove_Prompt";
     70     static public String UPDATE_PROMPT = "Overwrite_Prompt";
     71
     72     public MetaEditPrompt(String type, boolean multiple_selection, File file, String element, String current_value, String new_value) {
     73          super(Gatherer.g_man, true); // Needed for modal response!
     74         
     75          // Setup
    9376          this.setSize(SIZE);
    94           this.type = type;
    95           if(type == ADD_PROMPT) {
    96                 this.setTitle(get("Add_Title"));
    97                 title = new JLabel(get("Add_Title"));
    98           }
    99           else if(type == REMOVE_PROMPT) {
    100                 this.setTitle(get("Remove_Title"));
    101                 title = new JLabel(get("Remove_Title"));
    102           }
    103           else {
    104                 this.setTitle(get("Update_Title"));
    105                 title = new JLabel(get("Update_Title"));
    106           }
    107           title.setOpaque(false);
    108 
    109           content_pane = (JPanel)this.getContentPane();
    110           content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false));
    111           content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    112 
    113           // Set up some preset components.
    114           text = new JTextArea();
    115           text.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
    116           text.setEditable(false);
    117 
    118           button_row = new JPanel();
    119           button_row.setOpaque(false);
    120 
    121           accumulate_b = new JButton(get("Accumulate"));
    122           accumulate_b.addActionListener(this);
    123           accumulate_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    124           accumulate_b.setMnemonic(KeyEvent.VK_A);
    125 
    126           accumulate_all_b = new JButton(get("Accumulate_All"));
    127           accumulate_all_b.addActionListener(this);
    128           accumulate_all_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    129           accumulate_all_b.setMnemonic(KeyEvent.VK_D);
    130 
    131           cancel_b = new JButton(get("Cancel"));
    132           cancel_b.addActionListener(this);
    133           cancel_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    134           cancel_b.setMnemonic(KeyEvent.VK_C);
    135 
    136           skip_b = new JButton(get("Skip"));
    137           skip_b.addActionListener(this);
    138           skip_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    139           skip_b.setMnemonic(KeyEvent.VK_S);
    140 
    141           overwrite_b = new JButton(get("Overwrite"));
    142           overwrite_b.addActionListener(this);
    143           overwrite_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    144           overwrite_b.setMnemonic(KeyEvent.VK_R);
    145 
    146           overwrite_all_b = new JButton(get("Overwrite_All"));
    147           overwrite_all_b.addActionListener(this);
    148           overwrite_all_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    149           overwrite_all_b.setMnemonic(KeyEvent.VK_E);
    150 
    151           remove_b = new JButton(get("Remove"));
    152           remove_b.addActionListener(this);
    153           remove_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    154           remove_b.setMnemonic(KeyEvent.VK_R);
    155 
    156           remove_all_b = new JButton(get("Remove_All"));
    157           remove_all_b.addActionListener(this);
    158           remove_all_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    159           remove_all_b.setMnemonic(KeyEvent.VK_A);
    160 
    161           update_b = new JButton(get("Update"));
    162           update_b.addActionListener(this);
    163           update_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    164           update_b.setMnemonic(KeyEvent.VK_U);
    165 
    166           update_all_b = new JButton(get("Update_All"));
    167           update_all_b.addActionListener(this);
    168           update_all_b.setBackground(Gatherer.config.getColor("coloring.button_background", false));
    169           update_all_b.setMnemonic(KeyEvent.VK_A);
     77          this.setTitle(get("MetaEditPrompt.Title"));
     78
     79          // Creation
     80          JPanel content_pane = (JPanel)this.getContentPane();
     81          JLabel title_label = new JLabel(get("MetaEditPrompt." + type));
     82
     83          JPanel details_pane = new JPanel();
     84          JPanel filename_panel = new JPanel();
     85          JLabel filename_label = new JLabel(get("MetaEditPrompt.File"));
     86          filename_label.setPreferredSize(LABEL_SIZE);
     87          TextFieldLabel filename_field = new TextFieldLabel(Utility.trimCenter(file.getAbsolutePath(), 40));
     88          filename_field.setFont(Gatherer.config.getFont("general.tooltip_font", false));
     89          JPanel element_panel = new JPanel();
     90          JLabel element_label = new JLabel(get("MetaEditPrompt.Element"));
     91          element_label.setPreferredSize(LABEL_SIZE);
     92          TextFieldLabel element_field = new TextFieldLabel(element);         
     93          JPanel current_value_panel = new JPanel();
     94          JLabel current_value_label = new JLabel(get("MetaEditPrompt.Current_Value"));
     95          current_value_label.setPreferredSize(LABEL_SIZE);
     96          TextFieldLabel current_value_field = new TextFieldLabel(current_value);
     97          JPanel new_value_panel = new JPanel();
     98          JLabel new_value_label = new JLabel(get("MetaEditPrompt.New_Value"));
     99          new_value_label.setPreferredSize(LABEL_SIZE);
     100          TextFieldLabel new_value_field = new TextFieldLabel(new_value, (type == ADD_PROMPT || type == UPDATE_PROMPT));
     101
     102          JPanel buttons_pane = new JPanel();
     103          accumulate = new JButton(get("MetaEditPrompt.Accumulate"));
     104          accumulate.setEnabled(type == ADD_PROMPT);
     105          accumulate.setMnemonic(KeyEvent.VK_A);
     106          accumulate_all = new JButton(get("MetaEditPrompt.Accumulate_All"));
     107          accumulate_all.setEnabled(type == ADD_PROMPT && multiple_selection);
     108          accumulate_all.setMnemonic(KeyEvent.VK_L);
     109          cancel = new JButton(get("MetaEditPrompt.Cancel"));
     110          cancel.setMnemonic(KeyEvent.VK_C);
     111          skip = new JButton(get("MetaEditPrompt.Skip"));
     112          skip.setEnabled(multiple_selection);
     113          skip.setMnemonic(KeyEvent.VK_S);
     114          overwrite = new JButton(get("MetaEditPrompt.Overwrite"));
     115          overwrite.setEnabled((type == ADD_PROMPT || type == UPDATE_PROMPT));
     116          overwrite.setMnemonic(KeyEvent.VK_R);
     117          overwrite_all = new JButton(get("MetaEditPrompt.Overwrite_All"));
     118          overwrite_all.setEnabled((type == ADD_PROMPT || type == UPDATE_PROMPT) && multiple_selection);
     119          overwrite_all.setMnemonic(KeyEvent.VK_P);
     120          remove = new JButton(get("MetaEditPrompt.Remove"));
     121          remove.setEnabled(type == REMOVE_PROMPT);
     122          remove.setMnemonic(KeyEvent.VK_R);
     123          remove_all = new JButton(get("MetaEditPrompt.Remove_All"));
     124          remove_all.setEnabled(type == REMOVE_PROMPT && multiple_selection);
     125          remove_all.setMnemonic(KeyEvent.VK_A);
     126
     127          // Connection
     128          accumulate.addActionListener(this);
     129          accumulate_all.addActionListener(this);
     130          cancel.addActionListener(this);
     131          overwrite.addActionListener(this);
     132          overwrite_all.addActionListener(this);
     133          remove.addActionListener(this);
     134          remove_all.addActionListener(this);
     135          skip.addActionListener(this);
     136
     137          // Layout
     138          title_label.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
     139         
     140          filename_panel.setLayout(new BorderLayout());
     141          filename_panel.add(filename_label, BorderLayout.WEST);
     142          filename_panel.add(filename_field, BorderLayout.CENTER);
     143
     144          element_panel.setLayout(new BorderLayout());
     145          element_panel.add(element_label, BorderLayout.WEST);
     146          element_panel.add(element_field, BorderLayout.CENTER);
     147
     148          current_value_panel.setLayout(new BorderLayout());
     149          current_value_panel.add(current_value_label, BorderLayout.WEST);
     150          current_value_panel.add(current_value_field, BorderLayout.CENTER);
     151
     152          new_value_panel.setLayout(new BorderLayout());
     153          new_value_panel.add(new_value_label, BorderLayout.WEST);
     154          new_value_panel.add(new_value_field, BorderLayout.CENTER);
     155
     156          details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
     157          details_pane.setLayout(new GridLayout(4,1,0,4));
     158          details_pane.add(filename_panel);
     159          details_pane.add(element_panel);
     160          details_pane.add(current_value_panel);
     161          details_pane.add(new_value_panel);
     162
     163          buttons_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
     164          buttons_pane.setLayout(new GridLayout(4,2,0,0));
     165          buttons_pane.add(accumulate);
     166          buttons_pane.add(accumulate_all);
     167          buttons_pane.add(overwrite);
     168          buttons_pane.add(overwrite_all);
     169          buttons_pane.add(remove);
     170          buttons_pane.add(remove_all);
     171          buttons_pane.add(skip);
     172          buttons_pane.add(cancel);
     173
     174          content_pane.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
     175          content_pane.setLayout(new BorderLayout());
     176          content_pane.add(title_label, BorderLayout.NORTH);
     177          content_pane.add(details_pane, BorderLayout.CENTER);
     178          content_pane.add(buttons_pane, BorderLayout.SOUTH);
     179
     180          // Position
     181          Rectangle frame_bounds = Gatherer.g_man.getBounds();
     182          this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2));
    170183     }
    171184
    172185     public void actionPerformed(ActionEvent event) {
    173186          Object esrc = event.getSource();
    174           if(esrc == accumulate_b) {
     187          if(esrc == accumulate) {
    175188                value = ACCUMULATE;
    176189          }
    177           else if(esrc == accumulate_all_b) {
     190          else if(esrc == accumulate_all) {
    178191                value = ACCUMULATE_ALL;
    179192          }
    180           else if(esrc == cancel_b) {
     193          else if(esrc == cancel) {
    181194                value = CANCEL;
    182195          }
    183           else if(esrc == skip_b) {
     196          else if(esrc == skip) {
    184197                value = SKIP;
    185198          }       
    186           else if(esrc == overwrite_b) {
     199          else if(esrc == overwrite) {
    187200                value = OVERWRITE;
    188201          }
    189           else if(esrc == overwrite_all_b) {
     202          else if(esrc == overwrite_all) {
    190203                value = OVERWRITE_ALL;
    191204          }
    192           else if(esrc == remove_b) {
     205          else if(esrc == remove) {
    193206                value = REMOVE;
    194207          }
    195           else if(esrc == remove_all_b) {
     208          else if(esrc == remove_all) {
    196209                value = REMOVE_ALL;
    197210          }
    198           else if(esrc == update_b) {
    199                 value = UPDATE;
    200           }
    201           else if(esrc == update_all_b) {
    202                 value = UPDATE_ALL;
    203           }
    204211          this.dispose();
    205212     }
    206213
    207      public int display(String f, String k, String v) {
    208           String args[] = new String[1];
    209 
    210           content_pane.setLayout(new BorderLayout());
    211 
    212           content_pane.add(title, BorderLayout.NORTH);
    213 
    214           JPanel middle_pane = new JPanel(new BorderLayout());
    215           middle_pane.setOpaque(false);
    216           middle_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createLoweredBevelBorder()));
    217 
    218           args[0] = f;
    219           text.append(get("File", args));
    220           text.append("\n");
    221           args[0] = k;
    222           text.append(get("Key", args));
    223           text.append("\n");
    224           args[0] = v;
    225           text.append(get("Value", args));
    226           text.append("\n");
    227          
    228           button_row.setLayout(new GridLayout(4,1,2,2));
    229 
    230           // Add the components
    231           middle_pane.add(new JScrollPane(text), BorderLayout.CENTER);
    232 
    233           button_row.add(remove_b);
    234           if(multiple_selection) {
    235                 button_row.add(remove_all_b);
    236           }
    237           else {
    238                 button_row.add(new JPanel());
    239           }
    240           button_row.add(skip_b);
    241           button_row.add(cancel_b);
    242 
    243           content_pane.add(title, BorderLayout.NORTH);
    244           content_pane.add(middle_pane, BorderLayout.CENTER);
    245           content_pane.add(button_row, BorderLayout.SOUTH);
    246 
    247           text.setCaretPosition(0);
    248 
    249           Rectangle frame_bounds = Gatherer.g_man.getBounds();
    250           this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2));
     214     public int display() {
    251215          show();
    252216          return value;
    253217     }
    254218
    255      public int display(String f, String k, String o_v, String n_v) {
    256           String args[] = new String[1];
    257          
    258           content_pane.setLayout(new BorderLayout());
    259          
    260           content_pane.add(title, BorderLayout.NORTH);
    261          
    262           JPanel middle_pane = new JPanel(new BorderLayout());
    263           middle_pane.setOpaque(false);
    264           middle_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createLoweredBevelBorder()));
    265                  
    266           args[0] = f;
    267           text.append(get("File", args));
    268           text.append("\n");
    269           args[0] = k;
    270           text.append(get("Key", args));
    271           text.append("\n");
    272           args[0] = o_v;
    273           text.append(get("Old_Value", args));
    274           text.append("\n");
    275           args[0] = n_v;
    276           text.append(get("New_Value", args));
    277           text.append("\n");
    278 
    279           if(type == ADD_PROMPT) {
    280                 button_row.setLayout(new GridLayout(3,2,2,2));
    281           }
    282           else {
    283                 button_row.setLayout(new GridLayout(2,2,2,2));
    284           }
    285          
    286           // Add the components
    287           middle_pane.add(new JScrollPane(text), BorderLayout.CENTER);
    288 
    289           if(type == ADD_PROMPT) {
    290                 button_row.add(accumulate_b);
    291                 if(multiple_selection) {
    292                      button_row.add(accumulate_all_b);
    293                 }
    294                 else {
    295                      button_row.add(new JPanel());
    296                 }
    297                 button_row.add(overwrite_b);
    298                 if(multiple_selection) {
    299                      button_row.add(overwrite_all_b);
    300                 }
    301                 else {
    302                      button_row.add(new JPanel());
    303                 }
    304                 button_row.add(skip_b);
    305                 button_row.add(cancel_b);
    306           }
    307           else {
    308                 button_row.add(update_b);
    309                 if(multiple_selection) {
    310                      button_row.add(update_all_b);
    311                 }
    312                 else {
    313                      button_row.add(new JPanel());
    314                 }
    315                 button_row.add(skip_b);
    316                 button_row.add(cancel_b);
    317           }
    318 
    319           content_pane.add(title, BorderLayout.NORTH);
    320           content_pane.add(middle_pane, BorderLayout.CENTER);
    321           content_pane.add(button_row, BorderLayout.SOUTH);
    322 
    323           text.setCaretPosition(0);
    324 
    325           Rectangle frame_bounds = Gatherer.g_man.getBounds();
    326           this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2));
    327           show();
    328           return value;
    329      }
    330 
    331219     private String get(String key) {
    332           return get(key, null);
    333      }
    334 
    335      private String get(String key, String args[]) {
    336           if(key.indexOf(".") == -1) {
    337                 key = "MetaEditPrompt." + key;
    338           }
    339           return Gatherer.dictionary.get(key, args);
     220          return Gatherer.dictionary.get(key);
    340221     }
    341222}
Note: See TracChangeset for help on using the changeset viewer.