Skip to content

Commit

Permalink
add Search window, fix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kryptonbutterfly committed Mar 25, 2023
1 parent e00d427 commit d03be1a
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 34 deletions.
7 changes: 7 additions & 0 deletions src/assets/lang/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ FileType.Lang = lang
FileType.Properties = properties
Main.Menu.Create = Erstellen
Main.Menu.Delete = Löschen
Main.Menu.Edit = Bearbeiten
Main.Menu.Edit.Find = Finden
Main.Menu.File = Datei
Main.Menu.General Settings = Allgemeine Einstellungen
Main.Menu.Import = Sprache Importieren
Expand Down Expand Up @@ -50,6 +52,11 @@ New Project.label.Location = Position:
New Project.title = Neues Projekt
New Project.titleBorder.languages = Sprachen
New Project.titleBorder.sources = Quellen
Search.Checkbox.Case Sensitive = Kasus sensitiv
Search.Tab.Key = Schlüssel Suche
Search.button.cancel = Abbrechen
Search.button.search = Suchen
Search.title = Suche
Settings.button.cancle = Abbrechen
Settings.button.ok = OK
Settings.label.File type = Dateityp:
Expand Down
7 changes: 7 additions & 0 deletions src/assets/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ FileType.Lang = lang
FileType.Properties = properties
Main.Menu.Create = Create
Main.Menu.Delete = Delete
Main.Menu.Edit = Edit
Main.Menu.Edit.Find = Find
Main.Menu.File = File
Main.Menu.General Settings = General Settings
Main.Menu.Import = Import Language
Expand Down Expand Up @@ -50,6 +52,11 @@ New Project.label.Location = Location:
New Project.title = New Project
New Project.titleBorder.languages = Languages
New Project.titleBorder.sources = Sources
Search.Checkbox.Case Sensitive = Case Sensitive
Search.Tab.Key = Key Search
Search.button.cancel = Cancel
Search.button.search = Search
Search.title = Search
Settings.button.cancle = Cancel
Settings.button.ok = OK
Settings.label.File type = File type:
Expand Down
4 changes: 2 additions & 2 deletions src/assets/lang/lang_versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<languages type="0">
<item>
<key type="1" value="en_US"/>
<value type="2" value="25"/>
<value type="2" value="26"/>
</item>
<item>
<key type="1" value="de_DE"/>
<value type="2" value="7"/>
<value type="2" value="8"/>
</item>
</languages>
</config>
Expand Down
5 changes: 4 additions & 1 deletion src/de/tinycodecrank/l4j/prefs/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Prefs(File config)
{
super(config);
}

@Value
public GuiPrefs mainWindow = new GuiPrefs(100, 100, 810, 442, Frame.MAXIMIZED_BOTH);

Expand All @@ -25,6 +25,9 @@ public Prefs(File config)
@Value
public GuiPrefs newProjectWindow = new GuiPrefs(100, 100, 550, 450, Frame.NORMAL);

@Value
public GuiPrefs searchWindow = new GuiPrefs(100, 100, 450, 300, Frame.NORMAL);

@Value
public FileSettings fileSettings = new FileSettings();

Expand Down
25 changes: 24 additions & 1 deletion src/de/tinycodecrank/l4j/ui/main/BusinessLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import de.tinycodecrank.l4j.startup.ProgramArgs;
import de.tinycodecrank.l4j.ui.lang.LangGui;
import de.tinycodecrank.l4j.ui.project.ProjectGui;
import de.tinycodecrank.l4j.ui.search.SearchGui;
import de.tinycodecrank.l4j.ui.search.SearchKeyData;
import de.tinycodecrank.l4j.ui.settings.Settings;
import de.tinycodecrank.l4j.util.DocumentListenerAdapter;
import de.tinycodecrank.l4j.util.KeyEventListener;
Expand All @@ -53,6 +55,8 @@ class BusinessLogic extends BusinessLogicTemplate<MainGui, Localizer>

private final Localizer l10n;

private SearchGui searchGui = null;

