]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/threedee/LineDialog.java
Version 11, August 2010
[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                 final int numLatLines = (_latLines == null?0:_latLines.length);
68                 final int numLonLines = (_lonLines == null?0:_lonLines.length);
69                 if (numLatLines == 0 && numLonLines == 0)
70                 {
71                         descBuffer.append("<p>").append(I18nManager.getText("dialog.3dlines.empty")).append("</p>");
72                 }
73                 else
74                 {
75                         descBuffer.append("<p>").append(I18nManager.getText("dialog.3dlines.intro")).append(":</p>");
76                         descBuffer.append("<p>").append(I18nManager.getText("fieldname.latitude")).append("<ul>");
77                         Latitude lat = null;
78                         for (int i=0; i<numLatLines; i++)
79                         {
80                                 lat = new Latitude(_latLines[i], Latitude.FORMAT_DEG);
81                                 descBuffer.append("<li>").append(lat.output(Latitude.FORMAT_DEG_WHOLE_MIN)).append("</li>");
82                         }
83                         descBuffer.append("</ul></p>");
84                         descBuffer.append("<p>").append(I18nManager.getText("fieldname.longitude")).append("<ul>");
85                         Longitude lon = null;
86                         for (int i=0; i<numLonLines; i++)
87                         {
88                                 lon = new Longitude(_lonLines[i], Longitude.FORMAT_DEG);
89                                 descBuffer.append("<li>").append(lon.output(Longitude.FORMAT_DEG_WHOLE_MIN)).append("</li>");
90                         }
91                         descBuffer.append("</ul></p>");
92                 }
93                 JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
94                 descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
95                 descPane.setEditable(false);
96                 descPane.setOpaque(false);
97                 panel.add(descPane, BorderLayout.CENTER);
98                 // ok button
99                 JPanel buttonPanel = new JPanel();
100                 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
101                 JButton okButton = new JButton(I18nManager.getText("button.ok"));
102                 okButton.addActionListener(new ActionListener() {
103                         public void actionPerformed(ActionEvent e)
104                         {
105                                 _dialog.dispose();
106                                 _dialog = null;
107                         }
108                 });
109                 buttonPanel.add(okButton);
110                 panel.add(buttonPanel, BorderLayout.SOUTH);
111                 return panel;
112         }
113 }