Skip to content

Commit

Permalink
LUCENE-10261: Remove preset analyzer panel from Luke Analysis UI. (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
mocobeta committed Nov 25, 2021
1 parent 800f002 commit 40b3843
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 266 deletions.
Expand Up @@ -27,15 +27,11 @@
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
Expand All @@ -48,8 +44,6 @@
import org.apache.lucene.luke.app.desktop.components.dialog.documents.AddDocumentDialogOperator;
import org.apache.lucene.luke.app.desktop.components.fragments.analysis.CustomAnalyzerPanelOperator;
import org.apache.lucene.luke.app.desktop.components.fragments.analysis.CustomAnalyzerPanelProvider;
import org.apache.lucene.luke.app.desktop.components.fragments.analysis.PresetAnalyzerPanelOperator;
import org.apache.lucene.luke.app.desktop.components.fragments.analysis.PresetAnalyzerPanelProvider;
import org.apache.lucene.luke.app.desktop.components.fragments.analysis.SimpleAnalyzeResultPanelOperator;
import org.apache.lucene.luke.app.desktop.components.fragments.analysis.SimpleAnalyzeResultPanelProvider;
import org.apache.lucene.luke.app.desktop.components.fragments.analysis.StepByStepAnalyzeResultPanelOperator;
Expand All @@ -63,15 +57,10 @@
import org.apache.lucene.luke.models.analysis.Analysis;
import org.apache.lucene.luke.models.analysis.AnalysisFactory;
import org.apache.lucene.luke.models.analysis.CustomAnalyzerConfig;
import org.apache.lucene.util.NamedThreadFactory;

/** Provider of the Analysis panel */
public final class AnalysisPanelProvider implements AnalysisTabOperator {

private static final String TYPE_PRESET = "preset";

private static final String TYPE_CUSTOM = "custom";

private final ComponentOperatorRegistry operatorRegistry;

private final AnalysisChainDialogFactory analysisChainDialogFactory;
Expand All @@ -82,14 +71,8 @@ public final class AnalysisPanelProvider implements AnalysisTabOperator {

private final JPanel mainPanel = new JPanel();

private final JPanel preset;

private final JPanel custom;

private final JRadioButton presetRB = new JRadioButton();

private final JRadioButton customRB = new JRadioButton();

private final JLabel analyzerNameLbl = new JLabel();

private final JLabel showChainLbl = new JLabel();
Expand All @@ -109,7 +92,6 @@ public final class AnalysisPanelProvider implements AnalysisTabOperator {
private Analysis analysisModel;

public AnalysisPanelProvider() throws IOException {
this.preset = new PresetAnalyzerPanelProvider().get();
this.custom = new CustomAnalyzerPanelProvider().get();

this.operatorRegistry = ComponentOperatorRegistry.getInstance();
Expand All @@ -126,20 +108,13 @@ public AnalysisPanelProvider() throws IOException {
operatorRegistry.register(AnalysisTabOperator.class, this);

operatorRegistry
.get(PresetAnalyzerPanelOperator.class)
.get(CustomAnalyzerPanelOperator.class)
.ifPresent(
operator -> {
// Scanning all Analyzer types will take time...
ExecutorService executorService =
Executors.newFixedThreadPool(
1, new NamedThreadFactory("load-preset-analyzer-types"));
executorService.execute(
() -> {
operator.setPresetAnalyzers(analysisModel.getPresetAnalyzerTypes());
operator.setSelectedAnalyzer(analysisModel.currentAnalyzer().getClass());
});
executorService.shutdown();
operator.setAnalysisModel(analysisModel);
operator.resetAnalysisComponents();
});
stepByStepCB.setVisible(true);
}

public JPanel get() {
Expand All @@ -161,38 +136,11 @@ private JPanel initUpperPanel() {
mainPanel.setLayout(new BorderLayout());
mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

mainPanel.add(initSwitcherPanel(), BorderLayout.PAGE_START);
mainPanel.add(preset, BorderLayout.CENTER);
mainPanel.add(custom, BorderLayout.CENTER);

return mainPanel;
}

private JPanel initSwitcherPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEADING));
panel.setOpaque(false);

presetRB.setText(MessageUtils.getLocalizedMessage("analysis.radio.preset"));
presetRB.setActionCommand(TYPE_PRESET);
presetRB.addActionListener(listeners::toggleMainPanel);
presetRB.setOpaque(false);
presetRB.setSelected(true);

customRB.setText(MessageUtils.getLocalizedMessage("analysis.radio.custom"));
customRB.setActionCommand(TYPE_CUSTOM);
customRB.addActionListener(listeners::toggleMainPanel);
customRB.setOpaque(false);
customRB.setSelected(false);

ButtonGroup group = new ButtonGroup();
group.add(presetRB);
group.add(customRB);

panel.add(presetRB);
panel.add(customRB);

return panel;
}

private JPanel initLowerPanel() {
JPanel inner1 = new JPanel(new BorderLayout());
inner1.setOpaque(false);
Expand Down Expand Up @@ -236,7 +184,7 @@ public void mouseClicked(MouseEvent e) {
stepByStepCB.setText(MessageUtils.getLocalizedMessage("analysis.checkbox.step_by_step"));
stepByStepCB.setSelected(false);
stepByStepCB.setOpaque(false);
stepByStepCB.setVisible(false);
stepByStepCB.setVisible(true);
input.add(stepByStepCB);

JButton clearBtn = new JButton(MessageUtils.getLocalizedMessage("button.clear"));
Expand Down Expand Up @@ -265,38 +213,6 @@ public void mouseClicked(MouseEvent e) {
}

// control methods

void toggleMainPanel(String command) {
if (command.equalsIgnoreCase(TYPE_PRESET)) {
mainPanel.remove(custom);
mainPanel.add(preset, BorderLayout.CENTER);

operatorRegistry
.get(PresetAnalyzerPanelOperator.class)
.ifPresent(
operator -> {
operator.setPresetAnalyzers(analysisModel.getPresetAnalyzerTypes());
operator.setSelectedAnalyzer(analysisModel.currentAnalyzer().getClass());
});
stepByStepCB.setSelected(false);
stepByStepCB.setVisible(false);
} else if (command.equalsIgnoreCase(TYPE_CUSTOM)) {
mainPanel.remove(preset);
mainPanel.add(custom, BorderLayout.CENTER);

operatorRegistry
.get(CustomAnalyzerPanelOperator.class)
.ifPresent(
operator -> {
operator.setAnalysisModel(analysisModel);
operator.resetAnalysisComponents();
});
stepByStepCB.setVisible(true);
}
mainPanel.setVisible(false);
mainPanel.setVisible(true);
}

void executeAnalysis() {
String text = inputArea.getText();
if (Objects.isNull(text) || text.isEmpty()) {
Expand Down Expand Up @@ -392,10 +308,6 @@ public Analyzer getCurrentAnalyzer() {

private class ListenerFunctions {

void toggleMainPanel(ActionEvent e) {
AnalysisPanelProvider.this.toggleMainPanel(e.getActionCommand());
}

void showAnalysisChain(MouseEvent e) {
AnalysisPanelProvider.this.showAnalysisChainDialog();
}
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -133,9 +133,6 @@ public List<NamedTokens> getNamedTokens() {
}
}

/** Returns built-in {@link Analyzer}s. */
Collection<Class<? extends Analyzer>> getPresetAnalyzerTypes();

/** Returns available char filter names. */
Collection<String> getAvailableCharFilters();

Expand Down

0 comments on commit 40b3843

Please sign in to comment.