Source Code Cross Referenced for ContentView.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.Color;
024:        import java.awt.Component;
025:        import java.awt.GridLayout;
026:        import java.awt.event.InputEvent;
027:        import java.awt.event.KeyAdapter;
028:        import java.awt.event.KeyEvent;
029:        import java.awt.event.MouseAdapter;
030:        import java.awt.event.MouseEvent;
031:        import java.sql.Types;
032:
033:        import javax.swing.JLabel;
034:        import javax.swing.JMenuItem;
035:        import javax.swing.JPanel;
036:        import javax.swing.JScrollPane;
037:        import javax.swing.JTable;
038:        import javax.swing.KeyStroke;
039:        import javax.swing.ListSelectionModel;
040:        import javax.swing.UIManager;
041:        import javax.swing.event.ListSelectionEvent;
042:        import javax.swing.event.ListSelectionListener;
043:        import javax.swing.event.TableModelEvent;
044:        import javax.swing.table.DefaultTableCellRenderer;
045:        import javax.swing.table.TableColumn;
046:
047:        import nickyb.sqleonardo.common.gui.CustomLineBorder;
048:        import nickyb.sqleonardo.common.gui.HeaderCellRenderer;
049:        import nickyb.sqleonardo.common.util.Appearance;
050:        import nickyb.sqleonardo.environment.ctrl.ContentPane;
051:
052:        public class ContentView extends JPanel implements 
053:                ListSelectionListener {
054:            private JTable data;
055:            private LineNumberView lines;
056:
057:            private ContentModel model;
058:            private ContentPopup popup;
059:            private ContentPane control;
060:
061:            public ContentView(ContentPane control) {
062:                super (new GridLayout(1, 1));
063:                this .control = control;
064:
065:                data = new JTable();
066:                data.setModel(model = new ContentModel());
067:                data.addMouseListener(popup = new ContentPopup(this ));
068:                data.addKeyListener(new KeyAdapter() {
069:                    public void keyPressed(KeyEvent key) {
070:                        if (key.getKeyCode() == KeyEvent.VK_DOWN) {
071:                            if (ContentView.this .data.getSelectedRow() == ContentView.this .data
072:                                    .getRowCount() - 1) {
073:                                if (ContentView.this .getBlock() < ContentView.this 
074:                                        .getBlockCount()) {
075:                                    int col = ContentView.this .data
076:                                            .getSelectedColumn();
077:
078:                                    ContentView.this .control
079:                                            .getSlider()
080:                                            .setValue(
081:                                                    ContentView.this .getBlock());
082:
083:                                    ContentView.this .data
084:                                            .setRowSelectionInterval(0, 0);
085:                                    ContentView.this .data
086:                                            .scrollRectToVisible(ContentView.this .data
087:                                                    .getCellRect(0, col, true));
088:                                    key.consume();
089:                                }
090:                            }
091:                        } else if (key.getKeyCode() == KeyEvent.VK_UP) {
092:                            if (ContentView.this .data.getSelectedRow() == 0) {
093:                                if (ContentView.this .getBlock() > 1) {
094:                                    int col = ContentView.this .data
095:                                            .getSelectedColumn();
096:
097:                                    ContentView.this .control
098:                                            .getSlider()
099:                                            .setValue(
100:                                                    ContentView.this .getBlock() - 2);
101:                                    int row = ContentView.this .data
102:                                            .getRowCount() - 1;
103:
104:                                    ContentView.this .data
105:                                            .setRowSelectionInterval(row, row);
106:                                    ContentView.this .data
107:                                            .scrollRectToVisible(ContentView.this .data
108:                                                    .getCellRect(row, col, true));
109:                                    key.consume();
110:                                }
111:                            }
112:
113:                        }
114:                    }
115:                });
116:
117:                JScrollPane scroll = new JScrollPane(data);
118:                scroll.getViewport().setBackground(
119:                        UIManager.getDefaults().getColor("Table.background"));
120:                add(scroll);
121:
122:                data.setRowSelectionAllowed(false);
123:                data.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
124:                data.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
125:                data.setDefaultRenderer(Object.class,
126:                        new InternalCellRenderer());
127:
128:                data.getTableHeader().addMouseListener(popup);
129:                data.getTableHeader().setReorderingAllowed(false);
130:
131:                lines = new LineNumberView();
132:                lines.addMouseListener(popup);
133:                lines.setSelectionModel(data.getSelectionModel());
134:                scroll.setRowHeaderView(lines);
135:
136:                JLabel cUL = new JLabel("#", JLabel.CENTER);
137:                cUL.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
138:                cUL.setFont(UIManager.getFont("TableHeader.font"));
139:                scroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, cUL);
140:
141:                JLabel cLL = new JLabel();
142:                cLL.setBorder(new CustomLineBorder(true, false, false, false));
143:                scroll.setCorner(JScrollPane.LOWER_LEFT_CORNER, cLL);
144:
145:                data.getColumnModel().getSelectionModel()
146:                        .addListSelectionListener(this );
147:
148:                data.getActionMap().put("copy",
149:                        ((JMenuItem) popup.getSubElementsAt(1)).getAction());
150:                data.getInputMap().put(
151:                        KeyStroke.getKeyStroke(KeyEvent.VK_C,
152:                                InputEvent.CTRL_MASK), "copy");
153:
154:                data.getActionMap().put("paste",
155:                        ((JMenuItem) popup.getSubElementsAt(2)).getAction());
156:                data.getInputMap().put(
157:                        KeyStroke.getKeyStroke(KeyEvent.VK_V,
158:                                InputEvent.CTRL_MASK), "paste");
159:
160:                data.getActionMap().put("set-null",
161:                        ((JMenuItem) popup.getSubElementsAt(3)).getAction());
162:                data.getInputMap().put(
163:                        KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
164:                        "set-null");
165:
166:                MouseAdapter ma = new MouseAdapter() {
167:                    public void mousePressed(MouseEvent me) {
168:                        ContentView.this .data.setColumnSelectionAllowed(me
169:                                .getSource() == ContentView.this .data
170:                                .getTableHeader());
171:                        ContentView.this .data.setRowSelectionAllowed(me
172:                                .getSource() == ContentView.this .lines);
173:                    }
174:                };
175:                data.getTableHeader().addMouseListener(ma);
176:                data.addMouseListener(ma);
177:                lines.addMouseListener(ma);
178:            }
179:
180:            ContentPane getControl() {
181:                return control;
182:            }
183:
184:            public void addRow(Object[] rowdata, boolean newrow) {
185:                model.addRow(rowdata, newrow);
186:                lines.setRowCount(this .getRowCount());
187:            }
188:
189:            public void addColumn(String text) {
190:                addColumn(text, Types.CHAR);
191:            }
192:
193:            public void addColumn(String text, int type) {
194:                model.addColumn(text, type);
195:            }
196:
197:            public void deleteRow(int row) {
198:                model.deleteRow(row);
199:                lines.setRowCount(this .getRowCount());
200:
201:                onTableChanged(true);
202:            }
203:
204:            public void insertRow(int row) {
205:                model.insertRow(row);
206:                lines.setRowCount(this .getRowCount());
207:
208:                onTableChanged(true);
209:            }
210:
211:            public int getRow() {
212:                return data.getSelectedRow();
213:            }
214:
215:            public int getColumn() {
216:                return data.getSelectedColumn();
217:            }
218:
219:            private HeaderCellRenderer getHeaderRenderer(int idx) {
220:                TableColumn tc = data.getColumnModel().getColumn(idx);
221:                if (tc.getHeaderRenderer() != null)
222:                    return (HeaderCellRenderer) tc.getHeaderRenderer();
223:
224:                HeaderCellRenderer hcr = new HeaderCellRenderer();
225:                tc.setHeaderRenderer(hcr);
226:
227:                return hcr;
228:            }
229:
230:            public void setToolTipText(int i, String text) {
231:                this .getHeaderRenderer(i).setToolTipText(text);
232:            }
233:
234:            public int getBlockCount() {
235:                return model.getBlockCount();
236:            }
237:
238:            public int getBlock() {
239:                return model.getBlock();
240:            }
241:
242:            public void setBlock(int idx) {
243:                model.setBlock(idx);
244:                lines.setBlock(idx);
245:                lines.setRowCount(this .getRowCount());
246:
247:                onTableChanged(true);
248:            }
249:
250:            public ContentChanges getChanges() {
251:                return model.getChanges();
252:            }
253:
254:            public int getColumnCount() {
255:                return model.getColumnCount();
256:            }
257:
258:            public int getColumnIndex(String name) {
259:                return model.getColumnIndex(name);
260:            }
261:
262:            public String getColumnName(int idx) {
263:                return model.getColumnName(idx);
264:            }
265:
266:            public int getColumnType(int idx) {
267:                return model.getColumnType(idx);
268:            }
269:
270:            public int getRowCount() {
271:                return model.getRowCount();
272:            }
273:
274:            public Object getLineAt(int row) {
275:                return lines.getValueAt(row, 0);
276:            }
277:
278:            Object[] getValues(int row) {
279:                return model.getValues(row);
280:            }
281:
282:            Object[] getValues(Long rid) {
283:                return model.getValues(rid);
284:            }
285:
286:            public Object getValueAt(int row, int col) {
287:                return model.getValueAt(row, col);
288:            }
289:
290:            public void setValueAt(Object aValue, int row, int col) {
291:                model.setValueAt(aValue, row, col);
292:            }
293:
294:            public int getFlatRow() {
295:                return model.toFlatRow(getRow());
296:            }
297:
298:            public int getFlatRowCount() {
299:                return model.getFlatRowCount();
300:            }
301:
302:            public Object getFlatValueAt(int row, int col) {
303:                return model.getFlatValueAt(row, col);
304:            }
305:
306:            public void resetFlatValueAt(int row, int col) {
307:                model.resetFlatValueAt(row, col);
308:            }
309:
310:            public void setFlatValueAt(Object aValue, int row, int col) {
311:                model.setFlatValueAt(aValue, row, col);
312:            }
313:
314:            public void reset() {
315:                data.setModel(model = new ContentModel());
316:                lines.setRowCount(0);
317:                lines.setBlock(1);
318:            }
319:
320:            public Object getCellValue() {
321:                return data.getValueAt(data.getSelectedRow(), data
322:                        .getSelectedColumn());
323:            }
324:
325:            public void resetCellValue() {
326:                model.resetValueAt(data.getSelectedRow(), data
327:                        .getSelectedColumn());
328:                data.tableChanged(new TableModelEvent(data.getModel(), data
329:                        .getSelectedRow()));
330:            }
331:
332:            public void setCellValue(Object value) {
333:                data.setValueAt(value, data.getSelectedRow(), data
334:                        .getSelectedColumn());
335:                data.tableChanged(new TableModelEvent(data.getModel(), data
336:                        .getSelectedRow()));
337:            }
338:
339:            public void setSelectedCell(int row, int col) {
340:                if (row == -1 || col == -1)
341:                    return;
342:
343:                data.setRowSelectionInterval(row, row);
344:                data.setColumnSelectionInterval(col, col);
345:                data.scrollRectToVisible(data.getCellRect(row, col, true));
346:            }
347:
348:            private ContentFlag flag;
349:
350:            public void mark(ContentFlag flag) {
351:                int row = this .getRow();
352:                int col = this .getColumn();
353:
354:                if ((this .flag = flag) != null) {
355:                    row = flag.row;
356:                    col = flag.col;
357:                } else {
358:                    if (row != -1)
359:                        data.removeRowSelectionInterval(row, row);
360:                    if (col != -1)
361:                        data.removeColumnSelectionInterval(col, col);
362:                }
363:
364:                setSelectedCell(row, col);
365:            }
366:
367:            public void sort(int col, short type) {
368:                model.sort(col, type);
369:            }
370:
371:            public void onTableChanged(boolean onlyData) {
372:                data.tableChanged(onlyData ? new TableModelEvent(model) : null);
373:                lines.tableChanged(null);
374:            }
375:
376:            public void valueChanged(ListSelectionEvent lse) {
377:                if (lse.getValueIsAdjusting())
378:                    return;
379:
380:                for (int i = 0; i < data.getColumnModel().getColumnCount(); i++) {
381:                    this .getHeaderRenderer(i)
382:                            .setSelected(this .getColumn() == i);
383:                }
384:                data.getTableHeader().repaint();
385:            }
386:
387:            private class InternalCellRenderer extends DefaultTableCellRenderer {
388:                public Component getTableCellRendererComponent(JTable table,
389:                        Object value, boolean isSelected, boolean hasFocus,
390:                        int row, int col) {
391:                    super .getTableCellRendererComponent(table, value,
392:                            isSelected, hasFocus, row, col);
393:                    super .setBackground(UIManager.getDefaults().getColor(
394:                            "Table.background"));
395:                    super .setFont(Appearance.fontPLAIN);
396:                    super .setOpaque(true);
397:
398:                    if (isSelected && !hasFocus)
399:                        super .setBackground(data.getSelectionBackground());
400:
401:                    if (ContentView.this .flag != null) {
402:                        if (ContentView.this .getBlock() == ContentView.this .flag.block
403:                                && col == ContentView.this .flag.col
404:                                && row == ContentView.this .flag.row)
405:                            super .setBackground(ContentView.this .flag.bgcolor);
406:                    }
407:
408:                    if (value == null) {
409:                        super .setText("<null>");
410:                        if (ContentView.this .model.isCellChanged(row, col))
411:                            super .setForeground(Color.green);
412:                        else
413:                            super .setForeground(Color.lightGray);
414:                    } else {
415:                        if (ContentView.this .model.isCellChanged(row, col))
416:                            super .setForeground(Color.blue);
417:                        else
418:                            super .setForeground(UIManager.getDefaults()
419:                                    .getColor("Table.foreground"));
420:                    }
421:
422:                    if (TaskRetrieve.isNumberType(ContentView.this
423:                            .getColumnType(col)))
424:                        super.setHorizontalAlignment(RIGHT);
425:                    else
426:                        super.setHorizontalAlignment(LEFT);
427:
428:                    return this;
429:                }
430:            }
431:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.