/* * Projecte Fressa a JAVA * TFormEdicioPlafo.java * Created on 13 / novembre / 2008, 09:09 * * @author Jordi Lagares Roset "jlagares@xtec.cat - www.lagares.org" * amb el suport del Departament d'Educacio de la Generalitat de Catalunya * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details (see the LICENSE file). */ import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.ImageIcon; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.DataFlavor; import javax.swing.filechooser.*; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import com.sun.image.codec.jpeg.*; import java.awt.Image; import java.awt.image.PixelGrabber; public class TFormEdicioPlafo extends javax.swing.JDialog { public javax.swing.JButton jButtonDAcord; public javax.swing.JButton jButtonCancelar; public javax.swing.JButton jButtonFont; public javax.swing.JButton jButtonGravar; public javax.swing.JButton jButtonFuncioEspecial; public javax.swing.JButton jButtonObrir; public javax.swing.JButton jButtonEnganxar; public javax.swing.JButton jButtonEsborrar; public javax.swing.JLabel jLabel1; public javax.swing.JLabel jLabel2; public javax.swing.JLabel jLabel3; public javax.swing.JLabel jLabel4; public javax.swing.JLabel jLabel5; public javax.swing.JTextField EditCaption; public javax.swing.JTextField EditRead; public javax.swing.JTextField EditLink; public javax.swing.JTextField EditNomFitxer; public javax.swing.JComboBox ComboBoxColor; public javax.swing.JPanel jPanel1; public javax.swing.JLabel jLabelImatge; public int resultat = 0; //public int Color = 1; public int FontSize=16; public int FontColor=0; public String FontName="Arial"; public int FontStyle=0; public int Columna=0; public int Fila=0; public int ColorMarc=0; //public ImageIcon PlafoImatge = new ImageIcon(); //Imatge public String DirectoriActual; public String DirectoriActualObrirRecurs; private Tools tool; private boolean HaCanviatLaImatge = false; private boolean SHaEnganxatLaImatge = false; private Image image; private String fnImatge=""; private String pnImatge=""; private String fnwav=""; private String pnwav=""; private boolean EsticGravantSo = false; public TFormFuncionsEspecials FormFuncionsEspecials; public TFormObrirRecurs FormObrirRecurs; GravarSoWav gravarso; public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TFormEdicioPlafo(new javax.swing.JFrame(), true).setVisible(true); } }); } public TFormEdicioPlafo(java.awt.Frame parent, boolean modal) { super(parent, modal); tool = new Tools(); gravarso = new GravarSoWav(); FormFuncionsEspecials = new TFormFuncionsEspecials(this,true); FormObrirRecurs = new TFormObrirRecurs(this,true); initComponents(); } private void initComponents() { setSize(433,505); getContentPane().setLayout(null); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Edici\u00f3 d'un plaf\u00f3"); setResizable(false); jButtonDAcord = new javax.swing.JButton(); //jButtonDAcord.setText("D'acord"); jButtonDAcord.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/ok.gif"))); jButtonDAcord.setBounds(336,376,81,41); jButtonDAcord.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonDAcord); jButtonDAcord.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonDAcordClick(); } }); jButtonCancelar = new javax.swing.JButton(); //jButtonCancelar.setText("Cancel.lar"); jButtonCancelar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/cancel.gif"))); jButtonCancelar.setBounds(336,424,81,41); jButtonCancelar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonCancelar); jButtonCancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonCancelarClick(); } }); jButtonFont = new javax.swing.JButton(); //jButtonFont.setText("Font"); jButtonFont.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/font.gif"))); //jButtonFont.setBounds(360,16,57,25); jButtonFont.setBounds(360,14,62,29); jButtonFont.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonFont); jButtonFont.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonFontClick(); } }); jButtonGravar = new javax.swing.JButton(); jButtonGravar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/gravarso.gif"))); //jButtonGravar.setBounds(360,48,25,25); jButtonGravar.setBounds(360,47,29,29); jButtonGravar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonGravar); jButtonGravar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonGravarClick(); } }); new FileDrop(jButtonGravar,new FileDrop.Listener() { public void filesDropped(java.io.File[] files) { filesDroppedReadClick(files); } }); jButtonFuncioEspecial = new javax.swing.JButton(); jButtonFuncioEspecial.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/funcionsespecials.gif"))); jButtonFuncioEspecial.setBounds(393,47,29,29); jButtonFuncioEspecial.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonFuncioEspecial); jButtonFuncioEspecial.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonFuncioEspecialClick(); } }); jButtonObrir = new javax.swing.JButton(); //jButtonObrir.setText("Obrir..."); jButtonObrir.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/obrir.gif"))); jButtonObrir.setBounds(336,144,81,41); jButtonObrir.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonObrir); jButtonObrir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonObrirClick(); } }); jButtonEnganxar = new javax.swing.JButton(); //jButtonEnganxar.setText("Enganxar"); jButtonEnganxar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/enganxar.gif"))); jButtonEnganxar.setBounds(336,192,81,41); jButtonEnganxar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonEnganxar); jButtonEnganxar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonEnganxarClick(); } }); jButtonEsborrar = new javax.swing.JButton(); //jButtonEsborrar.setText("Esborrar"); jButtonEsborrar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/catala/esborrar.gif"))); jButtonEsborrar.setBounds(336,240,81,41); jButtonEsborrar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); getContentPane().add(jButtonEsborrar); jButtonEsborrar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonEsborrarClick(); } }); jLabel1 = new javax.swing.JLabel(); jLabel1.setFont(new Font("sansserif",0,11)); jLabel1.setText("Text mostrat:"); jLabel1.setBounds(8,24,100,13); getContentPane().add(jLabel1); jLabel2 = new javax.swing.JLabel(); jLabel2.setFont(new Font("sansserif",0,11)); jLabel2.setText("Text a llegir:"); jLabel2.setBounds(8,56,100,13); getContentPane().add(jLabel2); jLabel3 = new javax.swing.JLabel(); jLabel3.setFont(new Font("sansserif",0,11)); jLabel3.setText("Link:"); jLabel3.setBounds(8,88,100,13); getContentPane().add(jLabel3); jLabel4 = new javax.swing.JLabel(); jLabel4.setFont(new Font("sansserif",0,11)); jLabel4.setText("Nom del fitxer:"); jLabel4.setBounds(8,120,100,13); getContentPane().add(jLabel4); jLabel5 = new javax.swing.JLabel(); jLabel5.setFont(new Font("sansserif",0,11)); jLabel5.setText("Color Marc:"); jLabel5.setBounds(336,288,66,13); getContentPane().add(jLabel5); EditCaption = new javax.swing.JTextField(); EditCaption.setBounds(120,16,233,21); getContentPane().add(EditCaption); EditCaption.addFocusListener(new java.awt.event.FocusListener() { public void focusLost(java.awt.event.FocusEvent evt) { if (!EditCaption.getText().equals("")) { if (EditRead.getText().equals("")) { EditRead.setText(EditCaption.getText()); EditRead.requestFocus(); EditRead.selectAll(); } } } public void focusGained(java.awt.event.FocusEvent evt) { EditCaption.selectAll(); } }); EditRead = new javax.swing.JTextField(); EditRead.setBounds(120,48,233,21); getContentPane().add(EditRead); EditRead.addFocusListener(new java.awt.event.FocusListener() { public void focusLost(java.awt.event.FocusEvent evt) { } public void focusGained(java.awt.event.FocusEvent evt) { EditRead.selectAll(); } }); new FileDrop(EditRead,new FileDrop.Listener() { public void filesDropped(java.io.File[] files) { filesDroppedReadClick(files); } }); EditLink = new javax.swing.JTextField(); EditLink.setBounds(120,80,233,21); getContentPane().add(EditLink); EditLink.addFocusListener(new java.awt.event.FocusListener() { public void focusLost(java.awt.event.FocusEvent evt) { } public void focusGained(java.awt.event.FocusEvent evt) { EditLink.selectAll(); } }); new FileDrop(EditLink,new FileDrop.Listener() { public void filesDropped(java.io.File[] files) { filesDroppedLinkClick(files); } }); EditNomFitxer = new javax.swing.JTextField(); EditNomFitxer.setBounds(120,112,233,21); getContentPane().add(EditNomFitxer); EditNomFitxer.addFocusListener(new java.awt.event.FocusListener() { public void focusLost(java.awt.event.FocusEvent evt) { } public void focusGained(java.awt.event.FocusEvent evt) { EditNomFitxer.selectAll(); } }); new FileDrop(EditNomFitxer,new FileDrop.Listener() { public void filesDropped(java.io.File[] files) { filesDroppedImatgeClick(files); } }); ComboBoxColor = new javax.swing.JComboBox(); ComboBoxColor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Negre", "Lila", "Groc", "Verd", "Taronja", "Blau", "Blanc" })); ComboBoxColor.setBounds(336,304,81,21); getContentPane().add(ComboBoxColor); jPanel1 = new javax.swing.JPanel(); //jPanel1.setBorder(javax.swing.BorderFactory.createLoweredBevelBorder()); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel1.setBounds(8,144,320,320); //No entenc perque no puc posar aixo: //jPanel1.setBackground(Color.white); jPanel1.setBackground(java.awt.Color.white); getContentPane().add(jPanel1); jPanel1.setLayout(null); jLabelImatge = new javax.swing.JLabel(); jLabelImatge.setBounds(4,4,jPanel1.getWidth()-8,jPanel1.getHeight()-8); jPanel1.add(jLabelImatge); new FileDrop(jLabelImatge,new FileDrop.Listener() { public void filesDropped(java.io.File[] files) { filesDroppedImatgeClick(files); } }); //Toolkit.getDefaultToolkit().addAWTEventListener(ListenerReturnEsc,AWTEvent.KEY_EVENT_MASK); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { FormClose(); } }); } public void FormClose() { if (EsticGravantSo==true) { gravarso.PararGravacio(); EsticGravantSo=false; jButtonGravar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/gravarso.gif"))); jButtonDAcord.setEnabled(true); jButtonCancelar.setEnabled(true); jButtonFont.setEnabled(true); jButtonObrir.setEnabled(true); jButtonEnganxar.setEnabled(true); jButtonEsborrar.setEnabled(true); EditCaption.setEnabled(true); EditRead.setEnabled(true); EditLink.setEnabled(true); EditNomFitxer.setEnabled(true); ComboBoxColor.setEnabled(true); jLabelImatge.setEnabled(true); } Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); } private AWTEventListener ListenerReturnEsc = new AWTEventListener() { public void eventDispatched(AWTEvent event) { KeyEvent ke = (KeyEvent)event; if (ke.getID() == KeyEvent.KEY_TYPED) { if (ke.getKeyChar() == KeyEvent.VK_ESCAPE) { jButtonCancelarClick(); } else if (ke.getKeyChar() == KeyEvent.VK_ENTER) { if (Global.EsWindowsLookAndFeel==1) { if (jButtonFont.isFocusOwner()) { } else if (jButtonGravar.isFocusOwner()) { } else if (jButtonObrir.isFocusOwner()) { } else if (jButtonEnganxar.isFocusOwner()) { } else if (jButtonEsborrar.isFocusOwner()) { } else if (jButtonCancelar.isFocusOwner()) { } else { jButtonDAcordClick(); } } else { if (jButtonFont.isFocusOwner()) { jButtonFontClick(); } else if (jButtonGravar.isFocusOwner()) { jButtonGravarClick(); } else if (jButtonObrir.isFocusOwner()) { jButtonObrirClick(); } else if (jButtonEnganxar.isFocusOwner()) { jButtonEnganxarClick(); } else if (jButtonEsborrar.isFocusOwner()) { jButtonEsborrarClick(); } else if (jButtonCancelar.isFocusOwner()) { jButtonCancelarClick() ; } else { jButtonDAcordClick(); } } } } } }; private void jButtonDAcordClick() { ColorMarc=ComboBoxColor.getSelectedIndex(); if (HaCanviatLaImatge==true) { if (!tool.Delete(pnImatge,tool.Length(pnImatge)-tool.Length(fnImatge)+1,tool.Length(fnImatge)).equals(DirectoriActual)) { Tools.FileCopy(pnImatge,DirectoriActual+fnImatge); } } if (SHaEnganxatLaImatge==true) { if (EditNomFitxer.getText().equals("")) { //JOptionPane.showMessageDialog(null,"Cal escriure el nom d'un fitxer","JAVA PLAPHOONS",JOptionPane.INFORMATION_MESSAGE); Llengua.MessageBox(45); EditNomFitxer.requestFocus(); return; } else { fnImatge=EditNomFitxer.getText(); if (!tool.RightS(fnImatge,4).toLowerCase().equals(".jpg")) fnImatge=fnImatge+".jpg"; EditNomFitxer.setText(fnImatge); //Per copiar una Image en un fitxer jpg //BEGIN http://www.rgagnon.com/javadetails/java-0266.html BufferedImage bimg = null; int w = image.getWidth(null); int h = image.getHeight(null); int [] pixels = new int[w * h]; PixelGrabber pg = new PixelGrabber(image,0,0,w,h,pixels,0,w); try { pg.grabPixels(); } catch(InterruptedException ie) { ie.printStackTrace(); } bimg = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB); bimg.setRGB(0,0,w,h,pixels,0,w); try { FileOutputStream fos = new FileOutputStream(DirectoriActual+fnImatge); JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(fos); jpeg.encode(bimg); fos.close(); } catch(Exception exception) { } //END http://www.rgagnon.com/javadetails/java-0266.html } } if (tool.RightS(EditRead.getText(),4).toLowerCase().equals(".wav")) { if (!tool.Delete(pnwav,tool.Length(pnwav)-tool.Length(fnwav)+1,tool.Length(fnwav)).equals(DirectoriActual)) { Tools.FileCopy(pnwav,DirectoriActual+fnwav); } } if (!EditLink.getText().equals("")) { if (!tool.RightS(EditLink.getText(),4).toLowerCase().equals(".pla")) { EditLink.setText(EditLink.getText()+".pla"); } } resultat=1; FormClose(); setVisible(false); } private void jButtonCancelarClick() { resultat=0; FormClose(); setVisible(false); } private void jButtonFontClick() { TFormFont FormFontDialog = new TFormFont(this,true); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = FormFontDialog.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; FormFontDialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); FormFontDialog.FontName=FontName; FormFontDialog.FontStyle=FontStyle; FormFontDialog.FontSize=FontSize; FormFontDialog.FontColor=FontColor; FormFontDialog.Activar(); Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); FormFontDialog.setVisible(true); Toolkit.getDefaultToolkit().addAWTEventListener(ListenerReturnEsc,AWTEvent.KEY_EVENT_MASK); if (FormFontDialog.resultat==1) { FontName=FormFontDialog.FontName; FontStyle=FormFontDialog.FontStyle; FontSize=FormFontDialog.FontSize; FontColor=FormFontDialog.FontColor; } EditCaption.requestFocus(); } private void jButtonFontReturn() { //JOptionPane.showMessageDialog(null,"FontReturn","JAVA PLAPHOONS",JOptionPane.INFORMATION_MESSAGE); TFormFont FormFontDialog = new TFormFont(this,true); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = FormFontDialog.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; FormFontDialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); FormFontDialog.FontName=FontName; FormFontDialog.FontStyle=FontStyle; FormFontDialog.FontSize=FontSize; FormFontDialog.FontColor=FontColor; FormFontDialog.Activar(); FormFontDialog.setVisible(true); if (FormFontDialog.resultat==1) { FontName=FormFontDialog.FontName; FontStyle=FormFontDialog.FontStyle; FontSize=FormFontDialog.FontSize; FontColor=FormFontDialog.FontColor; } } private void jButtonFuncioEspecialClick() { Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); FormFuncionsEspecials.ShowModalCentered(); if (FormFuncionsEspecials.resultat==1) { String s=FormFuncionsEspecials.ComboBoxFuncionsEspecials.getSelectedItem().toString(); EditRead.setText(s+EditRead.getText()); } Toolkit.getDefaultToolkit().addAWTEventListener(ListenerReturnEsc,AWTEvent.KEY_EVENT_MASK); } private void jButtonGravarClick() { if (EsticGravantSo==false) { EsticGravantSo=true; jButtonGravar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/parargravarso.gif"))); jButtonDAcord.setEnabled(false); jButtonCancelar.setEnabled(false); jButtonFont.setEnabled(false); jButtonObrir.setEnabled(false); jButtonEnganxar.setEnabled(false); jButtonEsborrar.setEnabled(false); EditCaption.setEnabled(false); EditRead.setEnabled(false); EditLink.setEnabled(false); EditNomFitxer.setEnabled(false); ComboBoxColor.setEnabled(false); jLabelImatge.setEnabled(false); gravarso.IniciarGravacio(); } else { String errStr1=gravarso.PararGravacio(); if (errStr1==null) { String res=JOptionPane.showInputDialog(null,Llengua.missatges[46],"JAVA PLAPHOONS",JOptionPane.QUESTION_MESSAGE); EditRead.requestFocus(); if (!(res==null)) { if (!res.equals("")) { String errStr2=gravarso.DesarFitxerWav(DirectoriActual+res+".wav"); if (errStr2==null) { EditRead.setText(res+".wav"); } else { JOptionPane.showMessageDialog(null,Llengua.missatges[47],"JAVA PLAPHOONS",JOptionPane.INFORMATION_MESSAGE); } } } } else { JOptionPane.showMessageDialog(null,Llengua.missatges[47],"JAVA PLAPHOONS",JOptionPane.INFORMATION_MESSAGE); } EsticGravantSo=false; jButtonGravar.setIcon(new javax.swing.ImageIcon(this.getClass().getResource("dibuixos/gravarso.gif"))); jButtonDAcord.setEnabled(true); jButtonCancelar.setEnabled(true); jButtonFont.setEnabled(true); jButtonObrir.setEnabled(true); jButtonEnganxar.setEnabled(true); jButtonEsborrar.setEnabled(true); EditCaption.setEnabled(true); EditRead.setEnabled(true); EditLink.setEnabled(true); EditNomFitxer.setEnabled(true); ComboBoxColor.setEnabled(true); jLabelImatge.setEnabled(true); } } private void filesDroppedReadClick(java.io.File[] files) { String fn, pn; try { File f=files[0]; String ext=Tools.getExtension(f); fn=f.getName(); pn=f.getCanonicalPath(); fnwav=fn; pnwav=pn; if (ext.equals("wav")) { EditRead.setText(fn); } } catch ( java.io.IOException e ) { } } private void filesDroppedLinkClick(java.io.File[] files) { String fn, pn; try { File f=files[0]; String ext=Tools.getExtension(f); fn=f.getName(); pn=f.getCanonicalPath(); if (ext.equals("pla")) { EditLink.setText(fn); } } catch ( java.io.IOException e ) { } } private void filesDroppedImatgeClick(java.io.File[] files) { String fn, pn; File f=files[0]; String ext=Tools.getExtension(f); fn=f.getName(); pn=f.getPath(); //if ((ext.equals("jpg")) || (ext.equals("png")) || (ext.equals("gif"))) { if ((ext.equals("jpg")) || (ext.equals("png")) || (ext.equals("gif")) || (ext.equals("bmp"))) { EditNomFitxer.setText(fn); //BEGIN 0005 //ImageIcon test = new ImageIcon(pn); ImageIcon test = new ImageIcon(); if (pn.toLowerCase().endsWith(".bmp")) { Image newMap = BMPLoader.load(pn); if(newMap != null) { test.setImage(newMap); } } else { test = new ImageIcon(pn); } //END 0005 jLabelImatge.setBounds(4,4,jPanel1.getWidth()-8,jPanel1.getHeight()-8); if ((test.getIconWidth()>0) && (test.getIconHeight()>0)&& (jLabelImatge.getHeight()>0)) { if ((float)jLabelImatge.getWidth()/(float)jLabelImatge.getHeight()<(float)test.getIconWidth()/test.getIconHeight()) { int comodi=(jLabelImatge.getWidth()*test.getIconHeight()/test.getIconWidth()); jLabelImatge.setBounds(jLabelImatge.getX(),jLabelImatge.getY()+(jLabelImatge.getHeight()-comodi)/2,jLabelImatge.getWidth(),comodi); } else { int comodi=(jLabelImatge.getHeight()*test.getIconWidth()/test.getIconHeight()); jLabelImatge.setBounds(jLabelImatge.getX()+(jLabelImatge.getWidth()-comodi)/2,jLabelImatge.getY(),comodi,jLabelImatge.getHeight()); } } test.setImage(test.getImage().getScaledInstance(jLabelImatge.getWidth(),jLabelImatge.getHeight(),1)); jLabelImatge.setIcon(test); HaCanviatLaImatge=true; SHaEnganxatLaImatge=false; fnImatge=fn; pnImatge=pn; } } //http://www.java2s.com/Code/Java/File-Input-Output/CopyfilesusingJavaIOAPI.htm //Aquest no xuta /* private void FileCopy1(String source, String Destination) { File inputFile = new File(source); File outputFile = new File(Destination); try { FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); } catch ( java.io.IOException e ) { } } */ /* //http://www.java2s.com/Code/Java/File-Input-Output/CopyfilesusingJavaIOAPI.htm private void FileCopy(String fromFileName, String toFileName) { File fromFile = new File(fromFileName); File toFile = new File(toFileName); if (toFile.exists()) toFile.delete(); try { if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: "+ fromFileName); if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: "+ fromFileName); if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: "+ fromFileName); if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName()); if (toFile.exists()) { if (!toFile.canWrite()) throw new IOException("FileCopy: "+ "destination file is unwriteable: " + toFileName); System.out.print("Overwrite existing file " + toFile.getName()+ "? (Y/N): "); System.out.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String response = in.readLine(); if (!response.equals("Y") && !response.equals("y")) throw new IOException("FileCopy: "+ "existing file was not overwritten."); } else { String parent = toFile.getParent(); if (parent == null) parent = System.getProperty("user.dir"); File dir = new File(parent); if (!dir.exists()) throw new IOException("FileCopy: "+ "destination directory doesn't exist: " + parent); if (dir.isFile()) throw new IOException("FileCopy: "+ "destination is not a directory: " + parent); if (!dir.canWrite()) throw new IOException("FileCopy: "+ "destination directory is unwriteable: " + parent); } FileInputStream from = null; FileOutputStream to = null; try { from = new FileInputStream(fromFile); to = new FileOutputStream(toFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead); // write } finally { if (from != null) try { from.close(); } catch (IOException e) { ; } if (to != null) try { to.close(); } catch (IOException e) { ; } } } catch ( java.io.IOException e ) { } } */ private void jButtonObrirClick() { Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); FormObrirRecurs.DirectoriActualObrirRecurs=DirectoriActualObrirRecurs; FormObrirRecurs.ShowModalCentered(); DirectoriActualObrirRecurs=FormObrirRecurs.DirectoriActualObrirRecurs; if (FormObrirRecurs.resultat==1) { //DirectoriActualObrirRecurs=FormObrirRecurs.DirectoriActualObrirRecurs; if (FormObrirRecurs.FileOK==null) {return;} File f=FormObrirRecurs.FileOK; String ext=Tools.getExtension(f); String fn, pn; fn=FormObrirRecurs.fn; pn=FormObrirRecurs.pn; //if ((ext.equals("jpg")) || (ext.equals("png")) || (ext.equals("gif"))) { if ((ext.equals("jpg")) || (ext.equals("png")) || (ext.equals("gif")) || (ext.equals("bmp"))) { EditNomFitxer.setText(fn); //BEGIN 0005 //ImageIcon test = new ImageIcon(pn); ImageIcon test = new ImageIcon(); if (pn.toLowerCase().endsWith(".bmp")) { Image newMap = BMPLoader.load(pn); if(newMap != null) { test.setImage(newMap); } } else { test = new ImageIcon(pn); } //END 0005 jLabelImatge.setBounds(4,4,jPanel1.getWidth()-8,jPanel1.getHeight()-8); if ((test.getIconWidth()>0) && (test.getIconHeight()>0)&& (jLabelImatge.getHeight()>0)) { if ((float)jLabelImatge.getWidth()/(float)jLabelImatge.getHeight()<(float)test.getIconWidth()/test.getIconHeight()) { int comodi=(jLabelImatge.getWidth()*test.getIconHeight()/test.getIconWidth()); jLabelImatge.setBounds(jLabelImatge.getX(),jLabelImatge.getY()+(jLabelImatge.getHeight()-comodi)/2,jLabelImatge.getWidth(),comodi); } else { int comodi=(jLabelImatge.getHeight()*test.getIconWidth()/test.getIconHeight()); jLabelImatge.setBounds(jLabelImatge.getX()+(jLabelImatge.getWidth()-comodi)/2,jLabelImatge.getY(),comodi,jLabelImatge.getHeight()); } } test.setImage(test.getImage().getScaledInstance(jLabelImatge.getWidth(),jLabelImatge.getHeight(),1)); jLabelImatge.setIcon(test); HaCanviatLaImatge=true; SHaEnganxatLaImatge=false; fnImatge=fn; pnImatge=pn; } else if (ext.equals("wav")) { EditRead.setText(fn); fnwav=fn; pnwav=pn; } } else if (FormObrirRecurs.resultat==2) { String fn, pn; javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); fc.setCurrentDirectory(new File(DirectoriActualObrirRecurs)); fc.addChoosableFileFilter(new FilterObrirFitxerRecurs()); if (fc.showOpenDialog(this)==fc.APPROVE_OPTION) { File f=fc.getSelectedFile(); DirectoriActualObrirRecurs=fc.getCurrentDirectory().toString()+fc.getSelectedFile().separator; String ext=Tools.getExtension(f); fn=fc.getName(fc.getSelectedFile()); pn=fc.getSelectedFile().getAbsolutePath(); //if ((ext.equals("jpg")) || (ext.equals("png")) || (ext.equals("gif"))) { if ((ext.equals("jpg")) || (ext.equals("png")) || (ext.equals("gif")) || (ext.equals("bmp"))) { EditNomFitxer.setText(fn); //BEGIN 0005 //ImageIcon test = new ImageIcon(pn); ImageIcon test = new ImageIcon(); if (pn.toLowerCase().endsWith(".bmp")) { Image newMap = BMPLoader.load(pn); if(newMap != null) { test.setImage(newMap); } } else { test = new ImageIcon(pn); } //END 0005 jLabelImatge.setBounds(4,4,jPanel1.getWidth()-8,jPanel1.getHeight()-8); if ((test.getIconWidth()>0) && (test.getIconHeight()>0)&& (jLabelImatge.getHeight()>0)) { if ((float)jLabelImatge.getWidth()/(float)jLabelImatge.getHeight()<(float)test.getIconWidth()/test.getIconHeight()) { int comodi=(jLabelImatge.getWidth()*test.getIconHeight()/test.getIconWidth()); jLabelImatge.setBounds(jLabelImatge.getX(),jLabelImatge.getY()+(jLabelImatge.getHeight()-comodi)/2,jLabelImatge.getWidth(),comodi); } else { int comodi=(jLabelImatge.getHeight()*test.getIconWidth()/test.getIconHeight()); jLabelImatge.setBounds(jLabelImatge.getX()+(jLabelImatge.getWidth()-comodi)/2,jLabelImatge.getY(),comodi,jLabelImatge.getHeight()); } } test.setImage(test.getImage().getScaledInstance(jLabelImatge.getWidth(),jLabelImatge.getHeight(),1)); jLabelImatge.setIcon(test); HaCanviatLaImatge=true; SHaEnganxatLaImatge=false; fnImatge=fn; pnImatge=pn; } else if (ext.equals("wav")) { EditRead.setText(fn); fnwav=fn; pnwav=pn; } } } Toolkit.getDefaultToolkit().addAWTEventListener(ListenerReturnEsc,AWTEvent.KEY_EVENT_MASK); /* String fn, pn; javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); fc.setCurrentDirectory(new File(DirectoriActualObrirRecurs)); fc.addChoosableFileFilter(new FilterObrirFitxerRecurs()); //fc.setApproveButtonText(missatges[4]); //fc.setDialogTitle(missatges[5]); Toolkit.getDefaultToolkit().removeAWTEventListener(ListenerReturnEsc); if (fc.showOpenDialog(this)==fc.APPROVE_OPTION) { //setTitle(fc.getSelectedFile().getAbsolutePath()); //setTitle(fc.getSelectedFile().getPath()); File f=fc.getSelectedFile(); DirectoriActualObrirRecurs=fc.getCurrentDirectory().toString()+fc.getSelectedFile().separator; String ext=Tools.getExtension(f); fn=fc.getName(fc.getSelectedFile()); pn=fc.getSelectedFile().getAbsolutePath(); if ((ext.equals("jpg")) || (ext.equals("png")) || (ext.equals("gif"))) { EditNomFitxer.setText(fn); ImageIcon test = new ImageIcon(pn); jLabelImatge.setBounds(4,4,jPanel1.getWidth()-8,jPanel1.getHeight()-8); if ((test.getIconWidth()>0) && (test.getIconHeight()>0)&& (jLabelImatge.getHeight()>0)) { if ((float)jLabelImatge.getWidth()/(float)jLabelImatge.getHeight()<(float)test.getIconWidth()/test.getIconHeight()) { int comodi=(jLabelImatge.getWidth()*test.getIconHeight()/test.getIconWidth()); jLabelImatge.setBounds(jLabelImatge.getX(),jLabelImatge.getY()+(jLabelImatge.getHeight()-comodi)/2,jLabelImatge.getWidth(),comodi); } else { int comodi=(jLabelImatge.getHeight()*test.getIconWidth()/test.getIconHeight()); jLabelImatge.setBounds(jLabelImatge.getX()+(jLabelImatge.getWidth()-comodi)/2,jLabelImatge.getY(),comodi,jLabelImatge.getHeight()); } } test.setImage(test.getImage().getScaledInstance(jLabelImatge.getWidth(),jLabelImatge.getHeight(),1)); jLabelImatge.setIcon(test); HaCanviatLaImatge=true; SHaEnganxatLaImatge=false; fnImatge=fn; pnImatge=pn; } if (ext.equals("wav")) { EditRead.setText(fn); } } Toolkit.getDefaultToolkit().addAWTEventListener(ListenerReturnEsc,AWTEvent.KEY_EVENT_MASK); */ } private void jButtonEnganxarClick() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferable = clipboard.getContents(null); if(transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) { try { image =(Image)transferable.getTransferData(DataFlavor.imageFlavor); ImageIcon test = new ImageIcon(); test.setImage(image); jLabelImatge.setBounds(4,4,jPanel1.getWidth()-8,jPanel1.getHeight()-8); if ((test.getIconWidth()>0) && (test.getIconHeight()>0)&& (jLabelImatge.getHeight()>0)) { if ((float)jLabelImatge.getWidth()/(float)jLabelImatge.getHeight()<(float)test.getIconWidth()/test.getIconHeight()) { int comodi=(jLabelImatge.getWidth()*test.getIconHeight()/test.getIconWidth()); jLabelImatge.setBounds(jLabelImatge.getX(),jLabelImatge.getY()+(jLabelImatge.getHeight()-comodi)/2,jLabelImatge.getWidth(),comodi); } else { int comodi=(jLabelImatge.getHeight()*test.getIconWidth()/test.getIconHeight()); jLabelImatge.setBounds(jLabelImatge.getX()+(jLabelImatge.getWidth()-comodi)/2,jLabelImatge.getY(),comodi,jLabelImatge.getHeight()); } } test.setImage(test.getImage().getScaledInstance(jLabelImatge.getWidth(),jLabelImatge.getHeight(),1)); jLabelImatge.setIcon(test); HaCanviatLaImatge=false; SHaEnganxatLaImatge=true; EditNomFitxer.setText(""); //Copiar sense canviar la grandaria //jLabelImatge.setIcon(new ImageIcon(image)); } catch(Exception exception) { System.out.println(exception); } } } private void jButtonEsborrarClick() { EditCaption.setText(""); EditRead.setText(""); EditLink.setText(""); EditNomFitxer.setText(""); jLabelImatge.setIcon(null); HaCanviatLaImatge=false; SHaEnganxatLaImatge=false; } public void ShowModalCentered () { Toolkit.getDefaultToolkit().addAWTEventListener(ListenerReturnEsc,AWTEvent.KEY_EVENT_MASK); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); EditCaption.requestFocus(); //BEGIN 14 HaCanviatLaImatge=false; SHaEnganxatLaImatge=false; //END 14 this.setVisible(true); } }