001: package vicazh.hyperpool.stream;
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 vicazh.hyperpool.*;
010: import vicazh.hyperpool.Start;
011:
012: /**
013: * The graphic file service
014: *
015: * @author Victor Zhigunov
016: * @version 0.4.0
017: */
018: abstract public class IFileService extends IService implements
019: FileServiceMBean, PropertyChangeListener {
020: private JButton buttonClear;
021:
022: private JDialog dialogClear;
023:
024: private JOptionPane optionPaneClear;
025:
026: /**
027: * @param interfaceClass
028: * interface class
029: * @param name
030: * service name
031: * @param buttonClear
032: * clear button
033: * @param dialogClear
034: * clear dialog
035: */
036: public IFileService(Class<?> interfaceClass, String name,
037: JButton buttonClear, JDialog dialogClear) {
038: super (interfaceClass, name);
039: this .buttonClear = buttonClear;
040: buttonClear.addActionListener(new ActionListener() {
041: public void actionPerformed(ActionEvent e) {
042: IFileService.this .dialogClear
043: .setLocationRelativeTo(IFileService.this .dialogClear
044: .getOwner());
045: IFileService.this .dialogClear.setVisible(true);
046: Object value = optionPaneClear.getValue();
047: if (value == JOptionPane.UNINITIALIZED_VALUE)
048: return;
049: optionPaneClear
050: .setValue(JOptionPane.UNINITIALIZED_VALUE);
051: if (((Integer) value).intValue() != JOptionPane.YES_OPTION)
052: return;
053: hold();
054: new Thread() {
055: public void run() {
056: try {
057: setAttribute(FileServiceMBean.CLEAR);
058: } catch (Exception e) {
059: Start.logger.log(Level.SEVERE, e
060: .getMessage(), e);
061: }
062: }
063: }.start();
064: }
065:
066: });
067: this .dialogClear = dialogClear;
068: optionPaneClear = (JOptionPane) dialogClear.getContentPane();
069: optionPaneClear.addPropertyChangeListener(this );
070: }
071:
072: private boolean isHold;
073:
074: protected void hold() {
075: isHold = true;
076: buttonClear.setEnabled(false);
077: }
078:
079: public byte[] get(File file) throws IOException {
080: return ((FileServiceMBean) melement).get(file);
081: }
082:
083: public void propertyChange(PropertyChangeEvent e) {
084: Component c = ((JComponent) e.getSource())
085: .getTopLevelAncestor();
086: String prop = e.getPropertyName();
087: if (c.isVisible()
088: && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop
089: .equals(JOptionPane.INPUT_VALUE_PROPERTY)))
090: c.setVisible(false);
091: }
092:
093: public void updateUI() {
094: SwingUtilities.updateComponentTreeUI(dialogClear);
095: }
096:
097: protected void set() {
098: buttonClear.setEnabled(isDirExists);
099: }
100:
101: protected boolean isDirExists;
102:
103: protected void set(FileData data) {
104: this .isDirExists = data.isDirExists;
105: isHold = false;
106: set();
107: }
108:
109: protected void otherNotification(String type, Object value) {
110: if (type.equals(FileServiceMBean.ZAP)) {
111: if (!isHold)
112: set((FileData) value);
113: } else if (type.equals(FileServiceMBean.CLEAR))
114: set((FileData) value);
115: }
116:
117: protected void currentNotification(String type, Object value) {
118: if (type.equals(FileServiceMBean.CLEAR)
119: || type.equals(FileServiceMBean.INIT)
120: || type.equals(FileServiceMBean.ZAP))
121: set((FileData) value);
122: }
123:
124: public char getSeparator() {
125: return ((FileServiceMBean) melement).getSeparator();
126: }
127:
128: public String d2p(String dir) {
129: return dir.replace('/', getSeparator());
130: }
131: }
|