1*cdf0e10cSrcweir package ov; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import java.awt.Color; 4*cdf0e10cSrcweir import java.awt.Dimension; 5*cdf0e10cSrcweir import java.awt.GridBagLayout; 6*cdf0e10cSrcweir import java.awt.GridBagConstraints; 7*cdf0e10cSrcweir 8*cdf0e10cSrcweir import java.awt.event.ActionListener; 9*cdf0e10cSrcweir import java.awt.event.ActionEvent; 10*cdf0e10cSrcweir 11*cdf0e10cSrcweir import javax.swing.JLabel; 12*cdf0e10cSrcweir import javax.swing.JTextField; 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleEventId; 15*cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleEventObject; 16*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 17*cdf0e10cSrcweir 18*cdf0e10cSrcweir import tools.NameProvider; 19*cdf0e10cSrcweir 20*cdf0e10cSrcweir public class ContextView 21*cdf0e10cSrcweir extends ListeningObjectView 22*cdf0e10cSrcweir implements ActionListener 23*cdf0e10cSrcweir { 24*cdf0e10cSrcweir static public ObjectView Create ( 25*cdf0e10cSrcweir ObjectViewContainer aContainer, 26*cdf0e10cSrcweir XAccessibleContext xContext) 27*cdf0e10cSrcweir { 28*cdf0e10cSrcweir System.out.println ("ContextView.CreateView"); 29*cdf0e10cSrcweir if (xContext != null) 30*cdf0e10cSrcweir return new ContextView (aContainer); 31*cdf0e10cSrcweir else 32*cdf0e10cSrcweir return null; 33*cdf0e10cSrcweir } 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir public ContextView (ObjectViewContainer aContainer) 36*cdf0e10cSrcweir { 37*cdf0e10cSrcweir super (aContainer); 38*cdf0e10cSrcweir maNameLabel = new JLabel ("Name: "); 39*cdf0e10cSrcweir maName = new JLabel (""); 40*cdf0e10cSrcweir maDescriptionLabel = new JLabel ("Description: "); 41*cdf0e10cSrcweir maDescription = new JLabel (""); 42*cdf0e10cSrcweir maRoleLabel = new JLabel ("Role: "); 43*cdf0e10cSrcweir maRole = new JLabel (""); 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // Make the background of name and description white and opaque so 46*cdf0e10cSrcweir // that leading and trailing spaces become visible. 47*cdf0e10cSrcweir maName.setOpaque (true); 48*cdf0e10cSrcweir maName.setBackground (Color.WHITE); 49*cdf0e10cSrcweir maDescription.setOpaque (true); 50*cdf0e10cSrcweir maDescription.setBackground (Color.WHITE); 51*cdf0e10cSrcweir maRole.setOpaque (true); 52*cdf0e10cSrcweir maRole.setBackground (Color.WHITE); 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir GridBagLayout aLayout = new GridBagLayout(); 55*cdf0e10cSrcweir setLayout (aLayout); 56*cdf0e10cSrcweir GridBagConstraints constraints = new GridBagConstraints (); 57*cdf0e10cSrcweir constraints.gridx = 0; 58*cdf0e10cSrcweir constraints.gridy = 0; 59*cdf0e10cSrcweir constraints.gridwidth = 1; 60*cdf0e10cSrcweir constraints.gridheight = 1; 61*cdf0e10cSrcweir constraints.weightx = 0; 62*cdf0e10cSrcweir constraints.weighty = 1; 63*cdf0e10cSrcweir constraints.anchor = GridBagConstraints.WEST; 64*cdf0e10cSrcweir constraints.fill = GridBagConstraints.NONE; 65*cdf0e10cSrcweir add (maNameLabel, constraints); 66*cdf0e10cSrcweir constraints.gridy = 1; 67*cdf0e10cSrcweir add (maDescriptionLabel, constraints); 68*cdf0e10cSrcweir constraints.gridy = 2; 69*cdf0e10cSrcweir add (maRoleLabel, constraints); 70*cdf0e10cSrcweir constraints.gridy = 0; 71*cdf0e10cSrcweir constraints.gridx = 1; 72*cdf0e10cSrcweir constraints.weightx = 2; 73*cdf0e10cSrcweir add (maName, constraints); 74*cdf0e10cSrcweir constraints.gridy = 1; 75*cdf0e10cSrcweir add (maDescription, constraints); 76*cdf0e10cSrcweir constraints.gridy = 2; 77*cdf0e10cSrcweir add (maRole, constraints); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir public void Update () 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir if (mxContext == null) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir maName.setText ("<null object>"); 85*cdf0e10cSrcweir maDescription.setText ("<null object>"); 86*cdf0e10cSrcweir maRole.setText ("<null object>"); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir else 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir maName.setText (mxContext.getAccessibleName()); 91*cdf0e10cSrcweir maDescription.setText (mxContext.getAccessibleDescription()); 92*cdf0e10cSrcweir maRole.setText (NameProvider.getRoleName (mxContext.getAccessibleRole())); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir public String GetTitle () 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir return ("Context"); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir /** Listen for changes regarding displayed values. 102*cdf0e10cSrcweir */ 103*cdf0e10cSrcweir public void notifyEvent (AccessibleEventObject aEvent) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir switch (aEvent.EventId) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir case AccessibleEventId.NAME_CHANGED : 108*cdf0e10cSrcweir case AccessibleEventId.DESCRIPTION_CHANGED : 109*cdf0e10cSrcweir Update (); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir public void actionPerformed (ActionEvent aEvent) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir private JLabel 119*cdf0e10cSrcweir maNameLabel, 120*cdf0e10cSrcweir maName, 121*cdf0e10cSrcweir maDescriptionLabel, 122*cdf0e10cSrcweir maDescription, 123*cdf0e10cSrcweir maRoleLabel, 124*cdf0e10cSrcweir maRole; 125*cdf0e10cSrcweir } 126