edit 2: SOLVED/HACKEDpresuming nothing drastic changes with the Jpanel/Container/Component hierarchy on the platform this works for mouselisteners on the main chart. your homework is to modify it to work even if the indicator panels below are the one's with the mouselisteners (hint: main chart is located at 0,0 top left, indicators are at 0,Y at various levels of Y)
console.getOut().println("-------------------------------------");
x = (double)e.getSourceEvent().getX(); //mouse x
y = (double)e.getSourceEvent().getY(); //mouse y
w = (double)e.getSourceEvent().getComponent().getParent().getParent().getWidth(); //whitearea w
h = (double)e.getSourceEvent().getComponent().getParent().getParent().getHeight(); //whitearea h
setx = (float)(x / w); // relative to the whitearea
sety = (float)(y / h); // relative to the whitearea
IOhlcChartObject o = chart.getChartObjectFactory().createOhlcInformer();
o.setPosX(setx);
o.setPosY(sety);
chart.addToMainChart(o);See compilable file attached as solved.java for further insight
**************************************************************************************************************************************************edit 1: quite a bit of work needed as things look shady with indicators plotted below the main chart
edit 1: (proportions address the entire white area, main chart and indicator panels, our mouselistener is within the main chart)
**************************************************************************************************************************************************Rough attempt - perhaps someone can find the obvious error as I've not given it thought0.0f to 1.0f tells me that instead of supporting absolute pixel positioning e.g. a fixed position of 200, 200, there's an attempt to use proportions (modelled in percentages).
If we have Chart 1 open up at 800w 800h and Chart 2 open up at 1000w, 1000h, in order to place some graphic widget in the middle requires two different coordinates 400x, 400y and 500x, 500y.
If we then resize the charts to 700w,700h and the second to 900w, 900h then the numbers we used for the centre are now off.
We can deal with this resizing/redrawing problem (if we consider it to be one) by using proportions. So instead of saying 400, 400 and 500, 500 above, we can say 50%, 50% (0.5x, 0.5y) to mean 400x,400y and 500x,500y. This translates into 350x,350y and 450x,450y after resizing as the proportion carries across after resizing.
As the chart size refers to the entire area wherein you may place your widget, then what you must do in order to determine the proportions for placement is a case of division.
Begin with a screen size you can work with such as 1000w,1000h for reference.
Then ask yourself 'where would l like to place my widget?'.
Top left corner - 0x, 0y
Left side with vertical middle - 0x, 500y
Top side 1/3rd across - 333x, 0y
Centre - 500x, 500y
Bottom right corner - 999x, 999y
Then to get the proportions divide the desired x/y positions by their reference width/height to give
Top left corner: 0x, 0y -> 0x/1000w, 0y/1000h = 0.0setx,0.0sety
Left side with vertical middle: 0x, 500y -> 0x/1000w, 500y/1000h = 0.0setx, 0.5sety
Top side 1/3rd across: 333x, 0y -> 333x/1000w, 0y/1000h -> 0.333setx, 0.0sety
Centre: 500x, 500y -> 500x/1000w, 500y/1000h -> 0.5setx, 0.5sety
Bottom right corner: 999x, 999y -> 999x/1000w, 999y/1000h -> 0.999setx, 0.999sety
As the resulting positions set are percentages, then the system only has to double check the current chart size after a resize to determine where to place the widget (if it wants to work in this way).
In the case of the mouse position, you also require the current width and height of the chart in order to determine the proportions.
ChartWidth = w
ChartHeight = h
MouseX = x
MouseY = y
setx = x/w
sety = y/h
double x = (double)e.getSourceEvent().getX();
double y = (double)e.getSourceEvent().getY();
double w = (double)e.getSourceEvent().getComponent().getWidth();
double h = (double)e.getSourceEvent().getComponent().getHeight();
IOhlcChartObject o = chart.getChartObjectFactory().createOhlcInformer();
o.setPosX((float)(x / w));
o.setPosY((float)(y / h));
chart.addToMainChart(o);
So as I said on the first line it's a ROUGH attempt as there is some drifting error I've not considered -
lazy right now but also wanted to get the help startedTowards the left it's accurate but it loses accuracy towards the right - obviously a rounding / pixel division / pixel compensation (+1 here, -1 there) issue.
Compilable file
Strategy1.java included for those looking for extra homework
SORRY FOR MULTIPLE FILES - RENAMED CLASS TO 'Solved' DURING EDIT - CAN'T DELETE ATTACHMENTS ALREADY MADE 