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

📄 jftp.java

📁 一个JAVA做的FTP软件,带源码的,可以很好的进行二次开发,,并带有详细说明文件的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        Log.out("starting up jftp...");        compile();        System.setProperty("sshtools.logfile", Settings.appHomeDir +                           "log4.txt");        if(Settings.autoUpdate)        {            checkForUpgrade();        }        Settings.enableResuming = true;        setSocksProxyOptions(Settings.getSocksProxyHost(),                             Settings.getSocksProxyPort());        JFtp jftp = new JFtp(true);        UIManager.getLookAndFeelDefaults().put("ClassLoader",                                               jftp.getClass().getClassLoader());        //boolean lookSet = false;        String tmp = Settings.getLookAndFeel();        //UIManager.installLookAndFeel("Metouia", "net.sourceforge.mlf.metouia.MetouiaLookAndFeel");        if(tmp != null)        {            jftp.setLookAndFeel(Settings.getLookAndFeel());        }        else        {            jftp.setLookAndFeel("net.sourceforge.mlf.metouia.MetouiaLookAndFeel");        }        //else        //{        //	jftp.setLookAndFeel("com.incors.plaf.kunststoff.KunststoffLookAndFeel");        //	lookSet = true;        //}        //if(!lookSet) UIManager.installLookAndFeel("Kunststoff", "com.incors.plaf.kunststoff.KunststoffLookAndFeel");        /*         * Don't try to add the Kunststoff look and feel if it has         * already been added.         */        if((Settings.getLookAndFeel() == null) ||               !Settings.getLookAndFeel().equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel"))        {            /*             * Somehow even though UIManager.installLookAndFeel throws a             * ClassNotFoundException, it ends up getting added to the             * list of installed look and feels anyway. What we do here is             * make Java throw a ClassNotFoundException before then by             * checking whether or not the class exists, and only if the             * class exists does it then get added to the list of             * available look and feel's.             */            try            {                Class.forName("com.incors.plaf.kunststoff.KunststoffLookAndFeel");                UIManager.installLookAndFeel("Kunststoff",                                             "com.incors.plaf.kunststoff.KunststoffLookAndFeel");            }            catch(ClassNotFoundException cnfe)            {            }        }        /*         * Don't try to add the Metouia look and feel if it has         * already been added.         */        if((Settings.getLookAndFeel() == null) ||               !Settings.getLookAndFeel().equals("net.sourceforge.mlf.metouia.MetouiaLookAndFeel"))        {            /*             * Somehow even though UIManager.installLookAndFeel throws a             * ClassNotFoundException, it ends up getting added to the             * list of installed look and feels anyway. What we do here is             * make Java throw a ClassNotFoundException before then by             * checking whether or not the class exists, and only if the             * class exists does it then get added to the list of             * available look and feel's.             */            try            {                Class.forName("net.sourceforge.mlf.metouia.MetouiaLookAndFeel");                UIManager.installLookAndFeel("Metouia",                                             "net.sourceforge.mlf.metouia.MetouiaLookAndFeel");            }            catch(ClassNotFoundException cnfe)            {            }        }        mainFrame = new JFrame();        mainFrame.setLocation(Settings.getWindowLocation());        mainFrame.setTitle(Settings.title + " - Version " + getVersion());        if(Settings.isInsomniacClient)        {            mainFrame.setTitle(Settings.insomniacTitle + " - Version " +                               getVersion());        }        mainFrame.setResizable(Settings.resize);        mainFrame.addWindowListener(jftp);        Image icon = HImage.getImage(jftp, Settings.iconImage);        mainFrame.setIconImage(icon);        mainFrame.setFont(GUIDefaults.font);        //*** MY CHANGES        //mainFrame.setJMenuBar(new AppMenuBar(jftp));        menuBar = new AppMenuBar(jftp);        mainFrame.setJMenuBar(menuBar);        //***        mainFrame.getContentPane().setLayout(new BorderLayout());        mainFrame.getContentPane().add("Center", jftp);        SwingUtilities.updateComponentTreeUI(mainFrame);        mainFrame.pack();        mainFrame.validate();        mainFrame.setVisible(true);        if(argv.length > 0)        {            jftp.hc.update(argv[0]);        }        else        {            //jftp.hc.update();        }        Log.out("jftp is up and running.");        long end = System.currentTimeMillis();        Log.out("startup time: " + (end - start) + "ms.");    }    private void log(String msg)    {        if(msg.startsWith("200") || msg.startsWith("227"))        {            if((msg.indexOf("NOOP") > 0) || (msg.indexOf("Type") > 0) ||                   (msg.indexOf("MODE") > 0) || (msg.indexOf("Passive") > 0))            {                if(Settings.hideStatus)                {                    return;                }            }        }        else if(log == null)        {            return;        }        if(!msg.equals(""))        {            buffer = buffer + " " + msg;        }        long time = System.currentTimeMillis();        if(((time - oldtime) < Settings.uiRefresh))        {            UpdateDaemon.updateLog();            return;        }        oldtime = time;        log.append(buffer);        buffer = "";        JScrollBar bar = logSp.getVerticalScrollBar();        bar.setValue(bar.getMaximum());        //logSp.paintImmediately(0, 0, logSp.getSize().width,        //                       logSp.getSize().height);        /*        SwingUtilities.invokeLater(new Runnable()            {                public void run()                {                    repaint();                    //paintImmediately(0, 0, getSize().width, getSize().height);                }            });        */        repaint();        revalidate();    }    private void logRaw(String msg)    {        log.append(" " + msg);        Log.out("NOTE: logRaw called");        paintImmediately(0, 0, getSize().width, getSize().height);        //logSp.paintImmediately(0,0,logSp.getSize().width,logSp.getSize().height);    }    public void clearLog()    {        log.setText("");        logSp.paintImmediately(0, 0, logSp.getSize().width,                               logSp.getSize().height);    }    private void log(String msg, Throwable throwable)    {        PrintWriter p = new PrintWriter(new StringWriter());        throwable.printStackTrace(p);        log(msg);        log(p.toString());    }    public void debug(String msg)    {        log(msg + "\n");    }    public void debugRaw(String msg)    {        logRaw(msg);    }    public void debug(String msg, Throwable throwable)    {        log(msg, throwable);    }    public void warn(String msg)    {        log(msg);    }    public void warn(String msg, Throwable throwable)    {        log(msg, throwable);    }    public void error(String msg)    {        log(msg);    }    public void error(String msg, Throwable throwable)    {        log(msg, throwable);    }    public void info(String msg)    {        log(msg);    }    public void info(String msg, Throwable throwable)    {        log(msg, throwable);    }    public void fatal(String msg)    {        log(msg);    }    public void fatal(String msg, Throwable throwable)    {        log(msg, throwable);    }    public void debugSize(int size, boolean recv, boolean last, String file)    {    }    public static String getVersion()    {        try        {            URL u = ClassLoader.getSystemResource(Settings.readme);            if(u == null)            {                u = HImage.class.getResource("/" + Settings.readme);            }            DataInputStream i = new DataInputStream(u.openStream());            String tmp = i.readLine();            tmp = tmp.substring(tmp.lastIndexOf(">") + 1);            tmp = tmp.substring(0, tmp.indexOf("<"));            return tmp;        }        catch(Exception ex)        {        }        return "";    }    private static void checkForUpgrade()    {        try        {            Log.out("Checking for updates...");            URL u = ClassLoader.getSystemResource(Settings.readme);            if(u == null)            {                u = HImage.class.getResource("/" + Settings.readme);            }            DataInputStream i = new DataInputStream(u.openStream());            String tmp = i.readLine();            tmp = tmp.substring(tmp.lastIndexOf(">"));            tmp = tmp.substring(tmp.indexOf(".") + 1);            tmp = tmp.substring(0, tmp.indexOf("<"));            int x = Integer.parseInt(tmp) + 1;            String nextVersion = "jftp-1.";            if(x < 10)            {                nextVersion = nextVersion + "0";            }            nextVersion = nextVersion + x + ".tar.gz";            //System.out.println(nextVersion);            File dl = new File(nextVersion);            if(!dl.exists() || (dl.length() <= 0))            {                URL url = new URL("http://osdn.dl.sourceforge.net/sourceforge/j-ftp/" +                                  nextVersion);                BufferedOutputStream f = new BufferedOutputStream(new FileOutputStream(dl));                BufferedInputStream in = new BufferedInputStream(url.openStream());                byte[] buf = new byte[4096];                int stat = 1;                Log.out("\ndownloading update: " + dl.getAbsolutePath() +                        "\n\n");                while(stat > 0)                {                    //while(in.available() <= 0) LocalIO.pause(10);                    stat = in.read(buf);                    if(stat == -1)                    {                        break;                    }                    f.write(buf, 0, stat);                    System.out.print(".");                }                f.flush();                f.close();                in.close();            }            Log.out("\n\n\na newer version was found!\nplease install the File " +                    dl.getAbsolutePath() +                    " or even better visit the homepage to download the latest version...\n" +                    "you can turn this feature off if you don't like it (view readme for details)\n\nStarting anyway...\n\n");            //LocalIO.pause(5000);            //System.exit(0);        }        catch(Exception ex)        {            // FileNotFoundException, everything is ok            //ex.printStackTrace();        }        Log.out("finished check...");    }    public static ConnectionHandler getConnectionHandler()    {        BasicConnection con = remoteDir.getCon();        if((con != null) && con instanceof FtpConnection)        {            return ((FtpConnection) con).getConnectionHandler();        }        else        {            return defaultConnectionHandler;        }    }    public void fireUpdate()    {        // if(!(JFtp.remoteDir.getCon() instanceof FilesystemConnection))        LocalIO.pause(200);        repaint();        /*         else         {                 LocalIO.pause(200);                 paintImmediately(0,0,getSize().width,getSize().height);         }         */    }    public void ensureLogging()    {        if(buffer.equals(""))        {            JScrollBar bar;            if((logSp == null) ||                   ((bar = logSp.getVerticalScrollBar()) == null) ||                   (bar.getValue() == bar.getMaximum()) ||                   bar.getValueIsAdjusting())            {                return;            }            else            {                bar.setValue(bar.getMaximum());                logSp.repaint();                /*                logSp.paintImmediately(0, 0, logSp.getSize().width,                               logSp.getSize().height);                */                /*                SwingUtilities.invokeLater(new Runnable()                    {                        public void run()                        {                            repaint();                            //paintImmediately(0, 0, getSize().width,                            //                 getSize().height);                        }                    });                 */                repaint();                revalidate();            }            return;        }        Log.out("flushing log buffer...");        oldtime = 0;        log("");    }    public void setLookAndFeel(String name)    {        if(name == null)        {            return;        }        try        {            UIManager.setLookAndFeel(name);

⌨️ 快捷键说明

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