Source Code Cross Referenced for ReportViewer.java in  » Profiler » JMeasurement » de » mcs » jmeasurement » 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 » Profiler » JMeasurement » de.mcs.jmeasurement.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * MCS Media Computer Software Copyright (c) 2006 by MCS
0003:         * -------------------------------------- Created on 07.08.2006 by w.klaas
0004:         * 
0005:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
0006:         * use this file except in compliance with the License. You may obtain a copy of
0007:         * the License at
0008:         * 
0009:         * http://www.apache.org/licenses/LICENSE-2.0
0010:         * 
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
0013:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
0014:         * License for the specific language governing permissions and limitations under
0015:         * the License.
0016:         */
0017:        /**
0018:         * 
0019:         */package de.mcs.jmeasurement.gui;
0020:
0021:        import java.awt.BorderLayout;
0022:        import java.awt.Component;
0023:        import java.awt.Dimension;
0024:        import java.awt.Event;
0025:        import java.awt.Graphics;
0026:        import java.awt.Graphics2D;
0027:        import java.awt.GridBagConstraints;
0028:        import java.awt.GridBagLayout;
0029:        import java.awt.Insets;
0030:        import java.awt.Paint;
0031:        import java.awt.Point;
0032:        import java.awt.TexturePaint;
0033:        import java.awt.Toolkit;
0034:        import java.awt.event.ActionEvent;
0035:        import java.awt.event.ActionListener;
0036:        import java.awt.event.KeyEvent;
0037:        import java.awt.event.MouseAdapter;
0038:        import java.awt.event.MouseEvent;
0039:        import java.awt.event.WindowAdapter;
0040:        import java.awt.event.WindowEvent;
0041:        import java.awt.geom.Rectangle2D;
0042:        import java.awt.image.BufferedImage;
0043:        import java.beans.PropertyChangeEvent;
0044:        import java.beans.PropertyChangeListener;
0045:        import java.io.BufferedInputStream;
0046:        import java.io.File;
0047:        import java.io.FileInputStream;
0048:        import java.io.FileNotFoundException;
0049:        import java.io.FileOutputStream;
0050:        import java.io.IOException;
0051:        import java.io.InputStream;
0052:        import java.net.URL;
0053:        import java.util.ArrayList;
0054:        import java.util.Arrays;
0055:        import java.util.Enumeration;
0056:        import java.util.HashMap;
0057:        import java.util.InvalidPropertiesFormatException;
0058:        import java.util.Timer;
0059:        import java.util.TimerTask;
0060:
0061:        import javax.imageio.ImageIO;
0062:        import javax.swing.AbstractAction;
0063:        import javax.swing.Action;
0064:        import javax.swing.JButton;
0065:        import javax.swing.JComboBox;
0066:        import javax.swing.JDialog;
0067:        import javax.swing.JFileChooser;
0068:        import javax.swing.JFrame;
0069:        import javax.swing.JLabel;
0070:        import javax.swing.JMenu;
0071:        import javax.swing.JMenuBar;
0072:        import javax.swing.JMenuItem;
0073:        import javax.swing.JOptionPane;
0074:        import javax.swing.JPanel;
0075:        import javax.swing.JProgressBar;
0076:        import javax.swing.JScrollPane;
0077:        import javax.swing.JTable;
0078:        import javax.swing.JToolBar;
0079:        import javax.swing.KeyStroke;
0080:        import javax.swing.ProgressMonitorInputStream;
0081:        import javax.swing.ScrollPaneLayout;
0082:        import javax.swing.SwingConstants;
0083:        import javax.swing.UIManager;
0084:        import javax.swing.UnsupportedLookAndFeelException;
0085:        import javax.swing.filechooser.FileFilter;
0086:        import javax.swing.table.JTableHeader;
0087:        import javax.swing.table.TableCellRenderer;
0088:        import javax.swing.table.TableColumn;
0089:
0090:        import org.jdesktop.swingx.IncidentInfo;
0091:        import org.jdesktop.swingx.JXErrorDialog;
0092:        import org.xml.sax.SAXException;
0093:
0094:        import de.mcs.jmeasurement.MeasureFactory;
0095:        import de.mcs.jmeasurement.MeasurePoint;
0096:        import de.mcs.jmeasurement.MeasurementException;
0097:
0098:        /**
0099:         * @author w.klaas
0100:         * 
0101:         */
0102:        public class ReportViewer extends JFrame {
0103:            /**
0104:             * Image panel for about dialog.
0105:             * 
0106:             * @author w.klaas
0107:             * 
0108:             */
0109:            public static final class ImagePanel extends JPanel {
0110:                /**
0111:                 * 
0112:                 */
0113:                private static final long serialVersionUID = -1949615036773091661L;
0114:
0115:                /** the texture. */
0116:                private transient Paint texture;
0117:
0118:                /**
0119:                 * constructiong a image panel.
0120:                 * 
0121:                 * @param name
0122:                 *            name of the image to load with resourceFrom Stream.
0123:                 */
0124:                public ImagePanel(final String name) {
0125:                    BufferedImage image;
0126:                    try {
0127:                        image = ImageIO.read(getClass().getResourceAsStream(
0128:                                name));
0129:                        Rectangle2D r = new Rectangle2D.Double(0, 0, image
0130:                                .getWidth(), image.getHeight());
0131:                        texture = new TexturePaint(image, r);
0132:                    } catch (IOException e) {
0133:                        e.printStackTrace();
0134:                    }
0135:                }
0136:
0137:                /**
0138:                 * paint hte image panel.
0139:                 * 
0140:                 * @param g
0141:                 *            the graphics
0142:                 * @see JPanel#paint(Graphics)
0143:                 */
0144:                public void paint(final Graphics g) {
0145:                    Graphics2D g2 = (Graphics2D) g;
0146:                    super .paint(g);
0147:                    g2.setPaint(texture);
0148:                    g2.fillRect(0, 0, getWidth(), getHeight());
0149:                }
0150:            }
0151:
0152:            /**
0153:             * 
0154:             */
0155:            private static final long serialVersionUID = -3627139012406024384L;
0156:
0157:            /** action names. */
0158:            private static final String FILE_EXIT = "file/exit"; //$NON-NLS-1$
0159:
0160:            /** action names. */
0161:            private static final String FILE_OPEN = "file/open"; //$NON-NLS-1$
0162:
0163:            /** action names. */
0164:            private static final String FILTER_PROCESS = "filter/process"; //$NON-NLS-1$
0165:
0166:            /** action names. */
0167:            private static final String FILE_OPEN_URL = "file/open/url"; //$NON-NLS-1$
0168:
0169:            /** action names. */
0170:            private static final String FILE_REFRESH_URL = "file/refresh/url"; //$NON-NLS-1$
0171:
0172:            /** action names. */
0173:            private static final String EXTRA_OPTIONS = "extra/options"; //$NON-NLS-1$
0174:
0175:            /** action names. */
0176:            private static final String HELP_ABOUT = "help/about";
0177:
0178:            /** component. */
0179:            private JPanel contentPane = null;
0180:
0181:            /** component. */
0182:            private JMenuBar jMenuBar = null;
0183:
0184:            /** component. */
0185:            private JMenu fileMenu = null;
0186:
0187:            /** component. */
0188:            private JMenu editMenu = null;
0189:
0190:            /** component. */
0191:            private JMenu helpMenu = null;
0192:
0193:            /** component. */
0194:            private JMenuItem exitMenuItem = null;
0195:
0196:            /** component. */
0197:            private JMenuItem aboutMenuItem = null;
0198:
0199:            /** component. */
0200:            private JMenuItem cutMenuItem = null;
0201:
0202:            /** component. */
0203:            private JMenuItem copyMenuItem = null;
0204:
0205:            /** component. */
0206:            private JMenuItem pasteMenuItem = null;
0207:
0208:            /** component. */
0209:            private JMenuItem openMenuItem = null;
0210:
0211:            /** component. */
0212:            private JToolBar toolBar;
0213:
0214:            /** component. */
0215:            private JPanel centerPane;
0216:
0217:            /** component. */
0218:            private JPanel filterPane;
0219:
0220:            /** component. */
0221:            private JComboBox jcFilter;
0222:
0223:            /** component. */
0224:            private JTable grid;
0225:
0226:            /** the data model forthe table. */
0227:            private MeasureTableModel model;
0228:
0229:            /** the sorter model. */
0230:            private TableSorter tableModel;
0231:
0232:            /** map with all actions. */
0233:            private HashMap<String, Action> actions;
0234:
0235:            /** panel for status messages and the progress bar. */
0236:            private JPanel statusPane;
0237:
0238:            /** label for status messages. */
0239:            private JLabel statusText;
0240:
0241:            /** the progress bar. */
0242:            private JProgressBar progressBar;
0243:
0244:            /** menu item. */
0245:            private JMenuItem openUrlMenuItem;
0246:
0247:            /** the singelton application. */
0248:            private static ReportViewer application;
0249:
0250:            /** url of the report data if set. */
0251:            private URL url = null;
0252:
0253:            /** configuration data. */
0254:            private StoreProperties config;
0255:
0256:            /** listof all used urls. */
0257:            private ArrayList<String> urllist;
0258:
0259:            /** the combobox with the snapshots. */
0260:            private JComboBox jcSnapShot;
0261:
0262:            /** menu item. */
0263:            private JMenuItem reloadMenuItem;
0264:
0265:            /** button for refresh, when url is loaded. */
0266:            private JButton jbRefresh;
0267:
0268:            /** timer for the about box. */
0269:            private transient Timer timer;
0270:
0271:            private JMenu extraMenu;
0272:
0273:            private JMenuItem optionsMenuItem;
0274:
0275:            private JButton jbOptions;
0276:
0277:            /**
0278:             * @param args
0279:             *            commandline arguments first argument is the file to show
0280:             * @throws UnsupportedLookAndFeelException
0281:             *             if something goes wrong.
0282:             * @throws IllegalAccessException
0283:             *             if something goes wrong.
0284:             * @throws InstantiationException
0285:             *             if something goes wrong.
0286:             * @throws ClassNotFoundException
0287:             *             if something goes wrong.
0288:             * @throws MeasurementException
0289:             *             if something goes wrong.
0290:             * @throws SAXException
0291:             *             if something goes wrong.
0292:             * @throws IOException
0293:             *             if something goes wrong.
0294:             */
0295:            public static void main(final String[] args)
0296:                    throws ClassNotFoundException, InstantiationException,
0297:                    IllegalAccessException, UnsupportedLookAndFeelException,
0298:                    IOException, SAXException, MeasurementException {
0299:                UIManager.setLookAndFeel(UIManager
0300:                        .getSystemLookAndFeelClassName());
0301:                JFrame.setDefaultLookAndFeelDecorated(true);
0302:                application = new ReportViewer();
0303:                if (args.length > 0) {
0304:                    File reportData = new File(args[0]);
0305:                    application.loadReport(reportData);
0306:                }
0307:                application.setVisible(true);
0308:            }
0309:
0310:            /**
0311:             * This is the default constructor.
0312:             */
0313:            public ReportViewer() {
0314:                super ();
0315:                urllist = new ArrayList<String>();
0316:                initialize();
0317:            }
0318:
0319:            /**
0320:             * This method initializes this.
0321:             * 
0322:             */
0323:            private void initialize() {
0324:                actions = new HashMap<String, Action>();
0325:                addStandardActions();
0326:
0327:                loadConfigurationData();
0328:                this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
0329:                this .setJMenuBar(getMyMenuBar());
0330:                this .setContentPane(getJContentPane());
0331:                this .setTitle(Messages
0332:                        .getString("ReportViewer.APPLICATION.TITLE")); //$NON-NLS-1$
0333:
0334:                addWindowListener(new WindowAdapter() {
0335:
0336:                    /*
0337:                     * (non-Javadoc)
0338:                     * 
0339:                     * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent)
0340:                     */
0341:                    @Override
0342:                    public void windowClosing(final WindowEvent e) {
0343:                        super .windowClosing(e);
0344:                        saveConfigurationData();
0345:                    }
0346:
0347:                });
0348:                jbRefresh.setEnabled(false);
0349:                showAbout();
0350:            }
0351:
0352:            /** adding standard sctions like file/exit help. */
0353:            private void addStandardActions() {
0354:                actions.put(FILE_EXIT, new AbstractAction() {
0355:
0356:                    private static final long serialVersionUID = 1L;
0357:
0358:                    public void actionPerformed(final ActionEvent e) {
0359:                        saveConfigurationData();
0360:                        exit();
0361:                    }
0362:
0363:                });
0364:                actions.put(FILE_OPEN, new AbstractAction() {
0365:
0366:                    private static final long serialVersionUID = 1L;
0367:
0368:                    public void actionPerformed(final ActionEvent e) {
0369:                        openReport();
0370:                    }
0371:
0372:                });
0373:                actions.put(FILE_OPEN_URL, new AbstractAction() {
0374:
0375:                    private static final long serialVersionUID = 1L;
0376:
0377:                    public void actionPerformed(final ActionEvent e) {
0378:                        openReportURL();
0379:                    }
0380:
0381:                });
0382:                actions.put(FILE_REFRESH_URL, new AbstractAction() {
0383:
0384:                    private static final long serialVersionUID = 1L;
0385:
0386:                    public void actionPerformed(final ActionEvent e) {
0387:                        if (null != url) {
0388:                            try {
0389:                                loadReportFromURL(url);
0390:                            } catch (Exception e1) {
0391:                                showException(e1);
0392:                            }
0393:                        }
0394:                    }
0395:                });
0396:                actions.put(FILTER_PROCESS, new AbstractAction() {
0397:
0398:                    private static final long serialVersionUID = 1L;
0399:
0400:                    public void actionPerformed(final ActionEvent e) {
0401:                        doFilter();
0402:                    }
0403:
0404:                });
0405:                actions.put(EXTRA_OPTIONS, new AbstractAction() {
0406:
0407:                    private static final long serialVersionUID = 1L;
0408:
0409:                    public void actionPerformed(final ActionEvent e) {
0410:                        showOptions();
0411:                    }
0412:
0413:                });
0414:                actions.put(HELP_ABOUT, new AbstractAction() {
0415:
0416:                    private static final long serialVersionUID = 1L;
0417:
0418:                    public void actionPerformed(final ActionEvent e) {
0419:                        showAbout();
0420:                    }
0421:
0422:                });
0423:            }
0424:
0425:            protected void showOptions() {
0426:                // TODO Auto-generated method stub
0427:                System.out.println("show options");
0428:            }
0429:
0430:            /**
0431:             * showing the about dialog.
0432:             * 
0433:             */
0434:            protected final void showAbout() {
0435:                final JDialog aboutDialog = new JDialog(ReportViewer.this ,
0436:                        Messages.getString("ReportViewer.ABOUT.TITLE"), false); //$NON-NLS-1$
0437:                // final JFrame aboutDialog = new JFrame(Messages
0438:                // .getString("ReportViewer.ABOUT.TITLE")); //$NON-NLS-1$
0439:                aboutDialog.setResizable(false);
0440:                ImagePanel imagePanel = new ImagePanel(
0441:                        "/de/mcs/jmeasurement/gui/images/logo_mcs.jpg");
0442:                imagePanel.setLayout(new BorderLayout());
0443:                imagePanel.addMouseListener(new MouseAdapter() {
0444:
0445:                    /*
0446:                     * (non-Javadoc)
0447:                     * 
0448:                     * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
0449:                     */
0450:                    @Override
0451:                    public void mouseClicked(final MouseEvent e) {
0452:                        if (aboutDialog.isVisible()) {
0453:                            aboutDialog.setVisible(false);
0454:                        }
0455:                    }
0456:
0457:                });
0458:
0459:                aboutDialog.getContentPane().add(imagePanel);
0460:                Dimension dimension = new Dimension(400, 320);
0461:                Point point = getCenterWindowPosition(dimension);
0462:                aboutDialog.setAlwaysOnTop(true);
0463:                aboutDialog.setLocation(point);
0464:                aboutDialog.setSize(dimension);
0465:                aboutDialog.setVisible(true);
0466:                timer = new Timer("about");
0467:                timer.schedule(new TimerTask() {
0468:
0469:                    @Override
0470:                    public void run() {
0471:                        if (aboutDialog.isVisible()) {
0472:                            aboutDialog.setVisible(false);
0473:                        }
0474:                    }
0475:
0476:                }, 5000);
0477:                // aboutDialog.pack();
0478:            }
0479:
0480:            /**
0481:             * getting one action from the action map.
0482:             * 
0483:             * @param actionName
0484:             *            action to get.
0485:             * @return ActionListener
0486:             */
0487:            private ActionListener getAction(final String actionName) {
0488:                return actions.get(actionName);
0489:            }
0490:
0491:            /**
0492:             * This method initializes jContentPane.
0493:             * 
0494:             * @return javax.swing.JPanel
0495:             */
0496:            private JPanel getJContentPane() {
0497:                if (contentPane == null) {
0498:                    contentPane = new JPanel();
0499:                    contentPane.setLayout(new BorderLayout());
0500:                    contentPane.add(BorderLayout.NORTH, getToolBar());
0501:                    contentPane.add(BorderLayout.CENTER, getCenterPane());
0502:                }
0503:                return contentPane;
0504:            }
0505:
0506:            /**
0507:             * This method initializes center pane.
0508:             * 
0509:             * @return javax.swing.JPanel
0510:             */
0511:            private JPanel getCenterPane() {
0512:                if (centerPane == null) {
0513:                    centerPane = new JPanel();
0514:                    centerPane.setLayout(new BorderLayout());
0515:                    centerPane.add(BorderLayout.NORTH, getFilterPane());
0516:                    centerPane.add(BorderLayout.CENTER, getMeasureGrid());
0517:                    centerPane.add(BorderLayout.SOUTH, getStatusPane());
0518:                }
0519:                return centerPane;
0520:            }
0521:
0522:            /**
0523:             * This method initializes filter pane.
0524:             * 
0525:             * @return javax.swing.JPanel
0526:             */
0527:            private JPanel getStatusPane() {
0528:                if (statusPane == null) {
0529:                    statusPane = new JPanel();
0530:                    GridBagLayout gbl = new GridBagLayout();
0531:                    gbl.columnWidths = new int[] { 300, 60 };
0532:                    statusPane.setLayout(gbl);
0533:                    GridBagConstraints gbc = new GridBagConstraints();
0534:                    gbc.gridx = 0;
0535:                    gbc.gridy = 0;
0536:                    gbc.fill = GridBagConstraints.HORIZONTAL;
0537:                    statusText = new JLabel(""); //$NON-NLS-1$
0538:                    statusPane.add(statusText, gbc);
0539:
0540:                    gbc.fill = GridBagConstraints.HORIZONTAL;
0541:                    gbc.gridx = 1;
0542:
0543:                    progressBar = new JProgressBar(0, 100);
0544:                    statusPane.add(progressBar, gbc);
0545:                }
0546:                return statusPane;
0547:            }
0548:
0549:            /**
0550:             * This method initializes filter pane.
0551:             * 
0552:             * @return javax.swing.JPanel
0553:             */
0554:            private JPanel getFilterPane() {
0555:                if (filterPane == null) {
0556:                    filterPane = new JPanel();
0557:                    GridBagLayout gbl = new GridBagLayout();
0558:                    gbl.columnWidths = new int[] { 60, 300, 60, 120 };
0559:                    filterPane.setLayout(gbl);
0560:                    GridBagConstraints gbc = new GridBagConstraints();
0561:                    gbc.gridx = 0;
0562:                    gbc.gridy = 0;
0563:                    gbc.fill = GridBagConstraints.HORIZONTAL;
0564:                    filterPane.add(new JLabel(Messages
0565:                            .getString("ReportViewer.Filter")), gbc); //$NON-NLS-1$
0566:
0567:                    gbc.fill = GridBagConstraints.HORIZONTAL;
0568:                    gbc.gridx = 1;
0569:                    filterPane.add(getFilterCombo(), gbc);
0570:
0571:                    gbc.fill = GridBagConstraints.HORIZONTAL;
0572:                    gbc.gridx = 2;
0573:                    gbc.insets = new Insets(0, 5, 0, 0);
0574:                    filterPane.add(new JLabel(Messages
0575:                            .getString("ReportViewer.Snapshots")), gbc); //$NON-NLS-1$
0576:
0577:                    gbc.fill = GridBagConstraints.HORIZONTAL;
0578:                    gbc.gridwidth = GridBagConstraints.REMAINDER;
0579:                    gbc.gridx = 3;
0580:                    filterPane.add(getSnapShotCombo(), gbc);
0581:                }
0582:                return filterPane;
0583:            }
0584:
0585:            /**
0586:             * This method initializes filter combo box.
0587:             * 
0588:             * @return JComboBox
0589:             */
0590:            private JComboBox getSnapShotCombo() {
0591:                if (jcSnapShot == null) {
0592:                    jcSnapShot = new JComboBox();
0593:                    // String[] items = config.getFilterItems();
0594:                    // if (items != null) {
0595:                    // for (int i = 0; i < items.length; i++) {
0596:                    // jcSnapShot.addItem(items[i]);
0597:                    // }
0598:                    // }
0599:
0600:                    jcSnapShot.setEditable(false);
0601:                    jcSnapShot.addActionListener(new ActionListener() {
0602:
0603:                        public void actionPerformed(final ActionEvent e) {
0604:                            if (model != null) {
0605:                                String selection = (String) jcSnapShot
0606:                                        .getSelectedItem();
0607:                                if (selection != null) {
0608:                                    if (jcSnapShot.getSelectedIndex() == 0) {
0609:                                        model.setSnapshot(null);
0610:                                    } else {
0611:                                        model.setSnapshot(selection);
0612:                                    }
0613:                                }
0614:                            }
0615:                        }
0616:
0617:                    });
0618:                }
0619:                return jcSnapShot;
0620:            }
0621:
0622:            /**
0623:             * This method initializes filter combo box.
0624:             * 
0625:             * @return JComboBox
0626:             */
0627:            private JComboBox getFilterCombo() {
0628:                if (jcFilter == null) {
0629:                    jcFilter = new JComboBox();
0630:                    String[] items = config.getFilterItems();
0631:                    if (items != null) {
0632:                        for (int i = 0; i < items.length; i++) {
0633:                            jcFilter.addItem(items[i]);
0634:                        }
0635:                    }
0636:
0637:                    jcFilter.setEditable(true);
0638:                    jcFilter.addActionListener(new ActionListener() {
0639:
0640:                        public void actionPerformed(final ActionEvent e) {
0641:                            String selection = (String) jcFilter
0642:                                    .getSelectedItem();
0643:                            for (int i = 0; i < jcFilter.getItemCount(); i++) {
0644:                                String string = (String) jcFilter.getItemAt(i);
0645:                                if (string.equals(selection)) {
0646:                                    doFilter();
0647:                                    return;
0648:                                }
0649:                            }
0650:                            jcFilter.insertItemAt(selection, 0);
0651:                            while (jcFilter.getItemCount() > 10) {
0652:                                jcFilter
0653:                                        .removeItemAt(jcFilter.getItemCount() - 1);
0654:                            }
0655:                            doFilter();
0656:                        }
0657:
0658:                    });
0659:                }
0660:                return jcFilter;
0661:            }
0662:
0663:            /**
0664:             * This method initializes the measure grid.
0665:             * 
0666:             * @return Component
0667:             */
0668:            private Component getMeasureGrid() {
0669:                if (null != model) {
0670:                    grid = new JTable(tableModel) {
0671:                        /**
0672:                         * 
0673:                         */
0674:                        private static final long serialVersionUID = 1L;
0675:
0676:                        // Implement table header tool tips.
0677:                        protected JTableHeader createDefaultTableHeader() {
0678:                            return new JTableHeader(columnModel) {
0679:                                /**
0680:                                 * 
0681:                                 */
0682:                                private static final long serialVersionUID = 1L;
0683:
0684:                                public String getToolTipText(final MouseEvent e) {
0685:                                    java.awt.Point p = e.getPoint();
0686:                                    int index = columnModel
0687:                                            .getColumnIndexAtX(p.x);
0688:                                    int realIndex = columnModel
0689:                                            .getColumn(index).getModelIndex();
0690:                                    return model
0691:                                            .getColumnDescription(realIndex);
0692:                                }
0693:                            };
0694:                        }
0695:                    };
0696:                    initGrid();
0697:                } else {
0698:                    grid = new JTable();
0699:                }
0700:                grid.addMouseListener(new MouseAdapter() {
0701:
0702:                    /**
0703:                     * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
0704:                     */
0705:                    @Override
0706:                    public void mouseClicked(final MouseEvent e) {
0707:                        if (e.getClickCount() > 1) {
0708:                            showSelectedPoint();
0709:                        }
0710:                    }
0711:
0712:                });
0713:
0714:                JScrollPane pane = new JScrollPane(grid);
0715:                pane.setLayout(new ScrollPaneLayout());
0716:                pane
0717:                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
0718:                pane
0719:                        .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
0720:
0721:                return pane;
0722:            }
0723:
0724:            /**
0725:             * This method initializes the toolbar.
0726:             * 
0727:             * @return JToolBar
0728:             */
0729:            private JToolBar getToolBar() {
0730:                toolBar = new JToolBar();
0731:                toolBar.setRollover(true);
0732:
0733:                JButton jbExit = new JButton(
0734:                // Messages.getString("ReportViewer.BUTTON.EXIT"),
0735:                        Messages.getImage( //$NON-NLS-1$
0736:                                "misc_goto", true)); //$NON-NLS-1$
0737:
0738:                jbExit.addActionListener(actions.get(FILE_EXIT));
0739:                jbExit.setHorizontalTextPosition(SwingConstants.CENTER);
0740:                jbExit.setVerticalTextPosition(SwingConstants.BOTTOM);
0741:                jbExit.setToolTipText(Messages
0742:                        .getString("ReportViewer.BUTTON.EXIT"));
0743:                toolBar.add(jbExit);
0744:
0745:                JButton jbAbout = new JButton(
0746:                // Messages.getString("ReportViewer.BUTTON.ABOUT"),
0747:                        Messages.getImage( //$NON-NLS-1$
0748:                                "win_info", true)); //$NON-NLS-1$
0749:
0750:                jbAbout.addActionListener(actions.get(HELP_ABOUT));
0751:                jbAbout.setHorizontalTextPosition(SwingConstants.CENTER);
0752:                jbAbout.setVerticalTextPosition(SwingConstants.BOTTOM);
0753:                jbAbout.setToolTipText(Messages
0754:                        .getString("ReportViewer.BUTTON.ABOUT"));
0755:                toolBar.add(jbAbout);
0756:
0757:                toolBar.addSeparator();
0758:
0759:                JButton jbOpen = new JButton(
0760:                // Messages.getString("ReportViewer.BUTTON.OPEN"),
0761:                        Messages.getImage( //$NON-NLS-1$
0762:                                "win_fileopen", true)); //$NON-NLS-1$
0763:                jbOpen.addActionListener(getAction(FILE_OPEN));
0764:                jbOpen.setHorizontalTextPosition(SwingConstants.CENTER);
0765:                jbOpen.setVerticalTextPosition(SwingConstants.BOTTOM);
0766:                jbOpen.setToolTipText(Messages
0767:                        .getString("ReportViewer.BUTTON.OPEN"));
0768:                toolBar.add(jbOpen);
0769:
0770:                jbRefresh = new JButton(
0771:                // Messages.getString("ReportViewer.BUTTON.REFRESH"),
0772:                        Messages.getImage( //$NON-NLS-1$
0773:                                "db_refresh", true));
0774:                jbRefresh.addActionListener(getAction(FILE_REFRESH_URL));
0775:                jbRefresh.setHorizontalTextPosition(SwingConstants.CENTER);
0776:                jbRefresh.setVerticalTextPosition(SwingConstants.BOTTOM);
0777:                jbRefresh.setToolTipText(Messages
0778:                        .getString("ReportViewer.BUTTON.REFRESH"));
0779:                toolBar.add(jbRefresh);
0780:
0781:                jbOptions = new JButton(
0782:                // Messages.getString("ReportViewer.BUTTON.OPTIONS"),
0783:                        Messages.getImage( //$NON-NLS-1$
0784:                                "db_refresh", true));
0785:                jbOptions.addActionListener(getAction(EXTRA_OPTIONS));
0786:                jbOptions.setHorizontalTextPosition(SwingConstants.CENTER);
0787:                jbOptions.setVerticalTextPosition(SwingConstants.BOTTOM);
0788:                jbOptions.setToolTipText(Messages
0789:                        .getString("ReportViewer.BUTTON.OPTIONS"));
0790:                //        toolBar.add(jbOptions);
0791:                return toolBar;
0792:            }
0793:
0794:            /**
0795:             * This method initializes MenuBar.
0796:             * 
0797:             * @return javax.swing.JMenuBar
0798:             */
0799:            private JMenuBar getMyMenuBar() {
0800:                if (jMenuBar == null) {
0801:                    jMenuBar = new JMenuBar();
0802:                    jMenuBar.add(getFileMenu());
0803:                    // jMenuBar.add(getEditMenu());
0804:                    //            jMenuBar.add(getExtraMenu());
0805:                    jMenuBar.add(getHelpMenu());
0806:                }
0807:                return jMenuBar;
0808:            }
0809:
0810:            /**
0811:             * This method initializes file menu.
0812:             * 
0813:             * @return javax.swing.JMenu
0814:             */
0815:            private JMenu getFileMenu() {
0816:                if (fileMenu == null) {
0817:                    fileMenu = new JMenu();
0818:                    fileMenu.setText(Messages
0819:                            .getString("ReportViewer.MENU.FILE")); //$NON-NLS-1$
0820:                    fileMenu.add(getOpenMenuItem());
0821:                    fileMenu.addSeparator();
0822:                    fileMenu.add(getOpenURLMenuItem());
0823:                    fileMenu.add(getReloadMenuItem());
0824:                    fileMenu.addSeparator();
0825:                    fileMenu.add(getExitMenuItem());
0826:                }
0827:                return fileMenu;
0828:            }
0829:
0830:            /**
0831:             * This method initializes edit menu.
0832:             * 
0833:             * @return javax.swing.JMenu
0834:             */
0835:            private JMenu getEditMenu() {
0836:                if (editMenu == null) {
0837:                    editMenu = new JMenu();
0838:                    editMenu.setText(Messages
0839:                            .getString("ReportViewer.MENU.EDIT")); //$NON-NLS-1$
0840:                    editMenu.add(getCutMenuItem());
0841:                    editMenu.add(getCopyMenuItem());
0842:                    editMenu.add(getPasteMenuItem());
0843:                }
0844:                return editMenu;
0845:            }
0846:
0847:            /**
0848:             * This method initializes edit menu.
0849:             * 
0850:             * @return javax.swing.JMenu
0851:             */
0852:            private JMenu getExtraMenu() {
0853:                if (extraMenu == null) {
0854:                    extraMenu = new JMenu();
0855:                    extraMenu.setText(Messages
0856:                            .getString("ReportViewer.MENU.EXTRA")); //$NON-NLS-1$
0857:                    extraMenu.add(getOptionsMenuItem());
0858:                }
0859:                return extraMenu;
0860:            }
0861:
0862:            /**
0863:             * This method initializes exit menu item.
0864:             * 
0865:             * @return javax.swing.JMenuItem
0866:             */
0867:            private JMenuItem getOptionsMenuItem() {
0868:                if (optionsMenuItem == null) {
0869:                    optionsMenuItem = new JMenuItem();
0870:                    optionsMenuItem.setText(Messages
0871:                            .getString("ReportViewer.MENU.EXTRA.OPTIONS")); //$NON-NLS-1$
0872:                    optionsMenuItem.addActionListener(actions
0873:                            .get(EXTRA_OPTIONS));
0874:                }
0875:                return optionsMenuItem;
0876:            }
0877:
0878:            /**
0879:             * This method initializes help menu.
0880:             * 
0881:             * @return javax.swing.JMenu
0882:             */
0883:            private JMenu getHelpMenu() {
0884:                if (helpMenu == null) {
0885:                    helpMenu = new JMenu();
0886:                    helpMenu.setText(Messages
0887:                            .getString("ReportViewer.MENU.HELP")); //$NON-NLS-1$
0888:                    helpMenu.add(getAboutMenuItem());
0889:                }
0890:                return helpMenu;
0891:            }
0892:
0893:            /**
0894:             * This method initializes exit menu item.
0895:             * 
0896:             * @return javax.swing.JMenuItem
0897:             */
0898:            private JMenuItem getExitMenuItem() {
0899:                if (exitMenuItem == null) {
0900:                    exitMenuItem = new JMenuItem();
0901:                    exitMenuItem.setText(Messages
0902:                            .getString("ReportViewer.MENU.FILE.EXIT")); //$NON-NLS-1$
0903:                    exitMenuItem.addActionListener(actions.get(FILE_EXIT));
0904:                }
0905:                return exitMenuItem;
0906:            }
0907:
0908:            /**
0909:             * This method initializes about menu item.
0910:             * 
0911:             * @return javax.swing.JMenuItem
0912:             */
0913:            private JMenuItem getAboutMenuItem() {
0914:                if (aboutMenuItem == null) {
0915:                    aboutMenuItem = new JMenuItem();
0916:                    aboutMenuItem.setText(Messages
0917:                            .getString("ReportViewer.MENU.HELP.ABOUT")); //$NON-NLS-1$
0918:                    aboutMenuItem.addActionListener(actions.get(HELP_ABOUT));
0919:                }
0920:                return aboutMenuItem;
0921:            }
0922:
0923:            /**
0924:             * getting the center position of a dialog.
0925:             * 
0926:             * @param dimension
0927:             *            dimensions of the dialog.
0928:             * @return Point the location the dialog must have.
0929:             */
0930:            public static final Point getCenterWindowPosition(
0931:                    final Dimension dimension) {
0932:                int divx = dimension.width / 2;
0933:                int divy = dimension.height / 2;
0934:                /** size of the screen. */
0935:                Dimension screensize = Toolkit.getDefaultToolkit()
0936:                        .getScreenSize();
0937:
0938:                return new Point((screensize.width / 2) - divx,
0939:                        (screensize.height / 2) - divy);
0940:            }
0941:
0942:            /**
0943:             * This method initializes jMenuItem.
0944:             * 
0945:             * @return javax.swing.JMenuItem
0946:             */
0947:            private JMenuItem getCutMenuItem() {
0948:                if (cutMenuItem == null) {
0949:                    cutMenuItem = new JMenuItem();
0950:                    cutMenuItem.setText(Messages.getString("ReportViewer.7")); //$NON-NLS-1$
0951:                    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(
0952:                            KeyEvent.VK_X, Event.CTRL_MASK, true));
0953:                }
0954:                return cutMenuItem;
0955:            }
0956:
0957:            /**
0958:             * This method initializes jMenuItem.
0959:             * 
0960:             * @return javax.swing.JMenuItem
0961:             */
0962:            private JMenuItem getCopyMenuItem() {
0963:                if (copyMenuItem == null) {
0964:                    copyMenuItem = new JMenuItem();
0965:                    copyMenuItem.setText(Messages.getString("ReportViewer.8")); //$NON-NLS-1$
0966:                    copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(
0967:                            KeyEvent.VK_C, Event.CTRL_MASK, true));
0968:                }
0969:                return copyMenuItem;
0970:            }
0971:
0972:            /**
0973:             * This method initializes jMenuItem.
0974:             * 
0975:             * @return javax.swing.JMenuItem
0976:             */
0977:            private JMenuItem getPasteMenuItem() {
0978:                if (pasteMenuItem == null) {
0979:                    pasteMenuItem = new JMenuItem();
0980:                    pasteMenuItem.setText(Messages.getString("ReportViewer.9")); //$NON-NLS-1$
0981:                    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(
0982:                            KeyEvent.VK_V, Event.CTRL_MASK, true));
0983:                }
0984:                return pasteMenuItem;
0985:            }
0986:
0987:            /**
0988:             * This method initializes open menu item.
0989:             * 
0990:             * @return javax.swing.JMenuItem
0991:             */
0992:            private JMenuItem getOpenMenuItem() {
0993:                if (openMenuItem == null) {
0994:                    openMenuItem = new JMenuItem();
0995:                    openMenuItem.setText(Messages
0996:                            .getString("ReportViewer.MENU.FILE.OPEN")); //$NON-NLS-1$
0997:                    openMenuItem.setAccelerator(KeyStroke.getKeyStroke(
0998:                            KeyEvent.VK_O, Event.CTRL_MASK, true));
0999:                    openMenuItem
1000:                            .addPropertyChangeListener(new java.beans.PropertyChangeListener() {
1001:                                public void propertyChange(
1002:                                        final java.beans.PropertyChangeEvent e) {
1003:                                    if ((e.getPropertyName()
1004:                                            .equals("accelerator"))) { //$NON-NLS-1$
1005:                                        System.out
1006:                                                .println("propertyChange(accelerator)"); //$NON-NLS-1$
1007:                                    }
1008:                                }
1009:                            });
1010:                    openMenuItem.addActionListener(getAction(FILE_OPEN));
1011:
1012:                }
1013:                return openMenuItem;
1014:            }
1015:
1016:            /**
1017:             * This method initializes open menu item.
1018:             * 
1019:             * @return javax.swing.JMenuItem
1020:             */
1021:            private JMenuItem getOpenURLMenuItem() {
1022:                if (openUrlMenuItem == null) {
1023:                    openUrlMenuItem = new JMenuItem();
1024:                    openUrlMenuItem.setText(Messages
1025:                            .getString("ReportViewer.MENU.FILE.OPEN.URL")); //$NON-NLS-1$)
1026:                    openUrlMenuItem.addActionListener(getAction(FILE_OPEN_URL));
1027:                }
1028:                return openUrlMenuItem;
1029:            }
1030:
1031:            /**
1032:             * This method initializes open menu item.
1033:             * 
1034:             * @return javax.swing.JMenuItem
1035:             */
1036:            private JMenuItem getReloadMenuItem() {
1037:                if (reloadMenuItem == null) {
1038:                    reloadMenuItem = new JMenuItem();
1039:                    reloadMenuItem.setText(Messages
1040:                            .getString("ReportViewer.MENU.FILE.RELOAD")); //$NON-NLS-1$)
1041:                    reloadMenuItem
1042:                            .addActionListener(getAction(FILE_REFRESH_URL));
1043:                }
1044:                return reloadMenuItem;
1045:            }
1046:
1047:            /**
1048:             * open a report with dialog.
1049:             * 
1050:             */
1051:            private void openReport() {
1052:                JFileChooser chooser = new JFileChooser(new File("")
1053:                        .getAbsoluteFile());
1054:                chooser.addChoosableFileFilter(new FileFilter() {
1055:
1056:                    @Override
1057:                    public boolean accept(final File f) {
1058:                        if (f.isDirectory()) {
1059:                            return true;
1060:                        }
1061:                        return f.getName().toLowerCase().endsWith(".xml"); //$NON-NLS-1$
1062:                    }
1063:
1064:                    @Override
1065:                    public String getDescription() {
1066:                        // TODO Auto-generated method stub
1067:                        return Messages.getString("ReportViewer.XMLFILE"); //$NON-NLS-1$
1068:                    }
1069:
1070:                });
1071:                chooser.setMultiSelectionEnabled(false);
1072:                chooser.setDialogTitle(Messages
1073:                        .getString("ReportViewer.DIALOG.OPEN.TITLE")); //$NON-NLS-1$
1074:                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
1075:                if (chooser.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
1076:                    try {
1077:                        loadReport(chooser.getSelectedFile());
1078:                    } catch (IOException e) {
1079:                        e.printStackTrace();
1080:                    } catch (SAXException e) {
1081:                        e.printStackTrace();
1082:                    } catch (MeasurementException e) {
1083:                        e.printStackTrace();
1084:                    }
1085:                }
1086:            }
1087:
1088:            /**
1089:             * open a report with dialog.
1090:             * 
1091:             */
1092:            private void openReportURL() {
1093:                String value = "";
1094:                if (urllist.size() > 0) {
1095:                    value = urllist.get(urllist.size() - 1);
1096:                }
1097:                String urlString = (String) JOptionPane.showInputDialog(this ,
1098:                        Messages.getString("ReportViewer.URL.Text"), value); //$NON-NLS-1$
1099:                urlString = urlString.trim();
1100:                if (!urllist.contains(urlString)) {
1101:                    urllist.add(urlString);
1102:                }
1103:                try {
1104:                    URL tmpurl = new URL(urlString);
1105:                    loadReportFromURL(tmpurl);
1106:                    url = tmpurl;
1107:                } catch (Exception e) {
1108:                    url = null;
1109:                    showException(e);
1110:                }
1111:            }
1112:
1113:            /**
1114:             * loading the desired report.
1115:             * 
1116:             * @param reportData
1117:             *            the report file to load.
1118:             * @throws IOException
1119:             *             if something goes wrong.
1120:             * @throws SAXException
1121:             *             if something goes wrong.
1122:             * @throws MeasurementException
1123:             *             if something goes wrong.
1124:             */
1125:            private void loadReportFromStream(final InputStream reportData)
1126:                    throws IOException, SAXException, MeasurementException {
1127:                MeasureFactory.clear();
1128:                Runnable run = new Runnable() {
1129:
1130:                    public void run() {
1131:                        try {
1132:                            InputStream in = new BufferedInputStream(
1133:                                    new ProgressMonitorInputStream(
1134:                                            application,
1135:                                            Messages
1136:                                                    .getString("ReportViewer.Progress.Reading")
1137:                                                    + reportData, reportData)); //$NON-NLS-1$
1138:                            MeasureFactory.loadFromXMLStream(in, true);
1139:                            in.close();
1140:                            String[] snapshotNames = MeasureFactory
1141:                                    .getSnapShotNames();
1142:                            jcSnapShot.removeAllItems();
1143:                            for (int i = 0; i < snapshotNames.length; i++) {
1144:                                jcSnapShot.addItem(snapshotNames[i]);
1145:                            }
1146:                            jcSnapShot.insertItemAt("Main", 0);
1147:                            jcSnapShot.setSelectedIndex(0);
1148:                            model = new MeasureTableModel();
1149:                            if (null == tableModel) {
1150:                                tableModel = new TableSorter(model);
1151:                            } else {
1152:                                tableModel.setTableModel(model);
1153:                            }
1154:                            if (null != grid) {
1155:                                grid.setModel(tableModel);
1156:                                initGrid();
1157:                            }
1158:                            if (getFilter() != null) {
1159:                                model.setFilter(getFilter());
1160:                            }
1161:                            if (url != null) {
1162:                                jbRefresh.setEnabled(true);
1163:                            }
1164:                        } catch (Exception e) {
1165:                            showException(e);
1166:                        }
1167:                    }
1168:
1169:                };
1170:                Thread thread = new Thread(run);
1171:                thread.start();
1172:            }
1173:
1174:            /**
1175:             * loading the desired report.
1176:             * 
1177:             * @param reportData
1178:             *            the report file to load.
1179:             * @throws IOException
1180:             *             if something goes wrong.
1181:             * @throws SAXException
1182:             *             if something goes wrong.
1183:             * @throws MeasurementException
1184:             *             if something goes wrong.
1185:             */
1186:            private void loadReport(final File reportData) throws IOException,
1187:                    SAXException, MeasurementException {
1188:                loadReportFromStream(new FileInputStream(reportData));
1189:                this .setTitle(Messages
1190:                        .getString("ReportViewer.APPLICATION.TITLE") //$NON-NLS-1$
1191:                        + " - " + reportData.getName()); //$NON-NLS-1$
1192:            }
1193:
1194:            /**
1195:             * loading the report from a url.
1196:             * 
1197:             * @param aUrl
1198:             *            where to load the report from.
1199:             * @throws IOException
1200:             *             if something goes wrong
1201:             * @throws SAXException
1202:             *             if something goes wrong
1203:             * @throws MeasurementException
1204:             *             if something goes wrong
1205:             */
1206:            private void loadReportFromURL(final URL aUrl) throws IOException,
1207:                    SAXException, MeasurementException {
1208:                loadReportFromStream(aUrl.openStream());
1209:                this .setTitle(Messages
1210:                        .getString("ReportViewer.APPLICATION.TITLE") //$NON-NLS-1$
1211:                        + " - " + aUrl.toExternalForm()); //$NON-NLS-1$
1212:            }
1213:
1214:            /**
1215:             * initialise the grid.
1216:             */
1217:            private void initGrid() {
1218:                grid.doLayout();
1219:                grid.updateUI();
1220:                initColumnSizes(grid);
1221:                grid.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
1222:                tableModel.setTableHeader(grid.getTableHeader());
1223:            }
1224:
1225:            /**
1226:             * showing the point dialog for the point selected in the grid.
1227:             * 
1228:             */
1229:            private void showSelectedPoint() {
1230:                int rowpos = grid.getSelectedRow();
1231:                int colpos = 0;
1232:                for (int i = 0; i < grid.getColumnCount(); i++) {
1233:                    String headerName = (String) grid.getColumnName(i);
1234:                    if (headerName.equalsIgnoreCase("pointname")) {
1235:                        colpos = i;
1236:                        break;
1237:                    }
1238:                }
1239:                String pointName = (String) grid.getValueAt(rowpos, colpos);
1240:                MeasurePoint point = model.getMeasurePoint(pointName);
1241:                showPointData(point);
1242:            }
1243:
1244:            /**
1245:             * showing the dialog for a measure point. Restore the last position and
1246:             * size of this dialog.
1247:             * 
1248:             * @param point
1249:             *            the point to show.
1250:             */
1251:            private void showPointData(final MeasurePoint point) {
1252:                PointDataDialog pointDataDialog = new PointDataDialog(point);
1253:                pointDataDialog.setAlwaysOnTop(true);
1254:                pointDataDialog.setModal(true);
1255:                pointDataDialog.setSize(config.getPointDialogDimesions());
1256:                pointDataDialog.setLocation(config.getPointDialogLocation());
1257:
1258:                pointDataDialog.setVisible(true);
1259:                config.setPointDialogDimesions(pointDataDialog.getSize());
1260:                config.setPointDialogLocation(pointDataDialog.getLocation());
1261:                pointDataDialog.dispose();
1262:                System.out.println("hide it.");
1263:            }
1264:
1265:            /**
1266:             * doing the filter.
1267:             * 
1268:             */
1269:            private void doFilter() {
1270:                model.setFilter(getFilter());
1271:            }
1272:
1273:            /**
1274:             * @return string the filter string.
1275:             * 
1276:             */
1277:            private String getFilter() {
1278:                if (null == jcFilter) {
1279:                    return null;
1280:                }
1281:                return (String) jcFilter.getSelectedItem();
1282:            }
1283:
1284:            /**
1285:             * initilise the column width, default or from the configuration.
1286:             * 
1287:             * @param table
1288:             *            the table to use.
1289:             */
1290:            private void initColumnSizes(final JTable table) {
1291:                TableColumn column = null;
1292:                Component comp = null;
1293:                int headerWidth = 0;
1294:                int cellWidth = 0;
1295:                Object[] longValues = model.getLongValues();
1296:                TableCellRenderer headerRenderer = table.getTableHeader()
1297:                        .getDefaultRenderer();
1298:
1299:                int[] sizes = config.getColumnSizes();
1300:                for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
1301:                    column = table.getColumnModel().getColumn(i);
1302:                    try {
1303:                        if ((sizes == null) || (sizes.length <= i)
1304:                                || (sizes[i] == 0)) {
1305:                            comp = headerRenderer
1306:                                    .getTableCellRendererComponent(null, column
1307:                                            .getHeaderValue(), false, false, 0,
1308:                                            0);
1309:                            headerWidth = comp.getPreferredSize().width;
1310:
1311:                            comp = table.getDefaultRenderer(
1312:                                    model.getColumnClass(i))
1313:                                    .getTableCellRendererComponent(table,
1314:                                            longValues[i], false, false, 0, i);
1315:                            cellWidth = comp.getPreferredSize().width;
1316:
1317:                            column.setPreferredWidth(Math.max(headerWidth,
1318:                                    cellWidth));
1319:                        } else {
1320:                            column.setPreferredWidth(sizes[i]);
1321:                        }
1322:                    } catch (Exception e) {
1323:                        // nothing to do here.
1324:                    }
1325:                }
1326:                // : listener that watches the width of a column
1327:                PropertyChangeListener pcl = new PropertyChangeListener() {
1328:                    public void propertyChange(final PropertyChangeEvent evt) {
1329:                        if (evt.getPropertyName().equals("preferredWidth")) {
1330:                            saveColumnWidths();
1331:                        }
1332:                    }
1333:                };
1334:
1335:                // : add the column width lister to each column
1336:                for (Enumeration e = table.getColumnModel().getColumns(); e
1337:                        .hasMoreElements();) {
1338:                    TableColumn tc = (TableColumn) e.nextElement();
1339:                    tc.addPropertyChangeListener(pcl);
1340:                }
1341:            }
1342:
1343:            /**
1344:             * loading the configuration data from a config.xml file in the working
1345:             * directory.
1346:             * 
1347:             */
1348:            private void loadConfigurationData() {
1349:                if (config == null) {
1350:                    config = new StoreProperties();
1351:                }
1352:                File configFile = new File("config.xml"); //$NON-NLS-1$
1353:                if (configFile.exists()) {
1354:                    try {
1355:                        config.loadFromXML(new FileInputStream(configFile));
1356:                    } catch (InvalidPropertiesFormatException e) {
1357:                        // TODO Auto-generated catch block
1358:                        e.printStackTrace();
1359:                    } catch (FileNotFoundException e) {
1360:                        // TODO Auto-generated catch block
1361:                        e.printStackTrace();
1362:                    } catch (IOException e) {
1363:                        // TODO Auto-generated catch block
1364:                        e.printStackTrace();
1365:                    }
1366:                }
1367:                this .setSize(config.getWindowDimesions());
1368:                this .setLocation(config.getWindowLocation());
1369:                String[] urlValue = config.getUrlList();
1370:                if (urlValue != null) {
1371:                    urllist = new ArrayList<String>(Arrays.asList(urlValue));
1372:                }
1373:            }
1374:
1375:            /**
1376:             * saving the configuration data to a config.xml file in the working
1377:             * directory.
1378:             * 
1379:             */
1380:            private void saveConfigurationData() {
1381:                config.setWindowDimesions(this .getSize());
1382:                config.setWindowoLocation(this .getLocation());
1383:                String[] items = new String[jcFilter.getItemCount()];
1384:                for (int i = 0; i < jcFilter.getItemCount(); i++) {
1385:                    items[i] = (String) jcFilter.getItemAt(i);
1386:                }
1387:                config.setFilterItems(items);
1388:                config.setUrlList((String[]) urllist.toArray(new String[0]));
1389:                saveColumnWidths();
1390:                File configFile = new File("config.xml"); //$NON-NLS-1$
1391:                try {
1392:                    config.storeToXML(new FileOutputStream(configFile), ""); //$NON-NLS-1$
1393:                } catch (FileNotFoundException e) {
1394:                    // TODO Auto-generated catch block
1395:                    e.printStackTrace();
1396:                } catch (IOException e) {
1397:                    // TODO Auto-generated catch block
1398:                    e.printStackTrace();
1399:                }
1400:            }
1401:
1402:            /**
1403:             * saving the column width of the grid.
1404:             * 
1405:             */
1406:            private void saveColumnWidths() {
1407:                int[] colwidth = new int[grid.getColumnModel().getColumnCount()];
1408:                TableColumn column = null;
1409:                for (int i = 0; i < grid.getColumnModel().getColumnCount(); i++) {
1410:                    column = grid.getColumnModel().getColumn(i);
1411:                    colwidth[i] = column.getWidth();
1412:                }
1413:                config.setColumnSizes(colwidth);
1414:            }
1415:
1416:            /**
1417:             * showing an error dialog.
1418:             * 
1419:             * @param e
1420:             *            exception to show.
1421:             */
1422:            public final void showException(final Throwable e) {
1423:                IncidentInfo ii = new IncidentInfo(Messages
1424:                        .getString("ReportViewer.Error.Title"), //$NON-NLS-1$
1425:                        Messages.getString("ReportViewer.Error.Text"), null, e); //$NON-NLS-1$
1426:                JXErrorDialog.showDialog(null, ii);
1427:            }
1428:
1429:            /**
1430:             * exit this application.
1431:             * 
1432:             */
1433:            private void exit() {
1434:                System.exit(0);
1435:            }
1436:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.