1 package com.explosion.datastream.exql.gui.table;
2
3 import java.awt.Component;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.FocusEvent;
6 import java.awt.event.FocusListener;
7 import java.util.HashMap;
8 import java.util.Map;
9
10 import javax.swing.SwingUtilities;
11
12 import com.explosion.expf.Application;
13 import com.explosion.expf.ExpActionListener;
14 import com.explosion.expf.ExpConstants;
15 import com.explosion.expf.ExpFrame;
16 import com.explosion.expfmodules.texteditor.Editable;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 /***
39 * @author Stephen
40 * Created on 28-Jun-2004
41 */
42 public class DsProTableLocalListener implements ExpActionListener, FocusListener
43 {
44 private static org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(DsProTableLocalListener.class);
45 private HashMap map;
46 private int newDocumentNumbers = 1;
47 private Editable component;
48 private Component highLevelParent;
49
50 /***
51 * Constructor for DsProTableLocalListener.
52 */
53 public DsProTableLocalListener(Editable component, Component highLevelParent)
54 {
55 this.component = component;
56 this.highLevelParent = highLevelParent;
57 setCookie(1);
58 component.addFocusListener(this);
59
60 map = new HashMap();
61 map.put(ExpConstants.MENU_CUT,ExpConstants.MENU_CUT);
62 map.put(ExpConstants.MENU_COPY,ExpConstants.MENU_COPY);
63 map.put(ExpConstants.MENU_PASTE,ExpConstants.MENU_PASTE);
64 map.put(ExpConstants.MENU_SELECTALL,ExpConstants.MENU_SELECTALL);
65
66 ((ExpFrame) Application.getApplicationFrame()).getListener().addComponentActionListener(this,highLevelParent,component);
67 log.debug("Component for DsProTableLocalListener is " + highLevelParent);
68 }
69
70 /***
71 * @see package com.explosion.expf.Interfaces.ExpActionListener#getListensFor()
72 */
73 public Map getListensFor()
74 {
75 return map;
76 }
77
78 /***
79 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
80 */
81 public void actionPerformed(ActionEvent e)
82 {
83 try
84 {
85 if (e.getActionCommand().equals(ExpConstants.MENU_CUT)) { component.cut(); }
86 else if (e.getActionCommand().equals(ExpConstants.MENU_COPY)) { component.copy(); }
87 else if (e.getActionCommand().equals(ExpConstants.MENU_PASTE)) { component.paste(); }
88 else if (e.getActionCommand().equals(ExpConstants.MENU_SELECTALL)) { component.selectAll(); }
89 }
90 catch (Exception ex)
91 {
92 com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(ex, "Exception caught while responding to SimpleProcess Event." );
93 }
94 }
95
96 public void setCookie(int number)
97 {
98
99 Application.ensureComponentCookie(ExpConstants.MENU_EDIT,number,highLevelParent,component);
100 Application.ensureComponentCookie(ExpConstants.MENU_SELECTALL,number,highLevelParent,component);
101 Application.ensureComponentCookie(ExpConstants.MENU_CUT,number,highLevelParent,component);
102 Application.ensureComponentCookie(ExpConstants.MENU_COPY,number,highLevelParent,component);
103 Application.ensureComponentCookie(ExpConstants.MENU_PASTE,number,highLevelParent,component);
104 }
105
106 public void focusGained(FocusEvent e)
107 {
108 Application.setActiveComponent(highLevelParent,component);
109 }
110
111 public void focusLost(FocusEvent e)
112 {
113 Component opposite = e.getOppositeComponent();
114 if (opposite != null)
115 {
116 if (SwingUtilities.isDescendingFrom(opposite,highLevelParent))
117 Application.unsetActiveComponent();
118 }
119 }
120 }