|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
     | 
  |  18 |     | 
     | 
  |  19 |     | 
     | 
  |  20 |     | 
     | 
  |  21 |     | 
     | 
  |  22 |     | 
   package net.sf.webphotos.gui.component;  | 
  |  23 |     | 
     | 
  |  24 |     | 
   import net.sf.webphotos.gui.Visualizador;  | 
  |  25 |     | 
   import net.sf.webphotos.util.Util;  | 
  |  26 |     | 
     | 
  |  27 |     | 
     | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |    0 |    public class PainelFoto extends javax.swing.JPanel { | 
  |  34 |     | 
         | 
  |  35 |     | 
         | 
  |  36 |     | 
     | 
  |  37 |     | 
     | 
  |  38 |     | 
       public static final int FOLGA = 1;  | 
  |  39 |     | 
             | 
  |  40 |     | 
       private java.awt.Image foto;  | 
  |  41 |    3 |        private int tamMax=200;  | 
  |  42 |     | 
       private float novaLargura;  | 
  |  43 |     | 
       private float novaAltura;  | 
  |  44 |     | 
       private float x,y;  | 
  |  45 |     | 
       private String nomeArquivo;  | 
  |  46 |     | 
       private boolean mostrandoMsgErro;  | 
  |  47 |    3 |        private javax.swing.ImageIcon ico=new javax.swing.ImageIcon();  | 
  |  48 |     | 
     | 
  |  49 |     | 
         | 
  |  50 |     | 
     | 
  |  51 |     | 
     | 
  |  52 |     | 
     | 
  |  53 |    3 |        public PainelFoto() { | 
  |  54 |    3 |            initComponents();  | 
  |  55 |    3 |        }  | 
  |  56 |     | 
         | 
  |  57 |     | 
         | 
  |  58 |     | 
     | 
  |  59 |     | 
     | 
  |  60 |     | 
     | 
  |  61 |     | 
     | 
  |  62 |     | 
         | 
  |  63 |     | 
       private void initComponents() { | 
  |  64 |     | 
     | 
  |  65 |    3 |            lblPainelFoto = new javax.swing.JLabel();  | 
  |  66 |    3 |            lblFotoInfo = new javax.swing.JLabel();  | 
  |  67 |     | 
     | 
  |  68 |    3 |            setMaximumSize(new java.awt.Dimension(210, 2147483647));  | 
  |  69 |    3 |            setMinimumSize(new java.awt.Dimension(210, 10));  | 
  |  70 |    3 |            setPreferredSize(new java.awt.Dimension(210, 210));  | 
  |  71 |    3 |            setLayout(new java.awt.BorderLayout());  | 
  |  72 |     | 
     | 
  |  73 |    3 |            lblPainelFoto.setToolTipText("Clique para visualizar a foto"); | 
  |  74 |    3 |            lblPainelFoto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));  | 
  |  75 |    3 |            lblPainelFoto.addMouseListener(new java.awt.event.MouseAdapter() { | 
  |  76 |     | 
               public void mouseClicked(java.awt.event.MouseEvent evt) { | 
  |  77 |    0 |                    lblPainelFotoMouseClicked(evt);  | 
  |  78 |    0 |                }  | 
  |  79 |     | 
               public void mouseEntered(java.awt.event.MouseEvent evt) { | 
  |  80 |    0 |                    lblPainelFotoMouseEntered(evt);  | 
  |  81 |    0 |                }  | 
  |  82 |     | 
               public void mouseExited(java.awt.event.MouseEvent evt) { | 
  |  83 |    0 |                    lblPainelFotoMouseExited(evt);  | 
  |  84 |    0 |                }  | 
  |  85 |     | 
           });  | 
  |  86 |    3 |            add(lblPainelFoto, java.awt.BorderLayout.CENTER);  | 
  |  87 |     | 
     | 
  |  88 |    3 |            lblFotoInfo.setFont(new java.awt.Font("SansSerif", 0, 10));  | 
  |  89 |    3 |            lblFotoInfo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);  | 
  |  90 |    3 |            lblFotoInfo.setText("??x??"); | 
  |  91 |    3 |            add(lblFotoInfo, java.awt.BorderLayout.SOUTH);  | 
  |  92 |    3 |        }  | 
  |  93 |     | 
     | 
  |  94 |     | 
       private void lblPainelFotoMouseClicked(java.awt.event.MouseEvent evt) { | 
  |  95 |    0 |            if(getFoto() != null) { | 
  |  96 |    0 |                String foto=getNomeArquivo().replaceFirst("_b","_d"); | 
  |  97 |    0 |                Visualizador fotoMaior=new Visualizador(foto,null,"zOOm");  | 
  |  98 |     | 
           }  | 
  |  99 |    0 |        }  | 
  |  100 |     | 
     | 
  |  101 |     | 
       private void lblPainelFotoMouseExited(java.awt.event.MouseEvent evt) { | 
  |  102 |    0 |            setCursor(null);  | 
  |  103 |    0 |        }  | 
  |  104 |     | 
     | 
  |  105 |     | 
       private void lblPainelFotoMouseEntered(java.awt.event.MouseEvent evt) { | 
  |  106 |    0 |            setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));  | 
  |  107 |    0 |        }  | 
  |  108 |     | 
         | 
  |  109 |     | 
         | 
  |  110 |     | 
     | 
  |  111 |     | 
     | 
  |  112 |     | 
     | 
  |  113 |     | 
     | 
  |  114 |     | 
     | 
  |  115 |     | 
       public void clear() { | 
  |  116 |    18 |            if(mostrandoMsgErro) { | 
  |  117 |    0 |                mostrandoMsgErro=false;  | 
  |  118 |    0 |                java.awt.Graphics2D g2=(java.awt.Graphics2D) this.getGraphics();  | 
  |  119 |    0 |                g2.setPaint(java.awt.Color.GRAY);  | 
  |  120 |    0 |                g2.fillRect(0,0,200,200);  | 
  |  121 |    0 |                repaint();                          | 
  |  122 |     | 
           }  | 
  |  123 |    18 |            if(getFoto()==null) { | 
  |  124 |    15 |                return;  | 
  |  125 |     | 
           }  | 
  |  126 |    3 |            setFoto(null);  | 
  |  127 |    3 |            repaint();  | 
  |  128 |    3 |        }  | 
  |  129 |     | 
     | 
  |  130 |     | 
         | 
  |  131 |     | 
     | 
  |  132 |     | 
     | 
  |  133 |     | 
     | 
  |  134 |     | 
     | 
  |  135 |     | 
       public void loadImage(String caminhoImagem) { | 
  |  136 |    12 |            setNomeArquivo(caminhoImagem);  | 
  |  137 |    12 |            System.out.println ("Lendo:" + caminhoImagem); | 
  |  138 |    12 |            this.loadImage();  | 
  |  139 |    12 |        }  | 
  |  140 |     | 
         | 
  |  141 |     | 
         | 
  |  142 |     | 
     | 
  |  143 |     | 
     | 
  |  144 |     | 
     | 
  |  145 |     | 
     | 
  |  146 |     | 
       public void loadImage() { | 
  |  147 |     | 
           try { | 
  |  148 |    12 |                ico.setImage(java.awt.Toolkit.getDefaultToolkit().getImage(getNomeArquivo()));  | 
  |  149 |    0 |            } catch (Exception e) { | 
  |  150 |    0 |                System.out.println("Erro:"); | 
  |  151 |    0 |                e.printStackTrace();  | 
  |  152 |    12 |            }  | 
  |  153 |    12 |            System.out.println ("Fim toolkit"); | 
  |  154 |     | 
     | 
  |  155 |     | 
             | 
  |  156 |    12 |            int status=ico.getImageLoadStatus();  | 
  |  157 |    12 |            if(status != java.awt.MediaTracker.COMPLETE) { | 
  |  158 |    0 |                lblPainelFoto.setIcon(null);  | 
  |  159 |    0 |                repaint();  | 
  |  160 |    0 |                mostrandoMsgErro=true;  | 
  |  161 |    0 |                return;  | 
  |  162 |     | 
           }  | 
  |  163 |    12 |            System.out.println ("obtendo informacoes"); | 
  |  164 |     | 
     | 
  |  165 |    12 |            setFoto(ico.getImage());  | 
  |  166 |     | 
     | 
  |  167 |    12 |            float largura=getFoto().getWidth(this);  | 
  |  168 |    12 |            float altura=getFoto().getHeight(this);  | 
  |  169 |    12 |            tamMax = lblPainelFoto.getWidth();  | 
  |  170 |    12 |            System.out.println("Tamanho: "+tamMax); | 
  |  171 |     | 
     | 
  |  172 |     | 
             | 
  |  173 |    12 |            if(largura > altura) { | 
  |  174 |     | 
                 | 
  |  175 |    12 |                novaLargura=tamMax;  | 
  |  176 |    12 |                novaAltura=-1;  | 
  |  177 |    0 |            } else if (largura < altura) { | 
  |  178 |     | 
                 | 
  |  179 |    0 |                novaLargura=-1;  | 
  |  180 |    0 |                novaAltura=tamMax;  | 
  |  181 |     | 
           } else { | 
  |  182 |     | 
                 | 
  |  183 |    0 |                novaLargura=tamMax;  | 
  |  184 |    0 |                novaAltura=tamMax;  | 
  |  185 |     | 
           }  | 
  |  186 |     | 
             | 
  |  187 |    12 |            System.out.println ("Fim do redimensionamento"); | 
  |  188 |    12 |            lblPainelFoto.setIcon(new javax.swing.ImageIcon(getFoto().getScaledInstance((int) novaLargura - (FOLGA*2),  (int) novaAltura - (FOLGA*2), java.awt.Image.SCALE_SMOOTH)));  | 
  |  189 |    12 |            System.out.println ("Fim repintagem"); | 
  |  190 |    12 |        }  | 
  |  191 |     | 
     | 
  |  192 |     | 
         | 
  |  193 |     | 
       private javax.swing.JLabel lblFotoInfo;  | 
  |  194 |     | 
       private javax.swing.JLabel lblPainelFoto;  | 
  |  195 |     | 
         | 
  |  196 |     | 
     | 
  |  197 |     | 
         | 
  |  198 |     | 
     | 
  |  199 |     | 
     | 
  |  200 |     | 
     | 
  |  201 |     | 
       public java.awt.Image getFoto() { | 
  |  202 |    54 |            return foto;  | 
  |  203 |     | 
       }  | 
  |  204 |     | 
     | 
  |  205 |     | 
         | 
  |  206 |     | 
     | 
  |  207 |     | 
     | 
  |  208 |     | 
     | 
  |  209 |     | 
       public void setFoto(java.awt.Image foto) { | 
  |  210 |    15 |            this.foto = foto;  | 
  |  211 |    15 |        }  | 
  |  212 |     | 
     | 
  |  213 |     | 
         | 
  |  214 |     | 
     | 
  |  215 |     | 
     | 
  |  216 |     | 
     | 
  |  217 |     | 
       public String getNomeArquivo() { | 
  |  218 |    12 |            return nomeArquivo;  | 
  |  219 |     | 
       }  | 
  |  220 |     | 
     | 
  |  221 |     | 
         | 
  |  222 |     | 
     | 
  |  223 |     | 
     | 
  |  224 |     | 
     | 
  |  225 |     | 
       public void setNomeArquivo(String nomeArquivo) { | 
  |  226 |    12 |            this.nomeArquivo = nomeArquivo;  | 
  |  227 |    12 |        }  | 
  |  228 |     | 
     | 
  |  229 |     | 
         | 
  |  230 |     | 
     | 
  |  231 |     | 
     | 
  |  232 |     | 
     | 
  |  233 |     | 
       public javax.swing.JLabel getLblFotoInfo() { | 
  |  234 |    18 |            return lblFotoInfo;  | 
  |  235 |     | 
       }  | 
  |  236 |     | 
     | 
  |  237 |     | 
         | 
  |  238 |     | 
     | 
  |  239 |     | 
     | 
  |  240 |     | 
     | 
  |  241 |     | 
       public void setLblFotoInfo(javax.swing.JLabel lblFotoInfo) { | 
  |  242 |    0 |            this.lblFotoInfo = lblFotoInfo;  | 
  |  243 |    0 |        }  | 
  |  244 |     | 
         | 
  |  245 |     | 
         | 
  |  246 |     | 
     | 
  |  247 |     | 
     | 
  |  248 |     | 
     | 
  |  249 |     | 
     | 
  |  250 |     | 
       public static java.awt.Dimension getDefaultSize() { | 
  |  251 |    0 |            return new java.awt.Dimension(Util.getConfig().getInt("thumbnail2"), Util.getConfig().getInt("thumbnail2")); | 
  |  252 |     | 
       }  | 
  |  253 |     | 
         | 
  |  254 |     | 
   }  |