From f90af0bfc9e352b3fae8234cf591f56dd4c3c8dd Mon Sep 17 00:00:00 2001 From: subhra74 Date: Fri, 7 Feb 2020 11:02:33 +0100 Subject: [PATCH 1/6] Create LazyInitComponent.java --- .../java/snowflake/components/main/LazyInitComponent.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/snowflake/components/main/LazyInitComponent.java diff --git a/src/main/java/snowflake/components/main/LazyInitComponent.java b/src/main/java/snowflake/components/main/LazyInitComponent.java new file mode 100644 index 00000000..59f2ee82 --- /dev/null +++ b/src/main/java/snowflake/components/main/LazyInitComponent.java @@ -0,0 +1,4 @@ +package snowflake.components.main; +public interface LazyInitComponent{ +public void lazyInit(); +} From 17e18b114f09d74952701608d0fba6c724b23ffc Mon Sep 17 00:00:00 2001 From: subhra74 Date: Fri, 7 Feb 2020 11:12:46 +0100 Subject: [PATCH 2/6] Update FileComponentHolder.java --- .../components/files/FileComponentHolder.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/snowflake/components/files/FileComponentHolder.java b/src/main/java/snowflake/components/files/FileComponentHolder.java index ba80bdce..7b13db5c 100644 --- a/src/main/java/snowflake/components/files/FileComponentHolder.java +++ b/src/main/java/snowflake/components/files/FileComponentHolder.java @@ -20,6 +20,9 @@ import snowflake.components.files.transfer.TransferProgressPanel; import snowflake.components.main.ConnectedResource; import snowflake.components.main.SessionContent; + +import snowflake.components.main.LazyInitComponent; + import snowflake.components.newsession.SessionInfo; import snowflake.components.newsession.SessionStore; import snowflake.utils.PathUtils; @@ -40,7 +43,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiConsumer; -public class FileComponentHolder extends JPanel implements FileTransferProgress, ConnectedResource { + +public class FileComponentHolder extends JPanel implements FileTransferProgress, ConnectedResource, LazyInitComponent { private ExecutorService threadPool = Executors.newSingleThreadExecutor(); private static final int DEFAULT_APP = 10, DEFAULT_EDITOR = 20; private JRootPane rootPane; @@ -65,14 +69,25 @@ public class FileComponentHolder extends JPanel implements FileTransferProgress, private FileSearchPanel fileSearchPanel; private SessionContent sessionContent; private Map> directoryCache = new ConcurrentHashMap<>(); + private AtomicBoolean init=new AtomicBoolean(false); public FileComponentHolder(SessionInfo info, ExternalEditor externalEditor, SessionContent sessionContent) { super(new BorderLayout()); - setOpaque(true); + this.sessionContent = sessionContent; //setBorder(new LineBorder(new Color(200, 200, 200), 1)); this.externalEditor = externalEditor; this.info = info; + + } + + @Override + public void lazyInit() { + if(init.get()){ + return; + } + init.set(true); + setOpaque(true); contentPane = new JPanel(new BorderLayout()); contentPane.setOpaque(true); rootPane = new JRootPane(); @@ -116,6 +131,7 @@ public void mouseClicked(MouseEvent e) { contentPane.add(tabs); + } @Override From ecb769196abe531a3243d8d32cb6ee2f1158645a Mon Sep 17 00:00:00 2001 From: subhra74 Date: Fri, 7 Feb 2020 11:21:03 +0100 Subject: [PATCH 3/6] Update TerminalHolder.java --- .../components/terminal/TerminalHolder.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/snowflake/components/terminal/TerminalHolder.java b/src/main/java/snowflake/components/terminal/TerminalHolder.java index 6217d122..cbe73fab 100644 --- a/src/main/java/snowflake/components/terminal/TerminalHolder.java +++ b/src/main/java/snowflake/components/terminal/TerminalHolder.java @@ -2,6 +2,7 @@ import snowflake.App; import snowflake.components.newsession.SessionInfo; +import snowflake.components.main.*; import snowflake.components.terminal.snippets.SnippetPanel; import javax.swing.*; @@ -9,9 +10,9 @@ import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.*; -public class TerminalHolder extends JPanel implements AutoCloseable { +public class TerminalHolder extends JPanel implements AutoCloseable , LazyInitComponent{ private SessionInfo info; private DefaultComboBoxModel terminals; private JComboBox cmbTerminals; @@ -21,14 +22,21 @@ public class TerminalHolder extends JPanel implements AutoCloseable { private ExecutorService threadPool = Executors.newFixedThreadPool(1); private JPopupMenu snippetPopupMenu; private SnippetPanel snippetPanel; - +private AtomicBoolean init=new AtomicBoolean(false); private int c = 1; public TerminalHolder(SessionInfo info) { super(new BorderLayout()); - card = new CardLayout(); + this.info = info; + } + +public void lazyInit(){ +if(init.get()){ +return;} +init.set(true); +card = new CardLayout(); content = new JPanel(card); - this.info = info; + this.terminals = new DefaultComboBoxModel<>(); this.cmbTerminals = new JComboBox<>(terminals); this.cmbTerminals.addItemListener(e -> { @@ -128,7 +136,8 @@ public void componentShown(ComponentEvent e) { requestFocusInWindow(); } }); - } + +} private void showSnippets() { this.snippetPanel.loadSnippets(); @@ -145,6 +154,7 @@ private void showSnippets() { } public void createNewTerminal(String command) { +lazyInit(); int count = terminals.getSize(); TerminalComponent tc = new TerminalComponent(info, c + "", command); c++; @@ -154,12 +164,7 @@ public void createNewTerminal(String command) { } public void createNewTerminal() { - int count = terminals.getSize(); - TerminalComponent tc = new TerminalComponent(info, c + "", null); - c++; - content.add(tc, tc.hashCode() + ""); - terminals.addElement(tc); - cmbTerminals.setSelectedIndex(count); + createNewTerminal(null); } public void removeTerminal() { From bdd8f8e1e071867ffbca5fad6be0e42f60d58889 Mon Sep 17 00:00:00 2001 From: subhra74 Date: Fri, 7 Feb 2020 11:24:56 +0100 Subject: [PATCH 4/6] Update SessionContent.java --- .../java/snowflake/components/main/SessionContent.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/snowflake/components/main/SessionContent.java b/src/main/java/snowflake/components/main/SessionContent.java index dd004ecd..30fa1323 100644 --- a/src/main/java/snowflake/components/main/SessionContent.java +++ b/src/main/java/snowflake/components/main/SessionContent.java @@ -240,6 +240,14 @@ void panelClicked(JPanel panel) { for (Component child : panel1.getComponents()) { child.setForeground(Color.WHITE); } + +if(panel.getName().equals(SnowflakePanel.TERMINAL.getName())){ +this.terminalHolder.lazyInit(); +}else if(panel.getName().equals(SnowflakePanel.FILES.getName())){ +this.fileComponentHolder.lazyInit(); +} + + //panel.requestFocusInWindow(); } else { panel1.setBackground(bg); From 8990a5a4f5a2c45487c837085db0be2c9c05b7c3 Mon Sep 17 00:00:00 2001 From: subhra74 Date: Fri, 7 Feb 2020 11:27:58 +0100 Subject: [PATCH 5/6] Update TerminalHolder.java --- src/main/java/snowflake/components/terminal/TerminalHolder.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/snowflake/components/terminal/TerminalHolder.java b/src/main/java/snowflake/components/terminal/TerminalHolder.java index cbe73fab..9f1d1565 100644 --- a/src/main/java/snowflake/components/terminal/TerminalHolder.java +++ b/src/main/java/snowflake/components/terminal/TerminalHolder.java @@ -12,6 +12,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + public class TerminalHolder extends JPanel implements AutoCloseable , LazyInitComponent{ private SessionInfo info; private DefaultComboBoxModel terminals; From 999a061c4a1e2761b45c4ff077d10d2627ad055d Mon Sep 17 00:00:00 2001 From: subhra74 Date: Fri, 7 Feb 2020 11:31:54 +0100 Subject: [PATCH 6/6] Update SessionContent.java --- src/main/java/snowflake/components/main/SessionContent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/snowflake/components/main/SessionContent.java b/src/main/java/snowflake/components/main/SessionContent.java index 30fa1323..7592544a 100644 --- a/src/main/java/snowflake/components/main/SessionContent.java +++ b/src/main/java/snowflake/components/main/SessionContent.java @@ -241,9 +241,9 @@ void panelClicked(JPanel panel) { child.setForeground(Color.WHITE); } -if(panel.getName().equals(SnowflakePanel.TERMINAL.getName())){ +if(panel.getName().equals(SnowFlakePanel.TERMINAL.getName())){ this.terminalHolder.lazyInit(); -}else if(panel.getName().equals(SnowflakePanel.FILES.getName())){ +}else if(panel.getName().equals(SnowFlakePanel.FILES.getName())){ this.fileComponentHolder.lazyInit(); }