Skip to content

Commit

Permalink
flatlaf integration
Browse files Browse the repository at this point in the history
  • Loading branch information
subhra74 committed Jan 5, 2024
1 parent c954086 commit 40c508e
Show file tree
Hide file tree
Showing 74 changed files with 804 additions and 590 deletions.
15 changes: 13 additions & 2 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<version>1.7.30</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
<dependency>
<!--<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.12.1</version>
Expand All @@ -57,7 +57,7 @@
<version>5.7.0</version>
<scope>compile</scope>
</dependency>

-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -137,6 +137,17 @@
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.formdev/flatlaf-extras -->
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf-extras</artifactId>
<version>3.2</version>
</dependency>

</dependencies>

Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/muon/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package muon;

import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
import muon.screens.appwin.MainContainer;
import muon.screens.dialogs.BannerDialog;
import muon.screens.dialogs.UserInputDialog;
Expand All @@ -11,6 +13,7 @@
import muon.widgets.CustomFrame;

import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;

/**
Expand Down Expand Up @@ -42,7 +45,17 @@ public static JFrame getAppWindow() {
public static void main(String[] args) throws InterruptedException, InvocationTargetException, UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
System.setProperty("sun.java2d.metal", "false");
System.setProperty("apple.awt.application.appearance", "system");
UIManager.setLookAndFeel(new FlatLookAndFeel());

FlatMacDarkLaf.setup();
//UIManager.setLookAndFeel(new FlatLookAndFeel());
UIManager.put("SplitPaneDivider.style","plain");
UIManager.put("Tree.showDefaultIcons",true);
UIManager.put("Tree.rendererMargins",5);
UIManager.put("Tree.showsRootHandles",true);
UIManager.put("Tree.rendererMargins",5);
UIManager.put("Tree.leftChildIndent",5);
UIManager.put("Tree.rightChildIndent",5);


var isWindows = "windows".equalsIgnoreCase(System.getProperty("os.name"));

Expand Down
109 changes: 66 additions & 43 deletions app/src/main/java/muon/screens/appwin/MainContainer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package muon.screens.appwin;

import com.formdev.flatlaf.extras.FlatSVGIcon;
import muon.AppContext;
import muon.exceptions.AuthenticationException;
import muon.screens.appwin.tabs.filebrowser.DualPaneFileBrowser;
Expand All @@ -14,34 +15,56 @@
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

public class MainContainer extends JPanel implements AppWin {
private JPanel contentPanel;
//private JPanel contentPanel;
private DualPaneFileBrowser dualPaneFileBrowser;
private TabbedTerminal tabbedTerminal;
private AtomicBoolean init = new AtomicBoolean(false);
private BottomTabItem tabs[];
private JPasswordField txtPassword;
private JButton btnPassword;

private ImageIcon createIcon(String name, int size) {
FlatSVGIcon.ColorFilter filter = new FlatSVGIcon.ColorFilter();
filter.add(Color.BLACK, Color.GRAY);
FlatSVGIcon icon = null;
try {
icon = new FlatSVGIcon(getClass().getResourceAsStream("/icons/" + name));
icon.setColorFilter(filter);
return icon.derive(size, size);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public MainContainer() {
super(new CardLayout());
setBorder(new MatteBorder(1, 0, 0, 0, UIManager.getColor("TableHeader.bottomSeparatorColor")));
var tabs = new JTabbedPane();
tabs.setTabPlacement(JTabbedPane.BOTTOM);

dualPaneFileBrowser = new DualPaneFileBrowser(this);
tabbedTerminal = new TabbedTerminal();

contentPanel = new JPanel(new CardLayout());
contentPanel.add(dualPaneFileBrowser, "FILES");
contentPanel.add(tabbedTerminal, "TERM");
tabs.addTab("File Browser", createIcon("folder-fill.svg", 16), dualPaneFileBrowser);
tabs.addTab("Remote Terminal", createIcon("terminal-box-fill.svg", 16), tabbedTerminal);
tabs.addTab("Port Forwarding", createIcon("swap-box-fill.svg", 16), new JPanel());
tabs.addTab("Key Manager", createIcon("key-fill.svg", 16), new JPanel());

var panel = new JPanel(new BorderLayout());
panel.add(contentPanel);
panel.add(createBottomTabs(), BorderLayout.SOUTH);
// contentPanel = new JPanel(new CardLayout());
// contentPanel.add(dualPaneFileBrowser, "FILES");
// contentPanel.add(tabbedTerminal, "TERM");
//
// var panel = new JPanel(new BorderLayout());
// panel.add(contentPanel);
// panel.add(createBottomTabs(), BorderLayout.SOUTH);

this.add(createProgressPanel(), "PROGRESS");
this.add(createPasswordPanel(), "PASSWORD");
this.add(panel, "CONTENT");
this.add(tabs, "CONTENT");

this.addComponentListener(new ComponentAdapter() {
@Override
Expand All @@ -64,7 +87,7 @@ public void componentResized(ComponentEvent e) {

private void initContent() {
((CardLayout) this.getLayout()).show(this, "CONTENT");
((CardLayout) contentPanel.getLayout()).show(contentPanel, "FILES");
// ((CardLayout) contentPanel.getLayout()).show(contentPanel, "FILES");
revalidate();
repaint();
dualPaneFileBrowser.init();
Expand All @@ -83,40 +106,40 @@ private void loadInitialSessionContext() {
});
}

private Container createBottomTabs() {
String[] str = new String[]{"FILES", "TERM"};
ActionListener tabSelection = e -> {
for (var i = 0; i < tabs.length; i++) {
tabs[i].setSelected(e.getSource() == tabs[i]);
if (e.getSource() == tabs[i] && i < str.length) {
((CardLayout) contentPanel.getLayout()).show(contentPanel, str[i]);
}
}
};

var box = Box.createHorizontalBox();
box.setOpaque(true);
box.setBackground(AppTheme.INSTANCE.getDarkControlBackground());

var btnFiles = new BottomTabItem(IconCode.RI_FOLDER_FILL, "File Browser", tabSelection);
var btnTerminal = new BottomTabItem(IconCode.RI_TERMINAL_BOX_FILL, "Remote Terminal", tabSelection);
var btnPortFwd = new BottomTabItem(IconCode.RI_SWAP_BOX_FILL, "Port Forwarding", tabSelection);
var btnKeyMgr = new BottomTabItem(IconCode.RI_KEY_FILL, "Key Manager", tabSelection);

tabs = new BottomTabItem[]{btnFiles, btnTerminal, btnPortFwd, btnKeyMgr};

btnFiles.setBackground(AppTheme.INSTANCE.getBackground());
//AppUtils.makeEqualSize(btnFiles, btnTerminal, btnPortFwd, btnKeyMgr);

box.add(btnFiles);
box.add(btnTerminal);
box.add(btnPortFwd);
box.add(btnKeyMgr);
box.add(Box.createHorizontalGlue());

box.setBorder(new MatteBorder(1, 0, 0, 0, AppTheme.INSTANCE.getButtonBorderColor()));
return box;
}
// private Container createBottomTabs() {
// String[] str = new String[]{"FILES", "TERM"};
// ActionListener tabSelection = e -> {
// for (var i = 0; i < tabs.length; i++) {
// tabs[i].setSelected(e.getSource() == tabs[i]);
// if (e.getSource() == tabs[i] && i < str.length) {
// ((CardLayout) contentPanel.getLayout()).show(contentPanel, str[i]);
// }
// }
// };
//
// var box = Box.createHorizontalBox();
// box.setOpaque(true);
// box.setBackground(AppTheme.INSTANCE.getDarkControlBackground());
//
// var btnFiles = new BottomTabItem(IconCode.RI_FOLDER_FILL, "File Browser", tabSelection);
// var btnTerminal = new BottomTabItem(IconCode.RI_TERMINAL_BOX_FILL, "Remote Terminal", tabSelection);
// var btnPortFwd = new BottomTabItem(IconCode.RI_SWAP_BOX_FILL, "Port Forwarding", tabSelection);
// var btnKeyMgr = new BottomTabItem(IconCode.RI_KEY_FILL, "Key Manager", tabSelection);
//
// tabs = new BottomTabItem[]{btnFiles, btnTerminal, btnPortFwd, btnKeyMgr};
//
// btnFiles.setBackground(AppTheme.INSTANCE.getBackground());
// //AppUtils.makeEqualSize(btnFiles, btnTerminal, btnPortFwd, btnKeyMgr);
//
// box.add(btnFiles);
// box.add(btnTerminal);
// box.add(btnPortFwd);
// box.add(btnKeyMgr);
// box.add(Box.createHorizontalGlue());
//
// box.setBorder(new MatteBorder(1, 0, 0, 0, AppTheme.INSTANCE.getButtonBorderColor()));
// return box;
// }

private JPanel createPasswordPanel() {
var lbl = new JLabel("Unlock with master password");
Expand Down
Loading

0 comments on commit 40c508e

Please sign in to comment.