001: /*
002: * Copyright (C) Jahia Ltd. All rights reserved.
003: *
004: * This software is published under the terms of the Jahia Open Software
005: * License version 1.1, a copy of which has been included with this
006: * distribution in the LICENSE.txt file.
007: */
008: package org.jahia.sqlprofiler.gui;
009:
010: import java.awt.*;
011: import javax.swing.JPanel;
012: import javax.swing.JToolBar;
013: import javax.swing.JButton;
014: import javax.swing.Icon;
015: import javax.swing.ImageIcon;
016: import javax.swing.JFileChooser;
017: import java.net.URL;
018: import java.io.InputStream;
019: import java.io.IOException;
020: import java.awt.event.ActionListener;
021: import java.awt.event.ActionEvent;
022:
023: /**
024: * <p>Title: SQL Profiler</p>
025: * <p>Description: </p>
026: * <p>Copyright: Copyright (c) 2003</p>
027: * <p>Company: Jahia Ltd</p>
028: * @author Serge Huber
029: * @author Jean-Philippe Valentin
030: * @version 1.0
031: *
032: * 11/14/2003 : Add button to save table profile statistics as report file CSV by Jean-Philippe VALENTIN (JPV)
033: */
034:
035: public class ToolbarPanel extends JPanel {
036: private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger
037: .getLogger(ToolbarPanel.class);
038:
039: BorderLayout borderLayout1 = new BorderLayout();
040:
041: private JButton playButton;
042: private JButton pauseButton;
043: private JButton reportButton; //jpv : Add a button to save SQL table profile statistics generated in a file
044: private boolean playing = true;
045:
046: private LoggerTableModel loggerModel;
047: private ProfileStatementTableModel profileStatementTableModel;
048:
049: public ToolbarPanel(LoggerTableModel loggerModel,
050: ProfileStatementTableModel profileStatementTableModel) {
051: this .loggerModel = loggerModel;
052: this .profileStatementTableModel = profileStatementTableModel;
053: try {
054: jbInit();
055: } catch (Exception ex) {
056: ex.printStackTrace();
057: }
058: }
059:
060: void jbInit() throws Exception {
061: this .setLayout(borderLayout1);
062: JToolBar toolbar = new JToolBar();
063: java.net.URL saveAsIconURL = ClassLoader
064: .getSystemResource("toolbarButtonGraphics/general/SaveAs16.gif");
065: Icon saveAsIcon = new ImageIcon(saveAsIconURL, "Save As");
066: JButton myButton = new JButton(saveAsIcon);
067: myButton
068: .setToolTipText("Save the generated SQL INDEX File as...");
069: myButton.addActionListener(new ActionListener() {
070: public void actionPerformed(ActionEvent aEvent) {
071: JFileChooser chooser = new JFileChooser();
072: // Note: source for ExampleFileFilter can be found in FileChooserDemo,
073: // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
074: chooser.setDialogTitle("Save Index SQL File As...");
075: int returnVal = chooser.showSaveDialog(null);
076: if (returnVal == JFileChooser.APPROVE_OPTION) {
077: profileStatementTableModel.saveSQLIndexFile(chooser
078: .getSelectedFile().toString());
079: }
080: }
081: });
082: toolbar.add(myButton);
083: toolbar.addSeparator();
084: java.net.URL clearIconURL = ClassLoader
085: .getSystemResource("toolbarButtonGraphics/general/Delete16.gif");
086: Icon clearIcon = new ImageIcon(clearIconURL, "Clear");
087: myButton = new JButton(clearIcon);
088: myButton
089: .setToolTipText("Clear all the log entries from memory");
090: myButton.addActionListener(new ActionListener() {
091: public void actionPerformed(ActionEvent aEvent) {
092: loggerModel.clear();
093: }
094: });
095: toolbar.add(myButton);
096: toolbar.addSeparator();
097: java.net.URL playIconURL = ClassLoader
098: .getSystemResource("toolbarButtonGraphics/media/Play16.gif");
099: Icon playIcon = new ImageIcon(playIconURL, "Play");
100: playButton = new JButton(playIcon);
101: playButton.setEnabled(false);
102: playButton
103: .setToolTipText("Resume real-time display and gather SQL statistics");
104: playButton.addActionListener(new ActionListener() {
105: public void actionPerformed(ActionEvent aEvent) {
106: loggerModel.toggle();
107: togglePlayButtons();
108: }
109: });
110: toolbar.add(playButton);
111: java.net.URL pauseIconURL = ClassLoader
112: .getSystemResource("toolbarButtonGraphics/media/Pause16.gif");
113: Icon pauseIcon = new ImageIcon(pauseIconURL, "Pause");
114: pauseButton = new JButton(pauseIcon);
115: pauseButton
116: .setToolTipText("Pause real-time display and display SQL table profile statistics");
117: pauseButton.addActionListener(new ActionListener() {
118: public void actionPerformed(ActionEvent aEvent) {
119: loggerModel.toggle();
120: togglePlayButtons();
121: }
122: });
123: toolbar.add(pauseButton);
124: // JPV Add a button to save SQL table profile statistics generated in a file
125: java.net.URL reportIconURL = ClassLoader
126: .getSystemResource("toolbarButtonGraphics/general/Edit16.gif");
127: Icon reportIcon = new ImageIcon(reportIconURL, "Report");
128: reportButton = new JButton(reportIcon);
129: reportButton.setEnabled(false);
130: reportButton
131: .setToolTipText("Save SQL table profile statistics generated in a file ...");
132: reportButton.addActionListener(new ActionListener() {
133: public void actionPerformed(ActionEvent aEvent) {
134: JFileChooser chooser = new JFileChooser();
135: // Note: source for ExampleFileFilter can be found in FileChooserDemo,
136: // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
137: chooser.setDialogTitle("Save Report File As...");
138: int returnVal = chooser.showSaveDialog(null);
139: if (returnVal == JFileChooser.APPROVE_OPTION) {
140: profileStatementTableModel.saveReportFile(chooser
141: .getSelectedFile().toString());
142: }
143: }
144: });
145: toolbar.addSeparator();
146: toolbar.add(reportButton);
147: //End JPV
148: add(toolbar, BorderLayout.NORTH);
149: }
150:
151: public void togglePlayButtons() {
152: playing = !playing;
153: if (playing) {
154: playButton.setEnabled(false);
155: pauseButton.setEnabled(true);
156: reportButton.setEnabled(false); //JPV : set to false the button to save SQL table profile statistics generated in a file
157: } else {
158: playButton.setEnabled(true);
159: pauseButton.setEnabled(false);
160: reportButton.setEnabled(true); //JPV : set to true the button to save SQL table profile statistics generated in a file
161: }
162: }
163:
164: }
|