Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/main/java/org/quiltmc/syntaxpain/QuickFindDialog.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.quiltmc.syntaxpain;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
Expand Down Expand Up @@ -54,6 +55,8 @@ public class QuickFindDialog extends JDialog implements DocumentListener, Action
protected JCheckBox ignoreCaseCheckBox;
protected JCheckBox regexCheckBox;
protected JCheckBox wrapCheckBox;
protected JCheckBox persistentCheckBox;
protected JButton closeButton;

protected String prev = "prev";
protected String next = "next";
Expand All @@ -62,6 +65,8 @@ public class QuickFindDialog extends JDialog implements DocumentListener, Action
protected String useRegex = "Use regex";
protected String wrap = "Wrap";
protected String notFound = "Not found";
protected String persistent = "Persistent";
protected String close = "Close";

public QuickFindDialog(JTextComponent target) {
this(target, DocumentSearchData.getFromEditor(target));
Expand Down Expand Up @@ -98,11 +103,13 @@ public void showFor(JTextComponent target) {
WindowFocusListener focusListener = new WindowAdapter() {
@Override
public void windowLostFocus(WindowEvent e) {
target.getDocument().removeDocumentListener(QuickFindDialog.this);
Markers.removeMarkers(target, QuickFindDialog.this.marker);
QuickFindDialog.this.removeWindowListener(this);
QuickFindDialog.this.setVisible(false);
target.requestFocus();
if (!QuickFindDialog.this.persistentCheckBox.isSelected()) {
target.getDocument().removeDocumentListener(QuickFindDialog.this);
Markers.removeMarkers(target, QuickFindDialog.this.marker);
QuickFindDialog.this.removeWindowListener(this);
QuickFindDialog.this.setVisible(false);
target.requestFocus();
}
}
};
this.addWindowFocusListener(focusListener);
Expand Down Expand Up @@ -137,6 +144,8 @@ protected void initComponents() {
this.ignoreCaseCheckBox = new JCheckBox(this.ignoreCase);
this.regexCheckBox = new JCheckBox(this.useRegex);
this.wrapCheckBox = new JCheckBox(this.wrap);
this.persistentCheckBox = new JCheckBox(this.persistent);
this.closeButton = new JButton(this.close);

this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setBackground(Color.DARK_GRAY);
Expand All @@ -146,6 +155,7 @@ protected void initComponents() {
toolBar.setBorder(BorderFactory.createEtchedBorder());
toolBar.setFloatable(false);
toolBar.setRollover(true);

toolBar.addSeparator();

this.searchField.setColumns(30);
Expand Down Expand Up @@ -195,6 +205,24 @@ protected void initComponents() {
toolBar.addSeparator();
toolBar.add(this.statusLabel);

// push the rest of the components to the right
toolBar.add(Box.createHorizontalGlue());

this.persistentCheckBox.setFocusable(false);
this.persistentCheckBox.setOpaque(false);
this.persistentCheckBox.setVerticalTextPosition(SwingConstants.BOTTOM);
this.persistentCheckBox.addActionListener(this);
toolBar.add(this.persistentCheckBox);

toolBar.addSeparator();

this.closeButton.setHorizontalTextPosition(SwingConstants.CENTER);
this.closeButton.setFocusable(false);
this.closeButton.setOpaque(false);
this.closeButton.setVerticalTextPosition(SwingConstants.BOTTOM);
this.closeButton.addActionListener(event -> this.setVisible(false));
toolBar.add(this.closeButton);

GroupLayout layout = new GroupLayout(this.getContentPane());
this.getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
Expand All @@ -212,6 +240,8 @@ protected void translate() {
this.ignoreCaseCheckBox.setText(this.ignoreCase);
this.regexCheckBox.setText(this.useRegex);
this.wrapCheckBox.setText(this.wrap);
this.persistentCheckBox.setText(this.persistent);
this.closeButton.setText(this.close);
this.pack();
}

Expand Down