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.text;
25 
26 import javax.swing.JDialog;
27 import javax.swing.text.JTextComponent;
28 
29 import com.sun.star.accessibility.XAccessibleContext;
30 import com.sun.star.accessibility.XAccessibleEditableText;
31 import com.sun.star.accessibility.XAccessibleText;
32 import com.sun.star.lang.IndexOutOfBoundsException;
33 import com.sun.star.uno.UnoRuntime;
34 
35 
36 /** Factory for dialogs of the text views.
37 */
38 public class TextDialogFactory
39 {
CreateSelectionDialog(XAccessibleContext xContext)40     static public JDialog CreateSelectionDialog (XAccessibleContext xContext)
41     {
42         JDialog aDialog = new TextActionDialog(
43             xContext,
44             "Select range:",
45             "select")
46             {
47                 boolean TextAction (XAccessibleText xText)
48                     throws IndexOutOfBoundsException
49                 {
50                     return xText.setSelection(
51                         GetSelectionStart(),
52                         GetSelectionEnd() );
53                 }
54             };
55         if (aDialog != null)
56             aDialog.show();
57         return aDialog;
58     }
59 
CreateCopyDialog(XAccessibleContext xContext)60     static public JDialog CreateCopyDialog (XAccessibleContext xContext)
61     {
62         JDialog aDialog = new TextActionDialog(
63             xContext,
64             "Select range and copy:",
65             "copy")
66             {
67                 boolean TextAction (XAccessibleText xText)
68                     throws IndexOutOfBoundsException
69                 {
70                     return xText.copyText(
71                         GetSelectionStart(),
72                         GetSelectionEnd());
73                 }
74             };
75         if (aDialog != null)
76             aDialog.show();
77         return aDialog;
78     }
CreateCutDialog(XAccessibleContext xContext)79     static public JDialog CreateCutDialog (XAccessibleContext xContext)
80     {
81         JDialog aDialog = new TextActionDialog(
82             xContext,
83             "Select range and cut:",
84             "cut")
85             {
86                 boolean EditableTextAction (XAccessibleEditableText xText)
87                     throws IndexOutOfBoundsException
88                 {
89                     return xText.cutText(
90                         GetSelectionStart(),
91                         GetSelectionEnd() );
92                 }
93             };
94         if (aDialog != null)
95             aDialog.show();
96         return aDialog;
97     }
CreatePasteDialog(XAccessibleContext xContext)98     static public JDialog CreatePasteDialog (XAccessibleContext xContext)
99     {
100         JDialog aDialog = new TextActionDialog (
101             xContext,
102             "Place Caret and paste:",
103             "paste")
104             {
105                 boolean EditableTextAction (XAccessibleEditableText xText)
106                     throws IndexOutOfBoundsException
107                 {
108                     return xText.pasteText(maText.getCaretPosition());
109                 }
110             };
111         if (aDialog != null)
112             aDialog.show();
113         return aDialog;
114     }
CreateEditDialog(XAccessibleContext xContext)115     static public JDialog CreateEditDialog (XAccessibleContext xContext)
116     {
117         JDialog aDialog = new TextEditDialog (
118             xContext,
119             "Edit text:",
120             "edit");
121         if (aDialog != null)
122             aDialog.show();
123         return aDialog;
124     }
CreateFormatDialog(XAccessibleContext xContext)125     static public JDialog CreateFormatDialog (XAccessibleContext xContext)
126     {
127         JDialog aDialog = new TextAttributeDialog (xContext);
128         if (aDialog != null)
129             aDialog.show();
130         return aDialog;
131     }
132 }
133