Advertisement
Guest User

0002-Shrink-very-large-icons-down-for-viewing-only.patch

a guest
Sep 9th, 2014
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.88 KB | None | 0 0
  1. From ee90bdae2ab2b900ccef30a2ea2caae287baacc2 Mon Sep 17 00:00:00 2001
  2. From: "Seth N. Hetu" <seth.hetu@gmail.com>
  3. Date: Tue, 9 Sep 2014 22:26:20 -0400
  4. Subject: [PATCH 2/2] Shrink very large icons down for viewing only.
  5.  
  6. ---
  7. org/lateralgm/subframes/GameSettingFrame.java | 40 ++++++++++++++++++++++-----
  8.  1 file changed, 33 insertions(+), 7 deletions(-)
  9.  
  10. diff --git a/org/lateralgm/subframes/GameSettingFrame.java b/org/lateralgm/subframes/GameSettingFrame.java
  11. index e701175..47c075a 100644
  12. --- a/org/lateralgm/subframes/GameSettingFrame.java
  13. +++ b/org/lateralgm/subframes/GameSettingFrame.java
  14. @@ -18,8 +18,11 @@ import static javax.swing.GroupLayout.PREFERRED_SIZE;
  15.  
  16.  import java.awt.CardLayout;
  17.  import java.awt.Component;
  18. +import java.awt.Graphics2D;
  19.  import java.awt.Image;
  20. +import java.awt.RenderingHints;
  21.  import java.awt.event.ActionEvent;
  22. +import java.awt.geom.AffineTransform;
  23.  import java.awt.image.BufferedImage;
  24.  import java.io.File;
  25.  import java.io.FileInputStream;
  26. @@ -81,6 +84,8 @@ import org.lateralgm.resources.Include;
  27.  public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  28.     {
  29.     private static final long serialVersionUID = 1L;
  30. +  
  31. +   private static final int MAX_VIEWABLE_ICON_SIZE = 64; //Icons bigger than this are scaled down (for viewing only).
  32.  
  33.     boolean imagesChanged = false;
  34.     public JPanel cardPane;
  35. @@ -354,6 +359,31 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  36.     public NumberField gameId;
  37.     public JButton randomise;
  38.     private CustomFileChooser iconFc;
  39. +  
  40. +   private static BufferedImage scale_image(BufferedImage src, int imgType, int destSize) {
  41. +       if(src == null) { return null; }
  42. +           BufferedImage dest = new BufferedImage(destSize, destSize, imgType);
  43. +           Graphics2D g = dest.createGraphics();
  44. +           g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  45. +          
  46. +           AffineTransform at = AffineTransform.getScaleInstance(destSize/((float)src.getWidth()), destSize/((float)src.getHeight()));
  47. +           g.drawRenderedImage(src, at);
  48. +
  49. +           return dest;
  50. +   }
  51. +
  52. +   private void setIconPreviewToGameIcon() {
  53. +       BufferedImage src = null;
  54. +       if (gameIcon != null) {
  55. +           src = (BufferedImage)gameIcon.getDisplayImage();
  56. +           if (src!=null) {
  57. +               if (src.getWidth()>32 || src.getHeight()>32) {
  58. +                   src = scale_image((BufferedImage)src, BufferedImage.TYPE_INT_ARGB, MAX_VIEWABLE_ICON_SIZE);
  59. +               }
  60. +           }
  61. +       }
  62. +       iconPreview.setIcon(new ImageIcon(src));
  63. +   }
  64.  
  65.     private JPanel makeLoadingPane()
  66.         {
  67. @@ -444,7 +474,7 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  68.  
  69.         gameIcon = res.properties.get(PGameSettings.GAME_ICON);
  70.         iconPreview = new JLabel(Messages.getString("GameSettingFrame.GAME_ICON")); //$NON-NLS-1$
  71. -       if (gameIcon != null) iconPreview.setIcon(new ImageIcon(gameIcon.getDisplayImage()));
  72. +       setIconPreviewToGameIcon();
  73.  
  74.         iconPreview.setHorizontalTextPosition(SwingConstants.LEFT);
  75.         changeIcon = new JButton(Messages.getString("GameSettingFrame.CHANGE_ICON")); //$NON-NLS-1$
  76. @@ -862,7 +892,7 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  77.                 if (f.exists()) try
  78.                     {
  79.                     gameIcon = new ICOFile(new FileInputStream(f));
  80. -                   iconPreview.setIcon(new ImageIcon(gameIcon.getDisplayImage()));
  81. +                   setIconPreviewToGameIcon();
  82.                     imagesChanged = true;
  83.                     }
  84.                 catch (FileNotFoundException e1)
  85. @@ -909,11 +939,7 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  86.         backLoadImage = g.get(PGameSettings.BACK_LOAD_BAR);
  87.         frontLoadImage = g.get(PGameSettings.FRONT_LOAD_BAR);
  88.         gameIcon = g.get(PGameSettings.GAME_ICON);
  89. -       Image icoimg = gameIcon.getDisplayImage();
  90. -       if (icoimg != null)
  91. -           {
  92. -           iconPreview.setIcon(new ImageIcon(icoimg));
  93. -           }
  94. +       setIconPreviewToGameIcon();
  95.         imagesChanged = true;
  96.         }
  97.  
  98. --
  99. 1.9.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement