⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conversiondialog.java

📁 java写的图片浏览器,类似acds
💻 JAVA
字号:
package org.net9.oops.jsee;import java.awt.*;import javax.swing.*;import java.awt.BorderLayout;import javax.swing.border.*;import java.awt.event.*;import java.io.*;import javax.media.jai.*;/** * Title: * Description: * Copyright:    Copyright (c) * Company: * @author * @version 1.0 */public class ConversionDialog extends JDialog {  JPanel panel1 = new JPanel();  BorderLayout borderLayout1 = new BorderLayout();  JPanel Destination_Panel = new JPanel();  JLabel jLabel1 = new JLabel();  JList jList1;  JButton SettingButton = new JButton();  int selectedFormat;  Jsee parentFrame;  JScrollPane listScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);  JPanel jPanel1 = new JPanel();  JButton CancelButton = new JButton();  JButton OKButton = new JButton();  private String ConvertedFileName = "";  class MyCellRenderer extends JLabel implements ListCellRenderer {     final ImageIcon iconList[] = {new ImageIcon(getClass().getResource("/image/gifIcon.gif")),                                    new ImageIcon(getClass().getResource("/image/jpgIcon.gif")),                                    new ImageIcon(getClass().getResource("/image/bmpIcon.gif")),                                    new ImageIcon(getClass().getResource("/image/pngIcon.gif")),                                    new ImageIcon(getClass().getResource("/image/pcxIcon.gif")),                                    new ImageIcon(getClass().getResource("/image/tifIcon.jpg")),                                    new ImageIcon(getClass().getResource("/image/pnmIcon.jpg"))                                    };      final String ItemText[] = {"Compuserve Gif",                                  "JPEG",                                  "Windows Bitmap",                                  "Portable Network Graphics",                                  "PCX",                                  "TIFF",                                  "PNM"                                  };     // This is the only method defined by ListCellRenderer.  We just     // reconfigure the Jlabel each time we're called.     public Component getListCellRendererComponent(       JList list,       Object value,            // value to display       int index,               // cell index       boolean isSelected,      // is the cell selected       boolean cellHasFocus)    // the list and the cell have the focus       {          String s = value.toString();          ImageIcon tempI;          setIcon(iconList[index]);           if (isSelected) {              setForeground(Color.blue);              setText(s + "  " + ItemText[index]);              setFont(new java.awt.Font("Dialog", 1, 12));              if (0 == index || 4 == index)                  OKButton.setEnabled(false);              else                  OKButton.setEnabled(true);           } else {              setForeground(Color.darkGray);              setText(s);              setFont(list.getFont());           }           return this;     } }  public ConversionDialog(Jsee frame, String title, boolean modal) {    super(frame, title, modal);    parentFrame = frame;    try {      jbInit();      pack();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  void jbInit() throws Exception {    Destination_Panel.setPreferredSize(new Dimension(423, 200));    panel1.setLayout(borderLayout1);    Destination_Panel.setLayout(null);    jLabel1.setText("Format:");    jLabel1.setBounds(new Rectangle(19, 66, 51, 69));    SettingButton.setEnabled(false);    SettingButton.setFont(new java.awt.Font("Dialog", 0, 12));    SettingButton.setText("Format setting");    SettingButton.setBounds(new Rectangle(294, 146, 113, 31));    String[] data = {"GIF", "JPG", "BMP", "PNG", "PCX", "TIF", "PNM"};    jList1 = new JList(data);    jList1.setCellRenderer(new MyCellRenderer());    listScrollPane.setBounds(new Rectangle(75, 32, 208, 145));    listScrollPane.getViewport().setView(jList1);    CancelButton.setText("Cancel");    CancelButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        CancelButton_actionPerformed(e);      }    });    OKButton.setPreferredSize(new Dimension(73, 27));    OKButton.setText("OK");    OKButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        OKButton_actionPerformed(e);      }    });    this.getContentPane().add(panel1, BorderLayout.NORTH);    panel1.add(Destination_Panel, BorderLayout.CENTER);    Destination_Panel.add(jLabel1, null);    Destination_Panel.add(listScrollPane, null);    Destination_Panel.add(SettingButton, null);    this.getContentPane().add(jPanel1, BorderLayout.SOUTH);    jPanel1.add(OKButton, null);    jPanel1.add(CancelButton, null);    Destination_Panel.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(),                               "Destination format"));  }  public void OKButton_actionPerformed(ActionEvent e) {    selectedFormat = jList1.getSelectedIndex();    switch (selectedFormat) {        case 0: // convert to Gif          break;        case 1: // convert to Jpg          convertImageFormat(".jpg", "JPEG");          break;        case 2: // convert to Bmp          convertImageFormat(".bmp", "BMP");          break;        case 3: // convert to Png          convertImageFormat(".png", "PNG");          break;        case 4: // convert to Pcx          break;        case 5: // convert to Tif          convertImageFormat(".tif", "TIFF");        case 6: // convert to Pnm          convertImageFormat(".pnm", "PNM");        break;    }    dispose();  }  public void convertImageFormat(String fileExtension, String ImageFormat) {      String  pathName,              fileName,              sourceFileName;      FileOutputStream os;      fileName = parentFrame.FileListScrollPane.getSelectedFile();      sourceFileName = fileName;      //pathName = get the path from file name      fileName = fileName.substring(0, fileName.lastIndexOf("."));      try {          fileName = fileName + fileExtension;          // load the source image file          RenderedOp src = JAI.create("fileload", sourceFileName);          try {              if (src.getHeight() > 0) {                  os = new FileOutputStream(fileName);                  JAI.create("encode", src, os, ImageFormat, null);                  JAI.create("filestore", src, fileName, ImageFormat, null);                  ConvertedFileName = fileName;              } else {                  System.out.println("Cannot load source image");                  dispose();              }          } catch (java.lang.RuntimeException rte) {System.out.println("Damn, image not supported by JAI");}      } catch (FileNotFoundException fnfe) {System.out.println("exception");}  }/*  public String GetConvertedFileName() {      return ConvertedFileName;  }*/  public void CancelButton_actionPerformed(ActionEvent e) {    dispose();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -