/
Program.java
1081 lines (978 loc) · 34.4 KB
/
Program.java
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2009-2021 Contributors (see credits.txt)
*
* This file is part of jEveAssets.
*
* jEveAssets is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* jEveAssets is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with jEveAssets; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.nikr.eve.jeveasset;
import apple.dts.samplecode.osxadapter.OSXAdapter;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.text.DefaultEditorKit;
import net.nikr.eve.jeveasset.data.api.accounts.OwnerType;
import net.nikr.eve.jeveasset.data.api.my.MyAccountBalance;
import net.nikr.eve.jeveasset.data.api.my.MyAsset;
import net.nikr.eve.jeveasset.data.api.my.MyContract;
import net.nikr.eve.jeveasset.data.api.my.MyContractItem;
import net.nikr.eve.jeveasset.data.api.my.MyIndustryJob;
import net.nikr.eve.jeveasset.data.api.my.MyJournal;
import net.nikr.eve.jeveasset.data.api.my.MyMarketOrder;
import net.nikr.eve.jeveasset.data.api.my.MyTransaction;
import net.nikr.eve.jeveasset.data.profile.ProfileData;
import net.nikr.eve.jeveasset.data.profile.ProfileManager;
import net.nikr.eve.jeveasset.data.sde.MyLocation;
import net.nikr.eve.jeveasset.data.sde.StaticData;
import net.nikr.eve.jeveasset.data.settings.AssetAddedData;
import net.nikr.eve.jeveasset.data.settings.Settings;
import net.nikr.eve.jeveasset.data.settings.TrackerData;
import net.nikr.eve.jeveasset.data.settings.tag.TagUpdate;
import net.nikr.eve.jeveasset.gui.dialogs.AboutDialog;
import net.nikr.eve.jeveasset.gui.dialogs.account.AccountManagerDialog;
import net.nikr.eve.jeveasset.gui.dialogs.profile.ProfileDialog;
import net.nikr.eve.jeveasset.gui.dialogs.settings.SettingsDialog;
import net.nikr.eve.jeveasset.gui.dialogs.settings.UserLocationSettingsPanel;
import net.nikr.eve.jeveasset.gui.dialogs.settings.UserNameSettingsPanel;
import net.nikr.eve.jeveasset.gui.dialogs.settings.UserPriceSettingsPanel;
import net.nikr.eve.jeveasset.gui.dialogs.update.StructureUpdateDialog;
import net.nikr.eve.jeveasset.gui.dialogs.update.UpdateDialog;
import net.nikr.eve.jeveasset.gui.frame.MainMenu.MainMenuAction;
import net.nikr.eve.jeveasset.gui.frame.MainWindow;
import net.nikr.eve.jeveasset.gui.frame.StatusPanel;
import net.nikr.eve.jeveasset.gui.frame.StatusPanel.UpdateType;
import net.nikr.eve.jeveasset.gui.images.Images;
import net.nikr.eve.jeveasset.gui.shared.Updatable;
import net.nikr.eve.jeveasset.gui.shared.components.JLockWindow;
import net.nikr.eve.jeveasset.gui.shared.components.JMainTab;
import net.nikr.eve.jeveasset.gui.tabs.assets.AssetsTab;
import net.nikr.eve.jeveasset.gui.tabs.contracts.ContractsTab;
import net.nikr.eve.jeveasset.gui.tabs.items.ItemsTab;
import net.nikr.eve.jeveasset.gui.tabs.jobs.IndustryJobsTab;
import net.nikr.eve.jeveasset.gui.tabs.journal.JournalTab;
import net.nikr.eve.jeveasset.gui.tabs.loadout.LoadoutsTab;
import net.nikr.eve.jeveasset.gui.tabs.materials.MaterialsTab;
import net.nikr.eve.jeveasset.gui.tabs.orders.MarketOrdersTab;
import net.nikr.eve.jeveasset.gui.tabs.overview.OverviewTab;
import net.nikr.eve.jeveasset.gui.tabs.reprocessed.ReprocessedTab;
import net.nikr.eve.jeveasset.gui.tabs.routing.RoutingTab;
import net.nikr.eve.jeveasset.gui.tabs.stockpile.StockpileTab;
import net.nikr.eve.jeveasset.gui.tabs.tracker.TrackerTab;
import net.nikr.eve.jeveasset.gui.tabs.transaction.TransactionTab;
import net.nikr.eve.jeveasset.gui.tabs.tree.TreeTab;
import net.nikr.eve.jeveasset.gui.tabs.values.DataSetCreator;
import net.nikr.eve.jeveasset.gui.tabs.values.ValueRetroTab;
import net.nikr.eve.jeveasset.gui.tabs.values.ValueTableTab;
import net.nikr.eve.jeveasset.i18n.GuiFrame;
import net.nikr.eve.jeveasset.i18n.GuiShared;
import net.nikr.eve.jeveasset.data.settings.ContractPriceManager;
import net.nikr.eve.jeveasset.gui.tabs.jobs.IndustrySlotsTab;
import net.nikr.eve.jeveasset.gui.tabs.orders.OutbidProcesser.OutbidProcesserOutput;
import net.nikr.eve.jeveasset.io.online.PriceDataGetter;
import net.nikr.eve.jeveasset.io.online.Updater;
import net.nikr.eve.jeveasset.io.shared.DesktopUtil;
import net.nikr.eve.jeveasset.io.shared.FileUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Program implements ActionListener {
private static final Logger LOG = LoggerFactory.getLogger(Program.class);
private enum ProgramAction {
TIMER
}
//Major.Minor.Bugfix [Release Candidate n] [BETA n] [DEV BUILD #n];
public static final String PROGRAM_VERSION = "6.9.4 DEV BUILD 1";
public static final String PROGRAM_NAME = "jEveAssets";
public static final String PROGRAM_HOMEPAGE = "https://eve.nikr.net/jeveasset";
public static final boolean PROGRAM_DEV_BUILD = false;
private static boolean debug = false;
private static boolean forceUpdate = false;
private static boolean forceNoUpdate = false;
private static boolean portable = false;
private static boolean lazySave = false;
//Height
private static int height = 22; //Defaults to 22
//GUI
private MainWindow mainWindow;
//Dialogs
private AccountManagerDialog accountManagerDialog;
private AboutDialog aboutDialog;
private ProfileDialog profileDialog;
private SettingsDialog settingsDialog;
private UpdateDialog updateDialog;
//Tabs
private ValueRetroTab valueRetroTab;
private ValueTableTab valueTableTab;
private MaterialsTab materialsTab;
private LoadoutsTab loadoutsTab;
private RoutingTab routingTab;
private MarketOrdersTab marketOrdersTab;
private JournalTab journalTab;
private TransactionTab transactionsTab;
private IndustryJobsTab industryJobsTab;
private IndustrySlotsTab industrySlotsTab;
private AssetsTab assetsTab;
private OverviewTab overviewTab;
private StockpileTab stockpileTab;
private ItemsTab itemsTab;
private TrackerTab trackerTab;
private ReprocessedTab reprocessedTab;
private ContractsTab contractsTab;
private TreeTab treeTab;
private StructureUpdateDialog structureUpdateDialog;
//Misc
private Updater updater;
private Timer timer;
private Updatable updatable;
private final Map<String, JMainTab> jMainTabs = new HashMap<>();
//Data
private final ProfileData profileData;
private final ProfileManager profileManager;
private final PriceDataGetter priceDataGetter;
private final String localData;
public Program() {
if (debug) {
LOG.debug("Force Update: {} Force No Update: {}", forceUpdate, forceNoUpdate);
DetectEdtViolationRepaintManager.install();
}
if (PROGRAM_DEV_BUILD) {
portable = true;
}
//Data
SplashUpdater.setText("Loading DATA");
LOG.info("DATA Loading...");
FileUtil.autoImportFileUtil();
StaticData.load();
Settings.load();
TrackerData.load();
AssetAddedData.load();
ContractPriceManager.load();
initLookAndFeel(Settings.get().getColorSettings().getLookAndFeelClass());
calcButtonsHeight(); //Must be done after setting the LAF
updater = new Updater();
localData = updater.getLocalData();
if (!PROGRAM_DEV_BUILD) {
update();
}
profileManager = new ProfileManager();
profileManager.searchProfile();
profileManager.loadActiveProfile();
profileData = new ProfileData(profileManager);
//Can not update profile data now - list needs to be empty doing creation...
priceDataGetter = new PriceDataGetter();
priceDataGetter.load();
//Timer
timer = new Timer(15000, this); //Once a minute
timer.setActionCommand(ProgramAction.TIMER.name());
//Updatable
updatable = new Updatable(this);
//GUI
SplashUpdater.setText("Loading GUI");
LOG.info("GUI Loading:");
LOG.info("Loading: Images");
Images.preload();
LOG.info("Loading: Main Window");
mainWindow = new MainWindow(this);
SplashUpdater.setProgress(50);
//Tools
LOG.info("Loading: Assets Tab");
assetsTab = new AssetsTab(this);
mainWindow.addTab(assetsTab);
SplashUpdater.setProgress(52);
LOG.info("Loading: Tree Tab");
treeTab = new TreeTab(this);
SplashUpdater.setProgress(54);
LOG.info("Loading: Industry Jobs Tab");
industryJobsTab = new IndustryJobsTab(this);
LOG.info("Loading: Industry Slot Tab");
industrySlotsTab = new IndustrySlotsTab(this);
LOG.info("Loading: Industry Plot Tab");
//FIXME - - > IndustryPlotTab - remove or ?
//industryPlotTab = new IndustryPlotTab(this);
SplashUpdater.setProgress(56);
LOG.info("Loading: Market Orders Tab");
marketOrdersTab = new MarketOrdersTab(this);
SplashUpdater.setProgress(58);
LOG.info("Loading: Journal Tab");
journalTab = new JournalTab(this);
SplashUpdater.setProgress(60);
LOG.info("Loading: Transactions Tab");
transactionsTab = new TransactionTab(this);
SplashUpdater.setProgress(62);
LOG.info("Loading: Materials Tab");
materialsTab = new MaterialsTab(this);
SplashUpdater.setProgress(64);
LOG.info("Loading: Ship Loadouts Tab");
loadoutsTab = new LoadoutsTab(this);
SplashUpdater.setProgress(66);
LOG.info("Loading: Values Tab");
valueRetroTab = new ValueRetroTab(this);
valueTableTab = new ValueTableTab(this);
SplashUpdater.setProgress(68);
LOG.info("Loading: Routing Tab");
routingTab = new RoutingTab(this);
SplashUpdater.setProgress(70);
LOG.info("Loading: Overview Tab");
overviewTab = new OverviewTab(this);
SplashUpdater.setProgress(72);
LOG.info("Loading: Stockpile Tab");
stockpileTab = new StockpileTab(this);
SplashUpdater.setProgress(74);
LOG.info("Loading: Items Tab");
itemsTab = new ItemsTab(this);
SplashUpdater.setProgress(76);
LOG.info("Loading: Tracker Tab");
trackerTab = new TrackerTab(this);
SplashUpdater.setProgress(78);
LOG.info("Loading: Reprocessed Tab");
reprocessedTab = new ReprocessedTab(this);
SplashUpdater.setProgress(80);
LOG.info("Loading: Contracts Tab");
contractsTab = new ContractsTab(this);
SplashUpdater.setProgress(82);
//Dialogs
LOG.info("Loading: Account Manager Dialog");
accountManagerDialog = new AccountManagerDialog(this);
SplashUpdater.setProgress(84);
LOG.info("Loading: About Dialog");
aboutDialog = new AboutDialog(this);
SplashUpdater.setProgress(86);
LOG.info("Loading: Profiles Dialog");
profileDialog = new ProfileDialog(this);
SplashUpdater.setProgress(88);
LOG.info("Loading: Update Dialog");
updateDialog = new UpdateDialog(this);
SplashUpdater.setProgress(90);
LOG.info("Loading: Options Dialog");
settingsDialog = new SettingsDialog(this);
SplashUpdater.setProgress(96);
LOG.info("Loading: Structure UpdateDialog");
structureUpdateDialog = new StructureUpdateDialog(this);
//GUI Done
LOG.info("GUI loaded");
//Updating data...
LOG.info("Updating data...");
updateEventLists(); //Update price
macOsxCode();
//Open Tools
for (String title : Settings.get().getShowTools()) {
for (JMainTab jMainTab : jMainTabs.values()) {
if (title.equals(jMainTab.getTitle())) {
mainWindow.addTab(jMainTab, false);
}
}
}
SplashUpdater.setProgress(100);
LOG.info("Showing GUI");
mainWindow.show();
SplashUpdater.hide();
//Start timer
timerTicked();
LOG.info("Startup Done");
if (debug) {
LOG.info("Show Debug Warning");
JOptionPane.showMessageDialog(mainWindow.getFrame(), "WARNING: Debug is enabled", "Debug", JOptionPane.WARNING_MESSAGE);
}
if (PROGRAM_DEV_BUILD) {
JOptionPane.showMessageDialog(mainWindow.getFrame(), "WARNING: This is a dev build\r\n\r\nNotes:\r\n- Always run portable\r\n- Settings and profiles are cloned\r\n- Does not check for updates\r\n- Expect bugs!", "DEV BUILD", JOptionPane.WARNING_MESSAGE);
}
if (Settings.get().isSettingsLoadError()) {
JOptionPane.showMessageDialog(mainWindow.getFrame(), GuiShared.get().errorLoadingSettingsMsg(), GuiShared.get().errorLoadingSettingsTitle(), JOptionPane.ERROR_MESSAGE);
}
profileManager.showProfileLoadErrorWarning(mainWindow.getFrame());
if (profileManager.getOwnerTypes().isEmpty()) {
LOG.info("Show Account Manager");
accountManagerDialog.setVisible(true);
}
}
/**
*
* @param load does nothing except change the signature.
*/
protected Program(final boolean load) {
profileData = null;
profileManager = null;
priceDataGetter = null;
localData = null;
}
private void initLookAndFeel(String lookAndFeel) {
initLookAndFeel(lookAndFeel, true);
}
private void initLookAndFeel(String lookAndFeel, boolean tryDefault) {
//Allow users to overwrite LaF
if (System.getProperty("swing.defaultlaf") != null) {
return;
}
//lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
//lookAndFeel = UIManager.getSystemLookAndFeelClassName(); //System
//lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName(); //Java
//lookAndFeel = "javax.swing.plaf.nimbus.NimbusLookAndFeel"; //Nimbus
//lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel"; //Metal
//lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; //GTK+
//lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; //CDE/Motif
//flatlaf
//lookAndFeel = "com.formdev.flatlaf.FlatLightLaf"; //Flat Light
//lookAndFeel = "com.formdev.flatlaf.FlatDarkLaf"; //Flat Dark
//lookAndFeel = "com.formdev.flatlaf.FlatIntelliJLaf"; //Flat IntelliJ
//lookAndFeel = "com.formdev.flatlaf.FlatDarculaLaf"; //Flat Darcula
try {
UIManager.setLookAndFeel(lookAndFeel);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
LOG.error(ex.getMessage(), ex);
//In case the settings is using an unsupported look and feel
//Try system look and feel
if (tryDefault) {
initLookAndFeel(UIManager.getSystemLookAndFeelClassName(), false);
}
}
setMacKeys(); // This must be performed immediately after the LaF has been set
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
}
private void setMacKeys() {
// Ensure Max OSX key bindings are useable for copy, cut, paste, and select all
addMacKeysText(UIManager.get("EditorPane.focusInputMap"));
addMacKeysText(UIManager.get("FormattedTextField.focusInputMap"));
addMacKeysText(UIManager.get("PasswordField.focusInputMap"));
addMacKeysText(UIManager.get("TextField.focusInputMap"));
addMacKeysText(UIManager.get("TextPane.focusInputMap"));
addMacKeysText(UIManager.get("TextArea.focusInputMap"));
addMacKeysMisc(UIManager.get("Table.ancestorInputMap"));
addMacKeysMisc(UIManager.get("Tree.focusInputMap"));
addMacKeysMisc(UIManager.get("List.focusInputMap"));
}
private void addMacKeysText(Object object) {
if (object instanceof InputMap) { //Better safe than sorry
InputMap inputMap = (InputMap) object;
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), DefaultEditorKit.copyAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), DefaultEditorKit.cutAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK), DefaultEditorKit.pasteAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_DOWN_MASK), DefaultEditorKit.selectAllAction);
}
}
private void addMacKeysMisc(Object object) {
if (object instanceof InputMap) { //Better safe than sorry
InputMap inputMap = (InputMap) object;
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), "copy");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), "cut");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK), "parse");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_DOWN_MASK), "selectAll");
}
}
public static int getButtonsHeight() {
return height;
}
private void calcButtonsHeight() {
height = Math.max(height, new JComboBox<>().getPreferredSize().height);
height = Math.max(height, new JTextField().getPreferredSize().height);
height = Math.max(height, new JButton().getPreferredSize().height);
}
public static int getButtonsWidth() {
return 90;
}
public void addMainTab(final String toolName, final JMainTab jMainTab) {
JMainTab old = jMainTabs.put(toolName, jMainTab);
if (old != null) {
throw new RuntimeException("toolName: " + toolName + " is duplicated");
}
}
public Map<String, JMainTab> getMainTabs() {
return jMainTabs;
}
private void timerTicked() {
if (!timer.isRunning()) {
timer.start();
}
boolean isUpdatable = updatable.isUpdatable();
this.getStatusPanel().timerTicked(isUpdatable);
this.getMainWindow().getMenu().timerTicked(isUpdatable, StructureUpdateDialog.structuresUpdatable(this));
}
public final void update() {
updater.update(Program.PROGRAM_VERSION, localData, Settings.get().getProxyData());
}
public boolean checkProgramUpdate() {
return updater.checkProgramUpdate(Program.PROGRAM_VERSION);
}
public boolean checkDataUpdate() {
return updater.checkDataUpdate(localData);
}
public final void updateMarketOrdersWithProgress(OutbidProcesserOutput output) {
JLockWindow jLockWindow = new JLockWindow(getMainWindow().getFrame());
jLockWindow.show(GuiShared.get().updating(), new JLockWindow.LockWorker() {
@Override
public void task() {
updateEventLists(null, null, null, output);
}
@Override
public void gui() { }
});
}
public final void updateMarketOrders(OutbidProcesserOutput output) {
updateEventLists(null, null, null, output);
}
public final void updateLocations(Set<Long> locationIDs) {
JLockWindow jLockWindow = new JLockWindow(getMainWindow().getFrame());
jLockWindow.show(GuiShared.get().updating(), new JLockWindow.LockWorker() {
@Override
public void task() {
updateEventLists(null, locationIDs, null, null);
}
@Override
public void gui() { }
});
}
public final void updatePrices(Set<Integer> typeIDs) {
JLockWindow jLockWindow = new JLockWindow(getMainWindow().getFrame());
jLockWindow.show(GuiShared.get().updating(), new JLockWindow.LockWorker() {
@Override
public void task() {
updateEventLists(null, null, typeIDs, null);
}
@Override
public void gui() { }
});
}
public final void updateNames(Set<Long> itemIDs) {
JLockWindow jLockWindow = new JLockWindow(getMainWindow().getFrame());
jLockWindow.show(GuiShared.get().updating(), new JLockWindow.LockWorker() {
@Override
public void task() {
updateEventLists(itemIDs, null, null, null);
}
@Override
public void gui() { }
});
}
public final void updateEventListsWithProgress() {
updateEventListsWithProgress(getMainWindow().getFrame());
}
public final void updateEventListsWithProgress(final Window parent) {
JLockWindow jLockWindow = new JLockWindow(parent);
jLockWindow.show(GuiShared.get().updating(), new JLockWindow.LockWorker() {
@Override
public void task() {
updateEventLists();
}
@Override
public void gui() { }
});
}
public final void updateEventLists() {
updateEventLists(null, null, null, null);
}
private synchronized void updateEventLists(Set<Long> itemIDs, Set<Long> locationIDs, Set<Integer> typeIDs, OutbidProcesserOutput output) {
LOG.info("Updating EventList");
for (JMainTab jMainTab : mainWindow.getTabs()) {
ensureEDT(new Runnable() {
@Override
public void run() {
jMainTab.beforeUpdateData();
}
});
}
if (output != null) {
profileData.updateMarketOrders(output);
} else if (itemIDs != null) {
profileData.updateNames(itemIDs);
} else if (locationIDs != null) {
profileData.updateLocations(locationIDs);
} else if (typeIDs != null) {
profileData.updatePrice(typeIDs);
} else {
profileData.updateEventLists();
}
if (locationIDs != null) { //Update locations
for (JMainTab jMainTab : mainWindow.getTabs()) {
ensureEDT(new Runnable() {
@Override
public void run() {
jMainTab.updateLocations(locationIDs);
}
});
}
} else if (typeIDs != null) { //Update prices
for (JMainTab jMainTab : mainWindow.getTabs()) {
ensureEDT(new Runnable() {
@Override
public void run() {
jMainTab.updatePrices(typeIDs);
}
});
}
} else if (itemIDs != null) { //Update names
for (JMainTab jMainTab : mainWindow.getTabs()) {
ensureEDT(new Runnable() {
@Override
public void run() {
jMainTab.updateNames(itemIDs);
}
});
}
} else { //Full update
for (JMainTab jMainTab : mainWindow.getTabs()) {
ensureEDT(new Runnable() {
@Override
public void run() {
jMainTab.updateData();
}
});
}
}
for (JMainTab jMainTab : mainWindow.getTabs()) {
ensureEDT(new Runnable() {
@Override
public void run() {
jMainTab.afterUpdateData();
jMainTab.updateCache();
}
});
}
ensureEDT(new Runnable() {
@Override
public void run() {
if (stockpileTab != null) {
stockpileTab.updateStockpileDialog();
}
}
});
ensureEDT(new Runnable() {
@Override
public void run() {
timerTicked();
}
});
ensureEDT(new Runnable() {
@Override
public void run() {
updateTableMenu();
}
});
}
public static void ensureEDT(Runnable runnable) {
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
try {
SwingUtilities.invokeAndWait(runnable);
} catch (InterruptedException | InvocationTargetException ex) {
throw new RuntimeException(ex);
}
}
}
/**
* Save Settings ASAP
* @param msg Who is saving what?
*/
public void saveSettings(final String msg) {
if (!lazySave && !Settings.ignoreSave()) {
Settings.saveStart();
Thread thread = new SaveSettings(msg, this);
thread.start();
}
}
private void doSaveSettings(final String msg) {
LOG.info("Saving Settings: " + msg);
Settings.lock("Table (Column/Width/Resize) and Window Settings"); //Lock for Table (Column/Width/Resize) and Window Settings
mainWindow.updateSettings();
for (JMainTab jMainTab : jMainTabs.values()) {
jMainTab.saveSettings();
}
Settings.unlock("Table (Column/Width/Resize) and Window Settings"); //Unlock for Table (Column/Width/Resize) and Window Settings
Settings.saveSettings();
}
public void saveSettingsAndProfile() {
if (lazySave) {
doSaveSettings("API Update");
} else {
saveSettings("API Update");
Settings.waitForEmptySaveQueue();
}
saveProfile();
}
public synchronized void saveProfile() {
LOG.info("Saving Profile");
profileManager.saveProfile();
}
/**
* Used by macOsxCode() - should not be changed
*/
public void exit() {
if (getStatusPanel().updateInProgress() > 0) {
int value = JOptionPane.showConfirmDialog(getMainWindow().getFrame(), GuiFrame.get().exitMsg(getStatusPanel().updateInProgress()), GuiFrame.get().exitTitle(getStatusPanel().updateInProgress()), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (value != JOptionPane.OK_OPTION) {
return;
}
}
getStatusPanel().cancelUpdates();
saveExit();
LOG.info("Running shutdown hook(s) and exiting...");
System.exit(0);
}
/**
* Used by macOsxCode() - should not be renamed
*/
public void saveExit() {
if (lazySave) {
doSaveSettings("Exit");
} else {
LOG.info("Waiting for save queue to finish...");
Settings.waitForEmptySaveQueue();
}
TrackerData.waitForEmptySaveQueue();
}
/**
* Used by macOsxCode() - should not be renamed
*/
public void showAbout() {
aboutDialog.setVisible(true);
}
/**
* Used by macOsxCode() - should not be renamed
*/
public void showSettings() {
settingsDialog.setVisible(true);
}
public String getProgramDataVersion() {
return localData;
}
private void macOsxCode() {
if (FileUtil.onMac()) {
try {
OSXAdapter.setQuitHandler(this, getClass().getDeclaredMethod("saveExit", (Class[]) null));
OSXAdapter.setAboutHandler(this, getClass().getDeclaredMethod("showAbout", (Class[]) null));
OSXAdapter.setPreferencesHandler(this, getClass().getDeclaredMethod("showSettings", (Class[]) null));
} catch (NoSuchMethodException ex) {
LOG.error("NoSuchMethodException: " + ex.getMessage(), ex);
} catch (SecurityException ex) {
LOG.error("SecurityException: " + ex.getMessage(), ex);
}
}
}
public MainWindow getMainWindow() {
return mainWindow;
}
public AssetsTab getAssetsTab() {
return assetsTab;
}
public IndustrySlotsTab getIndustrySlotsTab() {
return industrySlotsTab;
}
public OverviewTab getOverviewTab() {
return overviewTab;
}
public TreeTab getTreeTab() {
return treeTab;
}
public TransactionTab getTransactionsTab() {
return transactionsTab;
}
public StatusPanel getStatusPanel() {
return this.getMainWindow().getStatusPanel();
}
public UserNameSettingsPanel getUserNameSettingsPanel() {
if (settingsDialog != null) {
return settingsDialog.getUserNameSettingsPanel();
} else {
return null;
}
}
public UserPriceSettingsPanel getUserPriceSettingsPanel() {
if (settingsDialog != null) {
return settingsDialog.getUserPriceSettingsPanel();
} else {
return null;
}
}
public UserLocationSettingsPanel getUserLocationSettingsPanel() {
if (settingsDialog != null) {
return settingsDialog.getUserLocationSettingsPanel();
} else {
return null;
}
}
public StockpileTab getStockpileTool() {
return stockpileTab;
}
public ReprocessedTab getReprocessedTab() {
return reprocessedTab;
}
public RoutingTab getRoutingTab() {
return routingTab;
}
public TrackerTab getTrackerTab() {
return trackerTab;
}
public ValueTableTab getValueTableTab() {
return valueTableTab;
}
public ProfileData getProfileData() {
return profileData;
}
public List<MyAsset> getAssetList() {
return profileData.getAssetsList();
}
public List<MyContract> getContractList() {
return profileData.getContractList();
}
public List<MyContractItem> getContractItemList() {
return profileData.getContractItemList();
}
public List<MyIndustryJob> getIndustryJobsList() {
return profileData.getIndustryJobsList();
}
public List<MyMarketOrder> getMarketOrdersList() {
return profileData.getMarketOrdersList();
}
public List<MyJournal> getJournalList() {
return profileData.getJournalList();
}
public List<MyTransaction> getTransactionsList() {
return profileData.getTransactionsList();
}
public List<MyAccountBalance> getAccountBalanceList() {
return profileData.getAccountBalanceList();
}
public List<String> getOwnerNames(boolean all) {
return profileData.getOwnerNames(all);
}
public Map<Long, OwnerType> getOwners() {
return profileData.getOwners();
}
public List<OwnerType> getOwnerTypes() {
return profileManager.getOwnerTypes();
}
public ProfileManager getProfileManager() {
return profileManager;
}
public PriceDataGetter getPriceDataGetter() {
return priceDataGetter;
}
public void createTrackerDataPoint() {
DataSetCreator.createTrackerDataPoint(profileData, Settings.getNow());
TrackerData.save("Added", true);
ensureEDT(new Runnable() {
@Override
public void run() {
trackerTab.updateData();
}
});
}
public static boolean isDebug() {
return debug;
}
public static void setDebug(final boolean debug) {
Program.debug = debug;
}
public static boolean isForceNoUpdate() {
return forceNoUpdate;
}
public static void setForceNoUpdate(final boolean forceNoUpdate) {
Program.forceNoUpdate = forceNoUpdate;
}
public static boolean isForceUpdate() {
return forceUpdate;
}
public static void setForceUpdate(final boolean forceUpdate) {
Program.forceUpdate = forceUpdate;
}
public static void setPortable(final boolean portable) {
Program.portable = portable;
}
public static void setLazySave(final boolean lazySave) {
Program.lazySave = lazySave;
}
public static boolean isPortable() {
return portable;
}
public void updateStructures(Set<MyLocation> locations) {
structureUpdateDialog.show(locations);
}
/**
* Called when Tags are changed.
*/
public void updateTags() {
JLockWindow jLockWindow = new JLockWindow(getMainWindow().getFrame());
jLockWindow.show(GuiShared.get().updating(), new JLockWindow.LockWorker() {
@Override
public void task() {
for (JMainTab mainTab : jMainTabs.values()) {
if (mainTab instanceof TagUpdate) {
mainTab.updateCache();
}
}
}
@Override
public void gui() {
for (JMainTab mainTab : jMainTabs.values()) {
if (mainTab instanceof TagUpdate) {
TagUpdate tagUpdate = (TagUpdate) mainTab;
tagUpdate.updateTags();
}
}
}
});
}
/**
* Called when Overview Groups are changed.
*/
public void overviewGroupsChanged() {
routingTab.overviewGroupsChanged();
}
/**
* Called when the table menu needs update.
*/
public void updateTableMenu() {
this.getMainWindow().getSelectedTab().updateTableMenu();
}
/**
* Called when the active tab is change (close/open/change).
*/
public void tabChanged() {
getStatusPanel().tabChanged();
updateTableMenu();
}
@Override
public void actionPerformed(final ActionEvent e) {
//Tools
if (MainMenuAction.VALUES.name().equals(e.getActionCommand())) {
mainWindow.addTab(valueRetroTab);
} else if (MainMenuAction.VALUE_TABLE.name().equals(e.getActionCommand())) {
mainWindow.addTab(valueTableTab);
} else if (MainMenuAction.MATERIALS.name().equals(e.getActionCommand())) {
mainWindow.addTab(materialsTab);
} else if (MainMenuAction.LOADOUTS.name().equals(e.getActionCommand())) {
mainWindow.addTab(loadoutsTab);
} else if (MainMenuAction.MARKET_ORDERS.name().equals(e.getActionCommand())) {
mainWindow.addTab(marketOrdersTab);
} else if (MainMenuAction.JOURNAL.name().equals(e.getActionCommand())) {
mainWindow.addTab(journalTab);
} else if (MainMenuAction.TRANSACTION.name().equals(e.getActionCommand())) {
mainWindow.addTab(transactionsTab);
} else if (MainMenuAction.INDUSTRY_JOBS.name().equals(e.getActionCommand())) {
mainWindow.addTab(industryJobsTab);
} else if (MainMenuAction.INDUSTRY_SLOT.name().equals(e.getActionCommand())) {
mainWindow.addTab(industrySlotsTab);
} else if (MainMenuAction.OVERVIEW.name().equals(e.getActionCommand())) {
mainWindow.addTab(overviewTab);
} else if (MainMenuAction.ROUTING.name().equals(e.getActionCommand())) {
mainWindow.addTab(routingTab);
} else if (MainMenuAction.STOCKPILE.name().equals(e.getActionCommand())) {
mainWindow.addTab(stockpileTab);
} else if (MainMenuAction.ITEMS.name().equals(e.getActionCommand())) {
mainWindow.addTab(itemsTab);
} else if (MainMenuAction.TRACKER.name().equals(e.getActionCommand())) {
mainWindow.addTab(trackerTab);
trackerTab.checkAll();
} else if (MainMenuAction.REPROCESSED.name().equals(e.getActionCommand())) {
mainWindow.addTab(reprocessedTab);
} else if (MainMenuAction.CONTRACTS.name().equals(e.getActionCommand())) {
mainWindow.addTab(contractsTab);
} else if (MainMenuAction.TREE.name().equals(e.getActionCommand())) {
mainWindow.addTab(treeTab);
} else if (MainMenuAction.ACCOUNT_MANAGER.name().equals(e.getActionCommand())) { //Settings
accountManagerDialog.setVisible(true);
} else if (MainMenuAction.PROFILES.name().equals(e.getActionCommand())) {
profileDialog.setVisible(true);
} else if (MainMenuAction.OPTIONS.name().equals(e.getActionCommand())) {
showSettings();