Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/bdgp/apps/dagedit/dataadapter/GOFlatFileGUI.java


1   package org.bdgp.apps.dagedit.dataadapter;
2   
3   import javax.swing.*;
4   import javax.swing.border.*;
5   import java.awt.*;
6   import java.awt.event.*;
7   import java.io.*;
8   import java.net.*;
9   import java.util.*;
10  import org.bdgp.io.*;
11  import org.bdgp.util.*;
12  import org.bdgp.swing.*;
13  import org.bdgp.apps.dagedit.datamodel.*;
14  import org.bdgp.apps.dagedit.gui.*;
15  
16  public class GOFlatFileGUI extends AbstractIntDataAdapUI {
17  
18      private class FileProfile implements java.lang.Comparable {
19    protected Vector files;
20    protected String defFile;
21    protected String profileName;
22  
23    public FileProfile(Vector files, String defFile, String profileName) {
24        this.files = files;
25        this.defFile = defFile;
26        this.profileName = profileName;
27    }
28  
29    public Vector getFiles() {
30        return files;
31    }
32  
33    public String getDefFile() {
34        return defFile;
35    }
36  
37    public String getProfileName() {
38        return profileName;
39    }
40  
41    public void setFiles(Vector files) {
42        this.files = files;
43    }
44  
45    public void setDefFile(String defFile) {
46        this.defFile = defFile;
47    }
48  
49    public void setProfileName(String profileName) {
50        this.profileName = profileName;
51    }
52  
53    public String toString() {
54        return profileName;
55    }
56  
57    public int compareTo(Object o) {
58        FileProfile fileProfile = (FileProfile) o;
59        return profileName.compareToIgnoreCase(fileProfile.
60                 getProfileName());
61    }
62      }
63  
64      private class RelationshipTypeWrapper {
65    private String typeChar;
66    private String name;
67    private String desc;
68    boolean isDefaultType;
69  
70    public RelationshipTypeWrapper(String typeChar,
71                 String name,
72                 String desc,
73                 boolean isDefaultType) {
74        this.typeChar = typeChar;
75        this.name = name;
76        this.desc = desc;
77        this.isDefaultType = isDefaultType;
78    }
79  
80    public boolean getIsDefault() {
81        return isDefaultType;
82    }
83  
84    public void setIsDefault(boolean isDefaultType) {
85        this.isDefaultType = isDefaultType;
86    }
87  
88    public String toString() {
89        return typeChar+" - "+name;
90    }
91  
92    public String getTypeChar() {
93        return typeChar;
94    }
95  
96    public String getName() {
97        return name;
98    }
99  
100   public String getDesc() {
101       return desc;
102   }
103 
104   public void setTypeChar(String typeChar) {
105       this.typeChar = typeChar;
106   }
107 
108   public void setName(String name) {
109       this.name = name;
110   }
111 
112   public void setDesc(String desc) {
113       this.desc = desc;
114   }
115     }
116 
117     private class RelationshipTypeEditor extends JPanel
118   implements GenericEditorComponent {
119   
120   private JTextField charField;
121   private JTextField nameField;
122   private JTextField descField;
123   private JCheckBox defaultBox;
124 
125   protected ListEditor editor;
126 
127   public void setMasterComponent(Component c) {
128       if (c instanceof ListEditor)
129     editor = (ListEditor) c;
130   }
131 
132   public RelationshipTypeEditor() {
133       JLabel charLabel = new JLabel("Relationship type symbol");
134       JLabel nameLabel = new JLabel("Relationship type name");
135       JLabel descLabel = new JLabel("Relationship type description");
136       FocusListener listener = new FocusListener() {
137         public void focusLost(FocusEvent e) {
138       symbolList.commit();
139         }
140 
141         public void focusGained(FocusEvent e) {
142         }
143     };
144 
145       charField = new JTextField(1);
146       nameField = new JTextField(10);
147       descField = new JTextField();
148       defaultBox = new JCheckBox("Is default type");
149 
150       defaultBox.addActionListener(new ActionListener() {
151         public void actionPerformed(ActionEvent e) {
152       Vector symbols = symbolList.getData();
153       for(int i=0; i < symbols.size(); i++) {
154           RelationshipTypeWrapper rtw =
155         (RelationshipTypeWrapper) symbols.
156         elementAt(i);
157           rtw.setIsDefault(false);
158       }
159       symbolList.commit();
160         }
161     });
162 
163       charField.addFocusListener(listener);
164       nameField.addFocusListener(listener);
165       descField.addFocusListener(listener);
166 
167       charLabel.setFont(controller.getDefaultFont());
168       charField.setFont(controller.getDefaultFont());
169       nameField.setFont(controller.getDefaultFont());
170       nameLabel.setFont(controller.getDefaultFont());
171       descLabel.setFont(controller.getDefaultFont());
172       descField.setFont(controller.getDefaultFont());
173       defaultBox.setFont(controller.getDefaultFont());
174 
175       setLayout(new BoxLayout(RelationshipTypeEditor.this,
176             BoxLayout.Y_AXIS));
177       add(charLabel);
178       add(charField);
179       add(Box.createVerticalStrut(10));
180       add(nameLabel);
181       add(nameField);
182       add(Box.createVerticalStrut(10));
183       add(descLabel);
184       add(descField);
185       add(Box.createVerticalStrut(10));
186       add(defaultBox);
187       add(Box.createVerticalGlue());
188   }
189 
190   public void load(Object o) {
191       RelationshipTypeWrapper rtw = (RelationshipTypeWrapper) o;
192       charField.setText(rtw.getTypeChar()+"");
193       nameField.setText(rtw.getName());
194       descField.setText(rtw.getDesc());
195       defaultBox.setSelected(rtw.getIsDefault());
196   }
197 
198   public void store(Object o) {
199       RelationshipTypeWrapper rtw = (RelationshipTypeWrapper) o;
200       String charStr = charField.getText();
201       if (charStr.length() < 1)
202     rtw.setTypeChar("?");
203       else
204     rtw.setTypeChar(charStr);
205       rtw.setName(nameField.getText());
206       rtw.setDesc(descField.getText());
207       rtw.setIsDefault(defaultBox.isSelected());
208   }
209 
210   public Object createNewValue() {
211       return new RelationshipTypeWrapper("?", "NEWTYPE",
212                  "<new relationship type>",
213                  symbolList.getData().
214                  size() == 0);
215   }
216     }
217 
218     private class FilenameEditor extends JPanel
219   implements GenericEditorComponent {
220   
221   private JTextField filenameField;
222   private JButton browseButton;
223 
224   protected ListEditor editor;
225 
226   public void setMasterComponent(Component c) {
227       if (c instanceof ListEditor)
228     editor = (ListEditor) c;
229   }
230 
231   public FilenameEditor() {
232       JLabel filenameLabel = new JLabel("File Name or URL");
233 
234       FocusListener listener = new FocusListener() {
235         public void focusLost(FocusEvent e) {
236       editor.commit();
237         }
238 
239         public void focusGained(FocusEvent e) {
240         }
241     };
242 
243       filenameField = new JTextField();
244       browseButton = new JButton("Browse...");
245 
246       browseButton.addActionListener(new ActionListener() {
247         public void actionPerformed(ActionEvent e) {
248       JFileChooser chooser = new JFileChooser();
249       if (chooser.showOpenDialog(GOFlatFileGUI.this) ==
250           JFileChooser.APPROVE_OPTION) {
251           File file = chooser.getSelectedFile();
252           filenameField.setText(file.toString());
253           editor.commit();
254       }
255         }
256     });
257 
258       filenameField.addFocusListener(listener);
259 
260       filenameField.addActionListener(new ActionListener() {
261         public void actionPerformed(ActionEvent e) {
262       editor.commit();
263         }
264     });
265 
266       filenameLabel.setFont(controller.getDefaultFont());
267       filenameField.setFont(controller.getDefaultFont());
268       browseButton.setFont(controller.getDefaultFont());
269 
270       JPanel fieldBox = new JPanel();
271       fieldBox.setLayout(new BoxLayout(fieldBox, BoxLayout.X_AXIS));
272       fieldBox.setOpaque(false);
273 
274       fieldBox.add(filenameField);
275       fieldBox.add(Box.createHorizontalStrut(20));
276       fieldBox.add(browseButton);
277 
278       fieldBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
279       filenameLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
280       filenameField.setAlignmentX(JComponent.LEFT_ALIGNMENT);
281       browseButton.setAlignmentX(JComponent.LEFT_ALIGNMENT);
282 
283       filenameLabel.setAlignmentY(JComponent.TOP_ALIGNMENT);
284       fieldBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
285 /*
286       setPreferredSize(new Dimension((int) getPreferredSize().getWidth(),
287              150));
288 */
289       JPanel panel = new JPanel();
290       panel.setLayout(new BoxLayout(panel,
291             BoxLayout.Y_AXIS));
292       panel.add(filenameLabel);
293       panel.add(fieldBox);
294       setLayout(new BorderLayout());
295       add(panel, "North");
296   }
297 
298   public void load(Object o) {
299       filenameField.setText(o.toString());
300   }
301 
302   public void store(Object o) {
303       ((EditableString) o).setValue(filenameField.getText());
304   }
305 
306   public Object createNewValue() {
307       return new EditableString("<new file>");
308   }
309     }
310 
311     private class BrowseListener implements ActionListener {
312   protected JTextField field;
313 
314   public BrowseListener(JTextField field) {
315       this.field = field;
316   }
317 
318   public void actionPerformed(ActionEvent e) {
319       JFileChooser chooser = new JFileChooser();
320       if (chooser.showOpenDialog(GOFlatFileGUI.this) ==
321     JFileChooser.APPROVE_OPTION) {
322     File file = chooser.getSelectedFile();
323     field.setText(file.toString());
324       }
325   }
326     }
327 
328     public static final String NEW_PROFILE_NAME = "<new profile>";
329 
330     DataAdapter driver;
331     IOOperation op;
332 
333     JButton commitButton;
334     JButton cancelButton;
335     JButton browseDefButton;
336 
337     JLabel definitionLabel;
338     JButton advancedButton;
339     JScrollPane commentPane;
340 
341     ListEditor fileList;
342     JTextField filenameField;
343     JTextField definitionField;
344     JTextArea commentField;
345     JCheckBox hideDownstreamBox;
346     JCheckBox pathToRootBox;
347     JCheckBox allowCyclesBox;
348     JCheckBox allowDanglingBox;
349     JCheckBox reduceSizeBox;
350     JCheckBox useLegacyTypesBox;
351 
352     JComboBox historyBox;
353     JButton delButton;
354 
355     String comment;
356     boolean showPathToRoot = false;
357     boolean allowCycles = false;
358     boolean allowDangling = false;
359     boolean reduceSize = false;
360     boolean useLegacyTypes = false;
361     boolean hideDownstream = false;
362     Vector fileNames;
363     String defFileName;
364 
365     Vector relationshipTypes;
366 
367     Hashtable typeBindings;
368     TermRelationshipType defaultType;
369     ListEditor symbolList;
370     Properties props;
371     JDialog optionDialog;
372     Controller controller;
373 
374     boolean notListPick = false;
375     FileProfile currentProfile;
376     int currentSelectedIndex = -1;
377 
378     protected void showAdvancedOptions() {
379   JPanel advancedPanel = getAdvancedPanel(new JPanel());
380   optionDialog = new JDialog();
381   optionDialog.setModal(true);
382   optionDialog.setContentPane(advancedPanel);
383   optionDialog.setTitle("Advanced flat file options");
384   optionDialog.pack();
385   optionDialog.show();
386   SwingUtil.center(optionDialog);
387     }
388 
389     private Vector getRelationshipTypes() {
390   Vector out = new Vector();
391 
392   Enumeration e = typeBindings.keys();
393   while(e.hasMoreElements()) {
394       String c = (String) e.nextElement();
395       TermRelationshipType rt = (TermRelationshipType) typeBindings.
396     get(c);
397       out.addElement(new 
398     RelationshipTypeWrapper(c,
399           rt.getName(),
400           rt.getDesc(),
401           rt.equals(defaultType)));
402   }
403 
404   return out;
405     }
406 
407     protected void addOrModifyProfile() {
408   currentProfile.setProfileName(historyBox.getEditor().
409               getItem().toString());
410   if (currentSelectedIndex == 0) {
411       historyBox.
412     insertItemAt(new FileProfile(new Vector(),
413                null,
414                NEW_PROFILE_NAME),
415            0);
416   }
417   sortProfiles();
418     }
419 
420     public GOFlatFileGUI(IOOperation op) {
421   this.op = op;
422   controller = Controller.getController();
423 
424   JLabel noRelationshipLabel = new JLabel("Click a symbol to edit it.");
425   noRelationshipLabel.setFont(controller.getDefaultFont());
426   symbolList = new ListEditor(new RelationshipTypeEditor(),
427             noRelationshipLabel,
428             new Vector(),
429             true, true,
430             true, true,
431             false);
432   symbolList.setFont(controller.getDefaultFont());
433 
434   JLabel noFileLabel = new JLabel("Click a filename to edit it.");
435   noFileLabel.setFont(controller.getDefaultFont());
436   fileList = new ListEditor(new FilenameEditor(),
437           noFileLabel,
438           new Vector(),
439           true, true, true, true, false);
440   fileList.setFont(controller.getDefaultFont());
441   fileList.setListSize(100);
442 
443   TitledBorder fileListBorder = new TitledBorder("File paths");
444   fileListBorder.setTitleFont(controller.getDefaultFont());
445   fileList.setBorder(fileListBorder);
446   fileList.setOrientation(ListEditor.VERTICAL_SPLIT);
447 
448   definitionField = new JTextField();
449   filenameField = new JTextField();
450 
451   JLabel profileLabel = new JLabel("File collection");
452   profileLabel.setFont(controller.getDefaultFont());
453   historyBox = new JComboBox();
454   delButton = new JButton("Delete");
455   delButton.setFont(controller.getDefaultFont());
456 
457   commentField = new JTextArea(4, 30);
458   commentField.setWrapStyleWord(true);
459   commentField.setLineWrap(true);
460   commentField.setFont(controller.getDefaultFont());
461   commentPane = new JScrollPane(commentField,
462               JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
463               JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
464 
465   filenameField.setPreferredSize(new Dimension(300, 20));
466   definitionField.setPreferredSize(new Dimension(300, 20));
467 
468 
469   hideDownstreamBox = new JCheckBox("Hide downstream errors", true);
470   pathToRootBox = new JCheckBox("Export path to root", false);
471   allowCyclesBox = new JCheckBox("Allow cycles", false);
472   allowDanglingBox = new JCheckBox("Allow dangling parent references", false);
473   reduceSizeBox = new JCheckBox("Reduce file size", false);
474   useLegacyTypesBox = new JCheckBox("Use legacy compatible types",
475             false);
476 
477 
478   browseDefButton = new JButton("Browse...");
479   browseDefButton.addActionListener(new ActionListener() {
480     public void actionPerformed(ActionEvent e) {
481         JFileChooser chooser = new JFileChooser();
482         if (chooser.showOpenDialog(GOFlatFileGUI.this) ==
483       JFileChooser.APPROVE_OPTION) {
484       File file = chooser.getSelectedFile();
485       definitionField.setText(file.toString());
486         }
487     }
488       });
489 
490   commitButton = new JButton("Ok");
491   cancelButton = new JButton("Cancel");
492   advancedButton = new JButton("Advanced Options...");
493   advancedButton.setFont(new Font("Arial", 0, 7));
494 
495   advancedButton.addActionListener(new ActionListener () {
496     public void actionPerformed(ActionEvent e) {
497         showAdvancedOptions();
498     }
499       });
500   delButton.addActionListener(new ActionListener() {
501     public void actionPerformed(ActionEvent e) {
502         deleteProfile();
503     }
504       });
505   cancelButton.addActionListener(new ActionListener() {
506     public void actionPerformed(ActionEvent e) {
507         cancel();
508     }
509       });
510   commitButton.addActionListener(new ActionListener() {
511     public void actionPerformed(ActionEvent e) {
512         commit();
513     }
514       });
515   historyBox.addActionListener(new ActionListener() {
516     public void actionPerformed(ActionEvent e) {
517         if (notListPick)
518       notListPick = false;
519         else {
520       Object selectedItem = historyBox.getSelectedItem();
521       if (selectedItem instanceof FileProfile) {
522           if (currentProfile != null)
523         storeProfile(currentProfile);
524           currentProfile = (FileProfile) selectedItem;
525           currentSelectedIndex = historyBox.
526         getSelectedIndex();
527           if (currentSelectedIndex == 0)
528         delButton.setEnabled(false);
529           else
530         delButton.setEnabled(true);
531           loadProfile(currentProfile);
532       }
533         }
534     }
535       });
536   historyBox.getEditor().addActionListener(new ActionListener() {
537     public void actionPerformed(ActionEvent e) {
538         notListPick = true;
539         addOrModifyProfile();
540     }
541       });
542 
543   setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
544   definitionLabel = new JLabel("Definition file name:");
545 
546   JPanel definitionLabelBox = new JPanel();
547   definitionLabelBox.setLayout(new BoxLayout(definitionLabelBox,
548                BoxLayout.X_AXIS));
549   definitionLabelBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
550   definitionLabelBox.add(definitionLabel);
551   definitionLabelBox.add(Box.createHorizontalGlue());
552   
553   JPanel definitionNameBox = new JPanel();
554   definitionNameBox.setLayout(new BoxLayout(definitionNameBox,
555               BoxLayout.X_AXIS));
556   definitionNameBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
557   definitionNameBox.add(definitionField);
558   definitionNameBox.add(Box.createHorizontalStrut(10));
559   definitionNameBox.add(browseDefButton);
560   definitionNameBox.add(Box.createHorizontalGlue());
561 
562   advancedButton.setAlignmentX(JComponent.CENTER_ALIGNMENT);
563 
564   JPanel advancedButtonPanel = new JPanel();
565   advancedButtonPanel.setLayout(new BoxLayout(advancedButtonPanel,
566                 BoxLayout.X_AXIS));
567   advancedButtonPanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
568   advancedButtonPanel.add(Box.createHorizontalGlue());
569   advancedButtonPanel.add(advancedButton);
570   advancedButtonPanel.add(Box.createHorizontalGlue());
571 
572   JPanel advancedBox = new JPanel();
573   advancedBox.setLayout(new BoxLayout(advancedBox,
574               BoxLayout.X_AXIS));
575   advancedBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
576   advancedBox.add(advancedButtonPanel);
577   advancedBox.add(Box.createVerticalGlue());
578 
579   JPanel profileBox = new JPanel();
580   profileBox.setLayout(new BoxLayout(profileBox,
581              BoxLayout.X_AXIS));
582   profileBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
583   profileBox.add(profileLabel);
584   profileBox.add(Box.createHorizontalStrut(10));
585   profileBox.add(historyBox);
586   profileBox.add(Box.createHorizontalStrut(10));
587   profileBox.add(delButton);
588 
589   historyBox.setEditable(true);
590 
591   add(profileBox);
592   add(Box.createVerticalStrut(10));
593 
594   if (op.equals(DEDataAdapterI.READ_TERMS)) {
595       add(fileList);
596   }
597 
598   JPanel filenamePanel = new JPanel();
599   filenamePanel.setLayout(new BoxLayout(filenamePanel,
600                 BoxLayout.Y_AXIS));
601   JButton filenameBrowseButton = new JButton("Browse...");
602 
603   filenameBrowseButton.addActionListener(new ActionListener() {
604     public void actionPerformed(ActionEvent e) {
605         JFileChooser chooser = new JFileChooser();
606         if (chooser.showOpenDialog(GOFlatFileGUI.this) ==
607       JFileChooser.APPROVE_OPTION) {
608       File file = chooser.getSelectedFile();
609       filenameField.setText(file.toString());
610         }
611     }
612       });
613 
614 
615   JLabel filenameLabel = new JLabel("File name");
616   filenameLabel.setFont(controller.getDefaultFont());
617   filenameBrowseButton.setFont(controller.getDefaultFont());
618 /*
619   filenamePanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
620 */
621   JPanel filenameButtonPanel = new JPanel();
622   filenameButtonPanel.setLayout(new BoxLayout(filenameButtonPanel,
623                 BoxLayout.X_AXIS));
624   filenameButtonPanel.add(filenameField);
625   filenameButtonPanel.add(Box.createHorizontalStrut(10));
626   filenameButtonPanel.add(filenameBrowseButton);
627 
628   filenamePanel.add(filenameLabel);
629   filenamePanel.add(filenameButtonPanel);
630 
631   fileList.setAlignmentX(JComponent.LEFT_ALIGNMENT);
632   filenamePanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
633   filenameLabel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
634   filenameButtonPanel.setAlignmentX(JComponent.LEFT_ALIGNMENT);
635 
636   if (op.equals(DEDataAdapterI.WRITE_TERMS) ||
637       op.equals(DEDataAdapterI.EXPORT_TERMS) ||
638       op.equals(DEDataAdapterI.IMPORT_TERMS)) {
639 
640 /**
641  *
642 
643  Make sure that IMPORT and EXPORT work properly; add label and browse button
644 for filename field
645 
646 
647 
648 
649 
650 
651  */
652 
653 
654 
655 
656 
657 
658 
659       add(filenamePanel);
660   }
661 
662   add(Box.createVerticalStrut(20));
663 
664   add(definitionLabelBox);
665   add(definitionNameBox);
666 
667   add(Box.createVerticalStrut(10));
668   add(advancedBox);
669 
670   JPanel optionBox = new JPanel();
671   optionBox.setLayout(new BoxLayout(optionBox,
672             BoxLayout.X_AXIS));
673   optionBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
674   optionBox.add(Box.createHorizontalGlue());
675 
676   boolean showingOptions = false;
677 
678   if (op.equals(DEDataAdapterI.READ_TERMS) ||
679       op.equals(DEDataAdapterI.IMPORT_TERMS)) {
680       showingOptions = true;
681       optionBox.add(hideDownstreamBox);
682       optionBox.add(Box.createHorizontalGlue());
683   }
684 
685   if (op.equals(DEDataAdapterI.EXPORT_TERMS)) {
686       showingOptions = true;
687       optionBox.add(pathToRootBox);
688       optionBox.add(Box.createHorizontalGlue());
689   }
690 
691   showingOptions = true;
692   optionBox.add(allowCyclesBox);
693   optionBox.add(Box.createHorizontalGlue());
694 
695   optionBox.add(allowDanglingBox);
696   optionBox.add(Box.createHorizontalGlue());
697 
698   if (op.equals(DEDataAdapterI.EXPORT_TERMS) ||
699       op.equals(DEDataAdapterI.WRITE_TERMS)) {
700       showingOptions = true;
701       optionBox.add(reduceSizeBox);
702       optionBox.add(Box.createHorizontalGlue());
703       optionBox.add(useLegacyTypesBox);
704       optionBox.add(Box.createHorizontalGlue());
705   }
706 
707   if (showingOptions) {
708       add(Box.createVerticalStrut(20));
709 
710       add(optionBox);
711   }
712 
713   if (op.equals(DEDataAdapterI.EXPORT_TERMS) ||
714       op.equals(DEDataAdapterI.WRITE_TERMS)) {
715 
716       commentField.setText(controller.getHistory().getComment());
717 
718       JLabel commentLabel = new JLabel("Comment");
719       commentLabel.setFont(controller.getDefaultFont());
720 
721       Box commentBox = new Box(BoxLayout.X_AXIS);
722       commentBox.add(commentLabel);
723       commentBox.add(Box.createHorizontalGlue());
724 
725       add(Box.createVerticalStrut(20));
726       add(commentBox);
727       add(commentPane);      
728   }
729 
730   add(Box.createVerticalStrut(20));
731 
732   JPanel commitBox = new JPanel();
733   commitBox.setLayout(new BoxLayout(commitBox, BoxLayout.X_AXIS));
734   commitBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
735   commitBox.add(Box.createHorizontalGlue());
736   commitBox.add(commitButton);
737   commitBox.add(Box.createHorizontalStrut(10));
738   commitBox.add(cancelButton);
739   commitBox.add(Box.createHorizontalGlue());
740   add(commitBox);
741 
742   add(Box.createVerticalGlue());
743     }
744 
745     protected void sortProfiles() {
746   FileProfile currentProfile = this.currentProfile;
747   Vector v = new Vector();
748   for(int i=0; i < historyBox.getItemCount(); i++)
749       v.add(historyBox.getItemAt(i));
750   Collections.sort(v);
751   historyBox.removeAllItems();
752   for(int i=0; i < v.size(); i++)
753       historyBox.addItem(v.get(i));
754   historyBox.setSelectedItem(currentProfile);
755     }
756 
757     protected void commitAdvancedChanges() {
758 
759   Vector symbols = symbolList.getData();
760   Hashtable newBindings = new Hashtable();
761   TermRelationshipType newDefault = null;
762   boolean defaultIsSet = false;
763   if (symbols.size() < 1) {
764       JOptionPane.showMessageDialog(null,
765             "You must specify at least one "+
766             "term relationship type.");
767       return;
768   }
769   Hashtable nameList = new Hashtable();
770   for(int i=0; i < symbols.size(); i++) {
771       RelationshipTypeWrapper rtw = (RelationshipTypeWrapper)
772     symbols.elementAt(i);
773       if (newBindings.get(rtw.getTypeChar()) != null) {
774     JOptionPane.showMessageDialog(null,
775           "Each relationship must have a "+
776           "unique symbol. You may not reuse "+
777           "the character '"+
778           rtw.getTypeChar()+"'.");
779     return;
780       }
781       if ((rtw.getTypeChar().length() == 1 &&
782      GOFlatFileAdapter.isReservedCharacter(rtw.getTypeChar().
783                    charAt(0))) ||
784     (rtw.getTypeChar().length() != 1 &&
785      !(rtw.getTypeChar().charAt(0) ==
786        GOFlatFileAdapter.BOUNDARY_CHAR &&
787        rtw.getTypeChar().charAt(rtw.getTypeChar().length()-1) ==
788        GOFlatFileAdapter.BOUNDARY_CHAR))) {
789     JOptionPane.showMessageDialog(null,
790                 rtw.getTypeChar()+" is a "+
791                 "reserved character, and "+
792                 "cannot be used as a "+
793                 "relationship type "+
794                 "identifier.");
795     return;
796       }
797 
798       if (rtw.getName().length() < 1) {
799     JOptionPane.showMessageDialog(null,
800           "Each relationship must have a "+
801           "name!");
802     return;
803       }
804       if (rtw.getDesc().length() < 1) {
805     JOptionPane.showMessageDialog(null,
806           "Each relationship must have a "+
807           "description!");
808     return;
809       }
810       if (nameList.get(rtw.getName()) != null) {
811     JOptionPane.showMessageDialog(null,
812           "Each relationship must have a "+
813           "unique name. You may not reuse "+
814           "the name '"+
815           rtw.getName()+"'.");
816     return;
817       }
818       TermRelationshipType trt = new TermRelationshipType(rtw.getName(),
819                 rtw.getDesc());
820       newBindings.put(rtw.getTypeChar(), trt);
821       if (rtw.getIsDefault()) {
822     defaultIsSet = true;
823     newDefault = trt;
824       }
825 
826       nameList.put(rtw.getName(), rtw.getName());
827   }
828 
829   if (!defaultIsSet) {
830       JOptionPane.showMessageDialog(null,
831             "You must choose a default "+
832             "relationship");
833       return;
834   }      
835 
836   typeBindings = newBindings;
837   defaultType = newDefault;
838 
839   if (optionDialog != null)
840       optionDialog.dispose();
841   else
842       controllingObject.commit();
843     }
844 
845     public JPanel getAdvancedPanel(JPanel panel) {
846   panel.removeAll();
847   panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
848   JButton okButton = new JButton("Ok");
849   JButton cancelButton = new JButton("Cancel");
850 
851   okButton.setFont(controller.getDefaultFont());
852   cancelButton.setFont(controller.getDefaultFont());
853 
854   okButton.addActionListener(new ActionListener() {
855     public void actionPerformed(ActionEvent e) {
856         commitAdvancedChanges();
857     }
858       });
859 
860   cancelButton.addActionListener(new ActionListener() {
861     public void actionPerformed(ActionEvent e) {
862         if (optionDialog != null)
863       optionDialog.dispose();
864         else
865       controllingObject.cancel();
866     }
867       });
868 
869   Box buttonBox = new Box(BoxLayout.X_AXIS);
870   buttonBox.add(Box.createHorizontalGlue());
871   buttonBox.add(okButton);
872   buttonBox.add(Box.createHorizontalStrut(20));
873   buttonBox.add(cancelButton);
874   buttonBox.add(Box.createHorizontalGlue());
875 
876 
877   panel.add(symbolList);
878   panel.add(Box.createVerticalStrut(10));
879   panel.add(buttonBox);
880   panel.add(Box.createVerticalStrut(10));
881 
882   panel.setPreferredSize(new Dimension(450,250));
883   panel.setMinimumSize(new Dimension(450,250));
884   panel.setBorder(new TitledBorder("Define term relationship symbols"));
885   return panel;
886     }
887 
888     public void commit() {
889   if (op.equals(DEDataAdapterI.CONFIGURE))
890       return;
891   collectParams();
892   Vector files = (Vector) fileNames.clone();
893 
894   if (files.size() < 1) {
895       JOptionPane.showMessageDialog(null,
896             "You must provide at least one "+
897             "file name.");
898       return;
899   }      
900 
901   if (defFileName != null &&
902       defFileName.length() > 0)
903       files.addElement(defFileName);
904   int filesFound = 0;
905   Vector foundFiles = new Vector();
906   Vector missedFiles = new Vector();
907   boolean containsURLs = false;
908   for(int i=0; i < files.size(); i++) {
909       String fileName = (String) files.elementAt(i);
910       try {
911     URL url = new URL(fileName);
912     InputStream is = url.openStream();
913     is.close();
914     containsURLs = true;
915     foundFiles.addElement(fileName);
916       } catch (MalformedURLException e) {
917     File file = new File(fileName);
918     if (file.exists())
919         foundFiles.addElement(fileName);
920     else
921         missedFiles.addElement(fileName);
922       } catch (IOException e) {
923     missedFiles.add(fileName);
924       }
925   }
926 
927   if ((op.equals(DEDataAdapterI.READ_TERMS) ||
928        op.equals(DEDataAdapterI.IMPORT_TERMS)) &&
929       missedFiles.size() > 0) {
930       String message = "Couldn't find the following paths:\n";
931       for(int i=0; i < missedFiles.size(); i++) {
932     message += "   "+((String) missedFiles.elementAt(i)) + "\n";
933       }
934       JOptionPane.showMessageDialog(null, message);
935       return;
936   }
937 
938 
939         if ((op.equals(DEDataAdapterI.WRITE_TERMS) ||
940        op.equals(DEDataAdapterI.EXPORT_TERMS))) {
941       if (containsURLs) {
942     JOptionPane.showMessageDialog(null, "Can't write to a URL.");
943     return;
944       }
945 
946       if (controller.warnBeforeDefinitionLoss() &&
947     (defFileName == null || defFileName.length() == 0)) {
948     Term root = controller.getRoot();
949     Enumeration e = root.getAllDescendants(true);
950     boolean doWarning = false;
951     while(e.hasMoreElements()) {
952         Term term = (Term) e.nextElement();
953         if ((term.getDefinition() != null &&
954        term.getDefinition().length() > 0) ||
955       (term.getComment() != null &&
956        term.getComment().length() > 0)) {
957       doWarning = true;
958       break;
959         }
960     }
961     if (doWarning) {
962         String message = "You have not specified a definitions \n"+
963       "file, but some terms in this session are defined. \n"+
964       "Those definitions will be lost if you save \n"+
965       "without specifying a definitions file.\n"+
966       "Do you want to continue this save and \n"+
967       "discard the definitions?";
968         int response = JOptionPane.
969       showConfirmDialog(null,
970             message,
971             "Discard defintions?",
972             JOptionPane.YES_NO_OPTION);
973         if (response != JOptionPane.YES_OPTION)
974       return;
975     }
976       }
977 
978       if (foundFiles.size() > 0) {
979     String message = "The following files already exist:\n";
980     for(int i=0; i < foundFiles.size(); i++) {
981         message += "   "+((String) foundFiles.elementAt(i))
982       + "\n";
983     }
984     message += "Overwrite files?";
985     int response = JOptionPane.
986         showConfirmDialog(null,
987               message,
988               "Overwrite files?",
989               JOptionPane.YES_NO_OPTION);
990     if (response != JOptionPane.YES_OPTION)
991         return;
992       }
993   }
994   controllingObject.commit();
995     }
996 
997     public void cancel() {
998   controllingObject.cancel();
999     }
1000
1001    public void setFont(Font font) {
1002  super.setFont(font);
1003  if (browseDefButton != null) {
1004      historyBox.setFont(font);
1005      filenameField.setFont(font);
1006      browseDefButton.setFont(font);
1007      definitionField.setFont(font);
1008      definitionLabel.setFont(font);
1009      hideDownstreamBox.setFont(font);
1010      pathToRootBox.setFont(font);
1011      allowCyclesBox.setFont(font);
1012      allowDanglingBox.setFont(font);
1013      reduceSizeBox.setFont(font);
1014      useLegacyTypesBox.setFont(font);
1015      commitButton.setFont(font);
1016      cancelButton.setFont(font);
1017  }
1018    }
1019
1020    public void setDataAdapter(DataAdapter in) {
1021  driver = in;
1022    }
1023
1024    protected void collectParams() {
1025
1026  comment = commentField.getText();
1027
1028  fileNames = new Vector();
1029  if (op.equals(DEDataAdapterI.WRITE_TERMS) ||
1030      op.equals(DEDataAdapterI.EXPORT_TERMS) ||
1031      op.equals(DEDataAdapterI.IMPORT_TERMS)) {
1032      fileNames.add(filenameField.getText());
1033  } else {
1034      Vector v = fileList.getData();
1035      for(int i=0; i < v.size(); i++)
1036    fileNames.add(v.get(i).toString());
1037  }
1038
1039  defFileName = definitionField.getText();
1040
1041  hideDownstream = hideDownstreamBox.isSelected();
1042  showPathToRoot = pathToRootBox.isSelected();
1043  allowCycles = allowCyclesBox.isSelected();
1044  allowDangling = allowDanglingBox.isSelected();
1045  reduceSize = reduceSizeBox.isSelected();
1046  useLegacyTypes = useLegacyTypesBox.isSelected();
1047
1048  if (!historyBox.getEditor().getItem().toString().equals(currentProfile.getProfileName())) {
1049      addOrModifyProfile();
1050  }
1051  storeProfile(currentProfile);
1052    }
1053
1054    public Object doOperation(Object values)
1055  throws DataAdapterException {
1056  collectParams();
1057  if (typeBindings != null &&
1058      defaultType != null) {
1059      ((GOFlatFileAdapter) driver).
1060    setCharTypeMappings(typeBindings, defaultType);
1061  }
1062
1063  if (op.equals(DEDataAdapterI.READ_TERMS))
1064      return readTerms();
1065  else if (op.equals(DEDataAdapterI.IMPORT_TERMS))
1066      return importTerms();
1067  else if (op.equals(DEDataAdapterI.WRITE_TERMS)) {
1068      return writeTerms((DEEditHistory) values);
1069  } else if (op.equals(DEDataAdapterI.EXPORT_TERMS)) {
1070      exportTerms((DEEditHistory) values, showPathToRoot);
1071      return null;
1072  } else
1073      return null;
1074    }
1075
1076    protected Object importTerms() throws DataAdapterException {  
1077  GOFlatFileAdapter driver = (GOFlatFileAdapter) this.driver;
1078  fileNames.setSize(1);
1079  driver.setPath(fileNames);
1080  driver.setDefinitionPath(defFileName);
1081  driver.setHideDownstream(hideDownstream);
1082  driver.setAllowCycles(allowCycles);
1083  driver.setAllowDangling(allowDangling);
1084  return driver.getRoot();
1085    }
1086
1087    protected DEEditHistory writeTerms(DEEditHistory history)
1088  throws DataAdapterException {
1089  GOFlatFileAdapter driver = (GOFlatFileAdapter) this.driver;
1090  driver.setPath((String) fileNames.elementAt(0));
1091  driver.setDefinitionPath(defFileName);
1092  driver.setComment(comment);
1093  driver.setAllowCycles(allowCycles);
1094  driver.setAllowDangling(allowDangling);
1095  driver.setReduceSize(reduceSize);
1096  driver.setUseLegacyTypes(useLegacyTypes);
1097  return driver.write(history);
1098    }
1099
1100    protected void exportTerms(DEEditHistory history, boolean showPathToRoot)
1101  throws DataAdapterException {
1102  GOFlatFileAdapter driver = (GOFlatFileAdapter) this.driver;
1103  driver.setPath((String) fileNames.elementAt(0));
1104  driver.setDefinitionPath(defFileName);
1105  driver.setComment(comment);
1106  driver.setAllowCycles(allowCycles);
1107  driver.setAllowDangling(allowDangling);
1108  driver.setReduceSize(reduceSize);
1109  driver.setUseLegacyTypes(useLegacyTypes);
1110  driver.exportTerms(history.getRoot(),
1111         history.getRelationshipTypes(),
1112         history.getDefaultRelationshipType(),
1113         showPathToRoot);
1114    }
1115
1116    protected Object readTerms() throws DataAdapterException {
1117  GOFlatFileAdapter driver = (GOFlatFileAdapter) this.driver;
1118  driver.setPath(fileNames);
1119  driver.setDefinitionPath(defFileName);
1120  driver.setHideDownstream(hideDownstream);
1121  driver.setAllowCycles(allowCycles);
1122  driver.setAllowDangling(allowDangling);
1123  return driver.getRoot();
1124    }
1125
1126    protected void loadProfile(FileProfile fileProfile) {
1127  if (op.equals(DEDataAdapterI.WRITE_TERMS) ||
1128      op.equals(DEDataAdapterI.EXPORT_TERMS) ||
1129      op.equals(DEDataAdapterI.IMPORT_TERMS)) {
1130      if (fileProfile.getFiles().size() > 0) {
1131    filenameField.setText(fileProfile.getFiles().get(0).
1132              toString());
1133      }
1134  } else {
1135      Vector v = new Vector();
1136      for(int i=0; i < fileProfile.getFiles().size(); i++) {
1137    v.add(new EditableString(fileProfile.getFiles().
1138           get(i).toString()));
1139      }
1140      fileList.setData(v);
1141  }
1142  definitionField.setText(fileProfile.getDefFile());
1143    }
1144
1145    protected void storeProfile(FileProfile fileProfile) {
1146  if (op.equals(DEDataAdapterI.WRITE_TERMS) ||
1147      op.equals(DEDataAdapterI.EXPORT_TERMS) ||
1148      op.equals(DEDataAdapterI.IMPORT_TERMS)) {
1149      Vector v = fileProfile.getFiles();
1150      if (v.size() == 0)
1151    v.add(filenameField.getText());
1152      else
1153    v.set(0, filenameField.getText());
1154      fileProfile.setFiles(v);
1155  } else {
1156      Vector v = new Vector();
1157      for(int i=0; i < fileList.getData().size(); i++) {
1158    v.add(fileList.getData().get(i).toString());
1159      }
1160      fileProfile.setFiles(v);
1161  }
1162
1163  fileProfile.setDefFile(definitionField.getText());
1164    }
1165
1166    protected void deleteProfile() {
1167  historyBox.removeItem(currentProfile);
1168
1169  if (currentSelectedIndex < historyBox.getItemCount()) {
1170      historyBox.setSelectedIndex(currentSelectedIndex);
1171  } else {
1172      historyBox.setSelectedIndex(currentSelectedIndex-1);
1173  }
1174
1175    }
1176
1177    public void setProperties(Properties in) {
1178  if (in != null) {
1179      props = in;
1180
1181      historyBox.removeAllItems();
1182      historyBox.addItem(new FileProfile(new Vector(), null,
1183                 NEW_PROFILE_NAME));
1184      int profileCount = 0;
1185      try {
1186    profileCount = Integer.
1187        parseInt(props.getProperty("profileCount"));
1188      } catch (NumberFormatException e) {}
1189      for(int i=0; i < profileCount; i++) {
1190    int fileCount = 0;
1191    try {
1192        fileCount = Integer.
1193      parseInt(props.getProperty("profile"+i+".fileCount"));
1194    } catch (NumberFormatException e) {}
1195    String defFile = props.getProperty("profile"+i+".defFile");
1196    String profileName = props.getProperty("profile"+i+
1197                   ".profileName");
1198    Vector theFiles = new Vector();
1199    for(int j=0; j < fileCount; j++) {
1200        String file = props.getProperty("profile"+i+".file"+j);
1201        theFiles.add(file);
1202    }
1203    FileProfile fileProfile = new FileProfile(theFiles,
1204                defFile,
1205                profileName);
1206    historyBox.addItem(fileProfile);
1207      }
1208      int selectedProfile = 0;
1209      String selectedProfileStr = props.
1210    getProperty("selectedProfileIndex");
1211      try {
1212    selectedProfile = Integer.
1213        parseInt(props.getProperty("selectedProfileIndex"));
1214      } catch (NumberFormatException ex) {}
1215
1216      historyBox.setSelectedIndex(selectedProfile);
1217
1218      int typeBindingCount = 0;
1219      try {
1220    typeBindingCount = Integer.
1221        parseInt(props.getProperty("bindingCount"));
1222      } catch (NumberFormatException e) {}
1223      typeBindings = new Hashtable();
1224      if (typeBindingCount != 0) {
1225    defaultType = null;
1226    String defaultTypeStr = props.
1227        getProperty("defaultBindingType");
1228    for(int i=0; i < typeBindingCount; i++) {
1229        String typeCharStr = (String) props.
1230      getProperty("bindingChar"+i);
1231        String typeName = (String) props.
1232      getProperty("bindingName"+i);
1233        String typeDesc = (String) props.
1234      getProperty("bindingDesc"+i);
1235        if (typeName != null &&
1236      typeDesc != null &&
1237      typeCharStr != null &&
1238      typeName.length() > 0 &&
1239      typeDesc.length() > 0) {
1240      char typeChar = typeCharStr.charAt(0);
1241      if ((typeCharStr.length() == 1 &&
1242           !Character.isWhitespace(typeChar) &&
1243           !GOFlatFileAdapter.isReservedCharacter(typeChar))
1244          || typeCharStr.length() > 1) {
1245          TermRelationshipType type =
1246        new TermRelationshipType(typeName, typeDesc);
1247          if (i == 0)
1248        defaultType = type;
1249          if (defaultTypeStr != null &&
1250        type.getName().equals(defaultTypeStr))
1251        defaultType = type;
1252          typeBindings.put(typeCharStr, type);
1253      }
1254        }
1255    }
1256      }
1257      relationshipTypes = getRelationshipTypes();
1258      symbolList.setData(relationshipTypes);
1259
1260      hideDownstream = !ObjectUtil.
1261    equals(props.getProperty("hideDownstream"), "false");
1262
1263      allowCycles = ObjectUtil.
1264    equals(props.getProperty("allowCycles"), "true");
1265      allowDangling = ObjectUtil.
1266    equals(props.getProperty("allowDangling"), "true");
1267      reduceSize = ObjectUtil.
1268    equals(props.getProperty("reduceSize"), "true");
1269      useLegacyTypes = !ObjectUtil.
1270    equals(props.getProperty("useLegacyTypes"), "false");
1271      showPathToRoot = !ObjectUtil.
1272    equals(props.getProperty("showPathToRoot"), "false");
1273
1274      hideDownstreamBox.setSelected(hideDownstream);
1275      allowCyclesBox.setSelected(allowCycles);
1276      pathToRootBox.setSelected(showPathToRoot);
1277      allowDanglingBox.setSelected(allowDangling);
1278      reduceSizeBox.setSelected(reduceSize);
1279      useLegacyTypesBox.setSelected(useLegacyTypes);
1280
1281      sortProfiles();
1282  }
1283    }
1284
1285    private void encodeFileProfile(FileProfile fileProfile,
1286           int index,
1287           Properties out) {
1288  out.setProperty("profile"+index+".fileCount",
1289      fileProfile.getFiles().size()+"");
1290  if (fileProfile.getDefFile() != null)
1291      out.setProperty("profile"+index+".defFile",
1292          fileProfile.getDefFile());
1293  out.setProperty("profile"+index+".profileName",
1294      fileProfile.getProfileName());
1295  for(int j=0; j < fileProfile.getFiles().size(); j++) {
1296      out.setProperty("profile"+index+".file"+j,
1297          fileProfile.getFiles().get(j).toString());
1298  }
1299    }
1300
1301    public Properties getProperties() {
1302  Properties out = new Properties();
1303
1304  for(int i=1; i < historyBox.getItemCount(); i++) {
1305      FileProfile fileProfile = (FileProfile) historyBox.getItemAt(i);
1306      encodeFileProfile(fileProfile, i-1, out);
1307  }
1308  out.setProperty("profileCount", (historyBox.getItemCount()-1)+"");
1309  out.setProperty("selectedProfileIndex"</