Source Code Cross Referenced for TextAction.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Alexander T. Simbirtsev, Evgeniya G. Maenkova
019:         * @version $Revision$
020:         */package javax.swing.text;
021:
022:        import java.awt.Point;
023:        import java.awt.event.ActionEvent;
024:        import java.util.Comparator;
025:        import java.util.TreeMap;
026:        import javax.swing.AbstractAction;
027:        import javax.swing.Action;
028:
029:        import org.apache.harmony.awt.text.AWTTextAction;
030:        import org.apache.harmony.awt.text.ActionSet;
031:        import org.apache.harmony.awt.text.TextKit;
032:        import org.apache.harmony.awt.text.TextUtils;
033:
034:        public abstract class TextAction extends AbstractAction {
035:            public static final Action[] augmentList(final Action[] list1,
036:                    final Action[] list2) {
037:                Comparator comparator = new Comparator() {
038:                    public int compare(final Object item1, final Object item2) {
039:                        return ((String) item2).compareTo((String) item1);
040:                    }
041:                };
042:
043:                TreeMap map = new TreeMap(comparator);
044:                if (list2 != null) {
045:                    for (int i = 0; i < list2.length; i++) {
046:                        map.put(list2[i].getValue(Action.NAME), list2[i]);
047:                    }
048:                }
049:                if (list1 != null) {
050:                    for (int i = 0; i < list1.length; i++) {
051:                        String name = (String) list1[i].getValue(Action.NAME);
052:                        if (!map.containsKey(name)) {
053:                            map.put(name, list1[i]);
054:                        }
055:                    }
056:                }
057:
058:                return (Action[]) (map).values()
059:                        .toArray(new Action[map.size()]);
060:            }
061:
062:            public TextAction(final String name) {
063:                putValue(Action.NAME, name);
064:            }
065:
066:            protected final JTextComponent getFocusedComponent() {
067:                return JTextComponent.getLastFocusedTextComponent();
068:            }
069:
070:            protected final JTextComponent getTextComponent(final ActionEvent e) {
071:                if (e != null) {
072:                    Object eventSource = e.getSource();
073:                    if (eventSource instanceof  JTextComponent) {
074:                        return (JTextComponent) eventSource;
075:                    }
076:                }
077:
078:                return getFocusedComponent();
079:            }
080:
081:            final JTextComponent getEditableTextComponent(final ActionEvent e) {
082:                JTextComponent c = getTextComponent(e);
083:                return (c != null && c.isEditable()) ? c : null;
084:            }
085:
086:            /**
087:             * sets new value to dot or mark of given component's caret
088:             * depending on <code>isMovingCaret</code> value
089:             */
090:            final void changeCaretPosition(final JTextComponent component,
091:                    final int newPos, final boolean isMovingCaret) {
092:                changeCaretPosition(component, newPos, isMovingCaret,
093:                        Position.Bias.Forward);
094:            }
095:
096:            /**
097:             * sets new value to dot or mark of given component's caret
098:             * depending on <code>isMovingCaret</code> value
099:             */
100:            final void changeCaretPosition(final JTextComponent component,
101:                    final int newPos, final boolean isMovingCaret,
102:                    final Position.Bias newBias) {
103:                TextKit textKit = TextUtils.getTextKit(component);
104:                TextUtils.changeCaretPosition(textKit, newPos, isMovingCaret,
105:                        newBias);
106:            }
107:
108:            /**
109:             * determines and sets value to given component's caret magic position
110:             *
111:             * @param source - component which caret will be modified
112:             * @param pos - caret position
113:             * @param direction in which caret is moving one of
114:             * <code>SwingConstants</code> values
115:             * @param oldPoint - current magic position value
116:             * @throws BadLocationException
117:             */
118:            final void setMagicPosition(final JTextComponent source,
119:                    final int pos, final int direction, final Point oldPoint)
120:                    throws BadLocationException {
121:                TextKit textKit = TextUtils.getTextKit(source);
122:                textKit.getCaret().setMagicCaretPosition(pos, direction,
123:                        oldPoint);
124:            }
125:
126:            final void setCurrentPositionAsMagic(final JTextComponent c) {
127:                TextUtils.setCurrentPositionAsMagic(TextUtils.getTextKit(c));
128:            }
129:
130:            AWTTextAction action;
131:
132:            TextAction(final String name, final boolean findAWTTextAction) {
133:                super (name);
134:                this .action = (AWTTextAction) ActionSet.actionMap.get(name);
135:            }
136:
137:            final void performTextAction(final ActionEvent e) {
138:                JTextComponent source = getTextComponent(e);
139:                if (source != null) {
140:                    action.performAction(TextUtils.getTextKit(source));
141:                }
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.