mirror of https://github.com/zlatinb/muwire
drag-and-drop image
parent
771bce0160
commit
4acd42b8c7
|
@ -24,4 +24,15 @@ class EditProfileController {
|
||||||
void copyFull() {
|
void copyFull() {
|
||||||
CopyPasteSupport.copyToClipboard(model.core.me.toBase64())
|
CopyPasteSupport.copyToClipboard(model.core.me.toBase64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void save() {
|
||||||
|
// TODO: implement
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void cancel() {
|
||||||
|
view.dialog.setVisible(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,25 @@
|
||||||
package com.muwire.gui.profile
|
package com.muwire.gui.profile
|
||||||
|
|
||||||
|
import com.muwire.core.Constants
|
||||||
import griffon.core.GriffonApplication
|
import griffon.core.GriffonApplication
|
||||||
import griffon.core.artifact.GriffonView
|
import griffon.core.artifact.GriffonView
|
||||||
import griffon.inject.MVCMember
|
import griffon.inject.MVCMember
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
|
import javax.imageio.ImageIO
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.swing.JComponent
|
||||||
import javax.swing.JDialog
|
import javax.swing.JDialog
|
||||||
|
import javax.swing.JFrame
|
||||||
|
import javax.swing.JLabel
|
||||||
|
import javax.swing.JPanel
|
||||||
|
import javax.swing.TransferHandler
|
||||||
import javax.swing.border.TitledBorder
|
import javax.swing.border.TitledBorder
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
|
import java.awt.Dimension
|
||||||
|
import java.awt.datatransfer.DataFlavor
|
||||||
|
import java.awt.image.BufferedImage
|
||||||
|
|
||||||
import static com.muwire.gui.Translator.trans
|
import static com.muwire.gui.Translator.trans
|
||||||
|
|
||||||
|
@ -24,36 +34,73 @@ class EditProfileView {
|
||||||
@Inject
|
@Inject
|
||||||
GriffonApplication application
|
GriffonApplication application
|
||||||
|
|
||||||
def mainFrame
|
JFrame mainFrame
|
||||||
def dialog
|
JDialog dialog
|
||||||
|
JPanel imagePanel
|
||||||
def mainPanel
|
def mainPanel
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
mainFrame = application.windowManager.findWindow("main-frame")
|
mainFrame = application.windowManager.findWindow("main-frame")
|
||||||
|
|
||||||
|
int dimX = Math.max(700, (int)(mainFrame.getWidth() / 2))
|
||||||
|
int dimY = Math.max(700, (int)(mainFrame.getHeight() / 2))
|
||||||
dialog = new JDialog(mainFrame, "Profile Editor", true)
|
dialog = new JDialog(mainFrame, "Profile Editor", true)
|
||||||
|
dialog.setSize([dimX, dimY] as Dimension)
|
||||||
dialog.setResizable(false)
|
dialog.setResizable(false)
|
||||||
|
|
||||||
|
def transferHandler = new ImageTransferHandler()
|
||||||
|
|
||||||
mainPanel = builder.panel {
|
mainPanel = builder.panel {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
panel ( border: titledBorder(title: trans("PROFILE_EDITOR_MUWIRE_ID"), border: etchedBorder(),
|
panel ( border: titledBorder(title: trans("PROFILE_EDITOR_MUWIRE_ID"), border: etchedBorder(),
|
||||||
titlePosition: TitledBorder.TOP), constraints: BorderLayout.NORTH) {
|
titlePosition: TitledBorder.TOP), constraints: BorderLayout.NORTH) {
|
||||||
borderLayout()
|
|
||||||
label(text: model.core.me.getHumanReadableName(), constraints: BorderLayout.NORTH)
|
label(text: model.core.me.getHumanReadableName(), constraints: BorderLayout.NORTH)
|
||||||
panel(constraints: BorderLayout.SOUTH) {
|
button(text : trans("COPY_SHORT"), toolTipText: trans("TOOLTIP_COPY_SHORT_ID"),
|
||||||
button(text : trans("COPY_SHORT"), toolTipText: trans("TOOLTIP_COPY_SHORT_ID"),
|
copyShortAction)
|
||||||
copyShortAction)
|
button(text : trans("COPY_FULL"), toolTipText: trans("TOOLTIP_COPY_FULL_ID"),
|
||||||
button(text : trans("COPY_FULL"), toolTipText: trans("TOOLTIP_COPY_FULL_ID"),
|
copyFullAction)
|
||||||
copyFullAction)
|
}
|
||||||
}
|
panel(constraints: BorderLayout.CENTER, transferHandler: transferHandler) {
|
||||||
|
gridLayout(rows: 1, cols: 1)
|
||||||
|
imagePanel = panel()
|
||||||
|
}
|
||||||
|
panel (constraints: BorderLayout.SOUTH) {
|
||||||
|
button(text : trans("SAVE"), saveAction)
|
||||||
|
button(text : trans("CANCEL"), cancelAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mvcGroupInit(Map<String, String> args) {
|
void mvcGroupInit(Map<String, String> args) {
|
||||||
dialog.getContentPane().add(mainPanel)
|
dialog.getContentPane().add(mainPanel)
|
||||||
dialog.pack()
|
|
||||||
dialog.setLocationRelativeTo(mainFrame)
|
dialog.setLocationRelativeTo(mainFrame)
|
||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setImageAndThumbnail(BufferedImage image) {
|
||||||
|
def mainImage = ImageScaler.scaleToMax(image)
|
||||||
|
imagePanel.getGraphics().drawImage(image, 0, 0,null)
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ImageTransferHandler extends TransferHandler {
|
||||||
|
boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean importData(TransferHandler.TransferSupport support) {
|
||||||
|
def files = support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)
|
||||||
|
if (files == null)
|
||||||
|
return false
|
||||||
|
if (files.size() != 1)
|
||||||
|
return false
|
||||||
|
File f = files[0]
|
||||||
|
if (!(f.getName().endsWith("jpg") || f.getName().endsWith("jpeg") || f.getName().endsWith("png")))
|
||||||
|
return false
|
||||||
|
if (f.length() > Constants.MAX_PROFILE_IMAGE_LENGTH)
|
||||||
|
return false
|
||||||
|
setImageAndThumbnail(ImageIO.read(f))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue