@@ -105,6 +105,81 @@ public JPMain(Locale locale) {
105105
106106 }
107107
108+ public void setBearing (){
109+ if (listDir .getSelectedObjects ().length ==0 ){
110+ JOptionPane .showMessageDialog (null , new String (r .getString ("select_item" ).getBytes (),StandardCharsets .UTF_8 ), new String (r .getString ("attention" ).getBytes (),StandardCharsets .UTF_8 ), JOptionPane .INFORMATION_MESSAGE );
111+ return ; //Need selected elements to work
112+ }
113+ Object [] bearings = new Object [361 ];
114+ for (int i =0 ;i <=360 ;i ++){
115+ bearings [i ]=i ;
116+ }
117+ String [] dirs = listDir .getSelectedItems ();
118+ for (String dir :dirs ){
119+ Object bearing_offset = JOptionPane .showInputDialog (jbRemove , new String (r .getString ("set_offset" ).getBytes (),StandardCharsets .UTF_8 ), new String (r .getString ("attention" ).getBytes (),StandardCharsets .UTF_8 ), JOptionPane .QUESTION_MESSAGE , null , bearings , 0 );
120+ if (bearing_offset ==null ){
121+ return ;
122+ }
123+ Thread t = new Thread (){
124+ public void run (){
125+ processBearing (dir ,(int )bearing_offset );
126+ }
127+ };
128+ t .start ();
129+
130+ }
131+ }
132+
133+ public void processBearing (String directory , int Offset ){
134+ File dir_photos = new File (directory );
135+ //filter only .jpgs
136+ FilenameFilter fileNameFilter = new FilenameFilter () {
137+ public boolean accept (File dir , String name ) {
138+ if (name .lastIndexOf ('.' ) > 0 ) {
139+ int lastIndex = name .lastIndexOf ('.' );
140+ String str = name .substring (lastIndex );
141+ if (str .toLowerCase (Locale .ENGLISH ).equals (".jpg" )) {
142+ return true ;
143+ }
144+ }
145+ return false ;
146+ }
147+ };
148+ File [] file_list = dir_photos .listFiles (fileNameFilter );
149+ System .out .println ("Pictures found:" + String .valueOf (file_list .length ));
150+
151+ System .out .println ("Sorting files" );
152+ //sort by modified time
153+ Arrays .sort (file_list , new Comparator <File >(){
154+ public int compare (File f1 , File f2 )
155+ {
156+ return Long .valueOf (Helper .getFileTime (f1 )).compareTo (Helper .getFileTime (f2 ));
157+ }});
158+ System .out .println ("End sorting" );
159+
160+ Double last_bearing ;
161+ ImageProperties imTO = null ;
162+ ImageProperties imFROM = null ;
163+ for (int i =file_list .length -1 ;i >=0 ;i --){
164+ if (i ==0 ){
165+ //TODO: set last bearing
166+ continue ;
167+ }
168+ if (imTO ==null ){
169+ imTO = Helper .getImageProperties (file_list [i ]);
170+ imFROM = Helper .getImageProperties (file_list [i -1 ]);
171+ }
172+ else
173+ {
174+ imTO =imFROM ;
175+ imFROM = Helper .getImageProperties (file_list [i -1 ]);
176+ }
177+ last_bearing = (Helper .calc_bearing (imFROM .getLatitude (), imFROM .getLongitude (), imTO .getLatitude (), imTO .getLongitude ())+ Offset ) % 360.00 ;
178+ System .out .println ("Calculated bearing (with offset) at: " + last_bearing );
179+
180+ }
181+ }
182+
108183 private void setUILang (){
109184 jlDirectories .setText (new String (r .getString ("Directories" ).getBytes (), StandardCharsets .UTF_8 ));
110185 jbAdd .setText (new String (r .getString ("Add_Folder" ).getBytes (), StandardCharsets .UTF_8 ));
0 commit comments