* organized imports
* fix indentation
This commit is contained in:
teo_sarca 2008-09-03 10:39:29 +00:00
parent 805882802e
commit be2a7baee2
1 changed files with 184 additions and 182 deletions

View File

@ -16,22 +16,9 @@
package org.eevolution.form; package org.eevolution.form;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
//import org.jfree.chart.labels.StandardCategoryLabelGenerator;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.TextAnchor;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -39,8 +26,6 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.Color;
import java.awt.Dimension;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
@ -54,23 +39,40 @@ import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import org.compiere.apps.*; import org.compiere.apps.ConfirmPanel;
import org.compiere.util.*; import org.compiere.apps.form.FormFrame;
import org.compiere.grid.ed.VDate;
import org.compiere.grid.ed.VLookup;
import org.compiere.model.MColumn;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MResource;
import org.compiere.model.MUOM;
import org.compiere.swing.CLabel;
import org.compiere.swing.CPanel;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.eevolution.form.action.PopupAction; import org.eevolution.form.action.PopupAction;
import org.eevolution.form.action.ZoomMenuAction; import org.eevolution.form.action.ZoomMenuAction;
import org.eevolution.form.crp.CRPDatasetFactory; import org.eevolution.form.crp.CRPDatasetFactory;
import org.eevolution.form.crp.CRPModel; import org.eevolution.form.crp.CRPModel;
import org.compiere.model.*;
import org.compiere.apps.form.FormFrame;
import org.compiere.grid.ed.VDate;
import org.compiere.grid.ed.VLookup;
import org.compiere.swing.CLabel;
import org.compiere.swing.CPanel;
import org.eevolution.tools.worker.SingleWorker;
import org.eevolution.tools.swing.SwingTool;
import org.eevolution.model.MPPOrderNode; import org.eevolution.model.MPPOrderNode;
import org.eevolution.tools.swing.SwingTool;
import org.eevolution.tools.worker.SingleWorker;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.TextAnchor;
/** /**
* Capacity Requirement Planning Form * Capacity Requirement Planning Form
@ -86,45 +88,45 @@ public class CCRP extends CAbstractForm {
class ActionHandler implements ActionListener { class ActionHandler implements ActionListener {
public void actionPerformed (ActionEvent e) { public void actionPerformed (ActionEvent e) {
if (e.getActionCommand().equals(ConfirmPanel.A_OK)) { if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
SwingTool.setCursorsFromParent(getWindow(), true); SwingTool.setCursorsFromParent(getWindow(), true);
final ActionEvent evt = e; final ActionEvent evt = e;
worker = new SingleWorker() { worker = new SingleWorker() {
protected Object doIt() { protected Object doIt() {
handleActionEvent(evt); handleActionEvent(evt);
return null; return null;
} }
}; };
worker.start(); worker.start();
}
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
dispose();
} }
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
dispose();
}
} }
} }
class TreeHandler extends MouseInputAdapter implements TreeSelectionListener { class TreeHandler extends MouseInputAdapter implements TreeSelectionListener {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if(model.getTree().getPathForLocation(e.getX(), e.getY()) == null) { if(model.getTree().getPathForLocation(e.getX(), e.getY()) == null) {
return; return;
} }
SwingTool.setCursorsFromChild(e.getComponent(), true); SwingTool.setCursorsFromChild(e.getComponent(), true);
final MouseEvent evt = e; final MouseEvent evt = e;
worker = new SingleWorker() { worker = new SingleWorker() {
protected Object doIt() { protected Object doIt() {
handleTreeEvent(evt); handleTreeEvent(evt);
return null; return null;
} }
@ -137,212 +139,212 @@ public class CCRP extends CAbstractForm {
//m_tree.setToolTipText(msg.getToolTipText(e)); //m_tree.setToolTipText(msg.getToolTipText(e));
} }
public void valueChanged(TreeSelectionEvent event) { public void valueChanged(TreeSelectionEvent event) {
} }
} }
class FrameHandler extends WindowAdapter { class FrameHandler extends WindowAdapter {
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
dispose(); dispose();
} }
} }
class LabelGenerator extends StandardCategoryItemLabelGenerator class LabelGenerator extends StandardCategoryItemLabelGenerator
{ {
public String generateItemLabel(CategoryDataset categorydataset, int i, int j) { public String generateItemLabel(CategoryDataset categorydataset, int i, int j) {
return categorydataset.getRowKey(i).toString(); return categorydataset.getRowKey(i).toString();
} }
} }
private VLookup resource; private VLookup resource;
private VDate dateFrom; private VDate dateFrom;
private VDate dateTo; private VDate dateTo;
private ChartPanel chartPanel; private ChartPanel chartPanel;
private JSplitPane contentPanel; private JSplitPane contentPanel;
private SingleWorker worker; private SingleWorker worker;
protected CRPModel model; protected CRPModel model;
protected JPopupMenu popup; protected JPopupMenu popup;
public CCRP() { public CCRP() {
super(); super();
} }
public void init (int WindowNo, FormFrame frame) { public void init (int WindowNo, FormFrame frame) {
super.init(WindowNo, frame); super.init(WindowNo, frame);
fillPicks(); fillPicks();
jbInit(); jbInit();
} }
private void jbInit() { private void jbInit() {
dateFrom = new VDate("DateFrom", true, false, true, DisplayType.Date, "DateFrom"); dateFrom = new VDate("DateFrom", true, false, true, DisplayType.Date, "DateFrom");
dateTo = new VDate("DateTo", true, false, true, DisplayType.Date, "DateTo"); dateTo = new VDate("DateTo", true, false, true, DisplayType.Date, "DateTo");
CPanel northPanel = new CPanel(); CPanel northPanel = new CPanel();
northPanel.setLayout(new java.awt.GridBagLayout()); northPanel.setLayout(new java.awt.GridBagLayout());
northPanel.add( northPanel.add(
new CLabel(Msg.translate(Env.getCtx(), "S_Resource_ID")), new CLabel(Msg.translate(Env.getCtx(), "S_Resource_ID")),
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0) new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)
); );
northPanel.add( northPanel.add(
resource, resource,
new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0) new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)
); );
northPanel.add( northPanel.add(
new CLabel(Msg.translate(Env.getCtx(), "DateFrom")), new CLabel(Msg.translate(Env.getCtx(), "DateFrom")),
new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0) new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)
); );
northPanel.add( northPanel.add(
dateFrom, dateFrom,
new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0) new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)
); );
northPanel.add( northPanel.add(
new CLabel(Msg.translate(Env.getCtx(), "DateTo")), new CLabel(Msg.translate(Env.getCtx(), "DateTo")),
new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0) new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)
); );
northPanel.add( northPanel.add(
dateTo, dateTo,
new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0) new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)
); );
ConfirmPanel confirmPanel = new ConfirmPanel(true); ConfirmPanel confirmPanel = new ConfirmPanel(true);
confirmPanel.addActionListener(new ActionHandler()); confirmPanel.addActionListener(new ActionHandler());
contentPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); contentPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
contentPanel.setPreferredSize(new Dimension(800, 600)); contentPanel.setPreferredSize(new Dimension(800, 600));
getWindow().getContentPane().add(northPanel, BorderLayout.NORTH); getWindow().getContentPane().add(northPanel, BorderLayout.NORTH);
getWindow().getContentPane().add(contentPanel, BorderLayout.CENTER); getWindow().getContentPane().add(contentPanel, BorderLayout.CENTER);
getWindow().getContentPane().add(confirmPanel, BorderLayout.SOUTH); getWindow().getContentPane().add(confirmPanel, BorderLayout.SOUTH);
} }
private void fillPicks() { private void fillPicks() {
Properties ctx = Env.getCtx(); Properties ctx = Env.getCtx();
// Hardcoded Column ID - Manufacturing Resource ID // Hardcoded Column ID - Manufacturing Resource ID
MLookup resourceL = MLookupFactory.get (ctx, getWindowNo(), 0, MColumn.getColumn_ID(MResource.Table_Name,"S_Resource_ID"), DisplayType.TableDir); MLookup resourceL = MLookupFactory.get (ctx, getWindowNo(), 0, MColumn.getColumn_ID(MResource.Table_Name,"S_Resource_ID"), DisplayType.TableDir);
resource = new VLookup ("S_Resource_ID", false, false, true, resourceL); resource = new VLookup ("S_Resource_ID", false, false, true, resourceL);
} }
protected JPopupMenu createPopup(JTree tree) { protected JPopupMenu createPopup(JTree tree) {
JPopupMenu pm = new JPopupMenu(); JPopupMenu pm = new JPopupMenu();
PopupAction action = null; PopupAction action = null;
try { try {
action = new ZoomMenuAction(tree); action = new ZoomMenuAction(tree);
pm.add(action); pm.add(action);
} }
catch(Exception e) { catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return pm; return pm;
} }
private void handleTreeEvent(MouseEvent e) { private void handleTreeEvent(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON3) { if(e.getButton() == MouseEvent.BUTTON3) {
model.getTree().setSelectionPath(model.getTree().getPathForLocation(e.getX(), e.getY())); model.getTree().setSelectionPath(model.getTree().getPathForLocation(e.getX(), e.getY()));
DefaultMutableTreeNode node = (DefaultMutableTreeNode)model.getTree().getSelectionPath().getLastPathComponent(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)model.getTree().getSelectionPath().getLastPathComponent();
if(!(node.getUserObject() instanceof Date) && !(node.getUserObject() instanceof MPPOrderNode)) { if(!(node.getUserObject() instanceof Date) && !(node.getUserObject() instanceof MPPOrderNode)) {
popup.show(e.getComponent(), e.getX(), e.getY()); popup.show(e.getComponent(), e.getX(), e.getY());
} }
} }
SwingTool.setCursorsFromChild(e.getComponent(), false); SwingTool.setCursorsFromChild(e.getComponent(), false);
} }
private void handleActionEvent(ActionEvent e) { private void handleActionEvent(ActionEvent e) {
Timestamp df = getDateFrom(); Timestamp df = getDateFrom();
Timestamp dt = getDateTo(); Timestamp dt = getDateTo();
MResource r = getResource(); MResource r = getResource();
if (df != null && dt != null && r != null) { if (df != null && dt != null && r != null) {
model = CRPDatasetFactory.get(df, dt, r); model = CRPDatasetFactory.get(df, dt, r);
JFreeChart jfreechart = createChart(model.getDataset(), getChartTitle(), getSourceUOM());
chartPanel = new ChartPanel(jfreechart, false); JFreeChart jfreechart = createChart(model.getDataset(), getChartTitle(), getSourceUOM());
contentPanel.setLeftComponent(chartPanel);
JTree tree = model.getTree();
tree.addMouseListener(new TreeHandler());
contentPanel.setRightComponent(new JScrollPane(tree));
popup = createPopup(tree);
contentPanel.setVisible(true); chartPanel = new ChartPanel(jfreechart, false);
contentPanel.setLeftComponent(chartPanel);
contentPanel.validate();
contentPanel.repaint(); JTree tree = model.getTree();
} tree.addMouseListener(new TreeHandler());
contentPanel.setRightComponent(new JScrollPane(tree));
SwingTool.setCursorsFromParent(getWindow(), false); popup = createPopup(tree);
contentPanel.setVisible(true);
contentPanel.validate();
contentPanel.repaint();
}
SwingTool.setCursorsFromParent(getWindow(), false);
} }
private String getChartTitle() { private String getChartTitle() {
MResource r = getResource(); MResource r = getResource();
String title = r.getName() != null ? r.getName() : ""; String title = r.getName() != null ? r.getName() : "";
title = title + " " + r.getDescription() != null ? r.getDescription() : ""; title = title + " " + r.getDescription() != null ? r.getDescription() : "";
return title; return title;
} }
public Timestamp getDateFrom() { public Timestamp getDateFrom() {
Timestamp t = null; Timestamp t = null;
if(dateFrom.getValue() != null) { if(dateFrom.getValue() != null) {
t = (Timestamp)dateFrom.getValue(); t = (Timestamp)dateFrom.getValue();
} }
return t; return t;
} }
public Timestamp getDateTo() { public Timestamp getDateTo() {
Timestamp t = null; Timestamp t = null;
if(dateTo.getValue() != null) { if(dateTo.getValue() != null) {
t = (Timestamp)dateTo.getValue(); t = (Timestamp)dateTo.getValue();
} }
return t; return t;
} }
public MUOM getSourceUOM() { public MUOM getSourceUOM() {
MResource r = getResource(); MResource r = getResource();
int uom_id = r.getResourceType().getC_UOM_ID(); int uom_id = r.getResourceType().getC_UOM_ID();
return (uom_id > 0) ? MUOM.get(Env.getCtx(),uom_id) : null; return (uom_id > 0) ? MUOM.get(Env.getCtx(),uom_id) : null;
} }
public MResource getResource() { public MResource getResource() {
MResource r = null; MResource r = null;
if(resource.getValue() != null) { if(resource.getValue() != null) {
@ -358,9 +360,9 @@ public class CCRP extends CAbstractForm {
} }
return u; return u;
} }
private JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) { private JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) {
JFreeChart chart = ChartFactory.createBarChart3D( JFreeChart chart = ChartFactory.createBarChart3D(
title , title ,
Msg.translate(Env.getCtx(), "Day"), // X-Axis label Msg.translate(Env.getCtx(), "Day"), // X-Axis label
@ -371,67 +373,67 @@ public class CCRP extends CAbstractForm {
true, // tooltips? true, // tooltips?
false // URLs? false // URLs?
); );
chart.setBackgroundPaint(Color.WHITE); chart.setBackgroundPaint(Color.WHITE);
chart.setAntiAlias(true); chart.setAntiAlias(true);
chart.setBorderVisible(true); chart.setBorderVisible(true);
CategoryPlot plot = chart.getCategoryPlot(); CategoryPlot plot = chart.getCategoryPlot();
plot.setRangeGridlinesVisible(true); plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.GRAY); plot.setRangeGridlinePaint(Color.GRAY);
plot.setDomainGridlinesVisible(true); plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.GRAY); plot.setDomainGridlinePaint(Color.GRAY);
BarRenderer3D barrenderer = (BarRenderer3D)plot.getRenderer(); BarRenderer3D barrenderer = (BarRenderer3D)plot.getRenderer();
barrenderer.setDrawBarOutline(false); barrenderer.setDrawBarOutline(false);
barrenderer.setBaseItemLabelGenerator(new LabelGenerator()); barrenderer.setBaseItemLabelGenerator(new LabelGenerator());
//barrenderer.setBaseLabelGenerator(new LabelGenerator()); //barrenderer.setBaseLabelGenerator(new LabelGenerator());
barrenderer.setBaseItemLabelsVisible(true); barrenderer.setBaseItemLabelsVisible(true);
barrenderer.setSeriesPaint(0, new Color(200, 200, 200, 128)); barrenderer.setSeriesPaint(0, new Color(200, 200, 200, 128));
barrenderer.setSeriesPaint(1, new Color(60, 60, 100, 128)); barrenderer.setSeriesPaint(1, new Color(60, 60, 100, 128));
ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_CENTER); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_CENTER);
barrenderer.setPositiveItemLabelPosition(itemlabelposition); barrenderer.setPositiveItemLabelPosition(itemlabelposition);
CategoryAxis domainAxis = plot.getDomainAxis(); CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions( domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
); );
return chart; return chart;
} }
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
if(resource != null) { if(resource != null) {
resource.dispose(); resource.dispose();
} }
resource = null; resource = null;
if(dateFrom != null) { if(dateFrom != null) {
dateFrom.dispose(); dateFrom.dispose();
} }
dateFrom = null; dateFrom = null;
if(dateTo != null) { if(dateTo != null) {
dateTo.dispose(); dateTo.dispose();
} }
dateTo = null; dateTo = null;
if(worker != null) { if(worker != null) {
worker.stop(); worker.stop();
} }
worker = null; worker = null;
chartPanel = null; chartPanel = null;
contentPanel = null; contentPanel = null;
popup = null; popup = null;
} }