Source Code Cross Referenced for PasteFromListDialog.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:         * PasteFromListDialog.java - Paste previous/paste deleted dialog
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2003, 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.*;
027:        import javax.swing.border.*;
028:        import javax.swing.event.*;
029:        import java.awt.*;
030:        import java.awt.event.*;
031:        import org.gjt.sp.jedit.*;
032:
033:        //}}}
034:
035:        public class PasteFromListDialog extends EnhancedDialog {
036:            //{{{ PasteFromListDialog constructor
037:            public PasteFromListDialog(String name, View view,
038:                    MutableListModel model) {
039:                super (view, jEdit.getProperty(name + ".title"), true);
040:                this .view = view;
041:                this .listModel = model;
042:
043:                JPanel content = new JPanel(new BorderLayout());
044:                content.setBorder(new EmptyBorder(12, 12, 12, 12));
045:                setContentPane(content);
046:                JPanel center = new JPanel(new GridLayout(2, 1, 2, 12));
047:
048:                clips = new JList(model);
049:                clips.setCellRenderer(new Renderer());
050:                clips.setVisibleRowCount(12);
051:
052:                clips.addMouseListener(new MouseHandler());
053:                clips.addListSelectionListener(new ListHandler());
054:
055:                insert = new JButton(jEdit.getProperty("common.insert"));
056:                cancel = new JButton(jEdit.getProperty("common.cancel"));
057:
058:                JLabel label = new JLabel(jEdit.getProperty(name + ".caption"));
059:                label.setBorder(new EmptyBorder(0, 0, 6, 0));
060:                content.add(BorderLayout.NORTH, label);
061:
062:                JScrollPane scroller = new JScrollPane(clips);
063:                scroller.setPreferredSize(new Dimension(500, 150));
064:                center.add(scroller);
065:
066:                clipText = new JTextArea();
067:                clipText.setEditable(false);
068:                scroller = new JScrollPane(clipText);
069:                scroller.setPreferredSize(new Dimension(500, 150));
070:                center.add(scroller);
071:
072:                content.add(center, BorderLayout.CENTER);
073:
074:                JPanel panel = new JPanel();
075:                panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
076:                panel.setBorder(new EmptyBorder(12, 0, 0, 0));
077:                panel.add(Box.createGlue());
078:                panel.add(insert);
079:                panel.add(Box.createHorizontalStrut(6));
080:                panel.add(cancel);
081:                panel.add(Box.createGlue());
082:                content.add(panel, BorderLayout.SOUTH);
083:
084:                if (model.getSize() >= 1)
085:                    clips.setSelectedIndex(0);
086:                updateButtons();
087:
088:                getRootPane().setDefaultButton(insert);
089:                insert.addActionListener(new ActionHandler());
090:                cancel.addActionListener(new ActionHandler());
091:
092:                GUIUtilities.requestFocus(this , clips);
093:
094:                pack();
095:                setLocationRelativeTo(view);
096:                setVisible(true);
097:            } //}}}
098:
099:            //{{{ ok() method
100:            public void ok() {
101:                Object[] selected = clips.getSelectedValues();
102:                if (selected == null || selected.length == 0) {
103:                    getToolkit().beep();
104:                    return;
105:                }
106:
107:                String text = getSelectedClipText();
108:
109:                /**
110:                 * For each selected clip, we remove it, then add it back
111:                 * to the model. This has the effect of moving it to the
112:                 * top of the list.
113:                 */
114:                for (int i = 0; i < selected.length; i++) {
115:                    listModel.removeElement(selected[i]);
116:                    listModel.insertElementAt(selected[i], 0);
117:                }
118:
119:                view.getTextArea().setSelectedText(text);
120:
121:                dispose();
122:            } //}}}
123:
124:            //{{{ cancel() method
125:            public void cancel() {
126:                dispose();
127:            } //}}}
128:
129:            //{{{ Private members
130:
131:            //{{{ Instance variables
132:            private View view;
133:            private MutableListModel listModel;
134:            private JList clips;
135:            private JTextArea clipText;
136:            private JButton insert;
137:            private JButton cancel;
138:
139:            //}}}
140:
141:            //{{{ getSelectedClipText()
142:            private String getSelectedClipText() {
143:                Object[] selected = clips.getSelectedValues();
144:                StringBuffer clip = new StringBuffer();
145:                for (int i = 0; i < selected.length; i++) {
146:                    if (i != 0)
147:                        clip.append('\n');
148:                    clip.append(selected[i]);
149:                }
150:                return clip.toString();
151:            }
152:
153:            //}}}
154:
155:            //{{{ updateButtons() method
156:            private void updateButtons() {
157:                int selected = clips.getSelectedIndex();
158:                insert.setEnabled(selected != -1);
159:            } //}}}
160:
161:            //{{{ showClipText() method
162:            private void showClipText() {
163:                Object[] selected = clips.getSelectedValues();
164:                if (selected == null || selected.length == 0)
165:                    clipText.setText("");
166:                else
167:                    clipText.setText(getSelectedClipText());
168:                clipText.setCaretPosition(0);
169:            }
170:
171:            //}}}
172:
173:            //}}}
174:
175:            //{{{ Renderer class
176:            class Renderer extends DefaultListCellRenderer {
177:                String shorten(String item) {
178:                    StringBuffer buf = new StringBuffer();
179:                    // workaround for Swing rendering labels starting
180:                    // with <html> using the HTML engine
181:                    if (item.toLowerCase().startsWith("<html>"))
182:                        buf.append(' ');
183:                    boolean ws = true;
184:                    for (int i = 0; i < item.length(); i++) {
185:                        char ch = item.charAt(i);
186:                        if (Character.isWhitespace(ch)) {
187:                            if (ws)
188:                                /* do nothing */;
189:                            else {
190:                                buf.append(' ');
191:                                ws = true;
192:                            }
193:                        } else {
194:                            ws = false;
195:                            buf.append(ch);
196:                        }
197:                    }
198:
199:                    if (buf.length() == 0)
200:                        return jEdit.getProperty("paste-from-list.whitespace");
201:                    return buf.toString();
202:                }
203:
204:                public Component getListCellRendererComponent(JList list,
205:                        Object value, int index, boolean isSelected,
206:                        boolean cellHasFocus) {
207:                    super .getListCellRendererComponent(list, value, index,
208:                            isSelected, cellHasFocus);
209:
210:                    setText(shorten(value.toString()));
211:
212:                    return this ;
213:                }
214:            } //}}}
215:
216:            //{{{ ActionHandler class
217:            class ActionHandler implements  ActionListener {
218:                public void actionPerformed(ActionEvent evt) {
219:                    Object source = evt.getSource();
220:                    if (source == insert)
221:                        ok();
222:                    else if (source == cancel)
223:                        cancel();
224:                }
225:            } //}}}
226:
227:            //{{{ ListHandler class
228:            class ListHandler implements  ListSelectionListener {
229:                //{{{ valueChanged() method
230:                public void valueChanged(ListSelectionEvent evt) {
231:                    showClipText();
232:                    updateButtons();
233:                } //}}}
234:            } //}}}
235:
236:            //{{{ MouseHandler class
237:            class MouseHandler extends MouseAdapter {
238:                public void mouseClicked(MouseEvent evt) {
239:                    if (evt.getClickCount() == 2)
240:                        ok();
241:                }
242:            } //}}}
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.