BusinessLogic(MainGui gui, Localizer l10n)
{
super(gui);
Expand All @@ -61,6 +65,16 @@ class BusinessLogic extends BusinessLogicTemplate<MainGui, Localizer>

void init(ProgramArgs args)
{
gui.if_(
gui -> EventQueue.invokeLater(
() -> this.searchGui = new SearchGui(
gui,
ModalityType.MODELESS,
e ->
{},
l10n,
new SearchKeyData(gui.table, this::setSelection))));

if (args.projectFile == null || args.projectFile.length <= 0)
return;

Expand Down Expand Up @@ -226,7 +240,7 @@ void showProjectOptions(ActionEvent ae)
void showGeneralOptions(ActionEvent ae)
{
gui.if_(gui -> new Settings(gui, ModalityType.APPLICATION_MODAL, event ->
{}, Localizer4J.prefs.fileSettings, l10n));
{}, l10n));
}

KeyListener changeTranslation_Enter()
Expand Down Expand Up @@ -792,6 +806,15 @@ private static void updateSwapButton(MainGui gui)
gui.comboBoxLanguage.getSelectedItem() != null && gui.comboBoxFallback.getSelectedItem() != null);
}

void search(ActionEvent ae)
{
gui.if_(gui ->
{
searchGui.setVisible(true);
searchGui.requestFocus();
});
}

private void setSelection(String selection)
{
final int paddingVertical = 20;
Expand Down
11 changes: 11 additions & 0 deletions src/de/tinycodecrank/l4j/ui/main/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class MainGui extends ObservableLangGui<BusinessLogic, Void, Localizer>
private JMenuItem mntmGeneralSettings;
JMenuItem mntmProjectSettings;
JMenuItem mntmSaveProject;
JMenuItem mntmSearch;

JToggleButton pin;

Expand Down Expand Up @@ -160,6 +161,16 @@ public MainGui(Consumer<GuiCloseEvent<Void>> closeListener, ProgramArgs args, Lo
mnFile.add(mntmSaveProject);
businessLogic.if_(bl -> mntmSaveProject.addActionListener(bl::saveProject));

var mnEdit = new JMenu();
reg("Main.Menu.Edit", mnEdit::setText);
menuBar.add(mnEdit);

mntmSearch = new JMenuItem();
reg("Main.Menu.Edit.Find", mntmSearch::setText);
mntmSearch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK));
businessLogic.if_(bl -> mntmSearch.addActionListener(bl::search));
mnEdit.add(mntmSearch);

mnLanguage = new JMenu();
reg("Main.Menu.Language", mnLanguage::setText);
mnLanguage.setEnabled(false);
Expand Down
42 changes: 42 additions & 0 deletions src/de/tinycodecrank/l4j/ui/search/BL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.tinycodecrank.l4j.ui.search;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;

import de.tinycodecrank.l4j.startup.Localizer4J;
import de.tinycodecrank.util.swing.DialogLogicTemplate;

final class BL extends DialogLogicTemplate<SearchGui, SearchKeyData>
{
private SearchKeyData data;

BL(SearchGui gui, SearchKeyData data)
{
super(gui);
this.data = data;
}

ActionListener search(JTextField text)
{
return ae -> data.setSelection().accept(text.getText());
}

void abort(ActionEvent ae)
{
gui.if_(gui -> gui.setVisible(false));
}

@Override
protected void disposeAction()
{
gui.if_(gui ->
{
Localizer4J.prefs.searchWindow.posX = gui.getX();
Localizer4J.prefs.searchWindow.posY = gui.getY();
Localizer4J.prefs.searchWindow.width = gui.getWidth();
Localizer4J.prefs.searchWindow.height = gui.getHeight();
});
}
}
54 changes: 54 additions & 0 deletions src/de/tinycodecrank/l4j/ui/search/KeyTab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package de.tinycodecrank.l4j.ui.search;

import static de.tinycodecrank.l4j.ui.search.SearchGui.*;

import java.awt.BorderLayout;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTextField;

import de.tinycodecrank.l4j.prefs.GuiPrefs;
import de.tinycodecrank.monads.opt.Opt;
import de.tinycodecrank.util.swing.ApplyAbortPanel;

