org.adempiere.apps.graph package:

* BF [ 1874419 ] JDBC Statement not close in a finally block
* replace system.out with logging
* minor - HtmlDashboard: select only active PA_DASHBOARDCONTENT
* reorganized imports
* removed "TODO Auto-generated method stub"
This commit is contained in:
teo_sarca 2008-02-01 09:47:49 +00:00
parent 3d2bae2080
commit 53d68602fd
9 changed files with 135 additions and 150 deletions

View File

@ -16,31 +16,41 @@
*****************************************************************************/
package org.adempiere.apps.graph;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import java.util.logging.*;
import java.math.*;
import java.sql.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Point;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.logging.Level;
import org.compiere.apps.*;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
import org.compiere.apps.AEnv;
import org.compiere.model.MAchievement;
import org.compiere.model.MGoal;
import org.compiere.model.MMeasure;
import org.compiere.model.MMeasureCalc;
import org.compiere.model.MProjectType;
import org.compiere.model.MQuery;
import org.compiere.model.MRequestType;
import org.compiere.model.MRole;
import org.compiere.model.MStatus;
import org.compiere.swing.CPanel;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.CategoryItemEntity;
import org.jfree.chart.entity.ChartEntity;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultValueDataset;
/**
* Bar Graph
@ -120,10 +130,11 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
m_goal.getMeasureDisplay(), null,
MRole.getDefault()); // logged in role
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
ArrayList<Timestamp> dataList = new ArrayList<Timestamp>();
while (rs.next ())
{
@ -137,23 +148,15 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
dataList.add(date); // list of dates
list.add(pos, bgc);
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
try
finally
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
}
else if (MMeasure.MEASURETYPE_Achievements.equals(measure.getMeasureType()))
@ -188,11 +191,12 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
.append("GROUP BY ").append(trunc)
.append(" ORDER BY ").append(trunc);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql.toString(), null);
pstmt.setInt(1, measure.getPA_Measure_ID());
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
while (rs.next ())
{
BigDecimal data = rs.getBigDecimal(1);
@ -201,23 +205,15 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
bgc.setLabel(date, m_goal.getMeasureDisplay());
list.add(bgc);
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql.toString(), e);
}
try
finally
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
} // Achievement in time
} // Achievement
@ -230,10 +226,11 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
m_goal.getMeasureDisplay(), measure.getMeasureDataType(),
null, MRole.getDefault()); // logged in role
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
while (rs.next ())
{
BigDecimal data = rs.getBigDecimal(1);
@ -251,23 +248,15 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
}
list.add(bgc);
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
try
finally
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
} // Request
@ -279,10 +268,11 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
m_goal.getMeasureDisplay(), measure.getMeasureDataType(),
null, MRole.getDefault()); // logged in role
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery ();
rs = pstmt.executeQuery ();
while (rs.next ())
{
BigDecimal data = rs.getBigDecimal(1);
@ -292,23 +282,15 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
bgc.setLabel(date, m_goal.getMeasureDisplay());
list.add(bgc);
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
try
finally
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
} // Project
@ -496,15 +478,10 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
/*
public void componentHidden(ComponentEvent e) {
// TODO Auto-generated method stub
}
public void componentMoved(ComponentEvent e) {
// TODO Auto-generated method stub
}
public void componentResized(ComponentEvent e) {
// TODO Auto-generated method stub
float aspectRatio = 1.6f;
Dimension size = getSize();
if (size.width > size.height * aspectRatio)
@ -517,7 +494,6 @@ public class BarGraph extends CPanel implements ChartMouseListener //, Component
java.lang.Math.round(size.width / aspectRatio)));
}
public void componentShown(ComponentEvent e) {
// TODO Auto-generated method stub
}
*/
} // BarGraph

View File

@ -372,7 +372,7 @@ public class BarGraphColumn extends JComponent implements MouseListener
g2D.setColor(getBackground());
//Dimension size = getPreferredSize();
Dimension size =getSize();
System.out.println("bgc: " + size.width + " x " + size.height);
log.fine("bgc: " + size.width + " x " + size.height);
g2D.fill3DRect(0, 0, size.width, size.height, true);
// Paint Label & Value

View File

