Hi
I am trying to implement simplified chart linking by writing a strategy program that changes the chart instrument to the desired instrument when the mouse is clicked on a chart. However, I cannot get my program to change the chart instrument and I would appreciate any advice.
I have attached a simple program to illustrate the problem.
The program remembers the instrument of the active chart when the user makes a selection - the desired instrument.
When the user selects another chart and clicks on the chart, my program attempts to change the instrument of the newly active chart. This does not work.
I can change the feed descriptor, but the visible chart does not change and activeChart.getInstrument() does not change. I can't find a way of getting the chart to recognise the descriptor change.
I'm stuck and would like any help possible.
Cheers
Tony
This is the mouse listener method:
@Override
public void mouseClicked( IChartPanelMouseEvent e ) {
IChart activeChart = context.getLastActiveChart();
Instrument activeInstrument = activeChart.getInstrument();
// chart changed?
if( !activeChart.equals( prevActiveChart ) ) {
printDebug( "mouseClicked(): Chart changed." );
printDebug( "mouseClicked(): prevActiveChart = " + prevActiveChart.toString() + ": " + prevActiveChart.getInstrument().toString() + ", " + prevActiveChart.getSelectedPeriod().toString() );
printDebug( "mouseClicked(): activeChart = " + activeChart.toString() + ": " + activeInstrument.toString() + ", " + activeChart.getSelectedPeriod().toString() );
printDebug( "mouseClicked(): desiredInstrument = " + desiredInstrument.toString() + ", activeInstrument = " + activeInstrument.toString() );
if( !activeInstrument.equals( desiredInstrument ) ) {
// change the chart instrument
IFeedDescriptor feed = activeChart.getFeedDescriptor();
printDebug( "mouseClicked(): Current feed descriptor = " + feed.toString() + ", activeInstrument = " + activeInstrument.toString() );
feed.setInstrument( desiredInstrument );
// activeChart.setInstrument( desiredInstrument ); // deprecated
printDebug( "mouseClicked(): After setting, feed descriptor = " + feed.toString() + ", activeInstrument = " + activeInstrument.toString() );
//activeChart.repaint(); // ??? necessary?
}
prevActiveChart = activeChart;
}
// deisred instrument changed, i.e. instrument changed but not chart
else if ( !activeInstrument.equals( desiredInstrument ) ) {
printDebug( "mouseClicked(): Instrument changed." );
printDebug( "mouseClicked(): desiredInstrument was " + desiredInstrument.toString() + ", desiredInstrument becomes " + activeInstrument.toString() );
desiredInstrument = activeInstrument;
}
else {
printDebug( "mouseClicked(): No change." );
}
// print current state
openCharts = context.getCharts();
for( IChart c : openCharts ) {
printDebug( "mouseClicked(): " + c.toString() + ": " + c.getInstrument() + " " + c.getSelectedPeriod().toString() );
}
}