From 6b441d6ff9bb6dde8263c2fe2fe8f0d1e8b080db Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 6 Jun 2022 05:40:58 +0100 Subject: [PATCH] options to not display avatars or user ids --- .../com/muwire/gui/OptionsController.groovy | 8 ++++++++ gui/griffon-app/i18n/messages.properties | 3 +++ .../models/com/muwire/gui/OptionsModel.groovy | 6 ++++++ .../views/com/muwire/gui/ChatRoomView.groovy | 8 +++++++- .../views/com/muwire/gui/MainFrameView.groovy | 2 +- .../com/muwire/gui/MessageFolderView.groovy | 3 ++- .../views/com/muwire/gui/OptionsView.groovy | 14 +++++++++++++- .../views/com/muwire/gui/SearchTabView.groovy | 6 +++++- .../views/com/muwire/gui/TrustListView.groovy | 6 +++++- .../ResultDetailsFrameView.groovy | 3 ++- .../ResultDetailsTabsView.groovy | 7 ++++++- .../groovy/com/muwire/gui/UISettings.groovy | 10 ++++++++++ .../PersonaOrProfileCellRenderer.groovy | 19 +++++++++++++++++-- 13 files changed, 85 insertions(+), 10 deletions(-) diff --git a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy index 8fc228ae..68dfe04a 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy @@ -341,6 +341,14 @@ class OptionsController { if (model.closeDecisionMade) uiSettings.closeWarning = false } + + boolean personaRendererAvatars = view.personaRendererAvatarsCheckbox.model.isSelected() + model.personaRendererAvatars = personaRendererAvatars + uiSettings.personaRendererAvatars = personaRendererAvatars + + boolean personaRendererIds = view.personaRendererIdsCheckbox.model.isSelected() + model.personaRendererIds = personaRendererIds + uiSettings.personaRendererIds = personaRendererIds saveUISettings() diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 586a7dcd..d58be55e 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -364,6 +364,9 @@ OPTIONS_EXCLUDE_LOCAL_FILES=Exclude local files from results OPTIONS_CLEAR_FINISHED_UPLOADS=Automatically clear finished uploads OPTIONS_WHEN_CLOSING_MUWIRE=When closing MuWire OPTIONS_MINIMIZE_TO_TRAY=Minimize to tray +OPTIONS_PERSONA_RENDERING=User Name Display Options +OPTIONS_PERSONA_RENDERING_AVATARS=Show avatars +OPTIONS_PERSONA_RENDERING_IDS=Show IDs # Bandwidth tab OPTIONS_BANDWIDTH_SETTINGS=Changing bandwidth settings requires a restart diff --git a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy index fdbb7a9c..5bf68730 100644 --- a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy @@ -100,6 +100,10 @@ class OptionsModel { @Observable boolean allowOnlyTrustedMessages @Observable int messageSendInterval + // persona rendering options + @Observable boolean personaRendererAvatars + @Observable boolean personaRendererIds + boolean disableUpdates void mvcGroupInit(Map args) { @@ -155,6 +159,8 @@ class OptionsModel { groupByFile = uiSettings.groupByFile messageNotifications = uiSettings.messageNotifications showUnsharedPaths = uiSettings.showUnsharedPaths + personaRendererAvatars = uiSettings.personaRendererAvatars + personaRendererIds = uiSettings.personaRendererIds if (System.getProperty("embeddedRouter") == "true") { inBw = String.valueOf(settings.inBw) diff --git a/gui/griffon-app/views/com/muwire/gui/ChatRoomView.groovy b/gui/griffon-app/views/com/muwire/gui/ChatRoomView.groovy index f981007f..1771923c 100644 --- a/gui/griffon-app/views/com/muwire/gui/ChatRoomView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/ChatRoomView.groovy @@ -3,7 +3,11 @@ package com.muwire.gui import com.muwire.gui.profile.PersonaOrProfile import com.muwire.gui.profile.PersonaOrProfileCellRenderer import com.muwire.gui.profile.PersonaOrProfileComparator +import griffon.core.GriffonApplication import griffon.core.artifact.GriffonView + +import javax.inject.Inject + import static com.muwire.gui.Translator.trans import griffon.inject.MVCMember import griffon.metadata.ArtifactProviderFor @@ -40,6 +44,8 @@ class ChatRoomView { ChatRoomModel model @MVCMember @Nonnull ChatRoomController controller + @Inject + GriffonApplication application ChatNotificator chatNotificator @@ -128,7 +134,7 @@ class ChatRoomView { if (membersTable != null) { - membersTable.setDefaultRenderer(PersonaOrProfile.class, new PersonaOrProfileCellRenderer()) + membersTable.setDefaultRenderer(PersonaOrProfile.class, new PersonaOrProfileCellRenderer(application.context.get("ui-settings"))) membersTable.rowSorter.setComparator(0, new PersonaOrProfileComparator()) membersTable.rowSorter.addRowSorterListener({evt -> lastMembersTableSortEvent = evt}) membersTable.rowSorter.setSortsOnUpdates(true) diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index bb79fdb7..878ed8fd 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -891,7 +891,7 @@ class MainFrameView { WHEN_IN_FOCUSED_WINDOW) } - def popRenderer = new PersonaOrProfileCellRenderer() + def popRenderer = new PersonaOrProfileCellRenderer(application.context.get("ui-settings")) def popComparator = new PersonaOrProfileComparator() // downloads table diff --git a/gui/griffon-app/views/com/muwire/gui/MessageFolderView.groovy b/gui/griffon-app/views/com/muwire/gui/MessageFolderView.groovy index 0e8a09e6..402f02af 100644 --- a/gui/griffon-app/views/com/muwire/gui/MessageFolderView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MessageFolderView.groovy @@ -196,7 +196,8 @@ class MessageFolderView { def centerRenderer = new DefaultTableCellRenderer() centerRenderer.setHorizontalAlignment(JLabel.CENTER) - messageHeaderTable.setDefaultRenderer(PersonaOrProfile.class, new PersonaOrProfileCellRenderer()) + messageHeaderTable.setDefaultRenderer(PersonaOrProfile.class, + new PersonaOrProfileCellRenderer(application.context.get("ui-settings"))) messageHeaderTable.setDefaultRenderer(Integer.class, centerRenderer) messageHeaderTable.setDefaultRenderer(Long.class, new DateRenderer()) if (!model.outgoing) diff --git a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy index 3906bd76..445376c0 100644 --- a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy @@ -92,6 +92,8 @@ class OptionsView { def showUnsharedPathsCheckbox def storeSearchHistoryCheckbox def messageNotificationsCheckbox + def personaRendererAvatarsCheckbox + def personaRendererIdsCheckbox def inBwField def outBwField @@ -442,7 +444,17 @@ class OptionsView { } } } - panel (constraints : gbc(gridx: 0, gridy: 3, weighty: 100)) + panel (border : titledBorder(title : trans("OPTIONS_PERSONA_RENDERING"), border : etchedBorder(), titlePosition : TitledBorder.TOP), + constraints : gbc(gridx : 0, gridy : 3, fill : GridBagConstraints.HORIZONTAL, weightx : 100)) { + gridBagLayout() + label(text: trans("OPTIONS_PERSONA_RENDERING_AVATARS"), constraints: gbc(gridx: 0, gridy: 0, anchor: GridBagConstraints.LINE_START, weightx: 100)) + personaRendererAvatarsCheckbox = checkBox(selected: bind {model.personaRendererAvatars}, + constraints: gbc(gridx:1, gridy:0, anchor: GridBagConstraints.LINE_END)) + label(text: trans("OPTIONS_PERSONA_RENDERING_IDS"), constraints: gbc(gridx: 0, gridy: 1, anchor: GridBagConstraints.LINE_START, weightx: 100)) + personaRendererIdsCheckbox = checkBox(selected: bind {model.personaRendererIds}, + constraints: gbc(gridx:1, gridy:1, anchor: GridBagConstraints.LINE_END)) + } + panel (constraints : gbc(gridx: 0, gridy: 4, weighty: 100)) } bandwidth = builder.panel { gridBagLayout() diff --git a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy index 23426e28..27ed8034 100644 --- a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy @@ -6,9 +6,11 @@ import com.muwire.gui.profile.PersonaOrProfile import com.muwire.gui.profile.PersonaOrProfileCellRenderer import com.muwire.gui.profile.PersonaOrProfileComparator import com.muwire.gui.profile.ResultPOP +import griffon.core.GriffonApplication import griffon.core.artifact.GriffonView import net.i2p.data.Destination +import javax.inject.Inject import javax.swing.AbstractAction import javax.swing.Action import javax.swing.JPanel @@ -64,6 +66,8 @@ class SearchTabView { SearchTabModel model @MVCMember @Nonnull SearchTabController controller + @Inject + GriffonApplication application UISettings settings @@ -397,7 +401,7 @@ class SearchTabView { }) // senders table - def popRenderer = new PersonaOrProfileCellRenderer() + def popRenderer = new PersonaOrProfileCellRenderer(application.context.get("ui-settings")) def popComparator = new PersonaOrProfileComparator() sendersTable.addMouseListener(sendersMouseListener) sendersTable.setDefaultRenderer(Integer.class, centerRenderer) diff --git a/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy b/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy index b477a9d0..12da139e 100644 --- a/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/TrustListView.groovy @@ -4,10 +4,12 @@ import com.muwire.core.Persona import com.muwire.gui.profile.PersonaOrProfile import com.muwire.gui.profile.PersonaOrProfileCellRenderer import com.muwire.gui.profile.PersonaOrProfileComparator +import griffon.core.GriffonApplication import griffon.core.artifact.GriffonView import griffon.inject.MVCMember import griffon.metadata.ArtifactProviderFor +import javax.inject.Inject import javax.swing.JFrame import javax.swing.JTable import java.awt.Dimension @@ -29,6 +31,8 @@ class TrustListView { FactoryBuilderSupport builder @MVCMember @Nonnull TrustListModel model + @Inject + GriffonApplication application JFrame window JFrame mainFrame @@ -83,7 +87,7 @@ class TrustListView { void mvcGroupInit(Map args) { - def popRenderer = new PersonaOrProfileCellRenderer() + def popRenderer = new PersonaOrProfileCellRenderer(application.context.get("ui-settings")) def popComparator = new PersonaOrProfileComparator() contactsTable.setDefaultRenderer(PersonaOrProfile.class, popRenderer) diff --git a/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsFrameView.groovy index 0397c327..ce0ae495 100644 --- a/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsFrameView.groovy @@ -126,7 +126,8 @@ class ResultDetailsFrameView { void mvcGroupInit(Map args) { if (model.senders.size() > 1) { JTable sendersTable = builder.getVariable("senders-table") - sendersTable.setDefaultRenderer(PersonaOrProfile.class, new PersonaOrProfileCellRenderer()) + sendersTable.setDefaultRenderer(PersonaOrProfile.class, + new PersonaOrProfileCellRenderer(application.context.get("ui-settings"))) sendersTable.rowSorter.setComparator(0, new PersonaOrProfileComparator()) } if (certificatesPanel != null) { diff --git a/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsTabsView.groovy b/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsTabsView.groovy index 76ee8d1a..68945889 100644 --- a/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsTabsView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/resultdetails/ResultDetailsTabsView.groovy @@ -11,6 +11,7 @@ import com.muwire.gui.profile.PersonaOrProfileComparator import com.muwire.gui.profile.ResultPOP import com.muwire.gui.profile.ThumbnailIcon import com.muwire.gui.resultdetails.ResultListCellRenderer +import griffon.core.GriffonApplication import griffon.core.artifact.GriffonView import griffon.core.mvc.MVCGroup import griffon.inject.MVCMember @@ -18,6 +19,7 @@ import griffon.metadata.ArtifactProviderFor import net.i2p.data.Base64 import javax.annotation.Nonnull +import javax.inject.Inject import javax.swing.Icon import javax.swing.JList import javax.swing.JPanel @@ -36,6 +38,8 @@ class ResultDetailsTabsView { FactoryBuilderSupport builder @MVCMember @Nonnull ResultDetailsTabsModel model + @Inject + GriffonApplication application JPanel p @@ -182,7 +186,8 @@ class ResultDetailsTabsView { void mvcGroupInit(Map args) { // all senders table - sendersTable.setDefaultRenderer(PersonaOrProfile.class, new PersonaOrProfileCellRenderer()) + sendersTable.setDefaultRenderer(PersonaOrProfile.class, + new PersonaOrProfileCellRenderer(application.context.get("ui-settings"))) sendersTable.rowSorter.setComparator(0, new PersonaOrProfileComparator()) def selectionModel = sendersTable.getSelectionModel() selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) diff --git a/gui/src/main/groovy/com/muwire/gui/UISettings.groovy b/gui/src/main/groovy/com/muwire/gui/UISettings.groovy index 2bca2d5f..4bd6d402 100644 --- a/gui/src/main/groovy/com/muwire/gui/UISettings.groovy +++ b/gui/src/main/groovy/com/muwire/gui/UISettings.groovy @@ -33,6 +33,10 @@ class UISettings { Set openTabs boolean messageNotifications + // persona renderer settings + boolean personaRendererAvatars + boolean personaRendererIds + UISettings(Properties props) { lnf = props.getProperty("lnf", "system") locale = props.getProperty("locale","us") @@ -63,6 +67,9 @@ class UISettings { messageNotifications = Boolean.parseBoolean(props.getProperty("messageNotifications","true")) showUnsharedPaths = Boolean.parseBoolean(props.getProperty("showUnsharedPaths","false")) + + personaRendererAvatars = Boolean.parseBoolean(props.getProperty("personaRendererAvatars", "true")) + personaRendererIds = Boolean.parseBoolean(props.getProperty("personaRendererIds", "true")) } void write(OutputStream out) throws IOException { @@ -97,6 +104,9 @@ class UISettings { props.setProperty("messageNotifications", String.valueOf(messageNotifications)) props.setProperty("showUnsharedPaths", String.valueOf(showUnsharedPaths)) + + props.setProperty("personaRendererAvatars", String.valueOf(personaRendererAvatars)) + props.setProperty("personaRendererIds", String.valueOf(personaRendererIds)) props.store(out, "UI Properties") } diff --git a/gui/src/main/groovy/com/muwire/gui/profile/PersonaOrProfileCellRenderer.groovy b/gui/src/main/groovy/com/muwire/gui/profile/PersonaOrProfileCellRenderer.groovy index 5e1031be..2f21a632 100644 --- a/gui/src/main/groovy/com/muwire/gui/profile/PersonaOrProfileCellRenderer.groovy +++ b/gui/src/main/groovy/com/muwire/gui/profile/PersonaOrProfileCellRenderer.groovy @@ -1,6 +1,7 @@ package com.muwire.gui.profile import com.muwire.core.Persona +import com.muwire.gui.UISettings import javax.swing.JTable import javax.swing.table.DefaultTableCellRenderer @@ -9,13 +10,20 @@ import java.awt.Component import static com.muwire.gui.Translator.trans class PersonaOrProfileCellRenderer extends DefaultTableCellRenderer { + + private final UISettings settings + + PersonaOrProfileCellRenderer(UISettings settings) { + this.settings = settings + } + @Override Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column) PersonaOrProfile pop = (PersonaOrProfile) value - if (pop.getThumbnail() != null) + if (pop.getThumbnail() != null && settings.personaRendererAvatars) setIcon(pop.getThumbnail()) else setIcon(null) @@ -26,7 +34,14 @@ class PersonaOrProfileCellRenderer extends DefaultTableCellRenderer { setToolTipText(trans("NO_PROFILE")) Persona persona = pop.getPersona() - setText("${htmlize(persona)}") + if (settings.personaRendererIds) + setText("${htmlize(persona)}") + else { + String fullName = pop.getPersona().getHumanReadableName() + String justName = fullName.substring(0, fullName.indexOf("@")) + setText(justName) + } + if (isSelected) { setForeground(table.getSelectionForeground()) setBackground(table.getSelectionBackground())