add Choose button to profile editor

dbus-notify
Zlatin Balevsky 2022-06-04 09:16:33 +01:00
parent 56fda08271
commit 9def185a03
No known key found for this signature in database
GPG Key ID: A72832072D525E41
3 changed files with 40 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import com.muwire.core.profile.MWProfile
import com.muwire.core.profile.MWProfileHeader import com.muwire.core.profile.MWProfileHeader
import com.muwire.core.profile.MWProfileImageFormat import com.muwire.core.profile.MWProfileImageFormat
import com.muwire.gui.CopyPasteSupport import com.muwire.gui.CopyPasteSupport
import static com.muwire.gui.Translator.trans
import griffon.core.artifact.GriffonController import griffon.core.artifact.GriffonController
import griffon.core.controller.ControllerAction import griffon.core.controller.ControllerAction
import griffon.inject.MVCMember import griffon.inject.MVCMember
@ -12,7 +14,7 @@ import griffon.metadata.ArtifactProviderFor
import javax.annotation.Nonnull import javax.annotation.Nonnull
import javax.imageio.ImageIO import javax.imageio.ImageIO
import javax.swing.JOptionPane import javax.swing.JFileChooser
@ArtifactProviderFor(GriffonController) @ArtifactProviderFor(GriffonController)
class EditProfileController { class EditProfileController {
@ -41,6 +43,40 @@ class EditProfileController {
view.setImageAndThumbnail(baos.toByteArray()) view.setImageAndThumbnail(baos.toByteArray())
} }
@ControllerAction
void choose() {
def chooser = new JFileChooser()
chooser.setDialogTitle(trans("PROFILE_EDITOR_CHOOSER_TITLE"))
chooser.setFileHidingEnabled(false)
def filter = new javax.swing.filechooser.FileFilter() {
@Override
boolean accept(File pathname) {
String name = pathname.getName().toLowerCase()
if (!(name.endsWith("jpg") || name.endsWith("jpeg") || name.endsWith("png")))
return false
if (pathname.length() > Constants.MAX_PROFILE_IMAGE_LENGTH)
return false
return true
}
@Override
String getDescription() {
return trans("PROFILE_EDITOR_CHOOSER_DESCRIPTION")
}
}
chooser.setFileFilter(filter)
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY)
int rv = chooser.showOpenDialog(null)
if (rv != JFileChooser.APPROVE_OPTION)
return
File f = chooser.getSelectedFile()
f.withInputStream {view.setImageAndThumbnail(it)}
String name = f.getName().toLowerCase()
model.format = name.endsWith("png") ? MWProfileImageFormat.PNG : MWProfileImageFormat.JPG
model.imageData = f.bytes
}
@ControllerAction @ControllerAction
void save() { void save() {
if (model.imageData == null || model.thumbnailData == null) { if (model.imageData == null || model.thumbnailData == null) {

View File

@ -712,6 +712,8 @@ PROFILE_EDITOR_ERROR_LARGE_FILE=The selected file is too large
PROFILE_EDITOR_ERROR_NO_IMAGE=Please select an avatar or generate one PROFILE_EDITOR_ERROR_NO_IMAGE=Please select an avatar or generate one
PROFILE_EDITOR_ERROR_LARGE_TITLE=Profile title is too long PROFILE_EDITOR_ERROR_LARGE_TITLE=Profile title is too long
PROFILE_EDITOR_ERROR_LARGE_BODY=Profile is too long PROFILE_EDITOR_ERROR_LARGE_BODY=Profile is too long
PROFILE_EDITOR_CHOOSER_TITLE=Select a profile image
PROFILE_EDITOR_CHOOSER_DESCRIPTION=JPG or PNG
## View Profile Frame ## View Profile Frame
PROFILE_VIEWER_TITLE=Profile of {0} PROFILE_VIEWER_TITLE=Profile of {0}

View File

@ -110,6 +110,7 @@ class EditProfileView {
panel { panel {
button(text: trans("PROFILE_EDITOR_GENERATE"), toolTipText: trans("TOOLTIP_PROFILE_EDITOR_GENERATE"), button(text: trans("PROFILE_EDITOR_GENERATE"), toolTipText: trans("TOOLTIP_PROFILE_EDITOR_GENERATE"),
generateAction) generateAction)
button(text: trans("CHOOSE"), chooseAction)
} }
panel { panel {
button(text: trans("SAVE"), saveAction) button(text: trans("SAVE"), saveAction)