]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/threedee/LineDialog.java
a0f218a65e82bbcd8fe9221a906b957d894a984f
[GpsPrune.git] / tim / prune / threedee / LineDialog.java
1 package tim.prune.threedee;
2
3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7
8 import javax.swing.BorderFactory;
9 import javax.swing.JButton;
10 import javax.swing.JDialog;
11 import javax.swing.JEditorPane;
12 import javax.swing.JFrame;
13 import javax.swing.JPanel;
14
15 import tim.prune.I18nManager;
16 import tim.prune.data.Latitude;
17 import tim.prune.data.Longitude;
18
19 /**
20  * Class to show a dialog displaying the line coordinates
21  * for a 3d view (either java3d or povray)
22  */
23 public class LineDialog
24 {
25         private JDialog _dialog = null;
26         private JFrame _parent = null;
27         private double[] _latLines = null;
28         private double[] _lonLines = null;
29
30
31         /**
32          * Constructor giving parent frame, latitude and longitude lines
33          * @param inParent parent frame for dialog
34          * @param inLatLines latitude lines as doubles
35          * @param inLonLines longitude lines as doubles
36          */
37         public LineDialog(JFrame inParent, double[] inLatLines, double[] inLonLines)
38         {
39                 _parent = inParent;
40                 _latLines = inLatLines;
41                 _lonLines = inLonLines;
42         }
43
44
45         /**
46          * Show the dialog with the lines
47          */
48         public void showDialog()
49         {
50                 _dialog = new JDialog(_parent, I18nManager.getText("dialog.3dlines.title"), true);
51                 _dialog.setLocationRelativeTo(_parent);
52                 _dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
53                 _dialog.getContentPane().add(makeDialogComponents());
54                 _dialog.pack();
55                 _dialog.setVisible(true);
56         }
57
58
59         /**
60          * @return dialog components
61          */
62         private JPanel makeDialogComponents()
63         {
64                 JPanel panel = new JPanel();
65                 panel.setLayout(new BorderLayout());
66                 StringBuffer descBuffer = new StringBuffer();
67                 if (_latLines == null || _latLines.length == 0 || _lonLines == null || _lonLines.length == 0)
68                 {
69                         descBuffer.append("<p>").append(I18nManager.getText("dialog.3dlines.empty")).append("</p>");
70                 }
71                 else
72                 {
73                         descBuffer.append("<p>").append(I18nManager.getText("dialog.3dlines.intro")).append(":</p>");
74                         descBuffer.append("<p>").append(I18nManager.getText("fieldname.latitude")).append("<ul>");
75                         Latitude lat = null;
76                         for (int i=0; i<_latLines.length; i++)
77                         {
78                                 lat = new Latitude(_latLines[i], Latitude.FORMAT_DEG);
79                                 descBuffer.append("<li>").append(lat.output(Latitude.FORMAT_DEG_WHOLE_MIN)).append("</li>");
80                         }
81                         descBuffer.append("</ul></p>");
82                         descBuffer.append("<p>").append(I18nManager.getText("fieldname.longitude")).append("<ul>");
83                         Longitude lon = null;
84                         for (int i=0; i<_lonLines.length; i++)
85                         {
86                                 lon = new Longitude(_lonLines[i], Longitude.FORMAT_DEG);
87                                 descBuffer.append("<li>").append(lon.output(Longitude.FORMAT_DEG_WHOLE_MIN)).append("</li>");
88                         }
89                         descBuffer.append("</ul></p>");
90                 }
91                 JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
92                 descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
93                 descPane.setEditable(false);
94                 descPane.setOpaque(false);
95                 panel.add(descPane, BorderLayout.CENTER);
96                 // ok button
97                 JPanel buttonPanel = new JPanel();
98                 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
99                 JButton okButton = new JButton(I18nManager.getText("button.ok"));
100                 okButton.addActionListener(new ActionListener() {
101                         public void actionPerformed(ActionEvent e)
102                         {
103                                 _dialog.dispose();
104                                 _dialog = null;
105                         }
106                 });
107                 buttonPanel.add(okButton);
108                 panel.add(buttonPanel, BorderLayout.SOUTH);
109                 return panel;
110         }
111 }