Skip to content

Commit

Permalink
Merge pull request #89 from subhra74/lazy-int
Browse files Browse the repository at this point in the history
Lazy int
  • Loading branch information
subhra74 authored Feb 7, 2020
2 parents ca2cdc9 + 999a061 commit 1e83813
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
20 changes: 18 additions & 2 deletions src/main/java/snowflake/components/files/FileComponentHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -65,14 +69,25 @@ public class FileComponentHolder extends JPanel implements FileTransferProgress,
private FileSearchPanel fileSearchPanel;
private SessionContent sessionContent;
private Map<String, List<FileInfo>> 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();
Expand Down Expand Up @@ -116,6 +131,7 @@ public void mouseClicked(MouseEvent e) {


contentPane.add(tabs);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package snowflake.components.main;
public interface LazyInitComponent{
public void lazyInit();
}
8 changes: 8 additions & 0 deletions src/main/java/snowflake/components/main/SessionContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/snowflake/components/terminal/TerminalHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import snowflake.App;
import snowflake.components.newsession.SessionInfo;
import snowflake.components.main.*;
import snowflake.components.terminal.snippets.SnippetPanel;

import javax.swing.*;
import java.awt.*;
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 {
import java.util.concurrent.atomic.*;

public class TerminalHolder extends JPanel implements AutoCloseable , LazyInitComponent{
private SessionInfo info;
private DefaultComboBoxModel<TerminalComponent> terminals;
private JComboBox<TerminalComponent> cmbTerminals;
Expand All @@ -21,14 +24,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 -> {
Expand Down Expand Up @@ -128,7 +138,8 @@ public void componentShown(ComponentEvent e) {
requestFocusInWindow();
}
});
}

}

private void showSnippets() {
this.snippetPanel.loadSnippets();
Expand All @@ -145,6 +156,7 @@ private void showSnippets() {
}

public void createNewTerminal(String command) {
lazyInit();
int count = terminals.getSize();
TerminalComponent tc = new TerminalComponent(info, c + "", command);
c++;
Expand All @@ -154,12 +166,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() {
Expand Down

0 comments on commit 1e83813

Please sign in to comment.