Skip to content

Commit

Permalink
Update Subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
johnprif committed Jan 13, 2023
1 parent 306e289 commit df956ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/Control/CustomMouseListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
import org.jfree.chart.JFreeChart;
import org.jfree.chart.fx.interaction.ChartMouseEventFX;
import org.jfree.chart.fx.interaction.ChartMouseListenerFX;
import org.jfree.chart.title.TextTitle;

import javafx.scene.input.MouseButton;
import java.io.File;
import java.io.IOException;

public class CustomMouseListener implements ChartMouseListenerFX
{
JFreeChart chart;
public CustomMouseListener(JFreeChart chart)
// JFreeChart chart;
TextTitle textTitle;

public CustomMouseListener(TextTitle textTitle)
{
this.chart = chart;
// this.chart = chart;
this.textTitle = textTitle;
}

@Override
Expand All @@ -24,7 +28,9 @@ public void chartMouseClicked(ChartMouseEventFX arg0)
// TODO Auto-generated method stub
System.out.println("CLICK -> x="+arg0.getTrigger().getX()+" y="+arg0.getTrigger().getY());
System.out.println("Point -> x="+arg0.getChart().getXYPlot().getDomainCrosshairValue()+" y="+arg0.getChart().getXYPlot().getRangeCrosshairValue());
chart.setTitle("Current Point: ("+arg0.getChart().getXYPlot().getDomainCrosshairValue()+", "+arg0.getChart().getXYPlot().getRangeCrosshairValue()+")");
// chart.setTitle("Current Point: ("+arg0.getChart().getXYPlot().getDomainCrosshairValue()+", "+arg0.getChart().getXYPlot().getRangeCrosshairValue()+")");
// chart.addSubtitle(new TextTitle("Current Point: ("+arg0.getChart().getXYPlot().getDomainCrosshairValue()+", "+arg0.getChart().getXYPlot().getRangeCrosshairValue()+")"));
textTitle.setText("Current Point: ("+arg0.getChart().getXYPlot().getDomainCrosshairValue()+", "+arg0.getChart().getXYPlot().getRangeCrosshairValue()+")");
if(arg0.getTrigger().getButton()==MouseButton.SECONDARY)
{
System.out.println("RIGHT CLICK -> x="+arg0.getTrigger().getX()+" y="+arg0.getTrigger().getY());
Expand Down
5 changes: 3 additions & 2 deletions src/Model/DataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DataBase
// public instance initialized when loading the class
private static final DataBase instance = new DataBase();
private int indexOfMaxPoint = 0;
private int indexOfMaxPoint2 = 0;

private DataBase()
{
Expand Down Expand Up @@ -77,7 +78,7 @@ public int getCirclePointsSize()

public void deleteMaxNodeForVoronoi()
{
convexPoints.remove(indexOfMaxPoint);
convexPoints.remove(indexOfMaxPoint2);
}

public void deleteMaxNodeForCircle()
Expand Down Expand Up @@ -182,7 +183,7 @@ public double findMaxNodeforVoronoi()
double angle = getAngle(prev, curr, next);

if (radius > maxRadius || (radius == maxRadius && angle >= maxAngle)) {
indexOfMaxPoint = i;
indexOfMaxPoint2 = i;
maxRadius = radius;
maxAngle = angle;
}
Expand Down
10 changes: 7 additions & 3 deletions src/View/GraphGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
Expand All @@ -32,6 +33,7 @@
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.statistics.HistogramDataset;
import org.jfree.data.xy.DefaultXYZDataset;
Expand Down Expand Up @@ -101,15 +103,18 @@ private void createStage()

private void displaySmallestEnclosingCircle()
{
TextTitle textTitle = new TextTitle("Current Point: None");
textTitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
makeSeries();

makePlots();

JFreeChart chart = new JFreeChart(plot);
chart.setTitle("Current Point: None");
chart.setTitle("Smallest Enclosing Circle");
chart.addSubtitle(textTitle);
ChartViewer viewer = new ChartViewer(chart);
//---------------------------------------------------------------------------
viewer.addChartMouseListener(new CustomMouseListener(chart));
viewer.addChartMouseListener(new CustomMouseListener(textTitle));

//--------------------------------------------------
circleStage.setScene(new Scene(viewer));
Expand All @@ -136,7 +141,6 @@ private void makeSeries()
{
series3.add(dataBase.getCirclePoints().get(i).getX(), dataBase.getCirclePoints().get(i).getY());
}

dataset = new XYSeriesCollection();
dataset.addSeries(series3);
dataset.addSeries(series2);
Expand Down

0 comments on commit df956ef

Please sign in to comment.