mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
- nantuko84 patch for deck editor OOM problem
This commit is contained in:
@@ -6,58 +6,55 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This code was edited or generated using CloudGarden's Jigloo
|
||||
* SWT/Swing GUI Builder, which is free for non-commercial
|
||||
* use. If Jigloo is being used commercially (ie, by a corporation,
|
||||
* company or business for any purpose whatever) then you
|
||||
* should purchase a license for each developer using Jigloo.
|
||||
* Please visit www.cloudgarden.com for details.
|
||||
* Use of Jigloo implies acceptance of these licensing terms.
|
||||
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
|
||||
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
|
||||
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
|
||||
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
|
||||
* Builder, which is free for non-commercial use. If Jigloo is being used
|
||||
* commercially (ie, by a corporation, company or business for any purpose
|
||||
* whatever) then you should purchase a license for each developer using Jigloo.
|
||||
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
|
||||
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
|
||||
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
|
||||
* ANY CORPORATE OR COMMERCIAL PURPOSE.
|
||||
*/
|
||||
public class GUI_PictureHQ extends JDialog
|
||||
{
|
||||
public class GUI_PictureHQ extends JDialog {
|
||||
private static final long serialVersionUID = 7046993858415055058L;
|
||||
|
||||
public JPanel jPanelPictureHQ;
|
||||
public PicturePanel jPictureContainer;
|
||||
|
||||
|
||||
|
||||
public GUI_PictureHQ(JFrame frame, Card c)
|
||||
{
|
||||
public GUI_PictureHQ(JFrame frame, Card c) {
|
||||
super(frame);
|
||||
this.setUndecorated(true);
|
||||
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
{
|
||||
|
||||
jPanelPictureHQ = new JPanel();
|
||||
BorderLayout jPanelPictureHQLayout = new BorderLayout();
|
||||
jPanelPictureHQ.setLayout(jPanelPictureHQLayout);
|
||||
getContentPane().add(jPanelPictureHQ, BorderLayout.CENTER);
|
||||
jPanelPictureHQ.setBorder(BorderFactory.createEtchedBorder());;
|
||||
jPanelPictureHQ.removeAll();
|
||||
jPanelPictureHQ.add(GuiDisplayUtil.getPictureHQ(c));
|
||||
jPanelPictureHQ.revalidate();
|
||||
jPanelPictureHQ.setBorder(BorderFactory.createEtchedBorder());
|
||||
//jPanelPictureHQ.removeAll();
|
||||
jPictureContainer = GuiDisplayUtil.getPictureHQ(c);
|
||||
jPanelPictureHQ.add(jPictureContainer);
|
||||
//jPanelPictureHQ.revalidate();
|
||||
jPanelPictureHQ.addMouseListener(new CustomListener());
|
||||
}
|
||||
|
||||
pack();
|
||||
}
|
||||
|
||||
public void letsGo(JFrame frame, Card c) throws IOException
|
||||
{
|
||||
GUI_PictureHQ trayWindow = new GUI_PictureHQ(frame, c);
|
||||
public void letsGo(JFrame frame, Card c) throws IOException {
|
||||
// nantuko: we don't need this. why not just use {this} instance?
|
||||
// GUI_PictureHQ trayWindow = new GUI_PictureHQ(frame, c);
|
||||
int heightHQ = GuiDisplayUtil.getPictureHQheight(c);
|
||||
int widthHQ = GuiDisplayUtil.getPictureHQwidth(c);
|
||||
trayWindow.setBounds(frame.getBounds().x+ frame.getBounds().width-widthHQ-17,frame.getBounds().y+ frame.getBounds().height-heightHQ-17, widthHQ, heightHQ);
|
||||
trayWindow.pack();
|
||||
trayWindow.setVisible(true);
|
||||
setBounds(frame.getBounds().x + frame.getBounds().width - widthHQ - 17, frame.getBounds().y + frame.getBounds().height - heightHQ - 17,
|
||||
widthHQ, heightHQ);
|
||||
|
||||
// nantuko: now we will update the card image only as its container is singleton now
|
||||
jPictureContainer.updateCardImage(GuiDisplayUtil.getPictureHQFile(c));
|
||||
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public class CustomListener implements MouseListener {
|
||||
@@ -71,9 +68,8 @@ public class GUI_PictureHQ extends JDialog
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
|
||||
dispose();
|
||||
|
||||
//dispose();
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
|
||||
@@ -436,9 +436,16 @@ public class GuiDisplayUtil implements NewConstants {
|
||||
}//else
|
||||
}//getPicture()
|
||||
|
||||
public static PicturePanel getPictureHQ(Card c) {
|
||||
return new PicturePanel(getPictureHQFile(c));
|
||||
}
|
||||
|
||||
public static JPanel getPictureHQ(Card c) {
|
||||
|
||||
/**
|
||||
* Get picture location
|
||||
* @param c card to return picture location for
|
||||
* @return File
|
||||
*/
|
||||
public static File getPictureHQFile(Card c) {
|
||||
String loc = "";
|
||||
if (c.isToken()== false)
|
||||
loc = IMAGE_BASE;
|
||||
@@ -446,11 +453,9 @@ public class GuiDisplayUtil implements NewConstants {
|
||||
loc = IMAGE_TOKEN;
|
||||
String filename = GuiDisplayUtil.cleanString(c.getImageName()) + ".jpg";
|
||||
File file = new File(ForgeProps.getFile(loc), filename);
|
||||
return new PicturePanel(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int getPictureHQheight(Card c) throws IOException{
|
||||
String loc = "";
|
||||
if (c.isToken()== false)
|
||||
|
||||
@@ -106,6 +106,7 @@ public class Gui_DeckEditor extends JFrame implements CardDetail, DeckDisplay, N
|
||||
private CardList bottom;
|
||||
public Card cCardHQ;
|
||||
private static File previousDirectory = null;
|
||||
private GUI_PictureHQ hq;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -888,10 +889,11 @@ public class Gui_DeckEditor extends JFrame implements CardDetail, DeckDisplay, N
|
||||
}
|
||||
|
||||
if(cWidth>=312 &&cHeight >=445){
|
||||
GUI_PictureHQ hq = new GUI_PictureHQ(Gui_DeckEditor.this,cCardHQ);
|
||||
if (hq == null) {
|
||||
hq = new GUI_PictureHQ(Gui_DeckEditor.this,cCardHQ);
|
||||
}
|
||||
try {
|
||||
hq.letsGo(Gui_DeckEditor.this, cCardHQ);
|
||||
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,36 +1,64 @@
|
||||
package forge;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
|
||||
public class PicturePanel extends JPanel {
|
||||
private static final long serialVersionUID = 2282867940272644768L;
|
||||
|
||||
private static int nextUniqueNumber;
|
||||
private int uniqueNumber = nextUniqueNumber++;
|
||||
|
||||
private JLabel display;
|
||||
private ImageIcon imageIcon;
|
||||
private Image image;
|
||||
|
||||
public PicturePanel(File f) {
|
||||
if (!f.exists()) {
|
||||
ErrorViewer.showError("PicturePanel : file does not exist - %s", f);
|
||||
throw new RuntimeException("PicturePanel : file does not exist - " + f);
|
||||
}
|
||||
|
||||
ImageIcon i = new ImageIcon();
|
||||
Image im ;
|
||||
im=null;
|
||||
if (imageIcon == null) {
|
||||
imageIcon = new ImageIcon();
|
||||
}
|
||||
try {
|
||||
im=ImageIO.read(f);
|
||||
image = ImageIO.read(f);
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
i.setImage(im);
|
||||
this.add(new JLabel(i));
|
||||
imageIcon.setImage(image);
|
||||
if (display == null) {
|
||||
display = new JLabel();
|
||||
display.setIcon(imageIcon);
|
||||
this.add(display);
|
||||
}
|
||||
//System.out.println("PicturePanel: " + uniqueNumber);
|
||||
}
|
||||
|
||||
public void updateCardImage(File f) {
|
||||
if (!f.exists()) {
|
||||
ErrorViewer.showError("PicturePanel : file does not exist - %s", f);
|
||||
throw new RuntimeException("PicturePanel : file does not exist - " + f);
|
||||
}
|
||||
|
||||
try {
|
||||
image = ImageIO.read(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
imageIcon.setImage(image);
|
||||
System.gc();
|
||||
|
||||
//System.out.println("PicturePanel, update: " + uniqueNumber);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user