/**
* ================================
* Forms BI Bean Graph Integration
* ================================
*
* @author Frank Nimphius
* @version 1.1
*
* history of changes
* ================================
* 1. November 2002 initial creation
* 1. December 2002 added getProperty() method for property GET_DELIMITER to obtain the delimiter
* string from a get_custom_property() call
* 18. December , bug fixes 2708349,2708328
*
* added getProperty() method for property COLUMNCOUNT to obtain the number of
* columns from a get_custom_property() call
*
*
*/
package oracle.forms.demos.bigraph;
// Java classes
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.NumberFormatException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import oracle.dss.graph.BaseGraphComponent;
import oracle.dss.graph.Graph;
import oracle.dss.graph.GraphBackground;
import oracle.dss.graph.LegendArea;
import oracle.dss.graph.Series;
import oracle.dss.util.DefaultErrorHandler;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.CustomEvent;
import oracle.forms.ui.VBean;
/**
* <p><b>FormsGraph</b> is a charting client for Oracle Forms, including the BI Bean Graph
* component to Forms. This sample does not expose all of the functionality provided by the BI Graph Bean,
* but as much as was possible with <I>Oracle Graphics</I>, the previous charting solution used within
* Forms.</p>
* <p><b>FormsGraph</b> can be used in multiple instances, each running in a Bean Container managed
* by Forms. Mouse Click events are passed back to Forms firing the <I>when-custom-item-event</I> trigger
* so that interactive charts as well as drill down and master/detail relationships are within the
* control of the Forms application developer.</p>
*
* <p><b>version 1.0 Review</b></p>
*
*/
public class FormsGraph extends VBean
{
private String sDelimiter = ","; // default delimiter for the data passed to the graph
private int iSelectCol = 0; // defines the Bar or pie that is selected when first
private int iSelectRow = 0; // rendering the chart. Can be overwritten
private int mChart_height = 400; // default value for chart height.
private int mChart_width = 400; // default value for chart width.
private int mGraphType = Graph.BAR_VERT_CLUST; // default graph type is a simple vertical bar graph
private int mViewListenerCount = 0; // only one view listener shall get implemented
private int mSeparateFrameXPos=10; // xPos of the separate Graph frame
private int mSeparateFrameYPos=10; // yPos of the separate Graph frame
private boolean recoverGraphToVBean=false; // this flag is set when the Graph component
// in the Forms Bean component is replaced by a panel
// due to no data available in the graph
private int AlignRight = SwingConstants.RIGHT;
private int AlignLeft = SwingConstants.LEFT;
private int AlignCenter= SwingConstants.CENTER;
protected boolean showGraphAsSeries = false;
private boolean dataSuccess = false; // flag indicating if data row operation was successful
private boolean bDebugMode = false; // debug true/false
private String mWindowTitle = "Forms - BI Graph"; // title of separate frame
private String noDataFoundTxt = "Graph Contains No Data!"; // message shown when graph does not contain data
private String debugPrefix ="";
private IHandler mHandler;
private Component mBeanBox;
private Vector vGraphData = null; // vector storing the data rows passed from Forms
private Graph m_graph = null;
private Series graphSeries = null; // handler to the graph series
private mViewMouseListener instanceVMListener=null; // reacts to mouse events performed on a graph
private localRelationalData lrd=null;
private JTextPane NoDataFoundPanel = new JTextPane();
private ImageIcon emptyGraphImage=null;
// identifier used to define the data returned by a mouseclick
// on the Graph
public final int allData = 0;
public final int dataLabel = 1;
public final int dataColumn = 2;
public final int dataValue = 3;
public final int dataPrimKey= 4;
public final int noData = 5;
// by default returns null
protected int returnValueSelection = noData;
/**
* Forms property used to to add a data row in the Graph.
* If Graph Data exists, then the new row is appended. A row contains columns data which are separated
* by a defined delimiter. The default delimiter is ",", custom delimiters can be set using the Forms
* property <code>SET_DELIMITER </code> in a call to SET_CUSTOM_PROPERTY(). Used with SET_CUSTOM_PROPERTY()
* from the Form.
*
* Syntax: <column_label><delimiter><row_label><delimiter><value><delimiter><primaryKey> e.g
* 'SAL,SMITH,1200,7750'
*
* <p><b>Forms Example:</b></p>
* <code>set_custom_property('BeanArea',1,'ADD_ROWDATA','SAL,SMTITH,1200);</code>
* <p>or, if a primarey key needs to be passed</p>
* <code>set_custom_property('BeanArea',1,'ADD_ROWDATA','SAL,SMTITH,1200,7765);</code>
*/
protected static final ID pAddRowData = ID.registerProperty("ADD_ROWDATA");
/**
* Show the data in the Graph clearing out existing data
* <p><b>Forms Example:</b></p>
* <code>set_custom_property('BeanArea',1,'ADD_DATA_TO_GRAPH','');</code>
*/
protected static final ID pAddDataToGraph = ID.registerProperty("ADD_DATA_TO_GRAPH");
/**
* Property registered to determine the alignment for the title, subtitle and footnote text. The allowed values are "LEFT",
* "RIGHT" and "CENTER". One property call can be used to set all title alignments. The following attribute syntax sets the title first, then
* the subtitle and at lst the footnote 'title=CENTER,subtitle=LEFT,footnote=CENTER'. The delimiter by default it a comma (',') if not set other using
* the SET_DELIMITER property. Values can be omitted. For example. If the alignment should be
* set for the title and subtitle only, then the following syntax is valid
* 'title=CENTER,subtitle=LEFT'
*
* <p><b>Forms Example:</b></p>
* <code>set_custom_property('BeanArea',1,'ALIGN_TITLE_TEXT','title=CENTER,subtitle=LEFT');</code>
*/
protected static final ID pAlignTitleText = ID.registerProperty("ALIGN_TITLE_TEXT");
/**
* Forms property registered to reset the Forms Graph. Clearing the Graph empties the
* data cache of the graph. All data will be removed from the internal Graph store
*
* <p><b>Forms Example:</b></p>
* <code>set_custom_property('BeanArea',1,'CLEAR_GRAPH','');</code>
*
*/
protected static final ID pClearGraph = ID.registerProperty("CLEAR_GRAPH");
/**
* Forms registered property to enable Debug message (TRUE/FALSE). Arguments passed are either
* "TRUE" or "FALSE" to switch on/off verbose debug messages to system out.
* <p><b>Forms Example:</b></p>
* <code>set_custom_property('BeanArea',1,'DEBUG','TRUE');</code>
*/
protected static final ID pDebug = ID.registerProperty("DEBUG");
/**
* Property registered to disable/enable too