- nantuko84 patch for deck editor OOM problem

This commit is contained in:
jendave
2011-08-06 03:23:23 +00:00
parent 75388e3b9a
commit 772c2e60c6
4 changed files with 140 additions and 109 deletions

View File

@@ -6,58 +6,55 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.io.*; import java.io.*;
/** /**
* This code was edited or generated using CloudGarden's Jigloo * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* SWT/Swing GUI Builder, which is free for non-commercial * Builder, which is free for non-commercial use. If Jigloo is being used
* use. If Jigloo is being used commercially (ie, by a corporation, * commercially (ie, by a corporation, company or business for any purpose
* company or business for any purpose whatever) then you * whatever) then you should purchase a license for each developer using Jigloo.
* should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. Use of Jigloo implies
* Please visit www.cloudgarden.com for details. * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* Use of Jigloo implies acceptance of these licensing terms. * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR * ANY CORPORATE OR COMMERCIAL PURPOSE.
* 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; private static final long serialVersionUID = 7046993858415055058L;
public JPanel jPanelPictureHQ; public JPanel jPanelPictureHQ;
public PicturePanel jPictureContainer;
public GUI_PictureHQ(JFrame frame, Card c) {
public GUI_PictureHQ(JFrame frame, Card c)
{
super(frame); super(frame);
this.setUndecorated(true); this.setUndecorated(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
{
jPanelPictureHQ = new JPanel(); jPanelPictureHQ = new JPanel();
BorderLayout jPanelPictureHQLayout = new BorderLayout(); BorderLayout jPanelPictureHQLayout = new BorderLayout();
jPanelPictureHQ.setLayout(jPanelPictureHQLayout); jPanelPictureHQ.setLayout(jPanelPictureHQLayout);
getContentPane().add(jPanelPictureHQ, BorderLayout.CENTER); getContentPane().add(jPanelPictureHQ, BorderLayout.CENTER);
jPanelPictureHQ.setBorder(BorderFactory.createEtchedBorder());; jPanelPictureHQ.setBorder(BorderFactory.createEtchedBorder());
jPanelPictureHQ.removeAll(); //jPanelPictureHQ.removeAll();
jPanelPictureHQ.add(GuiDisplayUtil.getPictureHQ(c)); jPictureContainer = GuiDisplayUtil.getPictureHQ(c);
jPanelPictureHQ.revalidate(); jPanelPictureHQ.add(jPictureContainer);
//jPanelPictureHQ.revalidate();
jPanelPictureHQ.addMouseListener(new CustomListener()); jPanelPictureHQ.addMouseListener(new CustomListener());
}
pack(); pack();
} }
public void letsGo(JFrame frame, Card c) throws IOException 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); // GUI_PictureHQ trayWindow = new GUI_PictureHQ(frame, c);
int heightHQ = GuiDisplayUtil.getPictureHQheight(c); int heightHQ = GuiDisplayUtil.getPictureHQheight(c);
int widthHQ = GuiDisplayUtil.getPictureHQwidth(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); setBounds(frame.getBounds().x + frame.getBounds().width - widthHQ - 17, frame.getBounds().y + frame.getBounds().height - heightHQ - 17,
trayWindow.pack(); widthHQ, heightHQ);
trayWindow.setVisible(true);
// 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 { public class CustomListener implements MouseListener {
@@ -71,9 +68,8 @@ public class GUI_PictureHQ extends JDialog
} }
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
//dispose();
dispose(); setVisible(false);
} }
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {

View File

@@ -436,9 +436,16 @@ public class GuiDisplayUtil implements NewConstants {
}//else }//else
}//getPicture() }//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 = ""; String loc = "";
if (c.isToken()== false) if (c.isToken()== false)
loc = IMAGE_BASE; loc = IMAGE_BASE;
@@ -446,11 +453,9 @@ public class GuiDisplayUtil implements NewConstants {
loc = IMAGE_TOKEN; loc = IMAGE_TOKEN;
String filename = GuiDisplayUtil.cleanString(c.getImageName()) + ".jpg"; String filename = GuiDisplayUtil.cleanString(c.getImageName()) + ".jpg";
File file = new File(ForgeProps.getFile(loc), filename); File file = new File(ForgeProps.getFile(loc), filename);
return new PicturePanel(file); return file;
} }
public static int getPictureHQheight(Card c) throws IOException{ public static int getPictureHQheight(Card c) throws IOException{
String loc = ""; String loc = "";
if (c.isToken()== false) if (c.isToken()== false)

View File

@@ -106,6 +106,7 @@ public class Gui_DeckEditor extends JFrame implements CardDetail, DeckDisplay, N
private CardList bottom; private CardList bottom;
public Card cCardHQ; public Card cCardHQ;
private static File previousDirectory = null; private static File previousDirectory = null;
private GUI_PictureHQ hq;
public static void main(String[] args) { 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){ 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 { try {
hq.letsGo(Gui_DeckEditor.this, cCardHQ); hq.letsGo(Gui_DeckEditor.this, cCardHQ);
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }

View File

@@ -1,36 +1,64 @@
package forge; package forge;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
public class PicturePanel extends JPanel { public class PicturePanel extends JPanel {
private static final long serialVersionUID = 2282867940272644768L; 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) { public PicturePanel(File f) {
if (!f.exists()) { if (!f.exists()) {
ErrorViewer.showError("PicturePanel : file does not exist - %s", f); ErrorViewer.showError("PicturePanel : file does not exist - %s", f);
throw new RuntimeException("PicturePanel : file does not exist - " + f); throw new RuntimeException("PicturePanel : file does not exist - " + f);
} }
ImageIcon i = new ImageIcon(); if (imageIcon == null) {
Image im ; imageIcon = new ImageIcon();
im=null; }
try { try {
im=ImageIO.read(f); image = ImageIO.read(f);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
i.setImage(im); imageIcon.setImage(image);
this.add(new JLabel(i)); 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);
} }
} }