1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.accessibility.awb.view; 25 26 import java.awt.BorderLayout; 27 import java.awt.GridBagLayout; 28 import java.awt.GridBagConstraints; 29 import java.awt.Color; 30 import java.awt.Dimension; 31 import java.awt.Font; 32 import java.awt.Graphics; 33 import javax.swing.JScrollBar; 34 import javax.swing.JScrollPane; 35 import javax.swing.JTextArea; 36 37 import com.sun.star.accessibility.AccessibleEventId; 38 import com.sun.star.accessibility.AccessibleEventObject; 39 import com.sun.star.accessibility.XAccessibleContext; 40 41 import org.openoffice.accessibility.misc.NameProvider; 42 43 44 /** A simple event monitor that shows all events sent to one accessible 45 object. 46 */ 47 class EventMonitorView 48 extends ObjectView 49 { Create( ObjectViewContainer aContainer, XAccessibleContext xContext)50 static public ObjectView Create ( 51 ObjectViewContainer aContainer, 52 XAccessibleContext xContext) 53 { 54 if (xContext != null) 55 return new EventMonitorView (aContainer); 56 else 57 return null; 58 } 59 EventMonitorView(ObjectViewContainer aContainer)60 public EventMonitorView (ObjectViewContainer aContainer) 61 { 62 super (aContainer); 63 mnLineNo = 0; 64 Layout(); 65 } 66 GetTitle()67 public String GetTitle () 68 { 69 return "Event Monitor"; 70 } 71 72 /** Create and arrange the widgets for this view. 73 */ Layout()74 private void Layout () 75 { 76 setLayout (new GridBagLayout ()); 77 78 maText = new JTextArea(); 79 maText.setBackground (new Color (255,250,240)); 80 maText.setFont (new Font ("Helvetica", Font.PLAIN, 9)); 81 82 maScrollPane = new JScrollPane (maText, 83 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 84 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 85 maScrollPane.setPreferredSize (new Dimension (300,200)); 86 87 GridBagConstraints aConstraints = new GridBagConstraints (); 88 aConstraints.weightx = 1; 89 aConstraints.fill = GridBagConstraints.HORIZONTAL; 90 add (maScrollPane, aConstraints); 91 } 92 93 Update()94 public void Update () 95 { 96 } 97 98 UpdateVerticalScrollBar()99 private void UpdateVerticalScrollBar () 100 { 101 JScrollBar sb = maScrollPane.getVerticalScrollBar(); 102 if (sb != null) 103 { 104 int nScrollBarValue = sb.getMaximum() - sb.getVisibleAmount() - 1; 105 sb.setValue (nScrollBarValue); 106 } 107 } 108 109 notifyEvent(AccessibleEventObject aEvent)110 public void notifyEvent (AccessibleEventObject aEvent) 111 { 112 maText.append ((mnLineNo++) + ". " + NameProvider.getEventName (aEvent.EventId) + " : " 113 + aEvent.OldValue.toString() 114 + " -> " 115 + aEvent.NewValue.toString() + "\n"); 116 UpdateVerticalScrollBar(); 117 } 118 119 private JTextArea maText; 120 private int mnLineNo; 121 private JScrollPane maScrollPane; 122 } 123