Source Code Cross Referenced for SimpleCommandLog.java in  » Internationalization-Localization » icu4j » com » ibm » richtext » textpanel » 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 » Internationalization Localization » icu4j » com.ibm.richtext.textpanel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.
003:         *
004:         * The program is provided "as is" without any warranty express or
005:         * implied, including the warranty of non-infringement and the implied
006:         * warranties of merchantibility and fitness for a particular purpose.
007:         * IBM will not be liable for any damages suffered by you as a result
008:         * of using the Program. In no event will IBM be liable for any
009:         * special, indirect or consequential damages or lost profits even if
010:         * IBM has been advised of the possibility of their occurrence. IBM
011:         * will not be liable for any third party claims against you.
012:         */
013:        package com.ibm.richtext.textpanel;
014:
015:        final class SimpleCommandLog {
016:            static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
017:            private Command fLastCommand = null;
018:            private Command fCurrentCommand = null;
019:            private PanelEventBroadcaster fListener;
020:
021:            private boolean fBaseIsModified;
022:
023:            private int fLogSize = 14;
024:
025:            public SimpleCommandLog(PanelEventBroadcaster listener) {
026:                fListener = listener;
027:                fBaseIsModified = false;
028:            }
029:
030:            /** adds the specfied command to the top of the command stack
031:             * (any undone commands on the stack are removed)
032:             * This function assumes the command has already been executed (i.e., its execute() method
033:             * has been called, or an equivalent action has been taken) */
034:            void add(Command newCommand) {
035:                // if there are commands on the stack that have been undone, they are
036:                // dropped on the floor here
037:                newCommand.setPreviousCommand(fCurrentCommand);
038:
039:                final Command oldLastCommand = fLastCommand;
040:                fLastCommand = null;
041:
042:                fCurrentCommand = newCommand;
043:                limitCommands(fLogSize);
044:
045:                if (oldLastCommand != null) {
046:                    fListener
047:                            .textStateChanged(TextPanelEvent.UNDO_STATE_CHANGED);
048:                }
049:            }
050:
051:            /**
052:             * If the command list is longer than logSize, truncate it.
053:             * This method traverses the list each time, and is not a model
054:             * of efficiency.  It's a temporary way to plug this memory leak
055:             * until I can implement a bounded command log.
056:             */
057:            private void limitCommands(int logSize) {
058:
059:                if (logSize == 0) {
060:                    fCurrentCommand = null;
061:                } else {
062:                    Command currentCommand = fCurrentCommand;
063:                    int remaining = logSize - 1;
064:                    while (currentCommand != null && remaining > 0) {
065:                        currentCommand = currentCommand.previousCommand();
066:                        remaining -= 1;
067:                    }
068:                    if (currentCommand != null) {
069:                        currentCommand.setPreviousCommand(null);
070:                    }
071:                }
072:            }
073:
074:            /** adds the specfied command to the top of the command stack and executes it */
075:            void addAndDo(Command newCommand) {
076:                add(newCommand);
077:                newCommand.execute();
078:
079:                fListener.textStateChanged(TextPanelEvent.UNDO_STATE_CHANGED);
080:            }
081:
082:            /** undoes the command on the top of the command stack, if there is one */
083:            void undo() {
084:                if (fCurrentCommand != null) {
085:                    Command current = fCurrentCommand;
086:                    current.undo();
087:
088:                    fCurrentCommand = current.previousCommand();
089:
090:                    current.setPreviousCommand(fLastCommand);
091:                    fLastCommand = current;
092:
093:                    fListener
094:                            .textStateChanged(TextPanelEvent.UNDO_STATE_CHANGED);
095:                }
096:            }
097:
098:            /** redoes the last undone command on the command stack, if there are any */
099:            void redo() {
100:                if (fLastCommand != null) {
101:                    Command last = fLastCommand;
102:                    last.redo();
103:
104:                    fLastCommand = last.previousCommand();
105:
106:                    last.setPreviousCommand(fCurrentCommand);
107:                    fCurrentCommand = last;
108:
109:                    fListener
110:                            .textStateChanged(TextPanelEvent.UNDO_STATE_CHANGED);
111:                }
112:            }
113:
114:            public boolean canUndo() {
115:                return fCurrentCommand != null;
116:            }
117:
118:            public boolean canRedo() {
119:                return fLastCommand != null;
120:            }
121:
122:            public boolean isModified() {
123:
124:                if (fCurrentCommand == null) {
125:                    return fBaseIsModified;
126:                } else {
127:                    return fCurrentCommand.isModified();
128:                }
129:            }
130:
131:            public void setModified(boolean modified) {
132:
133:                if (fCurrentCommand == null) {
134:                    fBaseIsModified = modified;
135:                } else {
136:                    fCurrentCommand.setModified(modified);
137:                }
138:            }
139:
140:            public void clearLog() {
141:
142:                if (fCurrentCommand != null) {
143:                    fBaseIsModified = fCurrentCommand.isModified();
144:                }
145:                // variable not used boolean changed = fCurrentCommand != null || fLastCommand != null;
146:                fCurrentCommand = null;
147:                fLastCommand = null;
148:
149:                fListener.textStateChanged(TextPanelEvent.UNDO_STATE_CHANGED);
150:            }
151:
152:            public void setLogSize(int size) {
153:
154:                if (size < 0) {
155:                    throw new IllegalArgumentException(
156:                            "log size cannot be negative");
157:                }
158:
159:                if (size < fLogSize) {
160:                    limitCommands(size);
161:                }
162:
163:                fLogSize = size;
164:
165:                if (fLastCommand != null || size == 0) {
166:                    fLastCommand = null;
167:                    fListener
168:                            .textStateChanged(TextPanelEvent.UNDO_STATE_CHANGED);
169:                }
170:            }
171:
172:            public int getLogSize() {
173:
174:                return fLogSize;
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.