Skip to content

Commit

Permalink
extract smallbutton factory methods to their own class
Browse files Browse the repository at this point in the history
  • Loading branch information
grobmeier committed Oct 1, 2023
1 parent 4bc0183 commit 21a1e25
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.apache.log4j.chainsaw.components.logpanel;

import org.apache.log4j.chainsaw.components.elements.SmallButton;
import org.apache.log4j.chainsaw.icons.ChainsawIcons;

import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

public class ElementFactory {
public static SmallButton createFindNextButton(Runnable action) {
SmallButton button = new SmallButton.Builder()
.action(action)
.name("Find next")
.text("")
.smallIconUrl(ChainsawIcons.DOWN)
.shortDescription("Find the next occurrence of the rule from the current row")
.keyStroke(KeyStroke.getKeyStroke("F3"))
.build();

button.getActionMap().put(button.getActionName(), button.getAction());
button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(button.getActionAcceleratorKey(), button.getActionName());
return button;
}

public static SmallButton createFindPreviousButton(Runnable action) {
SmallButton button = new SmallButton.Builder()
.action(action)
.name("Find previous")
.text("")
.smallIconUrl(ChainsawIcons.UP)
.shortDescription("Find the previous occurrence of the rule from the current row")
.keyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_MASK))
.build();

button.getActionMap().put(button.getActionName(), button.getAction());
button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(button.getActionAcceleratorKey(), button.getActionName());
return button;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1728,8 +1728,8 @@ public void actionPerformed(ActionEvent e) {
upperPanel.add(Box.createHorizontalStrut(3));

//add up & down search
upperPanel.add(createFindNextButton());
upperPanel.add(createFindPreviousButton());
upperPanel.add(ElementFactory.createFindNextButton(this::findNext));
upperPanel.add(ElementFactory.createFindPreviousButton(this::findPrevious));

upperPanel.add(Box.createHorizontalStrut(3));

Expand Down Expand Up @@ -1806,37 +1806,7 @@ public void actionPerformed(ActionEvent actionEvent) {
return upperPanel;
}

private SmallButton createFindNextButton() {
SmallButton button = new SmallButton.Builder()
.action(this::findNext)
.name("Find next")
.text("")
.smallIconUrl(ChainsawIcons.DOWN)
.shortDescription("Find the next occurrence of the rule from the current row")
.keyStroke(KeyStroke.getKeyStroke("F3"))
.build();

button.getActionMap().put(button.getActionName(), button.getAction());
button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(button.getActionAcceleratorKey(), button.getActionName());
return button;
}

private SmallButton createFindPreviousButton() {
SmallButton button = new SmallButton.Builder()
.action(this::findPrevious)
.name("Find previous")
.text("")
.smallIconUrl(ChainsawIcons.UP)
.shortDescription("Find the previous occurrence of the rule from the current row")
.keyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_MASK))
.build();

button.getActionMap().put(button.getActionName(), button.getAction());
button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(button.getActionAcceleratorKey(), button.getActionName());
return button;
}

private String getValueOf(int row, int column) {
if (currentTable == null) {
Expand Down

0 comments on commit 21a1e25

Please sign in to comment.