[ FeatureRequests-1731662 ] Performance Dashboard Update Mechanism. Also did some cleanup.

This commit is contained in:
bmovaqar 2007-06-05 21:08:42 +00:00
parent d29162a086
commit 95d8e5ed95
2 changed files with 495 additions and 427 deletions

View File

@ -1,96 +1,166 @@
/****************************************************************************** /**********************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * This file is part of Adempiere ERP Bazaar *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * http://www.adempiere.org *
* This program is free software; you can redistribute it and/or modify it * * *
* under the terms version 2 of the GNU General Public License as published * * Copyright (C) 1999 - 2006 Compiere Inc. *
* by the Free Software Foundation. This program is distributed in the hope * * Copyright (C) Contributors *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This program is free software; you can redistribute it and/or *
* See the GNU General Public License for more details. * * modify it under the terms of the GNU General Public License *
* You should have received a copy of the GNU General Public License along * * as published by the Free Software Foundation; either version 2 *
* with this program; if not, write to the Free Software Foundation, Inc., * * of the License, or (at your option) any later version. *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * *
* For the text or an alternative of this public license, you may reach us * * This program is distributed in the hope that it will be useful, *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* or via info@compiere.org or http://www.compiere.org/license.html * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
*****************************************************************************/ * GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Bahman Movaqar (bmovaqar@users.sf.net) *
**********************************************************************/
package org.compiere.apps.graph; package org.compiere.apps.graph;
import java.awt.event.*; import java.awt.Component;
import javax.swing.*; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import org.compiere.model.*; import javax.swing.JPopupMenu;
import org.compiere.swing.*; import javax.swing.SwingUtilities;
import org.compiere.util.*;
import org.compiere.model.MGoal;
import org.compiere.swing.CMenuItem;
import org.compiere.swing.CPanel;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
/** /**
* Performance Analysis Panel. * Performance Analysis Panel. Key Performace Indicators
* Key Performace Indicators *
* * @author Jorg Janke
* @author Jorg Janke * @version $Id: PAPanel.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
* @version $Id: PAPanel.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
*/ */
public class PAPanel extends CPanel implements ActionListener public class PAPanel extends CPanel implements MouseListener, ActionListener {
{
/** /**
* Get Panel if User has Perfpormance Goals * Serial version UID
* @return panel pr null
*/ */
public static PAPanel get() private static final long serialVersionUID = 900002328486L;
{
/**
* Get Panel if User has Perfpormance Goals
*
* @return panel pr null
*/
public static PAPanel get() {
int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
MGoal[] goals = MGoal.getUserGoals(Env.getCtx(), AD_User_ID); MGoal[] goals = MGoal.getUserGoals(Env.getCtx(), AD_User_ID);
if (goals.length == 0) if (goals.length == 0)
return null; return null;
return new PAPanel(goals); return new PAPanel(goals);
} // get } // get
/***************************************************************************
/************************************************************************** * Constructor
* Constructor *
* @param goals * @param goals
*/ */
private PAPanel (MGoal[] goals) private PAPanel(MGoal[] goals) {
{ super();
super ();
m_goals = goals; m_goals = goals;
init(); init();
} // PAPanel } // PAPanel
/** Goals */ /** Goals */
private MGoal[] m_goals = null; private MGoal[] m_goals = null;
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger (PAPanel.class); private static CLogger log = CLogger.getCLogger(PAPanel.class);
/** /** Popup menu */
* Static/Dynamic Init JPopupMenu pmenu = new JPopupMenu();
*/
private void init() /** Update menu item */
{ CMenuItem menuUpdate = new CMenuItem();
BoxLayout layout = new BoxLayout(this, BoxLayout.PAGE_AXIS);
for (int i = 0; i < m_goals.length; i++)
{
PerformanceIndicator pi = new PerformanceIndicator(m_goals[i]);
pi.addActionListener(this);
add (pi);
}
} // init
/** /**
* Action Listener for Drill Down * Static/Dynamic Init
* @param e event
*/ */
public void actionPerformed (ActionEvent e) private void init() {
{ for (int i = 0; i < m_goals.length; i++) {
if (e.getSource() instanceof PerformanceIndicator) PerformanceIndicator pi = new PerformanceIndicator(m_goals[i]);
{ pi.addActionListener(this);
PerformanceIndicator pi = (PerformanceIndicator)e.getSource(); add(pi);
}
// Setup the popup menu
menuUpdate.setText("Update Indicators");
menuUpdate.setActionCommand("update");
menuUpdate.addActionListener(this);
pmenu.setLightWeightPopupEnabled(false);
pmenu.add(menuUpdate);
this.addMouseListener(this);
} // init
/**
* Action Listener for Drill Down
*
* @param e
* event
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof PerformanceIndicator) {
PerformanceIndicator pi = (PerformanceIndicator) e.getSource();
log.info(pi.getName()); log.info(pi.getName());
MGoal goal = pi.getGoal(); MGoal goal = pi.getGoal();
if (goal.getMeasure() != null) if (goal.getMeasure() != null)
new PerformanceDetail(goal); new PerformanceDetail(goal);
} } else if (e.getActionCommand().equals("update"))
} // actionPerformed updateInidcators();
} // actionPerformed
} // PAPanel /**
* Updates indicators.
*/
private void updateInidcators() {
for (int i = 0; i < m_goals.length; i++) {
log.info("Updating indicator \"" + m_goals[i].getName() + "\"...");
remove(i);
PerformanceIndicator pi = new PerformanceIndicator(m_goals[i]);
pi.addActionListener(this);
add(pi, i);
log.info("done.");
}
} // updateIndicators
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e))
pmenu.show((Component) e.getSource(), e.getX(), e.getY());
}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
} // PAPanel

View File

@ -1,446 +1,444 @@
/****************************************************************************** /**********************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * This file is part of Adempiere ERP Bazaar *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * http://www.adempiere.org *
* This program is free software; you can redistribute it and/or modify it * * *
* under the terms version 2 of the GNU General Public License as published * * Copyright (C) 1999 - 2006 Compiere Inc. *
* by the Free Software Foundation. This program is distributed in the hope * * Copyright (C) Contributors *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This program is free software; you can redistribute it and/or *
* See the GNU General Public License for more details. * * modify it under the terms of the GNU General Public License *
* You should have received a copy of the GNU General Public License along * * as published by the Free Software Foundation; either version 2 *
* with this program; if not, write to the Free Software Foundation, Inc., * * of the License, or (at your option) any later version. *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * *
* For the text or an alternative of this public license, you may reach us * * This program is distributed in the hope that it will be useful, *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* or via info@compiere.org or http://www.compiere.org/license.html * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
*****************************************************************************/ * GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Bahman Movaqar (bmovaqar@users.sf.net) *
**********************************************************************/
package org.compiere.apps.graph; package org.compiere.apps.graph;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
//vpj-cd e-evolution
import java.awt.Color; 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.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.Font; import java.awt.event.MouseEvent;
//import java.awt.R`; 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.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.ChartPanel;
import org.jfree.chart.JFreeChart; import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.*; import org.jfree.chart.plot.DialShape;
import org.jfree.data.general.*; import org.jfree.chart.plot.MeterInterval;
import org.jfree.chart.plot.MeterPlot;
import org.jfree.data.Range; import org.jfree.data.Range;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.RectangleInsets; import org.jfree.ui.RectangleInsets;
//vpj-cd e-evolution
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/** /**
* Performance Indicator * Performance Indicator
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: PerformanceIndicator.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ * @version $Id: PerformanceIndicator.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
*/ */
//vpj-cd e-evolution public class PerformanceIndicator extends JComponent // vpj-cd e-evolution public class PerformanceIndicator extends JComponent
public class PerformanceIndicator extends JPanel public class PerformanceIndicator extends JPanel implements MouseListener,
implements MouseListener, ActionListener ActionListener {
{
/** /**
* Constructor * Serial version UID
* @param goal goal model
*/ */
public PerformanceIndicator(MGoal goal) private static final long serialVersionUID = -3988387418888L;
{
/**
* Constructor
*
* @param goal
* goal model
*/
public PerformanceIndicator(MGoal goal) {
super(); super();
m_goal = goal; m_goal = goal;
setName(m_goal.getName()); setName(m_goal.getName());
//vpj-cd e-evolution getPreferredSize(); // calculate size // vpj-cd e-evolution getPreferredSize(); // calculate size
init(); init();
// //
setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
setOpaque(true); setOpaque(true);
//vpj-cd e-evolution updateDisplay(); // vpj-cd e-evolution updateDisplay();
// //
mRefresh.addActionListener(this); mRefresh.addActionListener(this);
popupMenu.add(mRefresh); popupMenu.add(mRefresh);
// //
addMouseListener(this); addMouseListener(this);
} // PerformanceIndicator } // PerformanceIndicator
private MGoal m_goal = null; private MGoal m_goal = null;
/** The Performance Name */
private String m_text = null;
/** Performance Line */
private double m_line = 0;
/** Height */
private static double s_height = 45;
/** 100% width */
private static double s_width100 = 150;
/** Max width */
private static double s_widthMax = 250;
/** Integer Number Format */
private static DecimalFormat s_format = DisplayType.getNumberFormat(DisplayType.Integer);
JPopupMenu popupMenu = new JPopupMenu(); /** The Performance Name */
private CMenuItem mRefresh = new CMenuItem(Msg.getMsg(Env.getCtx(), "Refresh"), Env.getImageIcon("Refresh16.gif")); private String m_text = null;
//Insert Pie Graph Kinamo (pelgrim) /** Performance Line */
private static Color colorOK = Color.magenta; private double m_line = 0;
private static Color colorNotOK = Color.lightGray;
//private static Dimension indicatordimension = new Dimension(150, 150); /** Height */
private static Dimension indicatordimension = new Dimension(190,130); private static double s_height = 45;
private static Dimension paneldimension = new Dimension(200, 200);
//private static Dimension /** 100% width */
private static double s_width100 = 150;
/** Max width */
private static double s_widthMax = 250;
/** Integer Number Format */
private static DecimalFormat s_format = DisplayType
.getNumberFormat(DisplayType.Integer);
JPopupMenu popupMenu = new JPopupMenu();
private CMenuItem mRefresh = new CMenuItem(Msg.getMsg(Env.getCtx(),
"Refresh"), Env.getImageIcon("Refresh16.gif"));
// Insert Pie Graph Kinamo (pelgrim)
private static Color colorOK = Color.magenta;
private static Color colorNotOK = Color.lightGray;
// private static Dimension indicatordimension = new Dimension(150, 150);
private static Dimension indicatordimension = new Dimension(190, 130);
private static Dimension paneldimension = new Dimension(200, 200);
// private static Dimension
/** /**
* Get Goal * Get Goal
* @return goal *
* @return goal
*/ */
public MGoal getGoal() public MGoal getGoal() {
{
return m_goal; return m_goal;
} // getGoal } // getGoal
/** /**
* Init Graph Display * Init Graph Display Kinamo (pelgrim)
* Kinamo (pelgrim)
*/ */
private void init() { private void init() {
// Set Text // Set Text
StringBuffer text = new StringBuffer(m_goal.getName()); StringBuffer text = new StringBuffer(m_goal.getName());
if (m_goal.isTarget()) if (m_goal.isTarget())
text.append(": ").append(m_goal.getPercent()).append("%"); text.append(": ").append(m_goal.getPercent()).append("%");
else else
text.append(": ").append(s_format.format(m_goal.getMeasureActual())); text.append(": ")
.append(s_format.format(m_goal.getMeasureActual()));
m_text = text.toString(); m_text = text.toString();
// ToolTip // ToolTip
text = new StringBuffer(); text = new StringBuffer();
if (m_goal.getDescription() != null) if (m_goal.getDescription() != null)
text.append(m_goal.getDescription()).append(": "); text.append(m_goal.getDescription()).append(": ");
text.append(s_format.format(m_goal.getMeasureActual())); text.append(s_format.format(m_goal.getMeasureActual()));
if (m_goal.isTarget()) if (m_goal.isTarget())
text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ") text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ")
.append(s_format.format(m_goal.getMeasureTarget())); .append(s_format.format(m_goal.getMeasureTarget()));
setToolTipText(text.toString()); setToolTipText(text.toString());
// //
setBackground(m_goal.getColor()); setBackground(m_goal.getColor());
setForeground(GraphUtil.getForeground(getBackground())); setForeground(GraphUtil.getForeground(getBackground()));
// Performance Line // Performance Line
int percent = m_goal.getPercent(); int percent = m_goal.getPercent();
if (percent > 100) // draw 100% line if (percent > 100) // draw 100% line
m_line = s_width100; m_line = s_width100;
else // draw Performance Line else
// draw Performance Line
m_line = s_width100 * m_goal.getGoalPerformanceDouble(); m_line = s_width100 * m_goal.getGoalPerformanceDouble();
//vpj-cd e-evolution Plot Meter -----------------------------------
JFreeChart chart = null;
String title = m_text; // vpj-cd e-evolution Plot Meter -----------------------------------
DefaultValueDataset data = new DefaultValueDataset((float)m_goal.getPercent()); JFreeChart chart = null;
MeterPlot plot = new MeterPlot(data);
plot.addInterval(new MeterInterval("Normal", new Range(0.0, 100.0)));
plot.setUnits(m_goal.getName()); String title = m_text;
plot.setRange(new Range(0, 100)); DefaultValueDataset data = new DefaultValueDataset((float) m_goal
plot.setDialShape(DialShape.CIRCLE); .getPercent());
plot.setDialBackgroundPaint(m_goal.getColor()); MeterPlot plot = new MeterPlot(data);
plot.setNeedlePaint(Color.white); plot.addInterval(new MeterInterval("Normal", new Range(0.0, 100.0)));
plot.setTickSize(10);
plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8));
plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
plot.setUnits(m_goal.getName());
plot.setRange(new Range(0, 100));
plot.setDialShape(DialShape.CIRCLE);
plot.setDialBackgroundPaint(m_goal.getColor());
plot.setNeedlePaint(Color.white);
plot.setTickSize(10);
plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8));
plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
chart = new JFreeChart( m_text, new Font("SansSerif", Font.BOLD, 12), plot,false); chart = new JFreeChart(m_text, new Font("SansSerif", Font.BOLD, 12),
//chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.ORANGE)); plot, false);
ChartPanel chartPanel = new ChartPanel(chart); // chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0,
chartPanel.setPreferredSize(indicatordimension); // 1000, Color.ORANGE));
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(indicatordimension);
chartPanel.addChartMouseListener( new org.jfree.chart.ChartMouseListener() chartPanel
{ .addChartMouseListener(new org.jfree.chart.ChartMouseListener() {
public void chartMouseClicked(org.jfree.chart.ChartMouseEvent e) public void chartMouseClicked(
{ org.jfree.chart.ChartMouseEvent e) {
//plot p = (MeterPlot) e.getSource(); // plot p = (MeterPlot) e.getSource();
MouseEvent me = e.getTrigger(); MouseEvent me = e.getTrigger();
if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() > 1) if (SwingUtilities.isLeftMouseButton(me)
fireActionPerformed(me); && me.getClickCount() > 1)
if (SwingUtilities.isRightMouseButton(me)) fireActionPerformed(me);
popupMenu.show((Component)me.getSource(), me.getX(), me.getY()); // if (SwingUtilities.isRightMouseButton(me))
} // popupMenu.show((Component)me.getSource(), me.getX(),
public void chartMouseMoved(org.jfree.chart.ChartMouseEvent e) // me.getY());
{ }
} public void chartMouseMoved(
org.jfree.chart.ChartMouseEvent e) {
}); }
this.add(chartPanel, BorderLayout.NORTH); });
//---------------------------------------------
this.add(chartPanel, BorderLayout.NORTH);
invalidate(); // ---------------------------------------------
invalidate();
} }
/** /**
* Update Display Data * Update Display Data
*/ */
protected void updateDisplay() protected void updateDisplay() {
{ // Set Text
// Set Text /*
/*begin vpj-cd e-evolution * begin vpj-cd e-evolution StringBuffer text = new
StringBuffer text = new StringBuffer(m_goal.getName()); * StringBuffer(m_goal.getName()); if (m_goal.isTarget()) text.append(":
if (m_goal.isTarget()) * ").append(m_goal.getPercent()).append("%"); else text.append(":
text.append(": ").append(m_goal.getPercent()).append("%"); * ").append(s_format.format(m_goal.getMeasureActual())); m_text =
else * text.toString(); // ToolTip text = new StringBuffer(); if
text.append(": ").append(s_format.format(m_goal.getMeasureActual())); * (m_goal.getDescription() != null)
m_text = text.toString(); * text.append(m_goal.getDescription()).append(": ");
// ToolTip * text.append(s_format.format(m_goal.getMeasureActual())); if
text = new StringBuffer(); * (m_goal.isTarget()) text.append(" ").append(Msg.getMsg(Env.getCtx(),
if (m_goal.getDescription() != null) * "of")).append(" ")
text.append(m_goal.getDescription()).append(": "); * .append(s_format.format(m_goal.getMeasureTarget()));
text.append(s_format.format(m_goal.getMeasureActual())); * setToolTipText(text.toString()); // setBackground(m_goal.getColor());
if (m_goal.isTarget()) * setForeground(GraphUtil.getForeground(getBackground())); //
text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ") * Performance Line int percent = m_goal.getPercent(); if (percent >
.append(s_format.format(m_goal.getMeasureTarget())); * 100) // draw 100% line m_line = s_width100; else // draw Performance
setToolTipText(text.toString()); * Line m_line = s_width100 * m_goal.getGoalPerformanceDouble();
// */
setBackground(m_goal.getColor()); JFreeChart chart = null;
setForeground(GraphUtil.getForeground(getBackground()));
// Performance Line
int percent = m_goal.getPercent();
if (percent > 100) // draw 100% line
m_line = s_width100;
else // draw Performance Line
m_line = s_width100 * m_goal.getGoalPerformanceDouble();
*/
JFreeChart chart = null;
String title = m_text; String title = m_text;
DefaultValueDataset data = new DefaultValueDataset((float)m_goal.getPercent()); DefaultValueDataset data = new DefaultValueDataset((float) m_goal
MeterPlot plot = new MeterPlot(data); .getPercent());
plot.addInterval(new MeterInterval("Normal", new Range(0.0, 100.0))); MeterPlot plot = new MeterPlot(data);
plot.addInterval(new MeterInterval("Normal", new Range(0.0, 100.0)));
plot.setUnits(m_goal.getName()); plot.setUnits(m_goal.getName());
plot.setRange(new Range(0, 100)); plot.setRange(new Range(0, 100));
plot.setDialShape(DialShape.CIRCLE); plot.setDialShape(DialShape.CIRCLE);
plot.setDialBackgroundPaint(m_goal.getColor()); plot.setDialBackgroundPaint(m_goal.getColor());
plot.setNeedlePaint(Color.white); plot.setNeedlePaint(Color.white);
plot.setTickSize(10); plot.setTickSize(10);
plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8)); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8));
plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
chart = new JFreeChart(m_text, new Font("SansSerif", Font.BOLD, 12),
plot, false);
// chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0,
// 1000, Color.ORANGE));
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(indicatordimension);
chart = new JFreeChart( m_text, new Font("SansSerif", Font.BOLD, 12), plot,false); chartPanel
//chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.ORANGE)); .addChartMouseListener(new org.jfree.chart.ChartMouseListener() {
ChartPanel chartPanel = new ChartPanel(chart); public void chartMouseClicked(
chartPanel.setPreferredSize(indicatordimension); org.jfree.chart.ChartMouseEvent e) {
// plot p = (MeterPlot) e.getSource();
System.out.println("evento" + e.getSource());
System.out.println("evento" + e.getTrigger());
System.out.println("evento" + e.getChart().getTitle());
chartPanel.addChartMouseListener( new org.jfree.chart.ChartMouseListener() MouseEvent me = e.getTrigger();
{
public void chartMouseClicked(org.jfree.chart.ChartMouseEvent e)
{
//plot p = (MeterPlot) e.getSource();
System.out.println("evento" + e.getSource());
System.out.println("evento" + e.getTrigger());
System.out.println("evento" + e.getChart().getTitle());
MouseEvent me = e.getTrigger(); if (SwingUtilities.isLeftMouseButton(me)
&& me.getClickCount() > 1)
fireActionPerformed(me);
if (SwingUtilities.isRightMouseButton(me))
popupMenu.show((Component) me.getSource(), me
.getX(), me.getY());
}
if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() > 1) public void chartMouseMoved(
fireActionPerformed(me); org.jfree.chart.ChartMouseEvent e) {
if (SwingUtilities.isRightMouseButton(me))
popupMenu.show((Component)me.getSource(), me.getX(), me.getY());
}
public void chartMouseMoved(org.jfree.chart.ChartMouseEvent e)
{
} }
}); });
this.add(chartPanel, BorderLayout.NORTH); this.add(chartPanel, BorderLayout.NORTH);
// vpj-cd e-evolution getPreferredSize(); // vpj-cd e-evolution getPreferredSize();
invalidate(); invalidate();
} // updateData } // updateData
/**************************************************************************
* Get Preferred Size
* @return size
*/
/* vpj-cd e-evolution
public Dimension getPreferredSize()
{
if (!isPreferredSizeSet())
{
double width = s_width100;
if (m_goal.getPercent() > 100)
{
width = width * m_goal.getGoalPerformanceDouble();
width = Math.min(width, s_widthMax);
}
Dimension size = new Dimension();
size.setSize(width, s_height);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
}
return super.getPreferredSize();
} // getPreferredSize
// end vpj-cd
/**
* Paint Component
* @param g Graphics
*/
/*vpj-cd e-evolution
protected void paintComponent (Graphics g)
{
Graphics2D g2D = (Graphics2D)g;
Rectangle bounds = getBounds();
Insets insets = getInsets();
// Background
// g2D.setColor(GraphUtil.darker(getBackground(), 0.85));
g2D.setColor(getBackground());
Dimension size = getPreferredSize();
g2D.fill3DRect(0+insets.right, 0+insets.top,
size.width-insets.right-insets.left,
size.height-insets.top-insets.bottom, true);
// Paint Text
Color color = getForeground();
g2D.setPaint(color);
Font font = getFont(); // Bold +1
font = new Font(font.getName(), Font.BOLD, font.getSize()+1);
//
AttributedString aString = new AttributedString(m_text);
aString.addAttribute(TextAttribute.FONT, font);
aString.addAttribute(TextAttribute.FOREGROUND, color);
AttributedCharacterIterator iter = aString.getIterator();
//
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
float width = getPreferredSize().width - 8; // 4 pt ;
float xPos = 4;
float yPos = 2;
while (measurer.getPosition() < iter.getEndIndex())
{
TextLayout layout = measurer.nextLayout(width);
yPos += layout.getAscent() + layout.getDescent() + layout.getLeading();
layout.draw(g2D, xPos, yPos);
}
// Paint Performance Line
int x = (int)(m_line);
int y = (int)(size.height-insets.bottom);
g2D.setPaint(Color.black);
g2D.drawLine(x, insets.top, x, y);
} // paintComponent
*/
// end vpj-cd e-evolution
/**************************************************************************
* Adds an <code>ActionListener</code> to the indicator.
* @param l the <code>ActionListener</code> to be added
*/
public void addActionListener(ActionListener l)
{
if (l != null)
listenerList.add(ActionListener.class, l);
} // addActionListener
/**
* Removes an <code>ActionListener</code> from the indicator.
* @param l the listener to be removed
*/
public void removeActionListener(ActionListener l)
{
if (l != null)
listenerList.remove(ActionListener.class, l);
} // removeActionListener
/**
* Returns an array of all the <code>ActionListener</code>s added
* to this indicator with addActionListener().
*
* @return all of the <code>ActionListener</code>s added or an empty
* array if no listeners have been added
*/
public ActionListener[] getActionListeners()
{
return (ActionListener[])(listenerList.getListeners(ActionListener.class));
} // getActionListeners
/** /***************************************************************************
* Notifies all listeners that have registered interest for * Get Preferred Size
* notification on this event type. The event instance *
* is lazily created using the <code>event</code> * @return size
* parameter. */
* /*
* @param event the <code>ActionEvent</code> object * vpj-cd e-evolution public Dimension getPreferredSize() { if
* @see EventListenerList * (!isPreferredSizeSet()) { double width = s_width100; if
*/ * (m_goal.getPercent() > 100) { width = width *
protected void fireActionPerformed(MouseEvent event) * m_goal.getGoalPerformanceDouble(); width = Math.min(width, s_widthMax); }
{ * Dimension size = new Dimension(); size.setSize(width, s_height);
// Guaranteed to return a non-null array * setPreferredSize(size); setMinimumSize(size); setMaximumSize(size); }
ActionListener[] listeners = getActionListeners(); * return super.getPreferredSize(); } // getPreferredSize // end vpj-cd
ActionEvent e = null; *
// Process the listeners first to last * /** Paint Component @param g Graphics
for (int i = 0; i < listeners.length; i++) */
{ /*
// Lazily create the event: * vpj-cd e-evolution protected void paintComponent (Graphics g) {
if (e == null) * Graphics2D g2D = (Graphics2D)g; Rectangle bounds = getBounds(); Insets
e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, * insets = getInsets(); // Background //
"pi", event.getWhen(), event.getModifiers()); * g2D.setColor(GraphUtil.darker(getBackground(), 0.85));
listeners[i].actionPerformed(e); * g2D.setColor(getBackground()); Dimension size = getPreferredSize();
} * g2D.fill3DRect(0+insets.right, 0+insets.top,
} // fireActionPerformed * size.width-insets.right-insets.left,
* size.height-insets.top-insets.bottom, true);
* // Paint Text Color color = getForeground(); g2D.setPaint(color); Font
/************************************************************************** * font = getFont(); // Bold +1 font = new Font(font.getName(), Font.BOLD,
* Mouse Clicked * font.getSize()+1); // AttributedString aString = new
* @param e mouse event * AttributedString(m_text); aString.addAttribute(TextAttribute.FONT, font);
*/ * aString.addAttribute(TextAttribute.FOREGROUND, color);
public void mouseClicked (MouseEvent e) * AttributedCharacterIterator iter = aString.getIterator(); //
{ * LineBreakMeasurer measurer = new LineBreakMeasurer(iter,
* g2D.getFontRenderContext()); float width = getPreferredSize().width - 8; //
* 4 pt ; float xPos = 4; float yPos = 2; while (measurer.getPosition() <
* iter.getEndIndex()) { TextLayout layout = measurer.nextLayout(width);
* yPos += layout.getAscent() + layout.getDescent() + layout.getLeading();
* layout.draw(g2D, xPos, yPos); }
* // Paint Performance Line int x = (int)(m_line); int y =
* (int)(size.height-insets.bottom); g2D.setPaint(Color.black);
* g2D.drawLine(x, insets.top, x, y); } // paintComponent
*/
// end vpj-cd e-evolution
/***************************************************************************
* Adds an <code>ActionListener</code> to the indicator.
*
* @param l
* the <code>ActionListener</code> to be added
*/
public void addActionListener(ActionListener l) {
if (l != null)
listenerList.add(ActionListener.class, l);
} // addActionListener
/**
* Removes an <code>ActionListener</code> from the indicator.
*
* @param l
* the listener to be removed
*/
public void removeActionListener(ActionListener l) {
if (l != null)
listenerList.remove(ActionListener.class, l);
} // removeActionListener
/**
* Returns an array of all the <code>ActionListener</code>s added to this
* indicator with addActionListener().
*
* @return all of the <code>ActionListener</code>s added or an empty
* array if no listeners have been added
*/
public ActionListener[] getActionListeners() {
return (ActionListener[]) (listenerList
.getListeners(ActionListener.class));
} // getActionListeners
/**
* Notifies all listeners that have registered interest for notification on
* this event type. The event instance is lazily created using the
* <code>event</code> parameter.
*
* @param event
* the <code>ActionEvent</code> object
* @see EventListenerList
*/
protected void fireActionPerformed(MouseEvent event) {
// Guaranteed to return a non-null array
ActionListener[] listeners = getActionListeners();
ActionEvent e = null;
// Process the listeners first to last
for (int i = 0; i < listeners.length; i++) {
// Lazily create the event:
if (e == null)
e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "pi",
event.getWhen(), event.getModifiers());
listeners[i].actionPerformed(e);
}
} // fireActionPerformed
/***************************************************************************
* Mouse Clicked
*
* @param e
* mouse event
*/
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1)
fireActionPerformed(e); fireActionPerformed(e);
if (SwingUtilities.isRightMouseButton(e)) if (SwingUtilities.isRightMouseButton(e))
popupMenu.show((Component)e.getSource(), e.getX(), e.getY()); popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
} // mouseClicked } // mouseClicked
public void mousePressed (MouseEvent e) public void mousePressed(MouseEvent e) {
{
} }
public void mouseReleased (MouseEvent e) public void mouseReleased(MouseEvent e) {
{
} }
public void mouseEntered (MouseEvent e) public void mouseEntered(MouseEvent e) {
{
} }
public void mouseExited (MouseEvent e) public void mouseExited(MouseEvent e) {
{
} }
/** /**
* Action Listener. * Action Listener. Update Display
* Update Display *
* @param e event * @param e
* event
*/ */
public void actionPerformed (ActionEvent e) public void actionPerformed(ActionEvent e) {
{ if (e.getSource() == mRefresh) {
if (e.getSource() == mRefresh)
{
m_goal.updateGoal(true); m_goal.updateGoal(true);
updateDisplay(); updateDisplay();
// //
@ -453,6 +451,6 @@ public class PerformanceIndicator extends JPanel
else else
repaint(); repaint();
} }
} // actionPerformed } // actionPerformed
} // PerformanceIndicator } // PerformanceIndicator