File: LineDialog.java

package info (click to toggle)
gpsprune 10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,220 kB
  • ctags: 3,013
  • sloc: java: 22,662; sh: 23; makefile: 16; python: 15
file content (111 lines) | stat: -rw-r--r-- 3,375 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package tim.prune.threedee;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;

import tim.prune.I18nManager;
import tim.prune.data.Latitude;
import tim.prune.data.Longitude;

/**
 * Class to show a dialog displaying the line coordinates
 * for a 3d view (either java3d or povray)
 */
public class LineDialog
{
	private JDialog _dialog = null;
	private JFrame _parent = null;
	private double[] _latLines = null;
	private double[] _lonLines = null;


	/**
	 * Constructor giving parent frame, latitude and longitude lines
	 * @param inParent parent frame for dialog
	 * @param inLatLines latitude lines as doubles
	 * @param inLonLines longitude lines as doubles
	 */
	public LineDialog(JFrame inParent, double[] inLatLines, double[] inLonLines)
	{
		_parent = inParent;
		_latLines = inLatLines;
		_lonLines = inLonLines;
	}


	/**
	 * Show the dialog with the lines
	 */
	public void showDialog()
	{
		_dialog = new JDialog(_parent, I18nManager.getText("dialog.3dlines.title"), true);
		_dialog.setLocationRelativeTo(_parent);
		_dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		_dialog.getContentPane().add(makeDialogComponents());
		_dialog.pack();
		_dialog.setVisible(true);
	}


	/**
	 * @return dialog components
	 */
	private JPanel makeDialogComponents()
	{
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		StringBuffer descBuffer = new StringBuffer();
		if (_latLines == null || _latLines.length == 0 || _lonLines == null || _lonLines.length == 0)
		{
			descBuffer.append("<p>").append(I18nManager.getText("dialog.3dlines.empty")).append("</p>");
		}
		else
		{
			descBuffer.append("<p>").append(I18nManager.getText("dialog.3dlines.intro")).append(":</p>");
			descBuffer.append("<p>").append(I18nManager.getText("fieldname.latitude")).append("<ul>");
			Latitude lat = null;
			for (int i=0; i<_latLines.length; i++)
			{
				lat = new Latitude(_latLines[i], Latitude.FORMAT_DEG);
				descBuffer.append("<li>").append(lat.output(Latitude.FORMAT_DEG_WHOLE_MIN)).append("</li>");
			}
			descBuffer.append("</ul></p>");
			descBuffer.append("<p>").append(I18nManager.getText("fieldname.longitude")).append("<ul>");
			Longitude lon = null;
			for (int i=0; i<_lonLines.length; i++)
			{
				lon = new Longitude(_lonLines[i], Longitude.FORMAT_DEG);
				descBuffer.append("<li>").append(lon.output(Longitude.FORMAT_DEG_WHOLE_MIN)).append("</li>");
			}
			descBuffer.append("</ul></p>");
		}
		JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
		descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
		descPane.setEditable(false);
		descPane.setOpaque(false);
		panel.add(descPane, BorderLayout.CENTER);
		// ok button
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JButton okButton = new JButton(I18nManager.getText("button.ok"));
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				_dialog.dispose();
				_dialog = null;
			}
		});
		buttonPanel.add(okButton);
		panel.add(buttonPanel, BorderLayout.SOUTH);
		return panel;
	}
}