Виктор Кон,   vkBook, Java-Second

Классы файла runPro



import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.beans.*;

//oooo

public class runPro implements Runnable {
 public runPro(){}
 public void run(){ Thread.yield();
  MyPro.isn = new MainPro().execalc(); 
 }
}  

//oooo

class MainPro{
 Frame parent;

 public MainPro(){parent=MyPro.parent();}

 public int execalc(){
  JFileChooser fch; File fd; String ls,txt; webFrame wfd; fileFrame eff;
  int i,id,k,km; boolean ok; id=-1;
  if( MyPro.isn == 1 ){
   fch = new JFileChooser(MyPro.fn); fch.setFileView(new MyFileView());
   i = fch.showDialog(parent,"Select");
   if(i == JFileChooser.APPROVE_OPTION){
    fd = fch.getSelectedFile(); txt = MyPro.getExt(fd);
    ls=fd.getAbsolutePath(); MyPro.fn=ls;
    if( txt != null ){ 
     if( txt.equals("htm") || txt.equals("html") ){
      try{wfd = new webFrame(ls,MyPro.ia);}catch(IOException ex){ex.printStackTrace();}}
     else{ km=MyPro.ext.length; ok = false;
      for(k=0; k < km; k++){ok = ok || txt.equals(MyPro.ext[k]);}
      if( ok ){
       eff = new fileFrame(ls,1,0,MyPro.ia); eff.setVisible(true); MainForm.deskt.add(eff); 
       try{eff.setSelected(true);}catch(java.beans.PropertyVetoException ex){}
  }}}}}
  else
  if( MyPro.isn == 2 ){ls=MyPro.fn; txt = null; km=ls.lastIndexOf(".");
   if(km > 0 && km < ls.length()-1){txt = ls.substring(km+1).toLowerCase();}
   if( txt != null ){ 
    if( txt.equals("htm") || txt.equals("html") ){
     try{wfd = new webFrame(ls,MyPro.ia);}catch(IOException ex){ex.printStackTrace();}}
    else{ km=MyPro.ext.length; ok = false;
     for(k=0; k < km; k++){ok = ok || txt.equals(MyPro.ext[k]);}
     if( ok ){
      eff = new fileFrame(ls,1,0,MyPro.ia); eff.setVisible(true); MainForm.deskt.add(eff); 
      try{eff.setSelected(true);}catch(java.beans.PropertyVetoException ex){}
  }}}}
  else
  if( MyPro.isn == 3 ){
   fch = new JFileChooser(MyPro.fn); fch.addChoosableFileFilter(new MyImgFilter());
   fch.setAcceptAllFileFilterUsed(false); fch.setFileView(new MyImgFileView());
   fch.setAccessory(new ImagePreview(fch)); i = fch.showDialog(parent,"Viewer");
   if(i == JFileChooser.APPROVE_OPTION){
    fd = fch.getSelectedFile(); ls=fd.getAbsolutePath(); MyPro.fn=ls;
    new butImage(parent,ls,new ImageIcon(ls),true); Thread.yield();
  }}
  else
  if( MyPro.isn == 4 ){
   fch = new JFileChooser(MyPro.fn); fch.addChoosableFileFilter(new MySpFilter());
   fch.setAcceptAllFileFilterUsed(false); fch.setFileView(new MyFileView());
   i = fch.showDialog(parent,"Special");
   if(i == JFileChooser.APPROVE_OPTION){
    fd = fch.getSelectedFile(); ls=fd.getAbsolutePath(); MyPro.fn=ls;
    eff = new fileFrame(ls,1,0,MyPro.ia); eff.setVisible(true); MainForm.deskt.add(eff); 
    try{eff.setSelected(true);}catch(java.beans.PropertyVetoException ex){}
  }}
  else
  if( MyPro.isn == 5 ){ls=MyPro.fn+"|"+MyPro.fs+"|"+MyPro.fk; MyPro.ok=true;
   MyPro.writeLine(ls,"data/Second.ini",4); System.exit(0);
  }
  else
  if( MyPro.isn == 6 ){
    eff = new fileFrame("data/help1.txt",0,0,MyPro.ia); eff.setVisible(true); MainForm.deskt.add(eff); 
    try{eff.setSelected(true);}catch(java.beans.PropertyVetoException ex){}
  }
  else
  if( MyPro.isn == 7 ){
    eff = new fileFrame("data/help2.txt",0,0,MyPro.ia); eff.setVisible(true); MainForm.deskt.add(eff); 
    try{eff.setSelected(true);}catch(java.beans.PropertyVetoException ex){}
  }
  else
  if( MyPro.isn == 8 ){
    eff = new fileFrame("data/help3.txt",0,0,MyPro.ia); eff.setVisible(true); MainForm.deskt.add(eff); 
    try{eff.setSelected(true);}catch(java.beans.PropertyVetoException ex){}
  }
  return id;
 }
}

//oooo

class MyFileView extends FileView{
 public String getName(File f){return null;}
 public String getDescription(File f){return null;}
 public Boolean isTraversable(File f){return null;}
 public String getTypeDescription(File f){return null;}
 
