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

📄 oyoahadirectorymodel.java

📁 java 开源,Swing外观:JGoodies look & feel. ... JGoodies look&feels让你的Swing 应用程序与applets看起来更漂亮.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  {
    return a.toString().toLowerCase().compareTo(b.toString().toLowerCase()) < 0;
  }

  protected File[] getFilesFromFileSystemView(File currentDirectory)
  {
    if(currentDirectory instanceof OyoahaVectorFolder)
    {
      return view.getChild(currentDirectory);
    }
    else
    {
      FileSystemView fileSystem = filechooser.getFileSystemView();

      File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled());
      File[] files = new File[list.length];

      int index = 0;

      for (int i=0;i<list.length;i++)
      {
        if(filechooser.accept(list[i]))
        {
          files[index++] = list[i];
        }
      }

      File[] tmp = new File[index];

      System.arraycopy(files, 0, tmp, 0, index);
      return tmp;
    }
  }

  public class OyoahaLoadFilesByExtentionThread extends Thread
  {
    protected File currentDirectory = null;
    protected int fid;

    protected ListFiles arrayDirectories;
    protected ListFiles arrayFiles;
    protected int sizeArraySortFiles;
    protected ListFiles[] arraySortFiles;

    protected Hashtable table;

    public OyoahaLoadFilesByExtentionThread(int fid, File currentDirectory)
    {
      super("Oyoaha L&F File Loading Thread");
      this.fid = fid;
      this.currentDirectory = currentDirectory;
    }

    protected ListFiles getListFiles(String key, int size)
    {
      if(table.containsKey(key))
      return (ListFiles)table.get(key);

      ListFiles list = new ListFiles(key, size);
      table.put(key, list);

      return list;
    }

    protected void addToArraySortFiles(ListFiles array)
    {
      if(sizeArraySortFiles==arraySortFiles.length)
      {
        ListFiles[] tmp = new ListFiles[sizeArraySortFiles+10];
        System.arraycopy(arraySortFiles, 0, tmp, 0, sizeArraySortFiles);
        arraySortFiles = tmp;
      }

      arraySortFiles[sizeArraySortFiles++] = array;
    }

    protected String getExtention(File file)
    {
      return view.getExtention(file, (use==USE_CASESENSITIVE_EXTENTION)? true : false);
    }

    public void run()
    {
      try
      {
        File[] files = getFilesFromFileSystemView(currentDirectory);

        //initialise...
        arrayDirectories = new ListFiles(40);
        arrayFiles = new ListFiles(files.length);
        table = new Hashtable();

        for(int i=0;i<files.length;i++)
        {
          boolean isTraversable = filechooser.isTraversable(files[i]);

          if(isTraversable)
          {
            arrayDirectories.add(files[i]);
          }
          else
          if(!isTraversable && filechooser.isFileSelectionEnabled())
          {
            String ext = getExtention(files[i]);

            if(ext!=null && !ext.equals("file"))
            getListFiles(ext, 20).add(files[i]);
            else
            arrayFiles.add(files[i]);
          }
        }

        arraySortFiles = new ListFiles[table.size()];
        Enumeration e = table.keys();

        while(e.hasMoreElements())
        {
          ListFiles tmp = (ListFiles)table.get(e.nextElement());
          addToArraySortFiles(tmp);
        }

        if(arraySortFiles!=null && sizeArraySortFiles>1)
        {
          quickSortListFiles(arraySortFiles, 0, sizeArraySortFiles-1);
        }

        if(isInterrupted())
        {
          cancelRunnables();
          return;
        }

        //now set the right size of cached...
        //WARNING THIS IS REALLY BAD!
        if(cached==null)
        {
          cached = new Object[files.length];
          length = 0;
        }
        else
        {
          if(isInterrupted())
          {
            cancelRunnables();
            return;
          }
          else
          {
            cached = new Object[files.length];
            length = 0;
          }
        }

        //start thread...
        if(arrayDirectories.getSize()>0)
        {
          arrayDirectories.setFid(fid);
          SwingUtilities.invokeLater(arrayDirectories);
        }

        if(arraySortFiles!=null)
        {
          for(int i=0;i<sizeArraySortFiles;i++)
          {
            arraySortFiles[i].setFid(fid);
            SwingUtilities.invokeLater(arraySortFiles[i]);
          }
        }

        if(arrayFiles.getSize()>0)
        {
          arrayFiles.setFid(fid);
          SwingUtilities.invokeLater(arrayFiles);
        }

        if(isInterrupted())
        {
          cancelRunnables();
        }
      }
      catch(Exception e)
      {
        cancelRunnables();
      }
    }

    public void cancelRunnables()
    {
      if(arrayDirectories!=null)
      {
        arrayDirectories.cancel();
        arrayDirectories = null;
      }

      if(arraySortFiles!=null)
      {
        for(int i=0;i<sizeArraySortFiles;i++)
        {
          arraySortFiles[i].cancel();
          arraySortFiles[i] = null;
        }

        arraySortFiles = null;
      }

      if(arrayFiles!=null)
      {
        arrayFiles.cancel();
        arrayFiles = null;
      }
    }
  }

  public class OyoahaLoadFilesByTypeThread extends OyoahaLoadFilesByExtentionThread
  {
    public OyoahaLoadFilesByTypeThread(int fid, File currentDirectory)
    {
      super(fid, currentDirectory);
    }

    protected String getExtention(File file)
    {
      return view.getType(file, false);
    }
  }

  public class OyoahaLoadFilesThread extends OyoahaLoadFilesByExtentionThread
  {
    public OyoahaLoadFilesThread(int fid, File currentDirectory)
    {
       super(fid, currentDirectory);
    }

    protected String getExtention(File file)
    {
      return null;
    }
  }

  public class DoChangeContents extends OyoahaSortFileArray implements Runnable
  {
    protected Object lock = new Object();
    protected int fid;

    public DoChangeContents()
    {
      this.mode = getMode();
      this.inverse = isInverse();
      file = new File[DELTA];
    }

    public DoChangeContents(int size)
    {
      this.mode = getMode();
      this.inverse = isInverse();
      file = new File[size];
    }

    protected void setFid(int fid)
    {
      this.fid = fid;
    }

    protected synchronized void cancel()
    {
      synchronized(lock)
      {
        file = null;
        count = 0;
      }
    }

    public void run()
    {
      if(fetchID == fid)
      {
        synchronized(lock)
        {
          if(count>0)
          {
            sort();

            //just in case...
            if(cached==null)
            {
              cached = new File[count];
              length = 0;
            }
            else
            if(length+count>=cached.length)
            {
              File[] tmp = new File[length+count];
              System.arraycopy(cached, 0, tmp, 0, length);
              cached = tmp;
            }

            System.arraycopy(file, 0, cached, length, count);
            int old = length;
            length += count;
            fireIntervalAdded(old, old+count-1);
          }
        }
      }
    }
  }

  public class ListFiles extends DoChangeContents
  {
    protected String suffix;

    public ListFiles(int size)
    {
      super(size);
      this.suffix = "";
    }

    public ListFiles(String suffix)
    {
      super(DELTA);
      this.suffix = suffix;
    }

    public ListFiles(String suffix, int size)
    {
      super(size);
      this.suffix = suffix;
    }

    public String toString()
    {
      return suffix;
    }
  }
}

⌨️ 快捷键说明

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