| 673 | | // TODO: put in a platformHook for system that have no console by default |
| 674 | | System.out.println(getHelp()); |
| | 653 | // We check if it's been launched via a detectable console. If returning null, switch to Swing Panel. |
| | 654 | if (System.console() == null) { |
| | 655 | guiGetHelp(); |
| | 656 | } else { |
| | 657 | // Console detected. Print to stdout. |
| | 658 | System.out.println(getHelp()); |
| | 659 | } |
| | 660 | } |
| | 661 | |
| | 662 | static void guiGetHelp() { |
| | 663 | JPanel optionPanel = new JPanel(); |
| | 664 | // Arrange options vertically. |
| | 665 | optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS)); |
| | 666 | |
| | 667 | // Boolean options |
| | 668 | JCheckBox debug = new JCheckBox(tr("Enable Debugging (Print Messages to console)")); |
| | 669 | optionPanel.add(debug); |
| | 670 | |
| | 671 | JCheckBox maximize = new JCheckBox(tr("Maximize the Window")); |
| | 672 | optionPanel.add(maximize); |
| | 673 | |
| | 674 | /* |
| | 675 | * TODO: Ensure it runs once, then gets reset. |
| | 676 | * Also: Create a warning box. |
| | 677 | * Reset User Preferences |
| | 678 | */ |
| | 679 | JCheckBox resetPreferences = new JCheckBox(tr("Reset user preferences (Highly dangerous)")); |
| | 680 | optionPanel.add(resetPreferences); |
| | 681 | |
| | 682 | // Text input options |
| | 683 | JPanel geometryPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 684 | geometryPanel.add(new JLabel(tr("Window geometry:"))); |
| | 685 | JTextField geometry = new JTextField(20); |
| | 686 | geometryPanel.add(geometry); |
| | 687 | optionPanel.add(geometryPanel); |
| | 688 | |
| | 689 | JPanel downloadPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 690 | downloadPanel.add(new JLabel(tr("Download URL, filename or bounding box:"))); |
| | 691 | JTextField download = new JTextField(25); |
| | 692 | downloadPanel.add(download); |
| | 693 | optionPanel.add(downloadPanel); |
| | 694 | |
| | 695 | JPanel downloadGpsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 696 | downloadGpsPanel.add(new JLabel(tr("Download GPS bounding box or URL:"))); |
| | 697 | JTextField downloadGps = new JTextField(25); |
| | 698 | downloadGpsPanel.add(downloadGps); |
| | 699 | optionPanel.add(downloadGpsPanel); |
| | 700 | |
| | 701 | JPanel selectionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 702 | selectionPanel.add(new JLabel(tr("Selection search string:"))); |
| | 703 | JTextField selection = new JTextField(25); |
| | 704 | selectionPanel.add(selection); |
| | 705 | optionPanel.add(selectionPanel); |
| | 706 | |
| | 707 | JPanel loadPreferencesPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 708 | loadPreferencesPanel.add(new JLabel(tr("Load preferences from XML:"))); |
| | 709 | JTextField loadPreferences = new JTextField(25); |
| | 710 | loadPreferencesPanel.add(loadPreferences); |
| | 711 | optionPanel.add(loadPreferencesPanel); |
| | 712 | |
| | 713 | JPanel setPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 714 | setPanel.add(new JLabel(tr("Set preference key=value:"))); |
| | 715 | JTextField setPreference = new JTextField(25); |
| | 716 | setPanel.add(setPreference); |
| | 717 | optionPanel.add(setPanel); |
| | 718 | |
| | 719 | JPanel languagePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 720 | languagePanel.add(new JLabel(tr("Language:"))); |
| | 721 | JTextField language = new JTextField(15); |
| | 722 | languagePanel.add(language); |
| | 723 | optionPanel.add(languagePanel); |
| | 724 | |
| | 725 | JPanel offlinePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 726 | offlinePanel.add(new JLabel(tr("Disable online resources:"))); |
| | 727 | JTextField offline = new JTextField(25); |
| | 728 | offlinePanel.add(offline); |
| | 729 | optionPanel.add(offlinePanel); |
| | 730 | |
| | 731 | |
| | 732 | JPanel prefPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 733 | prefPanel.add(new JLabel(tr("Preferences directory:"))); |
| | 734 | JTextField prefDirectory = new JTextField(25); |
| | 735 | prefPanel.add(prefDirectory); |
| | 736 | optionPanel.add(prefPanel); |
| | 737 | |
| | 738 | JPanel userDataPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 739 | userDataPanel.add(new JLabel(tr("User data directory:"))); |
| | 740 | JTextField userDataDirectory = new JTextField(25); |
| | 741 | userDataPanel.add(userDataDirectory); |
| | 742 | optionPanel.add(userDataPanel); |
| | 743 | |
| | 744 | JPanel cachePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 745 | cachePanel.add(new JLabel(tr("Cache directory:"))); |
| | 746 | JTextField cacheDirectory = new JTextField(25); |
| | 747 | cachePanel.add(cacheDirectory); |
| | 748 | optionPanel.add(cachePanel); |
| | 749 | |
| | 750 | JPanel homePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | 751 | homePanel.add(new JLabel(tr("JOSM home directory:"))); |
| | 752 | JTextField homeDirectory = new JTextField(25); |
| | 753 | homePanel.add(homeDirectory); |
| | 754 | optionPanel.add(homePanel); |
| | 755 | |
| | 756 | // Display the GUI |
| | 757 | int result = JOptionPane.showConfirmDialog( |
| | 758 | null, |
| | 759 | new JScrollPane(optionPanel), |
| | 760 | tr("JOSM Startup Options"), |
| | 761 | JOptionPane.OK_CANCEL_OPTION, |
| | 762 | JOptionPane.PLAIN_MESSAGE |
| | 763 | ); |
| | 764 | if (result == JOptionPane.OK_OPTION) { |
| | 765 | // Create a new list to store all options selected/filled. |
| | 766 | List<String> args = new ArrayList<>(); |
| | 767 | // Set the args for boolean options |
| | 768 | if (debug.isSelected()) args.add("--debug"); |
| | 769 | if (maximize.isSelected()) args.add("--maximize"); |
| | 770 | if(resetPreferences.isSelected()) args.add("--reset-preferences"); |
| | 771 | // Set args for all that require text values (if user typed a value) |
| | 772 | if (!geometry.getText().trim().isEmpty()) args.add("--geometry=" + geometry.getText().trim()); |
| | 773 | if (!download.getText().trim().isEmpty()) args.add("--download=" + download.getText().trim()); |
| | 774 | if (!downloadGps.getText().trim().isEmpty()) args.add("--downloadgps=" + downloadGps.getText().trim()); |
| | 775 | if (!selection.getText().trim().isEmpty()) args.add("--selection=" + selection.getText().trim()); |
| | 776 | if (!loadPreferences.getText().trim().isEmpty()) args.add("--load-preferences=" + loadPreferences.getText().trim()); |
| | 777 | if (!setPreference.getText().trim().isEmpty()) args.add("--set=" + setPreference.getText().trim()); |
| | 778 | if (!language.getText().trim().isEmpty()) args.add("--language=" + language.getText().trim()); |
| | 779 | if (!offline.getText().trim().isEmpty()) args.add("--offline=" + offline.getText().trim()); |
| | 780 | // Define system properties |
| | 781 | if(!prefDirectory.getText().trim().isEmpty()) System.setProperty("josm.pref", prefDirectory.getText().trim()); |
| | 782 | if(!userDataDirectory.getText().trim().isEmpty()) System.setProperty("josm.userdata", userDataDirectory.getText().trim()); |
| | 783 | if(!cacheDirectory.getText().trim().isEmpty()) System.setProperty("josm.cache", cacheDirectory.getText().trim()); |
| | 784 | if(!homeDirectory.getText().trim().isEmpty()) System.setProperty("josm.userdata", homeDirectory.getText().trim()); |
| | 785 | String[] selectedArgs = args.toArray(new String[0]); |
| | 786 | JOSM_CLI_MODULE.processArguments(selectedArgs); |
| | 787 | } |
| | 788 | else System.exit(0); |