001: package vicazh.hyperpool.stream.net.http;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005: import java.beans.*;
006: import java.util.logging.*;
007: import javax.swing.*;
008: import org.jfree.chart.*;
009: import org.jfree.chart.plot.*;
010: import org.jfree.chart.title.*;
011: import org.jfree.data.general.*;
012: import vicazh.hyperpool.*;
013: import vicazh.hyperpool.Start;
014:
015: /**
016: * The graphic cache service
017: *
018: * @author Victor Zhigunov
019: * @version 0.4.0
020: */
021: public class ICacheService extends IService implements
022: CacheServiceMBean, ActionListener, PropertyChangeListener {
023: private JFreeChart chart;
024:
025: private PiePlot plot;
026:
027: private JButton buttonReset;
028:
029: private LegendTitle legend;
030:
031: private DefaultPieDataset data;
032:
033: private JDialog dialog;
034:
035: private JOptionPane optionPane;
036:
037: private JTextField textDir;
038:
039: private Component component;
040:
041: /**
042: * @param name
043: * service name
044: * @param chart
045: * chart
046: * @param plot
047: * pie plot
048: * @param buttonReset
049: * reset button
050: * @param legend
051: * legend
052: * @param data
053: * pie dataset
054: * @param dialog
055: * options dialog
056: * @param textDir
057: * files directory value field
058: * @param component
059: * component for ui update
060: */
061: public ICacheService(String name, JFreeChart chart, PiePlot plot,
062: JButton buttonReset, LegendTitle legend,
063: DefaultPieDataset data, JDialog dialog, JTextField textDir,
064: Component component) {
065: super (CacheServiceMBean.class, name);
066: this .chart = chart;
067: this .plot = plot;
068: this .data = data;
069: this .buttonReset = buttonReset;
070: buttonReset.addActionListener(this );
071: this .legend = legend;
072: this .dialog = dialog;
073: optionPane = (JOptionPane) dialog.getContentPane();
074: optionPane.addPropertyChangeListener(this );
075: this .textDir = textDir;
076: this .component = component;
077: updateUI();
078: }
079:
080: public void actionPerformed(ActionEvent e) {
081: if (e.getSource() == buttonReset) {
082: try {
083: setAttribute(CacheServiceMBean.ACTION);
084: } catch (Exception ex) {
085: Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
086: }
087: buttonReset.setEnabled(false);
088: } else {
089: dialog.setLocationRelativeTo(dialog.getOwner());
090: dialog.setVisible(true);
091: Object value = optionPane.getValue();
092: if (value == JOptionPane.UNINITIALIZED_VALUE)
093: return;
094: optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
095: if (((Integer) value).intValue() != JOptionPane.OK_OPTION)
096: return;
097: try {
098: setAttribute(CacheServiceMBean.DIR, textDir.getText());
099: } catch (Exception ex) {
100: Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
101: }
102: }
103: }
104:
105: private static final String key = "activeCaption";
106:
107: private static final String keyi = "inactiveCaption";
108:
109: private static final String keyw = "window";
110:
111: private static final String keyt = "controlText";
112:
113: public void updateUI() {
114: plot.setSectionPaint(0, UIManager.getColor(key));
115: plot.setSectionPaint(1, UIManager.getColor(keyi));
116: chart.setBackgroundPaint(UIManager.getColor(keyw));
117: plot.setBackgroundPaint(UIManager.getColor(keyw));
118: legend.setBackgroundPaint(UIManager.getColor(keyw));
119: plot.setOutlinePaint(UIManager.getColor(keyw));
120: legend.setItemPaint(UIManager.getColor(keyt));
121: SwingUtilities.updateComponentTreeUI(dialog);
122: SwingUtilities.updateComponentTreeUI(component);
123: }
124:
125: public void propertyChange(PropertyChangeEvent e) {
126: Component c = ((JComponent) e.getSource())
127: .getTopLevelAncestor();
128: String prop = e.getPropertyName();
129: if (c.isVisible()
130: && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop
131: .equals(JOptionPane.INPUT_VALUE_PROPERTY)))
132: c.setVisible(false);
133: }
134:
135: private void set(Long[] value) {
136: data.setValue(data.getKey(0), value[0]);
137: data.setValue(data.getKey(1), value[1]);
138: buttonReset.setEnabled(value[0] != 0 || value[1] != 1);
139: }
140:
141: protected void currentNotification(String type, Object value) {
142: if (type.equals(ElementMBean.INIT))
143: set((Long[]) value);
144: }
145:
146: protected void otherNotification(String type, Object value) {
147: if (type.equals(CacheServiceMBean.DIR))
148: textDir.setText((String) value);
149: else
150: set((Long[]) value);
151: }
152:
153: public char getSeparator() {
154: return ((CacheServiceMBean) melement).getSeparator();
155: }
156:
157: public String d2p(String dir) {
158: return dir.replace('/', getSeparator());
159: }
160: }
|