File: MarkAndDeleteFunction.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (59 lines) | stat: -rw-r--r-- 1,823 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package tim.prune.function.compress;

import javax.swing.JOptionPane;

import tim.prune.App;
import tim.prune.FunctionLibrary;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;

/**
 * Superclass of those functions which mark points for deletion
 * (and optionally delete them automatically)
 */
public abstract class MarkAndDeleteFunction extends GenericFunction
{
	/** flag to remember whether the automatic deletion has been set to always */
	private boolean _automaticallyDelete = false;


	/**
	 * Constructor
	 * @param inApp App object
	 */
	public MarkAndDeleteFunction(App inApp)
	{
		super(inApp);
	}

	/**
	 * optionally delete the marked points
	 */
	protected void optionallyDeleteMarkedPoints(int inNumMarked)
	{
		// Allow calling of delete function with one click
		final String[] buttonTexts = {I18nManager.getText("button.yes"), I18nManager.getText("button.no"),
			I18nManager.getText("button.always")};
		int answer = _automaticallyDelete ? JOptionPane.YES_OPTION :
			JOptionPane.showOptionDialog(_parentFrame,
			I18nManager.getTextWithNumber("dialog.compress.confirm", inNumMarked),
			getName(), JOptionPane.YES_NO_CANCEL_OPTION,
			JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1]);
		if (answer == JOptionPane.CANCEL_OPTION) {
			// "always" is third option
			_automaticallyDelete = true;
		}

		// Make sure function knows what to do, whether we'll call it now or later
		FunctionLibrary.FUNCTION_DELETE_MARKED_POINTS.setParentFunction(
			getNameKey(), getShouldSplitSegments());
		if (_automaticallyDelete || answer == JOptionPane.YES_OPTION) {
			new Thread(() -> FunctionLibrary.FUNCTION_DELETE_MARKED_POINTS.begin()).start();
		}
	}

	/** by default, segments are not split at deleted points */
	protected boolean getShouldSplitSegments() {
		return false;
	}
}