Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
6a093710
by Tony Chemit at 2024-08-30T11:34:21+02:00
-
21265de1
by Tony Chemit at 2024-08-30T11:34:28+02:00
-
c1d72929
by Tony Chemit at 2024-08-30T11:35:12+02:00
-
8d17f01c
by Tony Chemit at 2024-08-30T11:48:45+02:00
3 changed files:
- + client/configuration/src/main/java/fr/ird/observe/client/FilterableComboBoxState.java
- + client/configuration/src/main/java/fr/ird/observe/client/ListHeaderState.java
- client/configuration/src/main/java/fr/ird/observe/client/ObserveSwingSession.java
Changes:
| 1 | +package fr.ird.observe.client;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Client :: Configuration
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2024 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import io.ultreia.java4all.jaxx.widgets.combobox.FilterableComboBox;
|
|
| 26 | +import org.nuiton.jaxx.runtime.swing.session.State;
|
|
| 27 | + |
|
| 28 | +/**
|
|
| 29 | + * All states to persist on a {@link FilterableComboBox}.
|
|
| 30 | + * <p>
|
|
| 31 | + * Created at 30/08/2024.
|
|
| 32 | + *
|
|
| 33 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 34 | + * @since 9.3.7
|
|
| 35 | + * <p>
|
|
| 36 | + * FIXME Move this back to JAXX
|
|
| 37 | + */
|
|
| 38 | +public class FilterableComboBoxState implements State {
|
|
| 39 | + |
|
| 40 | + protected int index = 0;
|
|
| 41 | + |
|
| 42 | + protected boolean reverseSort = false;
|
|
| 43 | + |
|
| 44 | + public FilterableComboBoxState() {
|
|
| 45 | + }
|
|
| 46 | + |
|
| 47 | + public FilterableComboBoxState(int index, boolean reverseSort) {
|
|
| 48 | + this.index = index;
|
|
| 49 | + this.reverseSort = reverseSort;
|
|
| 50 | + }
|
|
| 51 | + |
|
| 52 | + public int getIndex() {
|
|
| 53 | + return index;
|
|
| 54 | + }
|
|
| 55 | + |
|
| 56 | + public void setIndex(int index) {
|
|
| 57 | + this.index = index;
|
|
| 58 | + }
|
|
| 59 | + |
|
| 60 | + public boolean isReverseSort() {
|
|
| 61 | + return reverseSort;
|
|
| 62 | + }
|
|
| 63 | + |
|
| 64 | + public void setReverseSort(boolean reverseSort) {
|
|
| 65 | + this.reverseSort = reverseSort;
|
|
| 66 | + }
|
|
| 67 | + |
|
| 68 | + protected FilterableComboBox<?> checkComponent(Object o) {
|
|
| 69 | + if (o == null) {
|
|
| 70 | + throw new IllegalArgumentException("null component");
|
|
| 71 | + }
|
|
| 72 | + if (!(o instanceof FilterableComboBox)) {
|
|
| 73 | + throw new IllegalArgumentException("invalid component");
|
|
| 74 | + }
|
|
| 75 | + return (FilterableComboBox<?>) o;
|
|
| 76 | + }
|
|
| 77 | + |
|
| 78 | + @Override
|
|
| 79 | + public State getState(Object o) {
|
|
| 80 | + FilterableComboBox<?> combo = checkComponent(o);
|
|
| 81 | + return new FilterableComboBoxState(combo.getModel().getIndex(), combo.getModel().getReverseSort());
|
|
| 82 | + }
|
|
| 83 | + |
|
| 84 | + @Override
|
|
| 85 | + public void setState(Object o, State state) {
|
|
| 86 | + if (!(state instanceof FilterableComboBoxState)) {
|
|
| 87 | + throw new IllegalArgumentException("invalid state");
|
|
| 88 | + }
|
|
| 89 | + FilterableComboBox<?> ui = checkComponent(o);
|
|
| 90 | + FilterableComboBoxState typedState = (FilterableComboBoxState) state;
|
|
| 91 | + ui.getModel().setIndex(typedState.getIndex());
|
|
| 92 | + ui.getModel().setReverseSort(typedState.isReverseSort());
|
|
| 93 | + }
|
|
| 94 | + |
|
| 95 | + |
|
| 96 | +}
|
|
| 97 | + |
| 1 | +package fr.ird.observe.client;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Client :: Configuration
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2024 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import io.ultreia.java4all.jaxx.widgets.list.ListHeader;
|
|
| 26 | +import org.nuiton.jaxx.runtime.swing.JAXXButtonGroup;
|
|
| 27 | +import org.nuiton.jaxx.runtime.swing.session.State;
|
|
| 28 | + |
|
| 29 | +/**
|
|
| 30 | + * All states to persist on a {@link ListHeader}.
|
|
| 31 | + * <p>
|
|
| 32 | + * Created at 30/08/2024.
|
|
| 33 | + *
|
|
| 34 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 35 | + * @since 9.3.7
|
|
| 36 | + * <p>
|
|
| 37 | + * FIXME Move this back to JAXX
|
|
| 38 | + */
|
|
| 39 | +public class ListHeaderState implements State {
|
|
| 40 | + |
|
| 41 | + protected int index = 0;
|
|
| 42 | + |
|
| 43 | + protected boolean reverseSort = false;
|
|
| 44 | + |
|
| 45 | + public ListHeaderState() {
|
|
| 46 | + }
|
|
| 47 | + |
|
| 48 | + public ListHeaderState(int index, boolean reverseSort) {
|
|
| 49 | + this.index = index;
|
|
| 50 | + this.reverseSort = reverseSort;
|
|
| 51 | + }
|
|
| 52 | + |
|
| 53 | + public int getIndex() {
|
|
| 54 | + return index;
|
|
| 55 | + }
|
|
| 56 | + |
|
| 57 | + public void setIndex(int index) {
|
|
| 58 | + this.index = index;
|
|
| 59 | + }
|
|
| 60 | + |
|
| 61 | + public boolean isReverseSort() {
|
|
| 62 | + return reverseSort;
|
|
| 63 | + }
|
|
| 64 | + |
|
| 65 | + public void setReverseSort(boolean reverseSort) {
|
|
| 66 | + this.reverseSort = reverseSort;
|
|
| 67 | + }
|
|
| 68 | + |
|
| 69 | + protected ListHeader<?> checkComponent(Object o) {
|
|
| 70 | + if (o == null) {
|
|
| 71 | + throw new IllegalArgumentException("null component");
|
|
| 72 | + }
|
|
| 73 | + if (!(o instanceof ListHeader)) {
|
|
| 74 | + throw new IllegalArgumentException("invalid component");
|
|
| 75 | + }
|
|
| 76 | + return (ListHeader<?>) o;
|
|
| 77 | + }
|
|
| 78 | + |
|
| 79 | + @Override
|
|
| 80 | + public State getState(Object o) {
|
|
| 81 | + ListHeader<?> combo = checkComponent(o);
|
|
| 82 | + return new ListHeaderState(combo.getIndex(), combo.getReverseSort());
|
|
| 83 | + }
|
|
| 84 | + |
|
| 85 | + @Override
|
|
| 86 | + public void setState(Object o, State state) {
|
|
| 87 | + if (!(state instanceof ListHeaderState)) {
|
|
| 88 | + throw new IllegalArgumentException("invalid state");
|
|
| 89 | + }
|
|
| 90 | + ListHeader<?> ui = checkComponent(o);
|
|
| 91 | + ListHeaderState typedState = (ListHeaderState) state;
|
|
| 92 | + ui.setIndex(typedState.getIndex());
|
|
| 93 | + ui.setReverseSort(typedState.isReverseSort());
|
|
| 94 | + //FIXME Move this back to JListHeader.setIndex method
|
|
| 95 | + JAXXButtonGroup indexes = ui.getIndexes();
|
|
| 96 | + indexes.setSelectedButton(ui.getIndex());
|
|
| 97 | + }
|
|
| 98 | + |
|
| 99 | +} |
| ... | ... | @@ -22,6 +22,10 @@ package fr.ird.observe.client; |
| 22 | 22 | * #L%
|
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | +import io.ultreia.java4all.jaxx.widgets.combobox.FilterableComboBox;
|
|
| 26 | +import io.ultreia.java4all.jaxx.widgets.list.DoubleList;
|
|
| 27 | +import io.ultreia.java4all.jaxx.widgets.list.ListHeader;
|
|
| 28 | +import io.ultreia.java4all.jaxx.widgets.list.session.DoubleListState;
|
|
| 25 | 29 | import io.ultreia.java4all.util.SortedProperties;
|
| 26 | 30 | import org.nuiton.jaxx.runtime.swing.session.State;
|
| 27 | 31 | import org.nuiton.jaxx.runtime.swing.session.SwingSession;
|
| ... | ... | @@ -46,8 +50,12 @@ public class ObserveSwingSession extends SwingSession { |
| 46 | 50 | private final File preferencesFile;
|
| 47 | 51 | |
| 48 | 52 | private final Properties preferences;
|
| 53 | + |
|
| 49 | 54 | public ObserveSwingSession(File file, boolean autoSave, File preferencesFile) {
|
| 50 | - super(file, autoSave);
|
|
| 55 | + super(file, autoSave, Map.of(FilterableComboBox.class, new FilterableComboBoxState(),
|
|
| 56 | + DoubleList.class, new DoubleListState(),
|
|
| 57 | + ListHeader.class, new ListHeaderState()
|
|
| 58 | + ));
|
|
| 51 | 59 | this.preferencesFile = preferencesFile;
|
| 52 | 60 | this.preferences = new SortedProperties();
|
| 53 | 61 | loadPreferences(preferencesFile);
|
| ... | ... | @@ -68,8 +76,8 @@ public class ObserveSwingSession extends SwingSession { |
| 68 | 76 | return preferences;
|
| 69 | 77 | }
|
| 70 | 78 | |
| 71 | - private void loadPreferences(File preferencesFile) {
|
|
| 72 | - if(preferencesFile.exists()) {
|
|
| 79 | + private void loadPreferences(File preferencesFile) {
|
|
| 80 | + if (preferencesFile.exists()) {
|
|
| 73 | 81 | try (BufferedReader reader = Files.newBufferedReader(preferencesFile.toPath(), StandardCharsets.UTF_8)) {
|
| 74 | 82 | preferences.load(reader);
|
| 75 | 83 | } catch (IOException e) {
|