 public Icon getIcon(File f){
  String ext = MyPro.getExt(f); Icon icon = null;
  if(ext != null){
        if(ext.equals("acl")){icon = MyPro.aclic;}
   else if(ext.equals("aif") || ext.equals("aiff")){icon = MyPro.aific;}
   else if(ext.equals("au")){icon = MyPro.auic;}
   else if(ext.equals("bat")){icon = MyPro.batic;}
   else if(ext.equals("bmp")){icon = MyPro.bmpic;}
   else if(ext.equals("dat")){icon = MyPro.datic;}
   else if(ext.equals("doc")){icon = MyPro.docic;}
   else if(ext.equals("exe")){icon = MyPro.exeic;}
   else if(ext.equals("gif")){icon = MyPro.gific;}
   else if(ext.equals("htm") || ext.equals("html")){icon = MyPro.htmic;}
   else if(ext.equals("inf")){icon = MyPro.infic;}
   else if(ext.equals("ini")){icon = MyPro.iniic;}
   else if(ext.equals("jar")){icon = MyPro.jaric;}
   else if(ext.equals("java")){icon = MyPro.javaic;}
   else if(ext.equals("jpeg") || ext.equals("jpg")){icon = MyPro.jpgic;}
   else if(ext.equals("mid")){icon = MyPro.midic;}
   else if(ext.equals("mp3")){icon = MyPro.mp3ic;}
   else if(ext.equals("par")){icon = MyPro.paric;}
   else if(ext.equals("pdf")){icon = MyPro.pdfic;}
   else if(ext.equals("png")){icon = MyPro.pngic;}
   else if(ext.equals("ppt")){icon = MyPro.pptic;}
   else if(ext.equals("ps") || ext.equals("eps")){icon = MyPro.psic;}
   else if(ext.equals("tiff") || ext.equals("tif")){icon = MyPro.tific;}
   else if(ext.equals("txt")){icon = MyPro.txtic;}
   else if(ext.equals("wav")){icon = MyPro.wavic;}
   else if(ext.equals("wma")){icon = MyPro.wmaic;}
   else if(ext.equals("wmf")){icon = MyPro.wmfic;}
   else if(ext.equals("zip")){icon = MyPro.zipic;}
  } return icon;
 }
}

//oooo

class MyImgFileView extends FileView{
 public String getName(File f){return null;}
 public String getDescription(File f){return null;}
 public Boolean isTraversable(File f){return null;}

 public String getTypeDescription(File f){
  String ext = MyPro.getExt(f); String type = null;
  if(ext != null){
        if(ext.equals("jpeg") || ext.equals("jpg")){type = "JPEG Image";}
   else if(ext.equals("gif")){type = "GIF Image";}
   else if(ext.equals("png")){type = "PNG Image";}
  } return type;
 }
 
 public Icon getIcon(File f){
  String ext = MyPro.getExt(f); Icon icon = null;
  if(ext != null){
        if(ext.equals("gif")){icon = MyPro.gific;}
   else if(ext.equals("jpeg") || ext.equals("jpg")){icon = MyPro.jpgic;}
   else if(ext.equals("png")){icon = MyPro.pngic;}
  } return icon;
 }
}

//oooo

class MyImgFilter extends javax.swing.filechooser.FileFilter{
 public boolean accept(File f){
  if(f.isDirectory()){return true;}
  String ext = MyPro.getExt(f); 
  if(ext != null){
   if(ext.equals("gif") || ext.equals("jpeg") || ext.equals("jpg") || ext.equals("png")){return true;}
   else{return false;}
  } return false;
 }
 
 public String getDescription(){return "Images: jpg, gif, png";}
}

//oooo

class MySpFilter extends javax.swing.filechooser.FileFilter{
 public boolean accept(File f){
  if(f.isDirectory()){return true;}
  String ext = MyPro.getExt(f); 
  if(ext != null){
   if(ext.equals(MyPro.ext[0])){return true;}
   else{return false;}
  } return false;
 }
 
 public String getDescription(){return "Special: "+MyPro.ext[0];}
}

//oooo

class ImagePreview extends JComponent implements PropertyChangeListener {
 ImageIcon thumbnail = null;
 File file = null;
 
 public ImagePreview(JFileChooser fc){
  setPreferredSize(new Dimension(200,100));
  fc.addPropertyChangeListener(this);
 }
 
 public void loadImage(){
  if(file == null){thumbnail = null; return;}
  ImageIcon tmpIcon = new ImageIcon(file.getPath());
  if(tmpIcon != null){
   if(tmpIcon.getIconWidth() > 190){
    thumbnail = new ImageIcon(tmpIcon.getImage().getScaledInstance(190,-1,java.awt.Image.SCALE_DEFAULT));
   }else{thumbnail = tmpIcon;}
 }}
 
 public void propertyChange(PropertyChangeEvent e){
  boolean update = false;
  String prop = e.getPropertyName();
       if(JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)){file = null; update = true;}
  else if(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)){
          file = (File) e.getNewValue(); update = true; }
  if(update){thumbnail = null;
   if(isShowing()){loadImage(); repaint();
 }}}
 
 public void paintComponent(Graphics g){
  if(thumbnail == null){loadImage();}
  if (thumbnail != null){
   int x = getWidth()/2 - thumbnail.getIconWidth()/2;
   int y = getHeight()/2 - thumbnail.getIconHeight()/2;
   if(y < 0){y = 0;} if(x < 5){x = 5;}
   thumbnail.paintIcon(this, g, x, y);
 }}
}

Hosted by uCoz