Source Code Cross Referenced for JWorksheetProseClientPane.java in  » Byte-Code » PROSE » ch » ethz » prose » tools » 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 » Byte Code » PROSE » ch.ethz.prose.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //
002:        //  This file is part of the prose package.
003:        //
004:        //  The contents of this file are subject to the Mozilla Public License
005:        //  Version 1.1 (the "License"); you may not use this file except in
006:        //  compliance with the License. You may obtain a copy of the License at
007:        //  http://www.mozilla.org/MPL/
008:        //
009:        //  Software distributed under the License is distributed on an "AS IS" basis,
010:        //  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011:        //  for the specific language governing rights and limitations under the
012:        //  License.
013:        //
014:        //  The Original Code is prose.
015:        //
016:        //  The Initial Developer of the Original Code is Andrei Popovici. Portions
017:        //  created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018:        //  All Rights Reserved.
019:        //
020:        //  Contributor(s):
021:        /*
022:         * JWorksheetProseClientPane.java
023:         *
024:         * Created on December 26, 2002, 4:44 PM
025:         */
026:
027:        package ch.ethz.prose.tools;
028:
029:        import java.awt.Dimension;
030:        import java.awt.Point;
031:        import java.awt.event.InputEvent;
032:
033:        import javax.swing.JTable;
034:        import javax.swing.ListSelectionModel;
035:        import javax.swing.event.ListSelectionEvent;
036:        import javax.swing.event.ListSelectionListener;
037:        import javax.swing.event.TableModelEvent;
038:        import javax.swing.event.TableModelListener;
039:        import javax.swing.table.DefaultTableCellRenderer;
040:        import javax.swing.table.JTableHeader;
041:
042:        import javax.swing.BorderFactory;
043:        import java.awt.Color;
044:
045:        /**
046:         *
047:         * @author  pschoch
048:         */
049:        public class JWorksheetProseClientPane extends javax.swing.JSplitPane {
050:
051:            private static final long serialVersionUID = 4050765991929655860L;
052:
053:            public static final int ASPECT_COL_INDEX = 0;
054:            public static final int JOINPOINT_COL_INDEX = 2;
055:            public static final Color SEL_COLOR = new Color(255, 204, 204);
056:            public static final Color NOT_SEL_COLOR = new Color(153, 153, 153);
057:            public static final Color WHITE_COLOR = new Color(255, 255, 255);
058:            public static final Color SEL_TABCELL_COLOR = new Color(204, 204,
059:                    255);
060:
061:            private javax.swing.JScrollPane tableScrollPaneRight;
062:            private javax.swing.JScrollPane tableScrollPaneLeft;
063:
064:            private javax.swing.JTable leftTable;
065:            private javax.swing.JTable rightTable;
066:
067:            private JMultipleProseClient parent = null;
068:            private MultipleClientModel myModel = null;
069:            private String proseName = null;
070:            private String url = null;
071:            private String host = null;
072:            private String port = null;
073:            private JTable activeTable = null; // will be either the left or the right table
074:
075:            /** Creates new form BeanForm */
076:            public JWorksheetProseClientPane() {
077:            }
078:
079:            public JWorksheetProseClientPane(JMultipleProseClient parent,
080:                    String name, String host, String port)
081:                    throws IllegalUserInputException {
082:                //    setOrientation(VERTICAL_SPLIT);
083:                this .parent = parent;
084:                this .myModel = parent.getModel();
085:                this .proseName = name;
086:                this .url = host + ":" + port;
087:                this .host = host;
088:                this .port = port;
089:                initComponents();
090:
091:                setActiveTable(leftTable);
092:            }
093:
094:            public String getHost() {
095:                return host;
096:            }
097:
098:            public String getPort() {
099:                return port;
100:            }
101:
102:            /** This method is called from within the constructor to
103:             * initialize the form.
104:             * WARNING: Do NOT modify this code. The content of this method is
105:             * always regenerated by the Form Editor.
106:             */
107:            private void initComponents() throws IllegalUserInputException {
108:                tableScrollPaneLeft = new javax.swing.JScrollPane();
109:                leftTable = new JToolTipTable();
110:                tableScrollPaneRight = new javax.swing.JScrollPane();
111:                rightTable = new JToolTipTable();
112:
113:                setPreferredSize(new java.awt.Dimension(802, 452));
114:                setMinimumSize(new java.awt.Dimension(2, 2));
115:                setDividerLocation(0.5);
116:
117:                tableScrollPaneLeft
118:                        .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
119:                tableScrollPaneLeft.setPreferredSize(new java.awt.Dimension(
120:                        400, 450));
121:                tableScrollPaneLeft.setName("scrollPane");
122:                tableScrollPaneLeft
123:                        .setMinimumSize(new java.awt.Dimension(0, 0));
124:                leftTable.setModel(myModel.createTableModel(proseName, host,
125:                        port, true));
126:
127:                tableScrollPaneLeft.setBorder(BorderFactory
128:                        .createTitledBorder("REAL ASPECT MANAGER"));
129:                tableScrollPaneRight.setBorder(BorderFactory
130:                        .createTitledBorder("TEST ASPECT MANAGER"));
131:                leftTable.setIntercellSpacing(new java.awt.Dimension(2, 2));
132:                leftTable.setColumnSelectionAllowed(true);
133:                leftTable.setTableHeader(new JTableHeader(leftTable
134:                        .getColumnModel()));
135:                leftTable.getTableHeader().setBackground(NOT_SEL_COLOR);
136:                leftTable.getTableHeader().addMouseListener(
137:                        new java.awt.event.MouseAdapter() {
138:                            public void mousePressed(
139:                                    java.awt.event.MouseEvent evt) {
140:                                onMousePressed(evt);
141:                            }
142:                        });
143:
144:                leftTable.setPreferredSize(new Dimension(this .getWidth(),
145:                        ((WorksheetSingleClientModel) leftTable.getModel())
146:                                .getRowCount()
147:                                * leftTable.getRowHeight()));
148:                leftTable
149:                        .setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
150:                leftTable.setMaximumSize(new java.awt.Dimension(32767, 32767));
151:                leftTable.setName("leftTable");
152:                leftTable.setAutoCreateColumnsFromModel(false);
153:                leftTable.setMinimumSize(new java.awt.Dimension(450, 100));
154:                leftTable.setPreferredSize(new java.awt.Dimension(450, 400));
155:                customizeTable(leftTable);
156:                leftTable.addMouseListener(new java.awt.event.MouseAdapter() {
157:                    public void mouseClicked(java.awt.event.MouseEvent evt) {
158:                        tableMouseClicked(evt);
159:                        tableMouseRightClicked(evt);
160:                    }
161:                });
162:
163:                tableScrollPaneLeft.setViewportView(leftTable);
164:
165:                setLeftComponent(tableScrollPaneLeft);
166:
167:                tableScrollPaneRight
168:                        .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
169:                tableScrollPaneRight.setPreferredSize(new java.awt.Dimension(
170:                        400, 450));
171:                tableScrollPaneRight.setName("scrollPane");
172:                tableScrollPaneRight
173:                        .setMinimumSize(new java.awt.Dimension(0, 0));
174:                rightTable.setModel(myModel.createTableModel(proseName, host,
175:                        port, false));
176:                rightTable.setIntercellSpacing(new java.awt.Dimension(2, 2));
177:                rightTable.setColumnSelectionAllowed(true);
178:                rightTable.setTableHeader(new JTableHeader(rightTable
179:                        .getColumnModel()));
180:                rightTable.getTableHeader().setBackground(NOT_SEL_COLOR);
181:                rightTable.getTableHeader().addMouseListener(
182:                        new java.awt.event.MouseAdapter() {
183:                            public void mousePressed(
184:                                    java.awt.event.MouseEvent evt) {
185:                                onMousePressed(evt);
186:                            }
187:                        });
188:                rightTable.setPreferredSize(new Dimension(this .getWidth(),
189:                        ((WorksheetSingleClientModel) rightTable.getModel())
190:                                .getRowCount()
191:                                * rightTable.getRowHeight()));
192:                rightTable
193:                        .setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
194:                rightTable.setMaximumSize(new java.awt.Dimension(32767, 32767));
195:                rightTable.setPreferredSize(new java.awt.Dimension(450, 400));
196:                rightTable.setName("rightTable");
197:                rightTable.setAutoCreateColumnsFromModel(false);
198:                rightTable.setMinimumSize(new java.awt.Dimension(450, 100));
199:                customizeTable(rightTable);
200:                rightTable.addMouseListener(new java.awt.event.MouseAdapter() {
201:                    public void mouseClicked(java.awt.event.MouseEvent evt) {
202:                        tableMouseClicked(evt);
203:                        tableMouseRightClicked(evt);
204:                    }
205:                });
206:
207:                tableScrollPaneRight.setViewportView(rightTable);
208:
209:                setRightComponent(tableScrollPaneRight);
210:
211:            }//GEN-END:initComponents
212:
213:            private void tableMouseRightClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseRightClicked
214:                if (!((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK))
215:                    return;
216:                JTable myTable = (JTable) evt.getSource();
217:                Object value = myTable.getModel().getValueAt(
218:                        myTable.rowAtPoint(evt.getPoint()),
219:                        myTable.columnAtPoint(evt.getPoint()));
220:                if (value == null)
221:                    return;
222:                ((JMultipleProseClient) getTopLevelAncestor())
223:                        .newTextAreaContent(value.toString());
224:            }//GEN-LAST:event_tableMouseRightClicked
225:
226:            private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked
227:                JTable myTable = (JTable) evt.getSource();
228:                if (isActive(myTable))
229:                    return;
230:                setActiveTable(myTable);
231:                ((WorksheetSingleClientModel) myTable.getModel())
232:                        .setSelectedCells(new int[] { myTable.rowAtPoint(evt
233:                                .getPoint()) });
234:                ((WorksheetSingleClientModel) myTable.getModel())
235:                        .setSelectedColumn(myTable
236:                                .columnAtPoint(evt.getPoint()));
237:            }//GEN-LAST:event_tableMouseClicked
238:
239:            private void onMousePressed(java.awt.event.MouseEvent evt) {
240:                JTable myTable = ((JTableHeader) evt.getComponent()).getTable();
241:                if (isActive(myTable))
242:                    return;
243:                setActiveTable(myTable);
244:            }
245:
246:            public void select() {
247:                myModel
248:                        .setActualTableModel((WorksheetSingleClientModel) activeTable
249:                                .getModel());
250:            }
251:
252:            private void setActiveTable(JTable myTable) {
253:
254:                if (activeTable != null) {
255:                    activeTable.getTableHeader().setBackground(NOT_SEL_COLOR);
256:                    activeTable.setSelectionBackground(WHITE_COLOR);
257:                }
258:
259:                if (!myTable.equals(activeTable)) {
260:                    activeTable = myTable;
261:                    activeTable.getTableHeader().setBackground(SEL_COLOR);
262:                    activeTable.setSelectionBackground(SEL_TABCELL_COLOR);
263:                    myModel
264:                            .setActualTableModel((WorksheetSingleClientModel) activeTable
265:                                    .getModel());
266:                }
267:            }
268:
269:            public JTable getActiveTable() {
270:                return activeTable;
271:            }
272:
273:            public boolean isActive(JTable table) {
274:                return table.equals(activeTable);
275:            }
276:
277:            public JTable getLeftTable() {
278:                return leftTable;
279:            }
280:
281:            public JTable getRightTable() {
282:                return rightTable;
283:            }
284:
285:            public String getProseName() {
286:                return proseName;
287:            }
288:
289:            public String getProseURL() {
290:                return url;
291:            }
292:
293:            public String toString() {
294:                return ("JWorksheetProseClientPane: " + proseName);
295:            }
296:
297:            protected void customizeTable(JTable table)
298:                    throws IllegalUserInputException {
299:                setActiveTable(table);
300:                ((WorksheetSingleClientModel) table.getModel())
301:                        .addTableModelListener(new TableModelListener() {
302:                            public void tableChanged(TableModelEvent e) {
303:                                try {
304:                                    getActiveTable()
305:                                            .setPreferredSize(
306:                                                    new java.awt.Dimension(
307:                                                            getActiveTable()
308:                                                                    .getWidth(),
309:                                                            myModel
310:                                                                    .getActualTableModel()
311:                                                                    .getRowCount()
312:                                                                    * getActiveTable()
313:                                                                            .getRowHeight()));
314:                                } catch (IllegalUserInputException e1) {/*cannot happen */
315:                                }
316:                            }
317:                        });
318:
319:                table.getTableHeader().setReorderingAllowed(false);
320:                //assign selection model for row selection and for column selection
321:                table.getSelectionModel().setSelectionMode(
322:                        ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
323:                table.getColumnModel().getSelectionModel().setSelectionMode(
324:                        ListSelectionModel.SINGLE_SELECTION);
325:
326:                table.getSelectionModel().addListSelectionListener(
327:                        new ListSelectionListener() {
328:                            public void valueChanged(ListSelectionEvent e) {
329:                                try {
330:                                    // install the ListSelectionListener that listens on row selection changes
331:                                    if (e.getValueIsAdjusting())
332:                                        return;
333:
334:                                    myModel.getActualTableModel()
335:                                            .setSelectedCells(
336:                                                    getActiveTable()
337:                                                            .getSelectedRows());
338:
339:                                    if (getActiveTable().getSelectedRowCount() > 0) {
340:                                        if (getActiveTable()
341:                                                .getSelectedColumnCount() == 1)
342:                                            myModel
343:                                                    .getActualTableModel()
344:                                                    .setSelectedColumn(
345:                                                            getActiveTable()
346:                                                                    .getSelectedColumn());
347:                                    } else
348:                                        myModel.getActualTableModel()
349:                                                .setSelectedColumn(-1);
350:                                } catch (IllegalUserInputException e2) {/*cannot happen */
351:                                }
352:                            }
353:                        });
354:
355:                table.getColumnModel().getSelectionModel()
356:                        .addListSelectionListener(new ListSelectionListener() {
357:                            public void valueChanged(ListSelectionEvent e) {
358:                                try {
359:                                    // install the ListSelectionListener that listens on column selection changes
360:                                    if (e.getValueIsAdjusting())
361:                                        return;
362:
363:                                    myModel
364:                                            .getActualTableModel()
365:                                            .setSelectedColumn(
366:                                                    getActiveTable()
367:                                                            .getSelectedColumn());
368:                                } catch (IllegalUserInputException e3) {/*cannot happen */
369:                                }
370:                            }
371:                        });
372:
373:                table.addMouseListener(new java.awt.event.MouseAdapter() {
374:                    public void mousePressed(java.awt.event.MouseEvent evt) {
375:                        try {
376:                            // to indicate the selected cells correctly. By default the forground color is omitted every second time.
377:                            if (getActiveTable().getColumnModel()
378:                                    .getColumnIndexAtX(evt.getX()) == myModel
379:                                    .getActualTableModel().getSelectedColumn())
380:                                getActiveTable().getColumnModel()
381:                                        .getSelectionModel()
382:                                        .setSelectionInterval(
383:                                                myModel.getActualTableModel()
384:                                                        .getSelectedColumn(),
385:                                                myModel.getActualTableModel()
386:                                                        .getSelectedColumn());
387:                        } catch (IllegalUserInputException e4) {/*cannot happen */
388:                        }
389:                    }
390:                });
391:
392:                table.getColumnModel().getColumn(JOINPOINT_COL_INDEX)
393:                        .setCellRenderer(new MyJPSurrogateRenderer());
394:            }
395:
396:            public static class JToolTipTable extends JTable {
397:
398:                private static final long serialVersionUID = 3544395807361872688L;
399:
400:                public String getToolTipText(java.awt.event.MouseEvent e) {
401:                    Point p = e.getPoint();
402:                    Object value = getValueAt(rowAtPoint(p), columnAtPoint(p));
403:                    if (value != null)
404:                        return value.toString();
405:                    else
406:                        return "";
407:                }
408:            }
409:
410:            public class MyJPSurrogateRenderer extends DefaultTableCellRenderer {
411:
412:                private static final long serialVersionUID = 3256437023534627123L;
413:
414:                public java.awt.Component getTableCellRendererComponent(
415:                        JTable table, Object value, boolean isSelected,
416:                        boolean hasFocus, int row, int column) {
417:                    java.awt.Component component = super 
418:                            .getTableCellRendererComponent(table, value,
419:                                    isSelected, hasFocus, row, column);
420:                    int[] pastedCells = ((WorksheetSingleClientModel) table
421:                            .getModel()).pastedCells;
422:                    if ((pastedCells != null) && (row >= pastedCells[0])
423:                            && (row <= pastedCells[pastedCells.length - 1])) {
424:                        this .setFont(new java.awt.Font("Dialog",
425:                                java.awt.Font.ITALIC, 12));
426:                    }
427:                    return component;
428:                }
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.