/** * Search all the stars that could be in the hemisphere * * @param _date It's the date that will be use to search the stars * @param _dLat It's the latitude of the star's pointer * @param _dLon It's the longitude of the star's pointer * @throws SQLException * @return Return an arraylist that contains all the stars could be possible to see */ public ArrayList<CelestialObject> starsForCoordinates(Calendar _date, double _dLat, double _dLon) throws SQLException { ArrayList<CelestialObject> al_stars = new ArrayList<CelestialObject>(); int l_Bayer = 0; int l_id; int l_HIP; int l_HD; int l_HR; String l_ProperName; double l_dRA; double l_Dec; double l_dDistance; double l_dMag; double l_dColorIndex; try { if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat))) throw new IllegalArgumentException( "Error : Illegal latitude/longitude. Please check the coordinates !"); } catch (IllegalArgumentException e) { log.warning(e.getMessage()); _dLat = _dLon = 0; } Mathematics l_calc = new Mathematics(_date, _dLat, _dLon); for (CelestialObject star : this.allStars) { l_id = star.getId(); l_HIP = star.getHIP(); l_HD = star.getHD(); l_HR = star.getHR(); l_ProperName = star.getProperName(); l_dRA = star.getRA(); l_Dec = star.getDec(); l_dDistance = star.getDistance(); l_dMag = star.getMag(); l_dColorIndex = star.getColorIndex(); CelestialObject l_star = new CelestialObject( l_id, l_HIP, l_HD, l_HR, l_ProperName, l_dRA, l_Dec, l_dDistance, l_dMag, l_dColorIndex, l_Bayer); if (l_id == 1) // Sun { l_calc.calculatePositionSun(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); } else if (l_id == 2) // Moon { l_calc.calculatePositionMoon(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); double l_now = l_calc.getMoonBrightness(false); double l_yes = l_calc.getMoonBrightness(true); if (l_yes > l_now) l_now *= -1; l_star.setMag(l_now); } else l_calc.calculateAll(l_star.getDec(), l_star.getRA()); if (l_calc.getHeight() >= 0) { l_star.setXReal(l_calc.getX()); l_star.setYReal(l_calc.getY()); l_star.SetAzimuth(l_calc.getAzimuth()); l_star.SetHeight(l_calc.getHeight()); al_stars.add(l_star); } l_star = null; } return al_stars; }
/** * Search all the stars that has all the condition of the string * * @param _searchText The string that will be analyze by the function decryptText * @param _date It's the date that will be use to search the stars * @param _dLat It's the latitude of the star's pointer * @param _dLon It's the longitude of the star's pointer * @throws SQLException * @return Return an arraylist of CelestialObject. */ public ArrayList<CelestialObject> starsForText( String _searchText, Calendar _date, double _dLat, double _dLon) throws SQLException { ArrayList<CelestialObject> al_stars = new ArrayList<CelestialObject>(); int l_id; int l_HIP; int l_HD; int l_HR; String l_ProperName; double l_dRA; double l_Dec; double l_dDistance; double l_dMag; double l_dColorIndex; boolean secured = false; HashMap<String, String> hm_sWhere = decryptText(_searchText); Iterator<String> l_it = hm_sWhere.keySet().iterator(); String[] table = {this.sTable}; String[] field = {"*"}; String[][] where = new String[hm_sWhere.size()][3]; String[] orderby = {"id"}; int[] limit = {}; secured = true; int i = 0; while (l_it.hasNext()) { String l_sTemp = l_it.next().toString(); where[i][0] = l_sTemp; where[i][1] = "LIKE"; where[i][2] = "%" + hm_sWhere.get(l_sTemp).toString().trim() + "%"; i++; } ResultSet result = selectQuery(field, table, where, orderby, limit, secured); try { if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat))) throw new IllegalArgumentException( "Error : Illegal latitude/longitude. Please check the coordinates !"); } catch (IllegalArgumentException e) { log.warning(e.getMessage()); _dLat = _dLon = 0; } Mathematics l_calc = new Mathematics(_date, _dLat, _dLon); try { while (result.next()) { int l_Bayer = 0; l_id = result.getInt("id"); l_HIP = result.getInt("HIP"); l_HD = result.getInt("HD"); l_HR = result.getInt("HR"); l_ProperName = result.getString("ProperName"); l_dRA = result.getDouble("RA"); l_Dec = result.getDouble("Dec"); l_dDistance = result.getDouble("Distance"); l_dMag = result.getDouble("Mag"); l_dColorIndex = result.getDouble("ColorIndex"); CelestialObject l_star = new CelestialObject( l_id, l_HIP, l_HD, l_HR, l_ProperName, l_dRA, l_Dec, l_dDistance, l_dMag, l_dColorIndex, l_Bayer); if (l_id == 1) { l_calc.calculatePositionSun(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); } else if (l_id == 2) { l_calc.calculatePositionMoon(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); double l_now = l_calc.getMoonBrightness(false); double l_yes = l_calc.getMoonBrightness(true); if (l_yes > l_now) l_now *= -1; l_star.setMag(l_now); } else l_calc.calculateAll(l_star.getDec(), l_star.getRA()); if (l_calc.getHeight() > 0) { l_star.setXReal(l_calc.getX()); l_star.setYReal(l_calc.getY()); l_star.SetAzimuth(l_calc.getAzimuth()); l_star.SetHeight(l_calc.getHeight()); al_stars.add(l_star); } l_star = null; } } catch (SQLException e) { log.warning("Problem with the query's result !"); } result.close(); return al_stars; }
/** * Search all the constellations that could be in the hemisphere * * @param _date It's the date that will be use to search the stars * @param _dLat It's the latitude of the star's pointer * @param _dLon It's the longitude of the star's pointer * @throws SQLException * @return Return an arraylist that contains all the constellations could be possible to see */ public ArrayList<Constellation> getConstellations(Calendar _date, double _dLat, double _dLon) { ArrayList<Constellation> al_const = new ArrayList<Constellation>(); String l_ProperName; String l_oldProperName = ""; double l_dRA; double l_Dec; int l_Id; double l_X = 0.0; double l_Y = 0.0; double l_Xp = 0.0; double l_Yp = 0.0; boolean l_bStop = false; int i = 0; try { if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat))) throw new IllegalArgumentException( "Error : Illegal latitude/longitude. Please check the coordinates !"); } catch (IllegalArgumentException e) { log.warning(e.getMessage()); _dLat = _dLon = 0; } Mathematics l_calc = new Mathematics(_date, _dLat, _dLon); Constellation l_consts = new Constellation(); for (CelestialObject l_const : this.allConstellations) { l_ProperName = Messages.getString("MainView.Const_" + l_const.getProperName()); l_dRA = l_const.getRA(); l_Dec = l_const.getDec(); l_Id = l_const.getId(); if (!l_ProperName.equals(l_oldProperName)) l_bStop = false; if (!l_bStop) { if (!l_ProperName.equals(l_oldProperName) && !l_oldProperName.equals("")) { if (i != 0) { l_consts.setNameCoordinates(); al_const.add(l_consts); } l_consts = null; if (l_Id == 0) break; l_consts = new Constellation(); i = 0; } if (i++ == 0) l_consts.setProperName(l_ProperName); l_calc.calculateAll(l_Dec, l_dRA); if (l_calc.getHeight() >= 0) { l_X = l_calc.getX(); l_Y = l_calc.getY(); if (l_ProperName.equals(l_oldProperName) && i % 2 == 0) l_consts.addLine(l_Xp, -l_Yp, l_X, -l_Y); l_Xp = l_X; l_Yp = l_Y; } else l_bStop = true; l_oldProperName = l_ProperName; if (l_bStop) { l_consts = null; l_consts = new Constellation(); i = 0; } } } return al_const; }