mirror of https://github.com/zlatinb/muwire
add Choose button to profile editor
parent
56fda08271
commit
9def185a03
|
@ -5,6 +5,8 @@ import com.muwire.core.profile.MWProfile
|
|||
import com.muwire.core.profile.MWProfileHeader
|
||||
import com.muwire.core.profile.MWProfileImageFormat
|
||||
import com.muwire.gui.CopyPasteSupport
|
||||
import static com.muwire.gui.Translator.trans
|
||||
|
||||
import griffon.core.artifact.GriffonController
|
||||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
|
@ -12,7 +14,7 @@ import griffon.metadata.ArtifactProviderFor
|
|||
|
||||
import javax.annotation.Nonnull
|
||||
import javax.imageio.ImageIO
|
||||
import javax.swing.JOptionPane
|
||||
import javax.swing.JFileChooser
|
||||
|
||||
@ArtifactProviderFor(GriffonController)
|
||||
class EditProfileController {
|
||||
|
@ -41,6 +43,40 @@ class EditProfileController {
|
|||
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
|
||||
void save() {
|
||||
if (model.imageData == null || model.thumbnailData == null) {
|
||||
|
|
|
@ -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_LARGE_TITLE=Profile title 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
|
||||
PROFILE_VIEWER_TITLE=Profile of {0}
|
||||
|
|
|
@ -110,6 +110,7 @@ class EditProfileView {
|
|||
panel {
|
||||
button(text: trans("PROFILE_EDITOR_GENERATE"), toolTipText: trans("TOOLTIP_PROFILE_EDITOR_GENERATE"),
|
||||
generateAction)
|
||||
button(text: trans("CHOOSE"), chooseAction)
|
||||
}
|
||||
panel {
|
||||
button(text: trans("SAVE"), saveAction)
|
||||
|
|
Loading…
Reference in New Issue