Source Code Cross Referenced for HistoryModel.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » gui » 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 » Swing Library » jEdit » org.gjt.sp.jedit.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HistoryModel.java - History list model
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 1999, 2005 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.gui;
024:
025:        //{{{ Imports
026:        import javax.swing.DefaultListModel;
027:        import java.util.*;
028:
029:        //}}}
030:
031:        /**
032:         * A history list. One history list can be used by several history text
033:         * fields. Note that the list model implementation is incomplete; no events
034:         * are fired when the history model changes.
035:         *
036:         * @author Slava Pestov
037:         * @version $Id: HistoryModel.java 8265 2006-12-27 18:12:29Z vampire0 $
038:         */
039:        public class HistoryModel extends DefaultListModel implements 
040:                MutableListModel {
041:            //{{{ HistoryModel constructor
042:            /**
043:             * Creates a new history list. Calling this is normally not
044:             * necessary.
045:             */
046:            public HistoryModel(String name) {
047:                this .name = name;
048:            } //}}}
049:
050:            //{{{ addItem() method
051:            /**
052:             * Adds an item to the end of this history list, trimming the list
053:             * to the maximum number of items if necessary.
054:             * @param text The item
055:             */
056:            public void addItem(String text) {
057:                if (text == null || text.length() == 0)
058:                    return;
059:
060:                int index = indexOf(text);
061:                if (index != -1)
062:                    removeElementAt(index);
063:
064:                insertElementAt(text, 0);
065:
066:                while (getSize() > max)
067:                    removeElementAt(getSize() - 1);
068:            } //}}}
069:
070:            //{{{ insertElementAt() method
071:            public void insertElementAt(Object obj, int index) {
072:                modified = true;
073:                super .insertElementAt(obj, index);
074:            } //}}}
075:
076:            //{{{ getItem() method
077:            /**
078:             * Returns an item from the history list.
079:             * @param index The index
080:             */
081:            public String getItem(int index) {
082:                return (String) elementAt(index);
083:            } //}}}
084:
085:            //{{{ removeElement() method
086:            public boolean removeElement(Object obj) {
087:                modified = true;
088:                return super .removeElement(obj);
089:            } //}}}
090:
091:            //{{{ clear() method
092:            /**
093:             * @deprecated Call <code>removeAllElements()</code> instead.
094:             */
095:            public void clear() {
096:                removeAllElements();
097:            } //}}}
098:
099:            //{{{ removeAllElements() method
100:            public void removeAllElements() {
101:                modified = true;
102:                super .removeAllElements();
103:            } //}}}
104:
105:            //{{{ getName() method
106:            /**
107:             * Returns the name of this history list. This can be passed
108:             * to the HistoryTextField constructor.
109:             */
110:            public String getName() {
111:                return name;
112:            } //}}}
113:
114:            //{{{ getModel() method
115:            /**
116:             * Returns a named model. If the specified model does not
117:             * already exist, it will be created.
118:             * @param name The model name
119:             */
120:            public static HistoryModel getModel(String name) {
121:                if (models == null)
122:                    models = Collections
123:                            .synchronizedMap(new HashMap<String, HistoryModel>());
124:
125:                HistoryModel model = models.get(name);
126:                if (model == null) {
127:                    model = new HistoryModel(name);
128:                    models.put(name, model);
129:                }
130:
131:                return model;
132:            } //}}}
133:
134:            //{{{ loadHistory() method
135:            public static void loadHistory() {
136:                if (saver != null)
137:                    models = saver.load(models);
138:            } //}}}
139:
140:            //{{{ saveHistory() method
141:            public static void saveHistory() {
142:                if (saver != null && modified && saver.save(models))
143:                    modified = false;
144:            } //}}}
145:
146:            //{{{ setMax() method
147:            public static void setMax(int max) {
148:                HistoryModel.max = max;
149:            } //}}}
150:
151:            //{{{ setSaver() method
152:            public static void setSaver(HistoryModelSaver saver) {
153:                HistoryModel.saver = saver;
154:            } //}}}
155:
156:            //{{{ Private members
157:            private static int max;
158:
159:            private String name;
160:            private static Map<String, HistoryModel> models;
161:
162:            private static boolean modified;
163:            private static HistoryModelSaver saver;
164:            //}}}
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.