final class KeyTab
{
static JPanel buildKeyTab(
SearchGui gui,
Opt<BL> bL,
GuiPrefs guiPrefs,
BiConsumer<String, Consumer<String>> reg)
{
final var panelContent = Box.createVerticalBox();

final var txtSearch = new JTextField();
panelContent.add(txtSearch, BorderLayout.CENTER);

final var panelSettings = Box.createVerticalBox();
final var chckbxCaseSensitive = new JCheckBox();
chckbxCaseSensitive.setRolloverEnabled(true);
reg.accept("Search.Checkbox.Case Sensitive", chckbxCaseSensitive::setText);
panelSettings.add(chckbxCaseSensitive);

final var panel = new JPanel(new BorderLayout());
panel.add(panelContent, BorderLayout.CENTER);
panel.add(panelSettings, BorderLayout.EAST);

bL.if_(bl ->
{
final var applyAbortPanel = new ApplyAbortPanel(
buttonSearch,
bl.search(txtSearch),
buttonCancel,
bl::abort);
reg.accept(buttonSearch, applyAbortPanel.btnButton1::setText);
reg.accept(buttonCancel, applyAbortPanel.btnButton2::setText);
panel.add(applyAbortPanel, BorderLayout.SOUTH);
});
return panel;
}
}
49 changes: 49 additions & 0 deletions src/de/tinycodecrank/l4j/ui/search/SearchGui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.tinycodecrank.l4j.ui.search;

import java.awt.Dimension;
import java.awt.Window;
import java.util.function.Consumer;

import javax.swing.JTabbedPane;

import de.tinycodecrank.i18n.Localizer;
import de.tinycodecrank.l4j.startup.Localizer4J;
import de.tinycodecrank.l4j.util.ObservableLangDialog;
import de.tinycodecrank.util.swing.events.GuiCloseEvent;

@SuppressWarnings("serial")
public final class SearchGui extends ObservableLangDialog<BL, Void, SearchKeyData>
{
static final String buttonSearch = "Search.button.search";
static final String buttonCancel = "Search.button.cancel";

public SearchGui(
Window owner,
ModalityType modality,
Consumer<GuiCloseEvent<Void>> closeListener,
Localizer localizer,
SearchKeyData data)
{
super(owner, modality, closeListener, localizer, data);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);

final var guiPrefs = Localizer4J.prefs.searchWindow;

reg("Search.title", this::setTitle);
setMinimumSize(new Dimension(300, 175));
guiPrefs.setBounds(this);

final var tabbedPane = new JTabbedPane(JTabbedPane.TOP);
setContentPane(tabbedPane);

tabbedPane.addTab(null, KeyTab.buildKeyTab(this, businessLogic, guiPrefs, this::reg));
reg("Search.Tab.Key", s -> tabbedPane.setTitleAt(0, s));
tabbedPane.setEnabledAt(0, true);
}

@Override
protected BL createBusinessLogic(SearchKeyData data)
{
return new BL(this, data);
}
}
8 changes: 8 additions & 0 deletions src/de/tinycodecrank/l4j/ui/search/SearchKeyData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.tinycodecrank.l4j.ui.search;

import java.util.function.Consumer;

import javax.swing.JTable;

public record SearchKeyData(JTable table, Consumer<String> setSelection)
{}
15 changes: 9 additions & 6 deletions src/de/tinycodecrank/l4j/ui/settings/BusinessLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ void buttonOK(ActionEvent event)
fileSettings.langFileExtension = langFileExtension;
fileSettings.localizationDelimiter = gui.textField_1.getText().trim();
fileSettings.versionListFile = gui.chckbxSaveVersionFile.isSelected();
Localizer4J.prefs.history.maxLength = (int) gui.spinnerHistoryLength.getModel().getValue();

while (Localizer4J.prefs.history.recent.size() > Localizer4J.prefs.history.maxLength)
Localizer4J.prefs.history.recent.removeLast();

Localizer4J.prefs.language = gui.localizer().currentLanguage();
if (gui.isGeneral)
{
Localizer4J.prefs.history.maxLength = (int) gui.spinnerHistoryLength.getModel().getValue();

while (Localizer4J.prefs.history.recent.size() > Localizer4J.prefs.history.maxLength)
Localizer4J.prefs.history.recent.removeLast();

Localizer4J.prefs.language = gui.localizer().currentLanguage();
}
gui.dispose();
});
}
Expand Down
Loading

0 comments on commit d03be1a

Please sign in to comment.