📄 jftp.java
字号:
if(mainFrame != null) { //SwingUtilities.updateComponentTreeUI(mainFrame); //invalidate(); //validate(); //repaint(); SwingUtilities.invokeLater(new Runnable() { public void run() { SwingUtilities.updateComponentTreeUI(mainFrame); SwingUtilities.updateComponentTreeUI(JFtp.statusP); } }); } } catch(Exception ex) { Log.debug("Error setting look and feel: " + ex); } } public void addConnection(String name, BasicConnection con) { verifyVisibleFrames(); con.addConnectionListener((ConnectionListener) localDir); Dir tmp = (Dir) new RemoteDir(); tmp.setDownloadList(dList); con.addConnectionListener((ConnectionListener) tmp); tmp.setCon(con); int x = remoteConnectionPanel.getSelectedIndex(); remoteConnectionPanel.addTab(parse(name), null, (Component) tmp, "Switch to: " + parse(name)); remoteConnectionPanel.setSelectedIndex(x + 1); j2.setClosable(true); } public void addLocalConnection(String name, BasicConnection con) { verifyVisibleFrames(); con.addConnectionListener((ConnectionListener) remoteDir); Dir tmp = (Dir) new LocalDir(); tmp.setDownloadList(dList); con.addConnectionListener((ConnectionListener) tmp); tmp.setCon(con); int x = localConnectionPanel.getSelectedIndex(); localConnectionPanel.addTab(parse(name), null, (Component) tmp, "Switch to: " + parse(name)); localConnectionPanel.setSelectedIndex(x + 1); j1.setClosable(true); } private String parse(String what) { if(what.indexOf("@") >= 0) { return what.substring(what.lastIndexOf("@") + 1); } else { return what; } } public void stateChanged(ChangeEvent e) { remoteDir = (Dir) remoteConnectionPanel.getSelectedComponent(); localDir = (Dir) localConnectionPanel.getSelectedComponent(); remoteDir.getCon().setLocalPath(localDir.getPath()); //localDir.getCon().setLocalPath(remoteDir.getPath()); } public void closeCurrentTab() { int x = remoteConnectionPanel.getSelectedIndex(); if(x > 0) { safeDisconnect(); remoteConnectionPanel.remove(x); remoteConnectionPanel.setSelectedIndex(x - 1); } if(remoteConnectionPanel.getTabCount() < 2) { j2.setClosable(false); } } public void closeCurrentLocalTab() { int x = localConnectionPanel.getSelectedIndex(); if(x > 0) { BasicConnection con = localDir.getCon(); if((con != null) && con.isConnected()) { try { con.disconnect(); } catch(Exception ex) { } } localConnectionPanel.remove(x); localConnectionPanel.setSelectedIndex(x - 1); } if(localConnectionPanel.getTabCount() < 2) { j1.setClosable(false); } } public void addToDesktop(String title, Component c, int w, int h) { JInternalFrame jt = new JInternalFrame(title, false, true, false, true); if(w < 500) { jt.setLocation(200, 100); } else { jt.setLocation(80, 100); } jt.getContentPane().add(c); desktop.add(jt); internalFrames.put("" + c.hashCode(), jt); jt.pack(); jt.setSize(new Dimension(w, h)); jt.show(); } public void removeFromDesktop(int component) { JInternalFrame f = (JInternalFrame) internalFrames.get("" + component); if(f != null) { f.dispose(); //internalFrames.remove(component); } else { Log.debug("ERROR: " + component + " not found in Hashtable!"); } } public void setClosable(int component, boolean ok) { JInternalFrame f = (JInternalFrame) internalFrames.get("" + component); if(f != null) { f.setClosable(ok); } else { Log.debug("ERROR: " + component + " not found in Hashtable!"); } } public void setLocation(int component, int x, int y) { JInternalFrame f = (JInternalFrame) internalFrames.get("" + component); if(f != null) { f.setLocation(x, y); } else { Log.debug("ERROR: " + component + " not found in Hashtable!"); } } //*** REFRESH MENU BAR public static void updateMenuBar() { //mainFrame.setJMenuBar(new AppMenuBar(this)); menuBar.resetFileItems(); } //*** public void switchToInsomniacUI() { try { j1.setIcon(true); j2.setIcon(true); j5.setIcon(true); } catch(java.beans.PropertyVetoException ex) { ex.printStackTrace(); } j6.show(); } private void verifyVisibleFrames() { if(Settings.isInsomniacClient) { try { j1.setIcon(false); j2.setIcon(false); j5.setIcon(false); j3.toFront(); j6.toBack(); } catch(java.beans.PropertyVetoException ex) { ex.printStackTrace(); } } } public void internalFrameClosing(InternalFrameEvent e) { if(e.getSource() == j1) { closeCurrentLocalTab(); } else if(e.getSource() == j2) { closeCurrentTab(); } } public void internalFrameActivated(InternalFrameEvent e) { } public void internalFrameClosed(InternalFrameEvent e) { } public void internalFrameDeactivated(InternalFrameEvent e) { } public void internalFrameDeiconified(InternalFrameEvent e) { } public void internalFrameIconified(InternalFrameEvent e) { } public void internalFrameOpened(InternalFrameEvent e) { } public void drop() { try { handleDrop(null, Toolkit.getDefaultToolkit().getSystemClipboard() .getContents(this)); } catch(Exception ex) { ex.printStackTrace(); } } public void handleDrop(DropTargetDropEvent e, Transferable t) throws Exception { System.out.println("Starting dropAttempt"); DataFlavor chosen = DataFlavor.javaFileListFlavor; DataFlavor second = FileTransferable.plainTextFlavor; DataFlavor flavor = null; Object data = null; if(e != null) { flavor = e.getCurrentDataFlavors()[0]; e.acceptDrop(acceptableActions); Class c = flavor.getDefaultRepresentationClass(); } if(flavor == null) { flavor = second; } String name = ""; if(t.isDataFlavorSupported(chosen)) { System.out.println("Using List DnD style"); java.util.List myList = (java.util.List) t.getTransferData(chosen); File[] f = (File[]) myList.toArray(); for(int i = 0; i < f.length; i++) { name = f[i].getAbsolutePath(); System.out.println("DnD file: " + name); } draggedTransfer(f, name); } else if(t.isDataFlavorSupported(second)) { System.out.println("Using text/plain DnD style"); data = t.getTransferData(flavor); String str = ""; int i = 0; if(data instanceof Reader) { int c; while((c = ((Reader) data).read()) != -1) { if(((i == 1) && (c == 0))) { //System.out.println("Applying charset bugfix"); i = -1; } else { str = str + new Character((char) c).toString(); } i++; } } else { str = "" + data; } System.out.println("Object data: \"" + str + "\""); if(str.startsWith("<")) { Log.debug("Mozilla DnD detected (preparsing)"); str = str.substring(str.indexOf("\"") + 1); str = str.substring(0, str.indexOf("\"")); Log.debug("Parsed data: " + str); } //str = "[c:\\windows\\test.txt]"; if(str.indexOf("[") >= 0) { Log.debug("Windows DnD detected"); name = str.substring(str.indexOf("[") + 1); name = name.substring(0, name.lastIndexOf("]")); // last was str } else if(new String(str).startsWith("file://")) { name = str.substring(7); Log.debug("File URL DnD detected: " + name); } if(!new File(name).exists()) { System.out.println("No file string in clipboard: " + name); return; } System.out.println("DnD file: " + name); File[] f1 = new File[1]; f1[0] = new File(name); draggedTransfer(f1, name); } } private void draggedTransfer(File[] f, String name) { if((f.length == 1) && f[0].isFile()) { String path = ""; if(name.indexOf("/") >= 0) { path = name.substring(0, name.lastIndexOf("/") + 1); name = name.substring(name.lastIndexOf("/") + 1); } Log.debug("DnD: " + path + " -> " + name); //TODO: parse "\\" if(!path.trim().equals("")) { ((LocalDir) localDir).chdir(path); } ((LocalDir) localDir).startTransfer(new DirEntry(name, ((ActionListener) localDir))); } else { Log.debug("Dragging multiple files or dirs is not yet supported."); } } class DTListener implements DropTargetListener { public void dragEnter(DropTargetDragEvent e) { e.acceptDrag(JFtp.acceptableActions); } public void dragOver(DropTargetDragEvent e) { e.acceptDrag(JFtp.acceptableActions); } public void dropActionChanged(DropTargetDragEvent e) { e.acceptDrag(JFtp.acceptableActions); } public void dragExit(DropTargetEvent e) { } public void drop(DropTargetDropEvent e) { try { handleDrop(e, e.getTransferable()); e.dropComplete(true); UpdateDaemon.updateRemoteDir(); } catch(Throwable t) { t.printStackTrace(); e.dropComplete(false); return; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -