Перенос.
This commit is contained in:
37
src/GlobalData/RemoteFile/RemoteFile.java
Normal file
37
src/GlobalData/RemoteFile/RemoteFile.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package GlobalData.RemoteFile;
|
||||
import java.io.Serializable;
|
||||
public class RemoteFile implements Serializable {
|
||||
public String name;
|
||||
public String full_name;
|
||||
public String parent;
|
||||
public boolean isDirectory;
|
||||
public long updateTime;
|
||||
public RemoteFile(String path, boolean isDirectory_in) {
|
||||
full_name = path;
|
||||
isDirectory = isDirectory_in;
|
||||
String[] data = full_name.split("/");
|
||||
name = (data.length > 0) ? data[data.length - 1] : "";
|
||||
int i = full_name.lastIndexOf('/');
|
||||
parent = (i > 0) ? full_name.substring(0, i) : "/";
|
||||
}
|
||||
public RemoteFile(String parent_in, String name_in, boolean isDirectory_in) {
|
||||
parent = parent_in;
|
||||
full_name = parent + (parent.endsWith("/") ? "" : "/") + name_in;
|
||||
name = name_in;
|
||||
isDirectory = isDirectory_in;
|
||||
}
|
||||
public RemoteFile(RemoteFile parent_in, String name_in){
|
||||
this(parent_in.full_name, name_in);
|
||||
}
|
||||
public RemoteFile(String parent_in, String name_in) {
|
||||
this(parent_in, name_in, false);
|
||||
}
|
||||
public static long convertUpdateTime(int mtime) {
|
||||
return (long) mtime * 1000L;
|
||||
}
|
||||
public boolean isDirectory() {
|
||||
return isDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
96
src/GlobalData/RemoteFile/UI/RemoteFileChooser.java
Normal file
96
src/GlobalData/RemoteFile/UI/RemoteFileChooser.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package GlobalData.RemoteFile.UI;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import Common.UI.Windows.Dialog.Dialog;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Vector;
|
||||
public class RemoteFileChooser extends Dialog<String, RemoteFileChooserFields> {
|
||||
public DefaultMutableTreeNode root = new DefaultMutableTreeNode("нет данных");
|
||||
ConnectionPass session;
|
||||
RemoteFile root_file;
|
||||
boolean target_is_directory = false;
|
||||
public RemoteFileChooser() {
|
||||
super(RemoteFileChooserFields.class);
|
||||
}
|
||||
@Override
|
||||
public boolean NeedsScroll() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
session = (ConnectionPass) params[0];
|
||||
target_is_directory = (boolean) params[1];
|
||||
try {
|
||||
Refresh(session.getSftpChannel().pwd());
|
||||
} catch (Exception ex) {
|
||||
Global.Log.PrintException(ex);
|
||||
onCancel(); //закрываем окно.
|
||||
}
|
||||
}
|
||||
public void ShowCurrentRemoteFile() {
|
||||
fields.lCurrentFile.setText(Current.getRemoteFile().full_name);
|
||||
}
|
||||
public void Refresh(String path) {
|
||||
try {
|
||||
Current.set(Current.RemoteFile, null);//сброс текущего файла перед любым обновлением.
|
||||
fields.lCurrentFile.setText("?");
|
||||
//-------------------------------------------------------------------
|
||||
root_file = new RemoteFile(path, true);
|
||||
root = new DefaultMutableTreeNode(root_file);
|
||||
//-------------------------------------------------------
|
||||
Vector<LsEntry> files = session.getSftpChannel().ls(path);
|
||||
Vector<RemoteFile> directories_ = new Vector<>();
|
||||
Vector<RemoteFile> files_ = new Vector<>();
|
||||
//отсортировать по принадлежности.
|
||||
for (LsEntry file : files) {
|
||||
if (!file.getFilename().equals(".") && !file.getFilename().equals("")) {
|
||||
if (file.getAttrs().isDir())
|
||||
directories_.add(new RemoteFile(root_file.full_name, file.getFilename(), true));
|
||||
else
|
||||
files_.add(new RemoteFile(root_file.full_name, file.getFilename(), false));
|
||||
}
|
||||
}
|
||||
//отсортировать по алфавиту
|
||||
Collections.sort(directories_, Comparator.comparing(o -> o.name));
|
||||
Collections.sort(files_, Comparator.comparing(o -> o.name));
|
||||
for (RemoteFile f : directories_)
|
||||
root.add(new DefaultMutableTreeNode(f));
|
||||
for (RemoteFile f : files_)
|
||||
root.add(new DefaultMutableTreeNode(f));
|
||||
//просто пересоздаем дерево
|
||||
fields.treeForm.Show();
|
||||
fields.lCurrentFolder.setText(path);
|
||||
} catch (Exception ex) {
|
||||
Global.Log.PrintException(ex);
|
||||
onCancel();
|
||||
}
|
||||
}
|
||||
public void goHome() {
|
||||
try {
|
||||
Refresh(session.getSftpChannel().getHome());
|
||||
} catch (Exception ex) {
|
||||
Global.Log.PrintException(ex);
|
||||
onCancel(); //закрываем окно.
|
||||
}
|
||||
}
|
||||
public void goUp() {
|
||||
if (!root_file.full_name.equals("/")) {
|
||||
Refresh(root_file.parent);
|
||||
} else UI.Info("Корневая папка файловой системы достигнута.");
|
||||
}
|
||||
@Override
|
||||
public void validateFields() {
|
||||
String target_name = target_is_directory ? "папка" : "файл";
|
||||
if (Current.HasRemoteFile()) {
|
||||
if (target_is_directory != Current.getRemoteFile().isDirectory)
|
||||
Log.Writeln("Выбранный объект - не " + target_name);
|
||||
} else Log.Writeln(target_name + " не выбран(а)");
|
||||
}
|
||||
}
|
||||
109
src/GlobalData/RemoteFile/UI/RemoteFileChooserFields.form
Normal file
109
src/GlobalData/RemoteFile/UI/RemoteFileChooserFields.form
Normal file
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="GlobalData.RemoteFile.UI.RemoteFileChooserFields">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<toolbar id="62a2c">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<floatable value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="3bc36" class="javax.swing.JButton" binding="bBack">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<icon value="icons/Back.png"/>
|
||||
<text value=""/>
|
||||
<toolTipText value="Уровень выше"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="57f3e" class="javax.swing.JButton" binding="bHome">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<icon value="icons/Home.png"/>
|
||||
<text value=""/>
|
||||
<toolTipText value="Домой"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</toolbar>
|
||||
<grid id="a6308" binding="TreePanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<toolbar id="6bcce">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<floatable value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e92d5" class="javax.swing.JLabel">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="1"/>
|
||||
<foreground color="-16777216"/>
|
||||
<text value="Текущая папка: "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b3611" class="javax.swing.JLabel" binding="lCurrentFolder">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="14" style="2"/>
|
||||
<foreground color="-16777216"/>
|
||||
<text value="?"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</toolbar>
|
||||
<toolbar id="1602e">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<floatable value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="bf8aa" class="javax.swing.JLabel">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="1"/>
|
||||
<foreground color="-16777216"/>
|
||||
<text value=" выбрано: "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2408c" class="javax.swing.JLabel" binding="lCurrentFile">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="14" style="2"/>
|
||||
<foreground color="-16777216"/>
|
||||
<text value="?"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</toolbar>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
40
src/GlobalData/RemoteFile/UI/RemoteFileChooserFields.java
Normal file
40
src/GlobalData/RemoteFile/UI/RemoteFileChooserFields.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package GlobalData.RemoteFile.UI;
|
||||
import Common.UI.Trees.TreeForm;
|
||||
import Common.UI.UI;
|
||||
import Common.UI.Windows.Dialog.DialogFields;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
public class RemoteFileChooserFields implements DialogFields {
|
||||
public JPanel MainPanel;
|
||||
public JLabel lCurrentFolder;
|
||||
public JLabel lCurrentFile;
|
||||
public TreeForm treeForm;
|
||||
private JPanel TreePanel;
|
||||
private JButton bBack;
|
||||
private JButton bHome;
|
||||
public RemoteFileChooserFields() {
|
||||
bBack.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
UI.getRemoteFileChooser().goUp();
|
||||
}
|
||||
});
|
||||
bHome.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
UI.getRemoteFileChooser().goHome();
|
||||
}
|
||||
});
|
||||
}
|
||||
private void createUIComponents() {
|
||||
// TODO: place custom component creation code here
|
||||
TreePanel = (treeForm = new TreeForm(RemoteFilesTree.class)).getContent();
|
||||
}
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return MainPanel;
|
||||
}
|
||||
}
|
||||
26
src/GlobalData/RemoteFile/UI/RemoteFileRenderer.java
Normal file
26
src/GlobalData/RemoteFile/UI/RemoteFileRenderer.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package GlobalData.RemoteFile.UI;
|
||||
import Common.Current;
|
||||
import Common.UI.Themes.VisualiserFonts;
|
||||
import Common.UI.Trees.StyledTreeCellRenderer;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
public class RemoteFileRenderer extends StyledTreeCellRenderer {
|
||||
public java.awt.Component getTreeCellRendererComponent(
|
||||
JTree tree, Object value,
|
||||
boolean selected, boolean expanded,
|
||||
boolean leaf, int row, boolean hasFocus) {
|
||||
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
|
||||
Object o = ((DefaultMutableTreeNode) value).getUserObject();
|
||||
if (o instanceof RemoteFile) {
|
||||
RemoteFile file = (RemoteFile) o;
|
||||
setText(file.name);
|
||||
setFont(Current.getTheme().Fonts.get(VisualiserFonts.TreePlain));
|
||||
if (file.isDirectory())
|
||||
setIcon(new ImageIcon(getClass().getResource("/icons/Folder.png")));
|
||||
}
|
||||
setForeground(tree.getForeground());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
28
src/GlobalData/RemoteFile/UI/RemoteFilesTree.java
Normal file
28
src/GlobalData/RemoteFile/UI/RemoteFilesTree.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package GlobalData.RemoteFile.UI;
|
||||
import Common.Current;
|
||||
import Common.UI.Trees.DataTree;
|
||||
import Common.UI.Trees.TreeRenderers;
|
||||
import Common.UI.UI;
|
||||
public class RemoteFilesTree extends DataTree {
|
||||
public RemoteFilesTree() {
|
||||
super(UI.getRemoteFileChooser().root);
|
||||
}
|
||||
@Override
|
||||
public TreeRenderers getRenderer() {
|
||||
return TreeRenderers.RendererRemoteFile;
|
||||
}
|
||||
@Override
|
||||
public Current getCurrent() {
|
||||
return Current.RemoteFile;
|
||||
}
|
||||
@Override
|
||||
public void ShowCurrentObject() {
|
||||
UI.getRemoteFileChooser().ShowCurrentRemoteFile();
|
||||
}
|
||||
@Override
|
||||
public void LeftMouseAction2() {
|
||||
if (Current.HasRemoteFile() && Current.getRemoteFile().isDirectory()) {
|
||||
UI.getRemoteFileChooser().Refresh(Current.getRemoteFile().full_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user