}
private static SimpleXYDataset createPlot(Container contentPane, boolean invertX, boolean invertY) {
final XYPlot plot = new XYPlot();
XYAxis xAxis = new LinearXYAxis(XYDimension.X);
XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
xAxis.setPreferredSize(new Dimension(1, 40));
yAxis.setPreferredSize(new Dimension(40, 1));
xAxis.setForeground(Color.white);
yAxis.setForeground(Color.white);
xAxis.setTextMargin(10);
yAxis.setTextMargin(10);
plot.add(xAxis);
plot.add(yAxis);
plot.setXAxis(xAxis);
plot.setYAxis(yAxis);
plot.setBackground(Color.darkGray);
XYPlotContents contents = new XYPlotContents();
contents.setBackground(Color.black);
plot.setBackground(Color.darkGray);
XYGrid grid = new XYGrid(xAxis, yAxis);
grid.setForeground(Color.lightGray);
contents.add(grid);
plot.add(contents);
plot.setPreferredSize(new Dimension(150, 100));
contentPane.setBackground(Color.darkGray);
XYLocationDisplay locationDisplay = new XYLocationDisplay();
// This is a hack to set the preferred height to the normal height so the component doesn't collapse to height 0 when the text is empty.
// Note that mimimumSize does not work for some reason.
locationDisplay.setText("Ag");
Dimension size = locationDisplay.getPreferredSize();
size.width = 100;
locationDisplay.setText("");
locationDisplay.setPreferredSize(size);
// End hack
locationDisplay.setForeground(Color.white);
locationDisplay.setFont(new Font("Arial", 0, 12));
locationDisplay.setFormat(new MessageFormat("<html><b>X:</b> {0} <b>Y:</b> {1}</html>"));
locationDisplay.attach(plot);
plot.add(locationDisplay);
SlopeLine slopeLine = new SlopeLine();
slopeLine.setForeground(Color.white);
slopeLine.attach(plot);
SlopeLineDisplay slopeLineDisplay = new SlopeLineDisplay();
slopeLine.addListenerForPlot(plot, slopeLineDisplay);
slopeLineDisplay.setFont(new Font("Arial", 0, 12));
slopeLineDisplay.setForeground(Color.white);
slopeLineDisplay.setFormat(new MessageFormat("<html><b>Δx:</b> {0} <b>Δy:</b> {1}</html>"));
plot.add(slopeLineDisplay);
new DefaultXYLayoutGenerator().generateLayout(plot);
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
contentPane.add(plot);
final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
line.setForeground(Color.white);
final SimpleXYDataset d = new SimpleXYDataset(line);
d.setMaxCapacity(10000);
d.setXData(line.getXData());
d.setYData(line.getYData());
contents.add(line);
contents.setComponentZOrder(grid, contents.getComponentCount() - 1);
if(invertY) {
yAxis.setStart(200);
yAxis.setEnd(0);
} else {
yAxis.setStart(0);
yAxis.setEnd(200);
}
if(invertX) {
xAxis.setStart(5);
xAxis.setEnd(0);
} else {