@ -16,10 +16,15 @@
*****************************************************************************/
package org.adempiere.apps.graph;
import java.awt.*;
import java.util.*;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.LayoutManager;
import java.awt.Point;
import java.util.ArrayList;
import org.compiere.util.*;
import org.compiere.util.CLogger;
/**
* Bar Graph Layout
@ -117,7 +122,7 @@ public class BarGraphLayout
//
//Dimension size = m_parent.getPreferredSize();
Dimension size =m_parent.getSize();
System.out.println("bgl: " +size.width + " x " + size.height);
log.fine("bgl: " +size.width + " x " + size.height);
Point point0_0 = m_parent.getPoint0_0();

View File

@ -1,13 +1,16 @@
package org.adempiere.apps.graph;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.image.*;
import java.net.MalformedURLException;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import java.sql.SQLException;
import javax.swing.ImageIcon;
import javax.swing.text.Element;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.ImageView;
public class FCHtmlEditorKit extends HTMLEditorKit {
public ViewFactory getViewFactory() {

View File

@ -16,9 +16,10 @@
*****************************************************************************/
package org.adempiere.apps.graph;
import java.awt.*;
import java.util.*;
import org.compiere.util.*;
import java.awt.Color;
import java.util.ArrayList;
import org.compiere.util.CLogger;
/**
* Graphic Utilities

View File

@ -3,10 +3,6 @@
*/
package org.adempiere.apps.graph;
import javax.swing.JPanel;
import javax.swing.event.*;
import javax.swing.text.Document;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
@ -19,19 +15,25 @@ import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.Document;
import org.compiere.apps.AEnv;
import org.compiere.apps.AWindow;
import org.compiere.model.MAchievement;
import org.compiere.model.MGoal;
import org.compiere.model.MMeasureCalc;
@ -46,9 +48,6 @@ import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Msg;
import org.compiere.apps.AEnv;
import org.compiere.apps.AWindow;
/**
* @author fcsku
*
@ -119,8 +118,7 @@ public class HtmlDashboard extends JPanel implements MouseListener,
while ((cssLine = bufferedReader.readLine()) != null)
result += cssLine + "\n";
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
log.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
}
//System.out.println(result);
switch (requestPage) {
@ -142,13 +140,15 @@ public class HtmlDashboard extends JPanel implements MouseListener,
String sql = " SELECT x.AD_CLIENT_ID, x.NAME, x.DESCRIPTION, x.AD_WINDOW_ID, x.PA_GOAL_ID, x.LINE, x.HTML, m.AD_MENU_ID"
+ " FROM PA_DASHBOARDCONTENT x"
+ " LEFT OUTER JOIN AD_MENU m ON x.ad_window_id=m.ad_window_id"
+ " WHERE x.AD_Client_ID=0 OR x.AD_Client_ID=?"
+ " WHERE (x.AD_Client_ID=0 OR x.AD_Client_ID=?) AND x.IsActive='Y'"
+ " ORDER BY LINE";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
ResultSet rs = pstmt.executeQuery();
rs = pstmt.executeQuery();
while (rs.next()) {
appendToHome = rs.getString("HTML");
if (appendToHome != null) {
@ -170,20 +170,22 @@ public class HtmlDashboard extends JPanel implements MouseListener,
result += goalsDetail(rs.getInt("PA_GOAL_ID"));
//result += goalsDetail(rs.getInt("AD_TABLE_ID"));
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
System.out.println("dashboard: " + e); //TODO catch-block
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
result += "<br><br><br>\n"
+ "</div>\n</body>\n</html>\n";
break;
break;
default: //**************************************************************
System.out.println("error");
log.warning("Unknown option - "+requestPage);
}
//System.out.println(result);
return result;
}
@ -286,7 +288,7 @@ public class HtmlDashboard extends JPanel implements MouseListener,
try {
htmlUpdate( new URL( url ) );
} catch( MalformedURLException e ) {
System.out.println( "Malformed URL: " + e );
log.warning("Malformed URL: " + e );
}
}
@ -361,7 +363,6 @@ public class HtmlDashboard extends JPanel implements MouseListener,
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if (SwingUtilities.isRightMouseButton(e))
popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
}
@ -370,38 +371,30 @@ public class HtmlDashboard extends JPanel implements MouseListener,
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
*/
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
*/
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
*/
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
*/
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == mRefresh)
{
if (m_goals != null)

View File

@ -18,13 +18,17 @@ package org.adempiere.apps.graph;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.Box;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
import org.compiere.model.MGoal;
import org.compiere.swing.CPanel;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
/**
* Performance Analysis Panel.

View File

@ -16,13 +16,15 @@
*****************************************************************************/
package org.adempiere.apps.graph;
import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.compiere.*;
import org.compiere.apps.*;
import org.compiere.swing.*;
import org.compiere.model.*;
import org.compiere.Adempiere;
import org.compiere.apps.AEnv;
import org.compiere.apps.ConfirmPanel;
import org.compiere.model.MGoal;
import org.compiere.swing.CFrame;
/**

View File

@ -16,39 +16,40 @@
*****************************************************************************/
package org.adempiere.apps.graph;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
//vpj-cd e-evolution
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
//import java.awt.R`;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.event.EventListenerList;
import org.compiere.model.MColorSchema;
import org.compiere.model.MGoal;
import org.compiere.swing.CMenuItem;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.*;
import org.jfree.data.general.*;
import org.jfree.chart.plot.DialShape;
import org.jfree.chart.plot.MeterInterval;
import org.jfree.chart.plot.MeterPlot;
import org.jfree.data.Range;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.RectangleInsets;
//vpj-cd e-evolution
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
import org.compiere.apps.graph.*;
import java.net.*;
import java.io.*;
import org.jfree.chart.ChartUtilities;
/**
* Performance Indicator