diff --git a/src/forge/GUI_PictureHQ.java b/src/forge/GUI_PictureHQ.java index 800f5d58a69..cdcc3dc5ca8 100644 --- a/src/forge/GUI_PictureHQ.java +++ b/src/forge/GUI_PictureHQ.java @@ -6,83 +6,79 @@ 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. -*/ -public class GUI_PictureHQ extends JDialog -{ + * 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 { private static final long serialVersionUID = 7046993858415055058L; public JPanel jPanelPictureHQ; - - + public PicturePanel jPictureContainer; - 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.addMouseListener(new CustomListener()); - } + public GUI_PictureHQ(JFrame frame, Card c) { + super(frame); + this.setUndecorated(true); - pack(); - } + setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - public void letsGo(JFrame frame, Card c) throws IOException - { - 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); - - } - - public class CustomListener implements MouseListener { + jPanelPictureHQ = new JPanel(); + BorderLayout jPanelPictureHQLayout = new BorderLayout(); + jPanelPictureHQ.setLayout(jPanelPictureHQLayout); + getContentPane().add(jPanelPictureHQ, BorderLayout.CENTER); + jPanelPictureHQ.setBorder(BorderFactory.createEtchedBorder()); + //jPanelPictureHQ.removeAll(); + jPictureContainer = GuiDisplayUtil.getPictureHQ(c); + jPanelPictureHQ.add(jPictureContainer); + //jPanelPictureHQ.revalidate(); + jPanelPictureHQ.addMouseListener(new CustomListener()); - public void mouseClicked(MouseEvent e) { - - } + pack(); + } - public void mouseEntered(MouseEvent e) { - - } + 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); + 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 void mouseExited(MouseEvent e) { - - dispose(); - - } + public class CustomListener implements MouseListener { - public void mousePressed(MouseEvent e) { - - } + public void mouseClicked(MouseEvent e) { + + } + + public void mouseEntered(MouseEvent e) { + + } + + public void mouseExited(MouseEvent e) { + //dispose(); + setVisible(false); + } + + public void mousePressed(MouseEvent e) { + + } + + public void mouseReleased(MouseEvent e) { + + } + } - public void mouseReleased(MouseEvent e) { - - } - } - } \ No newline at end of file diff --git a/src/forge/GuiDisplayUtil.java b/src/forge/GuiDisplayUtil.java index 1c05997d5fa..493d44f12d6 100644 --- a/src/forge/GuiDisplayUtil.java +++ b/src/forge/GuiDisplayUtil.java @@ -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) diff --git a/src/forge/Gui_DeckEditor.java b/src/forge/Gui_DeckEditor.java index e98d54994ad..290596e7f5a 100644 --- a/src/forge/Gui_DeckEditor.java +++ b/src/forge/Gui_DeckEditor.java @@ -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) { @@ -869,8 +870,8 @@ public class Gui_DeckEditor extends JFrame implements CardDetail, DeckDisplay, N public void mouseEntered(MouseEvent e) { - if (picturePanel.getComponentCount()!=0){ - + if (picturePanel.getComponentCount()!=0){ + if(GuiDisplayUtil.IsPictureHQExists(cCardHQ)){ int cWidth = 0; try { @@ -887,14 +888,15 @@ public class Gui_DeckEditor extends JFrame implements CardDetail, DeckDisplay, N e2.printStackTrace(); } - if(cWidth>=312 &&cHeight >=445){ - GUI_PictureHQ hq = new GUI_PictureHQ(Gui_DeckEditor.this,cCardHQ); - try { - hq.letsGo(Gui_DeckEditor.this, cCardHQ); - - } catch (IOException e1) { - e1.printStackTrace(); - } + if(cWidth>=312 &&cHeight >=445){ + if (hq == null) { + hq = new GUI_PictureHQ(Gui_DeckEditor.this,cCardHQ); + } + try { + hq.letsGo(Gui_DeckEditor.this, cCardHQ); + } catch (IOException e1) { + e1.printStackTrace(); + } } }} diff --git a/src/forge/PicturePanel.java b/src/forge/PicturePanel.java index 80617ff1053..27a1d0677bc 100644 --- a/src/forge/PicturePanel.java +++ b/src/forge/PicturePanel.java @@ -1,36 +1,64 @@ package forge; - import java.awt.Image; + +import java.awt.Image; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; - import javax.swing.ImageIcon; - import javax.swing.JLabel; - import javax.swing.JPanel; +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; - public class PicturePanel extends JPanel { - private static final long serialVersionUID = 2282867940272644768L; - - 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; - try { - im=ImageIO.read(f); - } catch (IOException e) { - - e.printStackTrace(); - } - i.setImage(im); - this.add(new JLabel(i)); - - } - } \ No newline at end of file + 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); + } + + if (imageIcon == null) { + imageIcon = new ImageIcon(); + } + try { + image = ImageIO.read(f); + } catch (IOException e) { + e.printStackTrace(); + } + 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); + } +} \ No newline at end of file