OSPE_LoadLocalObjectsCat.java
5.32 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package osp.ui;
import java.awt.geom.Point2D;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;
//import javafx.scene.layout.Priority;
import osp.FieldOfView;
import osp.LocalCatObject;
public class OSPE_LoadLocalObjectsCat
{
/** Parent Main Frame */
private OSPE_MainFrame pater;
/** Field of view */
private FieldOfView fov;
OSPE_LoadLocalObjectsCat(OSPE_MainFrame p, FieldOfView fov)
{
pater = p;
this.fov = fov;
}
public boolean loadLocalObjectsCat(File catFile)
{
boolean noError=false;
ArrayList<LocalCatObject> localObjectsList = new ArrayList<LocalCatObject>();
Point2D.Double position;
String prop="";
try
{
// Prepare to read from the file, using a Scanner object
Scanner in = new Scanner(catFile);
String idObj="";
String ra = null;
String dec = null;
String tab[]= new String[5];
String line;
int prior=0;
int i=0;
String temp="";
// Read each line until end of file is reached
while (in.hasNextLine())
{
i=0;
// Read an entire line, which contains all the details for 1 account
line = in.nextLine();
// Make a Scanner object to break up this line into parts
Scanner lineBreaker = new Scanner(line);
String firstChar = null;
if (lineBreaker.hasNext())
{
firstChar = lineBreaker.next();
idObj=firstChar;
}
if ((!firstChar.isEmpty()) && (!firstChar.equals("#")))
{
// 1st part is the account number
idObj=firstChar;
try
{
LocalCatObject obj;
// 2nd part is RA
if (lineBreaker.hasNext())
ra = lineBreaker.next();
// 3nd part is Dec
if (lineBreaker.hasNext())
dec = lineBreaker.next();
// Test if 4th field - if is number then is priority, if not, is from
if (lineBreaker.hasNext())
{
String field = lineBreaker.next();
if (!("".equals(field)))
{
if (isInt(field))
prior=Integer.parseInt(field);
else
{
tab[i] = field;
temp=temp+" "+tab[i];
i++;
}
}
}
// Read the rest of the file
while (lineBreaker.hasNext() && i<5)
{
tab[i] = lineBreaker.next();
temp=temp+"\\t"+tab[i];
i++;
}
obj=new LocalCatObject(idObj,ra,dec,prior,temp);
temp="";
/*
position = obj.getPosition();
if (nbObj==0)
{
posMin = new Point2D.Double(position.x,position.y);
posMax = new Point2D.Double(position.x,position.y);
}
// set the min and max of the objects imported.
if (position.x< posMin.x)
posMin.x=position.x;
if (position.y< posMin.y)
posMin.y=position.y;
if (position.x> posMax.x)
posMax.x=position.x;
if (position.y> posMax.y)
posMax.y=position.y;
*/
localObjectsList.add(obj);
ra=null;
dec=null;
prior=0;
}
catch (InputMismatchException e)
{
System.out.println("File not found.");
}
catch (NoSuchElementException e)
{
System.out.println("File not found");
}
}
lineBreaker.close();
} // End while
in.close();
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
} // Make an ArrayList to store all the accounts we will make
int objNb= localObjectsList.size();
String idObj ="";
int nbCat = pater.getVisuPanel().getOspeControl().getNbLoadCat();
nbCat++;
pater.getVisuPanel().getOspeControl().setNbLoadCat(nbCat);
if (objNb >0)
{
for(int i=0;i<objNb;i++)
{
//idObj =Integer.parseInt(localObjectsList.get(i).getId());
idObj=localObjectsList.get(i).getId();
position=localObjectsList.get(i).getPosition();
//String [] prop=localObjectsList.get(i).getProperties();
//String temp="";
int prior = localObjectsList.get(i).getPriority();
prop=localObjectsList.get(i).getProperty();
pater.getVisuPanel().addObject(idObj,nbCat, prop, position,prior);
}
fov.update();
}
return noError;
}
public boolean isInt(String ch) {
try {
Integer.parseInt(ch);
} catch (NumberFormatException e){
return false;
}
return true;
}
}