diff options
| author | bjculkin <bjculkin@BECK-DZ9BJB2.wvu-ad.wvu.edu> | 2018-04-11 15:29:25 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@BECK-DZ9BJB2.wvu-ad.wvu.edu> | 2018-04-11 15:29:25 -0400 |
| commit | dcb6c2159446135a142cad41eec185bb24c45bfb (patch) | |
| tree | 965dcc07fc0256a9a8254d5f968e316a1e928617 /CSMath/src/bezier/PointRemover.java | |
| parent | 8ecf52b6c5821e5c3de8a0f5c9e7ed3e357cb282 (diff) | |
Split #9 into one class/file
Diffstat (limited to 'CSMath/src/bezier/PointRemover.java')
| -rw-r--r-- | CSMath/src/bezier/PointRemover.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/CSMath/src/bezier/PointRemover.java b/CSMath/src/bezier/PointRemover.java new file mode 100644 index 0000000..98cf8c0 --- /dev/null +++ b/CSMath/src/bezier/PointRemover.java @@ -0,0 +1,72 @@ +package bezier;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JFrame;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+
+/**
+ * Listener to remove points from a bezier curve.
+ *
+ * @author bjculkin
+ *
+ */
+public class PointRemover implements ActionListener {
+ private final JFrame fram;
+ private final JList<TDPoint> pointList;
+ private final DefaultListModel<TDPoint> pointModel;
+
+ private Bezier curve;
+
+ /**
+ * Create a new listener to remove points from a bezier curve.
+ *
+ * @param fram
+ * The frame to use.
+ * @param pointList
+ * The list the points are stored in.
+ * @param pointModel
+ * The data backing the list.
+ * @param curveHolder
+ * The current curve.
+ */
+ public PointRemover(JFrame fram, JList<TDPoint> pointList, DefaultListModel<TDPoint> pointModel,
+ Holder<Bezier> curveHolder) {
+ this.fram = fram;
+ this.pointList = pointList;
+ this.pointModel = pointModel;
+
+ /*
+ * Change our curve if the current one changes.
+ */
+ curve = curveHolder.getVal();
+ curveHolder.addHolderListener((val) -> {
+ curve = val;
+ });
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent ev) {
+ int selectedIndex = pointList.getSelectedIndex();
+
+ /*
+ * Nothing selected.
+ */
+ if (selectedIndex == -1)
+ return;
+
+ TDPoint punkt = pointModel.get(selectedIndex);
+
+ String msg = String.format("Do you want to remove the control point (%.2f, %.2f)?", punkt.x, punkt.y);
+
+ int confirmed = JOptionPane.showConfirmDialog(fram, msg, "Remove Control Point?", JOptionPane.YES_NO_OPTION);
+
+ if (confirmed == JOptionPane.YES_OPTION) {
+ pointModel.remove(selectedIndex);
+ curve.controls.remove(punkt);
+ }
+ }
+}
\ No newline at end of file |
