public boolean showPanel()

in languagetool-gui-commons/src/main/java/org/languagetool/gui/ConfigurationDialog.java [189:502]


  public boolean showPanel(List<Rule> rules) {
    configChanged = false;
    if (original != null && !restartShow) {
      config.restoreState(original);
    }
    restartShow = false;
    dialog = new JDialog(owner, true);
    if (dialogTitle == null) {
      dialogTitle = messages.getString("guiConfigWindowTitle");
    }
    dialog.setTitle(dialogTitle);
    if (ltImage != null) {
      ((Frame) dialog.getOwner()).setIconImage(ltImage);
    }
    // close dialog when user presses Escape key:
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    ActionListener actionListener = actionEvent -> dialog.setVisible(false);
    JRootPane rootPane = dialog.getRootPane();
    rootPane.registerKeyboardAction(actionListener, stroke,
        JComponent.WHEN_IN_FOCUSED_WINDOW);

    configurableRules.clear();

    Language lang = config.getLanguage();
    if (lang == null) {
      lang = Languages.getLanguageForLocale(Locale.getDefault());
    }

    String[] specialTabNames = config.getSpecialTabNames();
    int numConfigTrees = 2 + specialTabNames.length;
    configTree = new JTree[numConfigTrees];
    rootNode = new DefaultMutableTreeNode[numConfigTrees];
    JPanel[] checkBoxPanel = new JPanel[numConfigTrees];
    GridBagConstraints cons;

    for (int i = 0; i < numConfigTrees; i++) {
      checkBoxPanel[i] = new JPanel();
      cons = new GridBagConstraints();
      checkBoxPanel[i].setLayout(new GridBagLayout());
      cons.anchor = GridBagConstraints.NORTHWEST;
      cons.gridx = 0;
      cons.weightx = 1.0;
      cons.weighty = 1.0;
      cons.fill = GridBagConstraints.HORIZONTAL;
      Collections.sort(rules, new CategoryComparator());
      if(i == 0) {
        rootNode[i] = createTree(rules, false, null, null);   //  grammar options
      } else if(i == 1) {
        rootNode[i] = createTree(rules, true, null, null);    //  Style options
      } else {
        rootNode[i] = createTree(rules, true, specialTabNames[i - 2], null);    //  Special tab options
      }
      configTree[i] = new JTree(getTreeModel(rootNode[i], rules));
      
      configTree[i].applyComponentOrientation(ComponentOrientation.getOrientation(lang.getLocale()));
  
      configTree[i].setRootVisible(false);
      configTree[i].setEditable(false);
      configTree[i].setCellRenderer(new CheckBoxTreeCellRenderer());
      TreeListener.install(configTree[i]);
      checkBoxPanel[i].add(configTree[i], cons);
      configTree[i].addMouseListener(getMouseAdapter());
    }
    

    JPanel portPanel = new JPanel();
    portPanel.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, SHIFT1, 0, 0);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.anchor = GridBagConstraints.WEST;
    cons.fill = GridBagConstraints.NONE;
    cons.weightx = 0.0f;
    if (!insideOffice) {
      createNonOfficeElements(cons, portPanel);
    }
    else {
      createOfficeElements(cons, portPanel);
    }

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    JButton okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton")));
    okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton")));
    okButton.setActionCommand(ACTION_COMMAND_OK);
    okButton.addActionListener(this);
    JButton cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton")));
    cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton")));
    cancelButton.setActionCommand(ACTION_COMMAND_CANCEL);
    cancelButton.addActionListener(this);
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, SHIFT1, 0, 0);
    buttonPanel.add(okButton, cons);
    buttonPanel.add(cancelButton, cons);

    JTabbedPane tabpane = new JTabbedPane();

//  Profile tab    
    JPanel jProfilePane = new JPanel();
    jProfilePane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);

    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    cons.anchor = GridBagConstraints.NORTHWEST;
    
    jProfilePane.add(new JScrollPane(getProfilePanel(rules)), cons);
    
    //  Disabled default rules
    cons.weighty = 1.0f;
    cons.gridy++;
    cons.insets = new Insets(16, 4, 0, 8);
    jProfilePane.add(new JLabel(addColonToMessageString("guiDisabledDefaultRules")), cons);
    cons.insets = new Insets(8, 4, 0, 8);
    cons.gridy++;
    cons.weighty = 3.0f;
    disabledRulesPanel = getChangedRulesPanel(rules, false, null);
    jProfilePane.add(new JScrollPane(disabledRulesPanel), cons);
    
    //  Enabled optional rules
    cons.gridy++;
    cons.insets = new Insets(16, 4, 0, 8);
    cons.weighty = 1.0f;
    jProfilePane.add(new JLabel(addColonToMessageString("guiEnabledOptionalRules")), cons);
    cons.insets = new Insets(8, 4, 0, 8);
    cons.gridy++;
    cons.weighty = 5.0f;
    enabledRulesPanel = getChangedRulesPanel(rules, true, null);
    jProfilePane.add(new JScrollPane(enabledRulesPanel), cons);
    jProfilePane.setName(messages.getString("guiProfiles"));
    
