Source Code Cross Referenced for DialogFindReplace.java in  » Database-Client » sqleonardo » nickyb » sqleonardo » environment » ctrl » content » 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 » Database Client » sqleonardo » nickyb.sqleonardo.environment.ctrl.content 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SQLeonardo :: java database frontend
003:         * Copyright (C) 2004 nickyb@users.sourceforge.net
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License
007:         * as published by the Free Software Foundation; either version 2
008:         * of the License, or (at your option) any later version.
009:         * 
010:         * This program is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * along with this program; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018:         *
019:         */
020:
021:        package nickyb.sqleonardo.environment.ctrl.content;
022:
023:        import java.awt.GridBagConstraints;
024:        import java.awt.GridBagLayout;
025:        import java.awt.GridLayout;
026:        import java.awt.Insets;
027:        import java.awt.event.ActionEvent;
028:        import java.awt.event.ActionListener;
029:        import java.util.Vector;
030:
031:        import javax.swing.JCheckBox;
032:        import javax.swing.JComboBox;
033:        import javax.swing.JDialog;
034:        import javax.swing.JLabel;
035:        import javax.swing.JPanel;
036:        import javax.swing.JTextField;
037:
038:        import nickyb.sqleonardo.common.gui.CommandButton;
039:        import nickyb.sqleonardo.environment.Application;
040:        import nickyb.sqleonardo.environment.ctrl.ContentPane;
041:
042:        public class DialogFindReplace extends JDialog implements 
043:                ActionListener {
044:            private CommandButton btnFind;
045:            private CommandButton btnReplace;
046:            private CommandButton btnReplaceAll;
047:
048:            private JCheckBox chxAll;
049:            private JCheckBox chxNullFind;
050:            private JCheckBox chxNullReplace;
051:            //	private JCheckBox chxBlock;
052:            //	private JCheckBox chxChanges;
053:            private JCheckBox chxCase;
054:
055:            private JComboBox cbxColumns;
056:            private JComboBox cbxOperator;
057:
058:            private JTextField txtFind;
059:            private JTextField txtReplace;
060:
061:            private ContentFlag flag;
062:            private ContentView view;
063:
064:            public DialogFindReplace(ContentPane content) {
065:                super (Application.window, "find/replace");
066:                this .flag = new ContentFlag();
067:                this .view = content.getView();
068:
069:                init();
070:                pack();
071:
072:                setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
073:                setLocationRelativeTo(Application.window);
074:                setResizable(false);
075:            }
076:
077:            public void dispose() {
078:                view.mark(null);
079:                super .dispose();
080:            }
081:
082:            private void init() {
083:                Vector vCols = new Vector();
084:                for (int i = 0; i < view.getColumnCount(); i++)
085:                    vCols.addElement(view.getColumnName(i));
086:
087:                JPanel pnlT = new JPanel(new GridLayout(3, 3, 2, 0));
088:                pnlT.add(new JLabel("find into:"));
089:                pnlT.add(cbxColumns = new JComboBox(vCols));
090:                pnlT.add(chxAll = new JCheckBox("all columns"));
091:
092:                pnlT.add(cbxOperator = new JComboBox(new String[] { "equals",
093:                        "contains", "starts with", "ends with" }));
094:                pnlT.add(txtFind = new JTextField());
095:                pnlT.add(chxNullFind = new JCheckBox("null"));
096:
097:                pnlT.add(new JLabel("replace with:"));
098:                pnlT.add(txtReplace = new JTextField());
099:                pnlT.add(chxNullReplace = new JCheckBox("null"));
100:
101:                JPanel pnlC = new JPanel(new GridLayout(1, 3, 2, 0));
102:                //		pnlC.add(chxBlock	= new JCheckBox("only current block"));
103:                //		pnlC.add(chxChanges	= new JCheckBox("only changed cells"));
104:                pnlC.add(chxCase = new JCheckBox("case sensitive"));
105:
106:                JPanel pnlB = new JPanel();
107:                pnlB.add(btnFind = new CommandButton("find", this ));
108:                pnlB.add(btnReplace = new CommandButton("replace", this ));
109:                pnlB
110:                        .add(btnReplaceAll = new CommandButton("replace all",
111:                                this ));
112:
113:                btnReplace.setEnabled(false);
114:
115:                GridBagConstraints gbc = new GridBagConstraints();
116:                gbc.insets = new Insets(8, 10, 0, 10);
117:                gbc.fill = GridBagConstraints.HORIZONTAL;
118:                gbc.gridwidth = GridBagConstraints.REMAINDER;
119:
120:                getContentPane().setLayout(new GridBagLayout());
121:                getContentPane().add(pnlT, gbc);
122:                getContentPane().add(pnlC, gbc);
123:                getContentPane().add(pnlB, gbc);
124:
125:                chxAll.addActionListener(this );
126:                chxNullFind.addActionListener(this );
127:                chxNullReplace.addActionListener(this );
128:            }
129:
130:            private void mark(int row, int col) {
131:                flag.block = (row / ContentModel.MAX_BLOCK_RECORDS) + 1;
132:                flag.row = row
133:                        - (ContentModel.MAX_BLOCK_RECORDS * (flag.block - 1));
134:                flag.col = col;
135:
136:                view.getControl().getSlider().setValue(flag.block - 1);
137:                view.mark(flag);
138:            }
139:
140:            private boolean find() {
141:                int cStart = view.getColumn();
142:                if (cStart == -1)
143:                    cStart = 0;
144:
145:                int rStart = view.getFlatRow();
146:                if (rStart == -1)
147:                    rStart = 0;
148:
149:                if (!chxAll.isSelected()) {
150:                    cStart = view.getColumnIndex(cbxColumns.getSelectedItem()
151:                            .toString());
152:                }
153:
154:                int col = cStart;
155:                int row = rStart;
156:
157:                view.mark(null);
158:
159:                do {
160:                    if (chxAll.isSelected()) {
161:                        if (++col == view.getColumnCount()) {
162:                            col = 0;
163:                            if (++row == view.getFlatRowCount())
164:                                row = 0;
165:                        }
166:                    } else {
167:                        if (++row == view.getFlatRowCount())
168:                            row = 0;
169:                    }
170:
171:                    Object value = view.getFlatValueAt(row, col);
172:
173:                    boolean bmark = false;
174:                    if (value != null) {
175:                        String f = chxCase.isSelected() ? txtFind.getText()
176:                                : txtFind.getText().toUpperCase();
177:                        String v = chxCase.isSelected() ? value.toString()
178:                                : value.toString().toUpperCase();
179:
180:                        if (cbxOperator.getSelectedItem().toString().equals(
181:                                "equals")) {
182:                            bmark = v.equals(f);
183:                        } else if (cbxOperator.getSelectedItem().toString()
184:                                .equals("contains")) {
185:                            bmark = v.indexOf(f) != -1;
186:                        } else if (cbxOperator.getSelectedItem().toString()
187:                                .equals("starts with")) {
188:                            bmark = v.startsWith(f);
189:                        } else if (cbxOperator.getSelectedItem().toString()
190:                                .equals("ends with")) {
191:                            bmark = v.endsWith(f);
192:                        }
193:                    } else {
194:                        bmark = chxNullFind.isSelected();
195:                    }
196:
197:                    if (bmark) {
198:                        mark(row, col);
199:                        return true;
200:                    }
201:                } while (!(col == cStart && row == rStart));
202:
203:                return false;
204:            }
205:
206:            private boolean replace() {
207:                Object value = txtReplace.getText();
208:                if (chxNullReplace.isSelected())
209:                    value = null;
210:
211:                view.getControl().getSlider().setValue(flag.block - 1);
212:                view.setValueAt(value, flag.row, flag.col);
213:                view.mark(null);
214:
215:                return find();
216:            }
217:
218:            public void actionPerformed(ActionEvent ae) {
219:                cbxColumns.setEnabled(!chxAll.isSelected());
220:                cbxOperator.setEnabled(!chxNullFind.isSelected());
221:                txtFind.setEnabled(!chxNullFind.isSelected());
222:                txtReplace.setEnabled(!chxNullReplace.isSelected());
223:
224:                if (ae.getSource() == btnFind) {
225:                    btnReplace.setEnabled(find());
226:                } else if (ae.getSource() == btnReplace) {
227:                    btnReplace.setEnabled(replace());
228:                } else if (ae.getSource() == btnReplaceAll) {
229:                    btnReplace.setEnabled(false);
230:                    while (replace())
231:                        ;
232:                }
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.