1    /*
2    Copyright 2000 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    import javax.swing.*;
7    import javax.swing.event.*;
8    import java.io.*;
9    import java.awt.event.*;
10   import java.awt.*;
11   import java.lang.reflect.*;
12   
13   public abstract class Editor extends JPanel implements ActionListener{
14   
15     static public int TYPE = 0;
16       // 1 -- MapEditor
17   
18     public static String NAME = "Name...";
19     public static String CLOSE = "Close";
20   
21     boolean dirty = false;
22   
23     JMenuBar bar = new JMenuBar();
24   
25     CartoFrame frame=null;
26     EditFrame editframe =null;
27     public Editable target=null;
28     public JScrollPane scroll=null;
29     public Scale scale = null;
30     public Rose rose = null;
31   
32     public static boolean findRefs(Object source,Class t,int level) {
33       for (Class c = source.getClass();
34            c != null;
35            c = c.getSuperclass()) {
36         Field[] fields = c.getDeclaredFields();
37         for (int i=0;i<fields.length;i++) {
38           Class type = fields[i].getType();
39           if (type.isPrimitive()){}
40           else if (level>1 && type.isArray()) {
41           }
42           else {
43             try {
44               Object value = fields[i].get(source);
45               for (int j=10;j>level;j--) System.out.print("  ");
46               System.out.println("checking "+c.getName()+"."+fields[i].getName());
47               if (type == t ||
48           	(level>0 && findRefs(value,t,level-1))) {
49                 for (int j=10;j>level;j--) System.out.print("  ");
50                 System.out.println("ref "+c.getName()+"."+fields[i].getName()+" ("+type.getName()+")");
51                 return(true);
52               }
53             } catch (IllegalAccessException ex) {
54   //            System.out.println("failed "+c.getName()+"."+fields[i].getName());
55             }
56           }
57         }
58       }
59       return(false);
60     }
61   
62     public Editor(CartoFrame frame,String s,boolean a,boolean b,boolean c,boolean d,boolean insert) {
63       super();
64       setLayout(new BorderLayout());
65       add(bar,BorderLayout.NORTH);
66       this.editframe = new EditFrame(s,a,b,c,d,this,insert);
67       this.frame = frame;
68     }
69   
70     public Editor(CartoFrame frame,String s,boolean a,boolean b,boolean c,boolean d) {
71       this(frame,s,a,b,c,d,true);
72     }
73   
74     public Editor(CartoFrame frame) {
75       super();
76       setLayout(new BorderLayout());
77       add(bar,BorderLayout.NORTH);
78       this.frame = frame;
79     }
80     
81     public void saveData() {}
82   
83     void cleanup() {
84       if (frame==null) {
85         System.out.println("Editor closed twice! (minor bug)");
86         return;   //We did this already!
87       }
88       saveData();
89       dirty = true;
90       
91   //    System.out.println("Editor closing (debug)");
92       if (frame.lastselected==this) frame.lastselected = null;
93   //    frame.editlist.remove(this);
94   //    dispose();
95       frame=null;
96       editframe = null;
97       bar = null;
98       target=null;
99       scroll=null;
100      if (scale!=null) scale.targets=null;
101      scale = null;
102      if (rose!=null) rose.target=null;
103      rose = null;
104    }
105  
106    public void addMenuItem(JMenu menu,String comand,char mne) {
107      JMenuItem item = new JMenuItem(comand);
108      item.setMnemonic(mne);
109      item.addActionListener(this);
110      menu.add(item);
111    }
112  
113    public void addMenuItem(JMenu menu,String comand) {
114      JMenuItem item = new JMenuItem(comand);
115      item.addActionListener(this);
116      menu.add(item);
117    }
118  
119    public boolean isDirty() {
120      return(dirty);
121    }
122  }
123