001: package vicazh.hyperpool;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005: import java.beans.*;
006: import java.io.*;
007: import java.util.logging.*;
008: import javax.swing.*;
009: import javax.xml.transform.*;
010:
011: /**
012: * The graphic object reader
013: *
014: * @author Victor Zhigunov
015: * @version 0.4.0
016: */
017: public class IReader extends Reader implements ActionListener,
018: PropertyChangeListener {
019:
020: /**
021: * @param tin
022: * xsl source transformer
023: */
024: public IReader(String tin) throws TransformerException {
025: super (tin);
026: }
027:
028: private IWriter writer;
029:
030: /**
031: * @param writer
032: * writer
033: */
034: public void setWriter(IWriter writer) {
035: this .writer = writer;
036: }
037:
038: private ICom com;
039:
040: /**
041: * @param com
042: * communicator
043: */
044: public void setCom(ICom com) {
045: this .com = com;
046: }
047:
048: void connect(String url) throws Exception {
049: com.connect(url);
050: }
051:
052: void disconnect() throws Exception {
053: getObject(closer);
054: }
055:
056: private JFileChooser chooser;
057:
058: /**
059: * @param chooser
060: * file chooser
061: */
062: public void setChooser(JFileChooser chooser) {
063: this .chooser = chooser;
064: }
065:
066: private Component parent;
067:
068: /**
069: * @param parent
070: * parent component
071: */
072: public void setParent(Component parent) {
073: this .parent = parent;
074: }
075:
076: private String closer;
077:
078: /**
079: * @param closer
080: * source
081: */
082: public void setCloser(String closer) {
083: this .closer = closer;
084: }
085:
086: private String creator;
087:
088: /**
089: * @param creator
090: * source
091: */
092: public void setCreator(String creator) {
093: this .creator = creator;
094: }
095:
096: private JList list;
097:
098: /**
099: * @param list
100: * start list
101: */
102: public void setList(JList list) {
103: this .list = list;
104: }
105:
106: private JDialog dialog;
107:
108: private JOptionPane optionPane;
109:
110: /**
111: * @param dialog
112: * start dialog
113: */
114: public void setDialog(JDialog dialog) {
115: this .dialog = dialog;
116: optionPane = (JOptionPane) dialog.getContentPane();
117: optionPane.addPropertyChangeListener(this );
118: }
119:
120: public void propertyChange(PropertyChangeEvent e) {
121: Component c = ((JComponent) e.getSource())
122: .getTopLevelAncestor();
123: String prop = e.getPropertyName();
124: if (c.isVisible()
125: && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop
126: .equals(JOptionPane.INPUT_VALUE_PROPERTY)))
127: c.setVisible(false);
128: }
129:
130: void send(String in) throws Exception {
131: this .in = null;
132: com.setAttribute(ComMBean.SET, new ComData(get(in)));
133: }
134:
135: void send(File in) throws Exception {
136: this .in = in;
137: com.setAttribute(ComMBean.READ, new ComData(get(in)));
138: }
139:
140: public void actionPerformed(ActionEvent e) {
141: try {
142: if (!com.isConnect())
143: com.connect();
144: if (!com.isConnect())
145: return;
146: IWriter.Status j = writer.check();
147: if (j == IWriter.Status.CANCEL)
148: return;
149: String command = e.getActionCommand();
150: if (command.equals("start")) {
151: dialog.setLocationRelativeTo(dialog.getOwner());
152: dialog.setVisible(true);
153: Object value = optionPane.getValue();
154: if (value == JOptionPane.UNINITIALIZED_VALUE)
155: return;
156: optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
157: if (((Integer) value).intValue() != JOptionPane.OK_OPTION)
158: return;
159: IResource r = (IResource) list.getSelectedValue();
160: if (r == null)
161: return;
162: if (j == IWriter.Status.OK)
163: send(closer);
164: send(r.resource);
165: } else if (command.equals("new")) {
166: if (j == IWriter.Status.OK)
167: send(closer);
168: send(creator);
169: } else if (command.equals("open")) {
170: if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION)
171: return;
172: if (j == IWriter.Status.OK)
173: send(closer);
174: send(chooser.getSelectedFile());
175: } else
176: send(closer);
177: } catch (Exception ex) {
178: Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
179: }
180: }
181:
182: private File in;
183:
184: /**
185: * Return xml source file
186: *
187: * @return xml source file
188: */
189: public File getIn() {
190: return in;
191: }
192:
193: private Object parameter;
194:
195: /**
196: * Get the parameter
197: */
198: public Object getParameter() {
199: return parameter;
200: }
201:
202: /**
203: * Set the parameter
204: */
205: public void setParameter(Object parameter) {
206: this.parameter = parameter;
207: }
208: }
|