From 45b609a0879e38cb2fefb266f6dd9043893a52af Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 23 Dec 2024 20:23:04 +0100 Subject: [PATCH 1/2] Ensure left search results panel is always visible. initialize divider position with a minimal value. --- .../search/ui/BasicReplaceResultsPanel.java | 4 +--- .../search/ui/BasicSearchResultsPanel.java | 17 +++++------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java b/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java index e0b72b851c59..5a80084c6214 100644 --- a/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java +++ b/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java @@ -109,9 +109,7 @@ private void initResultModelListener() { private void initSplitDividerLocationHandling() { int location = FindDialogMemory.getDefault().getReplaceResultsDivider(); - if (location > 0) { - splitPane.setDividerLocation(location); - } + splitPane.setDividerLocation(Math.max(location, 250)); splitPane.addPropertyChangeListener((PropertyChangeEvent evt) -> { String pn = evt.getPropertyName(); if (pn.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) { diff --git a/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java b/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java index 9516021af3ba..8992259e98f9 100644 --- a/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java +++ b/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java @@ -46,24 +46,17 @@ public BasicSearchResultsPanel(ResultModel resultModel, } private void init() { - JPanel leftPanel = new JPanel(); - leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); - leftPanel.add(resultsOutlineSupport.getOutlineView()); - - this.splitPane = new JSplitPane(); - splitPane.setLeftComponent(leftPanel); - splitPane.setRightComponent(new ContextView(resultModel, - getExplorerManager())); + splitPane = new JSplitPane(); + splitPane.setLeftComponent(resultsOutlineSupport.getOutlineView()); + splitPane.setRightComponent(new ContextView(resultModel, getExplorerManager())); initSplitDividerLocationHandling(); getContentPanel().add(splitPane); } private void initSplitDividerLocationHandling() { int location = FindDialogMemory.getDefault().getReplaceResultsDivider(); - if (location > 0) { - splitPane.setDividerLocation(location); - } - splitPane.addPropertyChangeListener((PropertyChangeEvent evt) -> { + splitPane.setDividerLocation(Math.max(location, 250)); + splitPane.addPropertyChangeListener(evt -> { String pn = evt.getPropertyName(); if (pn.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) { SAVE_TASK.schedule(1000); From 66355440d1618642de52c119e4059433d054b954 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Thu, 26 Dec 2024 03:52:34 +0100 Subject: [PATCH 2/2] Refactor BasicSearch and BasicReplaceResultsPanels - BasicReplaceResultsPanel extends BasicSearchResultsPanel - less code duplication --- .../search/ui/BasicReplaceResultsPanel.java | 71 +++++-------------- .../search/ui/BasicSearchResultsPanel.java | 55 ++++++-------- 2 files changed, 41 insertions(+), 85 deletions(-) diff --git a/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java b/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java index 5a80084c6214..43916ad95fd2 100644 --- a/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java +++ b/platform/api.search/src/org/netbeans/modules/search/ui/BasicReplaceResultsPanel.java @@ -22,17 +22,14 @@ import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.AbstractButton; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JComponent; import javax.swing.JPanel; -import javax.swing.JSplitPane; import org.netbeans.modules.search.BasicComposition; -import org.netbeans.modules.search.ContextView; -import org.netbeans.modules.search.FindDialogMemory; import org.netbeans.modules.search.Manager; import org.netbeans.modules.search.ReplaceTask; import org.netbeans.modules.search.ResultModel; @@ -43,55 +40,44 @@ import org.openide.nodes.Node; import org.openide.util.Mutex; import org.openide.util.NbBundle; -import org.openide.util.RequestProcessor; /** * * @author jhavlin */ -public class BasicReplaceResultsPanel extends BasicAbstractResultsPanel { +public class BasicReplaceResultsPanel extends BasicSearchResultsPanel { - private static final RequestProcessor RP = - new RequestProcessor(BasicReplaceResultsPanel.class.getName()); - private final RequestProcessor.Task SAVE_TASK = RP.create(new SaveTask()); private JButton replaceButton; - private JSplitPane splitPane; - - public BasicReplaceResultsPanel(ResultModel resultModel, - BasicComposition composition, Node infoNode) { - super(resultModel, composition, true, - new ResultsOutlineSupport(true, true, resultModel, composition, - infoNode)); - init(); + + public BasicReplaceResultsPanel(ResultModel resultModel, BasicComposition composition, Node infoNode) { + super(resultModel, composition, true, + new ResultsOutlineSupport(true, true, resultModel, composition, infoNode)); } - private void init() { - JPanel leftPanel = new JPanel(); + @Override + protected JComponent createLeftComponent() { replaceButton = new JButton(); replaceButton.addActionListener((ActionEvent e) -> replace()); + replaceButton.setMaximumSize(replaceButton.getPreferredSize()); + replaceButton.getAccessibleContext().setAccessibleDescription( + NbBundle.getMessage(ResultView.class, + "ACS_TEXT_BUTTON_REPLACE")); //NOI18N updateReplaceButton(); - leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); + JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.LEADING, 2, 1)); buttonPanel.add(replaceButton); - replaceButton.setMaximumSize(replaceButton.getPreferredSize()); buttonPanel.setMaximumSize(new Dimension( // #225246 (int) buttonPanel.getMaximumSize().getWidth(), (int) buttonPanel.getPreferredSize().getHeight())); + + JPanel leftPanel = new JPanel(); + leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); leftPanel.add(resultsOutlineSupport.getOutlineView()); leftPanel.add(buttonPanel); - - this.splitPane = new JSplitPane(); - splitPane.setLeftComponent(leftPanel); - splitPane.setRightComponent(new ContextView(resultModel, - getExplorerManager())); - initSplitDividerLocationHandling(); - - getContentPanel().add(splitPane); + initResultModelListener(); - replaceButton.getAccessibleContext().setAccessibleDescription( - NbBundle.getMessage(ResultView.class, - "ACS_TEXT_BUTTON_REPLACE")); //NOI18N + return leftPanel; } private void replace() { @@ -107,17 +93,6 @@ private void initResultModelListener() { resultModel.addPropertyChangeListener(new ModelListener()); } - private void initSplitDividerLocationHandling() { - int location = FindDialogMemory.getDefault().getReplaceResultsDivider(); - splitPane.setDividerLocation(Math.max(location, 250)); - splitPane.addPropertyChangeListener((PropertyChangeEvent evt) -> { - String pn = evt.getPropertyName(); - if (pn.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) { - SAVE_TASK.schedule(1000); - } - }); - } - @Override public void searchFinished() { super.searchFinished(); @@ -224,14 +199,4 @@ public void showFinishedInfo() { }); } - private class SaveTask implements Runnable { - - @Override - public void run() { - if (splitPane != null) { - FindDialogMemory.getDefault().setReplaceResultsDivider( - splitPane.getDividerLocation()); - } - } - } } diff --git a/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java b/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java index 8992259e98f9..c12d1fa77cd2 100644 --- a/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java +++ b/platform/api.search/src/org/netbeans/modules/search/ui/BasicSearchResultsPanel.java @@ -18,9 +18,7 @@ */ package org.netbeans.modules.search.ui; -import java.beans.PropertyChangeEvent; -import javax.swing.BoxLayout; -import javax.swing.JPanel; +import javax.swing.JComponent; import javax.swing.JSplitPane; import org.netbeans.modules.search.BasicComposition; import org.netbeans.modules.search.ContextView; @@ -34,44 +32,37 @@ * @author jhavlin */ public class BasicSearchResultsPanel extends BasicAbstractResultsPanel { - private final RequestProcessor.Task SAVE_TASK = RequestProcessor.getDefault().create(new BasicSearchResultsPanel.SaveTask()); - private JSplitPane splitPane; - public BasicSearchResultsPanel(ResultModel resultModel, - BasicComposition composition, boolean details, Node infoNode) { - super(resultModel, composition, details, - new ResultsOutlineSupport(false, details, resultModel, - composition, infoNode)); - init(); + public BasicSearchResultsPanel(ResultModel resultModel, BasicComposition composition, boolean details, Node infoNode) { + this(resultModel, composition, details, + new ResultsOutlineSupport(false, details, resultModel, composition, infoNode)); } - private void init() { - splitPane = new JSplitPane(); - splitPane.setLeftComponent(resultsOutlineSupport.getOutlineView()); - splitPane.setRightComponent(new ContextView(resultModel, getExplorerManager())); - initSplitDividerLocationHandling(); + BasicSearchResultsPanel(ResultModel resultModel, BasicComposition composition, boolean details, ResultsOutlineSupport resultsOutlineSupport) { + super(resultModel, composition, details, resultsOutlineSupport); + + JSplitPane splitPane = new JSplitPane(); + splitPane.setLeftComponent(createLeftComponent()); + splitPane.setRightComponent(createRightComponent()); getContentPanel().add(splitPane); - } - private void initSplitDividerLocationHandling() { + // divider persistance + RequestProcessor.Task dividerSaveTask = RequestProcessor.getDefault().create(() -> + FindDialogMemory.getDefault().setReplaceResultsDivider(splitPane.getDividerLocation()) + ); int location = FindDialogMemory.getDefault().getReplaceResultsDivider(); splitPane.setDividerLocation(Math.max(location, 250)); - splitPane.addPropertyChangeListener(evt -> { - String pn = evt.getPropertyName(); - if (pn.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) { - SAVE_TASK.schedule(1000); - } - }); + splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e -> + dividerSaveTask.schedule(1000) + ); } - private class SaveTask implements Runnable { + protected JComponent createLeftComponent() { + return resultsOutlineSupport.getOutlineView(); + } - @Override - public void run() { - if (splitPane != null) { - FindDialogMemory.getDefault().setReplaceResultsDivider( - splitPane.getDividerLocation()); - } - } + protected JComponent createRightComponent() { + return new ContextView(resultModel, getExplorerManager()); } + }