4 import java
.awt
.GridBagConstraints
;
5 import java
.awt
.GridBagLayout
;
6 import java
.awt
.event
.ActionListener
;
7 import java
.awt
.event
.ActionEvent
;
9 import javax
.swing
.JButton
;
10 import javax
.swing
.JLabel
;
12 import com
.sun
.star
.accessibility
.AccessibleEventId
;
13 import com
.sun
.star
.accessibility
.AccessibleEventObject
;
14 import com
.sun
.star
.accessibility
.AccessibleStateType
;
15 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
16 import com
.sun
.star
.accessibility
.XAccessibleContext
;
17 import com
.sun
.star
.accessibility
.XAccessibleStateSet
;
18 import com
.sun
.star
.uno
.UnoRuntime
;
20 public class FocusView
21 extends ListeningObjectView
22 implements ActionListener
24 /** Create a FocusView when the given object supports the
25 XAccessibleComponent interface.
27 static public ObjectView
Create (
28 ObjectViewContainer aContainer
,
29 XAccessibleContext xContext
)
31 XAccessibleComponent xComponent
= (XAccessibleComponent
)UnoRuntime
.queryInterface(
32 XAccessibleComponent
.class, xContext
);
33 if (xComponent
!= null)
34 return new FocusView (aContainer
);
39 public FocusView (ObjectViewContainer aContainer
)
43 setLayout (new GridBagLayout());
44 GridBagConstraints aConstraints
= new GridBagConstraints ();
46 maFocused
= new JLabel ();
47 aConstraints
.gridy
= 0;
48 aConstraints
.weightx
= 1;
49 aConstraints
.fill
= GridBagConstraints
.HORIZONTAL
;
50 add (maFocused
, aConstraints
);
52 maGrabFocus
= new JButton ("grabFocus");
53 aConstraints
.gridy
= 1;
54 aConstraints
.fill
= GridBagConstraints
.NONE
;
55 aConstraints
.anchor
= GridBagConstraints
.WEST
;
56 add (maGrabFocus
, aConstraints
);
58 maGrabFocus
.addActionListener (this);
61 /** Additionally to the context store a reference to the
62 XAccessibleComponent interface.
64 public void SetObject (XAccessibleContext xObject
)
66 mxComponent
= (XAccessibleComponent
)UnoRuntime
.queryInterface(
67 XAccessibleComponent
.class, xObject
);
68 super.SetObject (xObject
);
71 synchronized public void Destroy ()
74 maGrabFocus
.removeActionListener (this);
77 synchronized public void Update ()
79 if (mxContext
== null)
81 maFocused
.setText ("<null object>");
82 maGrabFocus
.setEnabled (false);
86 XAccessibleStateSet aStateSet
= mxContext
.getAccessibleStateSet();
87 if (aStateSet
.contains(AccessibleStateType
.FOCUSED
))
88 maFocused
.setText ("focused");
90 maFocused
.setText ("not focused");
91 if (maGrabFocus
!= null)
92 maGrabFocus
.setEnabled (true);
96 public String
GetTitle ()
101 synchronized public void actionPerformed (ActionEvent aEvent
)
103 if (aEvent
.getActionCommand().equals("grabFocus"))
105 mxComponent
.grabFocus();
109 public void notifyEvent (AccessibleEventObject aEvent
)
111 System
.out
.println (aEvent
);
112 if (aEvent
.EventId
== AccessibleEventId
.STATE_CHANGED
)
116 private JLabel maFocused
;
117 private JButton maGrabFocus
;
118 private XAccessibleComponent mxComponent
;