//  General tab
    JPanel jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);

    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.NORTHWEST;

    if(!insideOffice) {
      cons.gridy++;
      cons.anchor = GridBagConstraints.WEST;
      jPane.add(getMotherTonguePanel(cons), cons);
      cons.gridx = 0;
      cons.gridy++;
      jPane.add(getNgramPanel(), cons);
    }
    cons.gridy++;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(portPanel, cons);
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.anchor = GridBagConstraints.WEST;
    for(JPanel extra : extraPanels) {
      //in case it wasn't in a containment hierarchy when user changed L&F
      SwingUtilities.updateComponentTreeUI(extra);
      cons.gridy++;
      jPane.add(extra, cons);
    }

    cons.gridy++;
    cons.fill = GridBagConstraints.BOTH;
    cons.weighty = 1.0f;
    jPane.add(new JPanel(), cons);
    tabpane.addTab(messages.getString("guiGeneral"), new JScrollPane(jPane));

//  Grammar rules tab    
    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    jPane.add(new JScrollPane(checkBoxPanel[0]), cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;

    cons.gridx = 0;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    jPane.add(getTreeButtonPanel(0), cons);
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.anchor = GridBagConstraints.WEST;
    cons.gridx = 0;
    cons.gridy++;
    jPane.add(getRuleOptionsPanel(0), cons);

    tabpane.addTab(messages.getString("guiGrammarRules"), jPane);
    
//  Style rules tab    
    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    jPane.add(new JScrollPane(checkBoxPanel[1]), cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;

    cons.gridx = 0;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    jPane.add(getTreeButtonPanel(1), cons);
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.anchor = GridBagConstraints.WEST;
    cons.gridx = 0;
    cons.gridy++;
    jPane.add(getRuleOptionsPanel(1), cons);

    tabpane.addTab(messages.getString("guiStyleRules"), jPane);

//  Style special tabs (optional)
    for (int i = 0; i < specialTabNames.length; i++) {
      jPane = new JPanel();
      jPane.setLayout(new GridBagLayout());
      cons = new GridBagConstraints();
      cons.insets = new Insets(4, 4, 4, 4);
      cons.gridx = 0;
      cons.gridy = 0;
      cons.weightx = 10.0f;
      cons.weighty = 10.0f;
      cons.fill = GridBagConstraints.BOTH;
      jPane.add(new JScrollPane(checkBoxPanel[i + 2]), cons);
      cons.weightx = 0.0f;
      cons.weighty = 0.0f;
  
      cons.gridx = 0;
      cons.gridy++;
      cons.fill = GridBagConstraints.NONE;
      cons.anchor = GridBagConstraints.LINE_END;
      jPane.add(getTreeButtonPanel(i + 2), cons);
  
      cons.fill = GridBagConstraints.HORIZONTAL;
      cons.anchor = GridBagConstraints.WEST;
      cons.gridx = 0;
      cons.gridy++;
      jPane.add(getRuleOptionsPanel(i + 2), cons);

      tabpane.addTab(specialTabNames[i], jPane);
    }
    
    if(insideOffice) {
      //    technical options tab (only office)
      String label = messages.getString("guiTechnicalSettings");
      if (label.endsWith(":")) {
        label = label.substring(0, label.length() - 1);
      }
      tabpane.add(label, new JScrollPane(getOfficeTechnicalElements()));
      
      //    AI options tab (only office)
      label = messages.getString("guiAiSupportSettings");
      tabpane.add(label, new JScrollPane(getOfficeAiElements()));
    }

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    cons.anchor = GridBagConstraints.NORTHWEST;
    contentPane.add(tabpane, cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.EAST;
    contentPane.add(buttonPanel, cons);

    dialog.pack();
    // center on screen:
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    dialog.setLocation(screenSize.width / 2 - frameSize.width / 2,
        screenSize.height / 2 - frameSize.height / 2);
    dialog.setLocationByPlatform(true);
    //  add Profile tab after dimension was set
    tabpane.add(jProfilePane, 0);
    tabpane.setSelectedIndex(0);
    for(JPanel extra : this.extraPanels) {
      if(extra instanceof SavablePanel) {
        ((SavablePanel) extra).componentShowing();
      }
    }
    dialog.setAutoRequestFocus(true);
    
    if(insideOffice) {
      dialog.setAlwaysOnTop(true);
    }
    dialog.setVisible(true);
    dialog.toFront();
    return configChanged;
  }