Skip to content

Commit

Permalink
latest dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
subhra74 committed Aug 5, 2023
1 parent 5cca325 commit 5ba2fe7
Show file tree
Hide file tree
Showing 222 changed files with 1,112 additions and 26 deletions.
2 changes: 1 addition & 1 deletion muon-main/pom.xml → app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>muon-main</artifactId>
<artifactId>app</artifactId>
<packaging>jar</packaging>

<name>muon-main</name>
Expand Down
426 changes: 426 additions & 0 deletions app/src/main/java/muon/App.java

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions app/src/main/java/muon/ui/styles/AppTheme.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package muon.ui.styles;

import java.awt.*;

public class AppTheme {
public static final AppTheme INSTANCE=new AppTheme();

public Color getBackground(){
return new Color(31, 31, 31);
}

public Color getTabSelectionColor(){
return new Color(52, 117, 233);
}
}
80 changes: 80 additions & 0 deletions app/src/main/java/muon/ui/styles/FlatButtonUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package muon.ui.styles;

import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import java.awt.*;

public class FlatButtonUI extends BasicButtonUI {
static FlatButtonUI buttonUI;

public static ComponentUI createUI(JComponent c) {
if (buttonUI == null) {
buttonUI = new FlatButtonUI();
}
return buttonUI;
}

@Override
public void installUI(JComponent c) {
super.installUI(c);
if (c instanceof JButton) {
JButton btn = (JButton) c;
}
}

protected void paintButtonNormal(Graphics g, AbstractButton b) {
if (!b.isOpaque()) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.setPaint(b.getBackground());
g2.fillRect(0, 0, b.getWidth(), b.getHeight());
}
}

protected void paintButtonPressed(Graphics g, AbstractButton b) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.setColor(b.getBackground());
// Color color = (Color) b.getClientProperty("xdmbutton.pressedcolor");
// if (color != null) {
// g2.setPaint(color);
// } else {
// g2.setPaint(Color.GRAY);
// }
g2.fillRect(0, 0, b.getWidth(), b.getHeight());
}

protected void paintButtonRollOver(Graphics g, AbstractButton b) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
// if (b.getClientProperty("xdmbutton.grayrollover") != null) {
// g2.setPaint(Color.DARK_GRAY);
// } else {
// g2.setPaint(ColorResource.getSelectionColor());
// }
g2.setColor(b.getBackground());
g2.fillRect(0, 0, b.getWidth(), b.getHeight());
}

public void paint(Graphics g, JComponent c) {
try {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

AbstractButton b = (AbstractButton) c;
ButtonModel bm = b.getModel();
if (bm.isRollover()) {
paintButtonRollOver(g2, b);
} else {
paintButtonNormal(g2, b);
}
super.paint(g2, c);
} catch (Exception e) {
}
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/muon/ui/styles/FlatLookAndFeel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package muon.ui.styles;

import javax.swing.plaf.basic.BasicLookAndFeel;

public class FlatLookAndFeel extends BasicLookAndFeel {
@Override
public String getName() {
return "FlatLookAndFeel";
}

@Override
public String getID() {
return "FlatLookAndFeel";
}

@Override
public String getDescription() {
return "FlatLookAndFeel";
}

@Override
public boolean isNativeLookAndFeel() {
return false;
}

@Override
public boolean isSupportedLookAndFeel() {
return true;
}
}
26 changes: 26 additions & 0 deletions app/src/main/java/muon/ui/widgets/HomePanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package muon.ui.widgets;

import muon.ui.styles.AppTheme;
import muon.ui.styles.FlatButtonUI;

import javax.swing.*;
import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.*;

public class HomePanel extends JPanel {
public HomePanel() {
super(null);
setBackground(AppTheme.INSTANCE.getBackground());
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
var iconLabel = new JLabel("Jdadasdasd");
iconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
var btn2 = new JButton("Jdadasdasd");
btn2.setUI(new FlatButtonUI());
btn2.setAlignmentX(Component.CENTER_ALIGNMENT);
add(Box.createVerticalGlue());
add(iconLabel);
add(Box.createRigidArea(new Dimension(0,10)));
add(btn2);
add(Box.createVerticalGlue());
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/muon/ui/widgets/TabEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package muon.ui.widgets;

import java.awt.event.ActionEvent;

public class TabEvent extends ActionEvent {
private int selectedIndex;

public TabEvent(Object source, int index) {
super(source, index, "tab_event");
this.selectedIndex = index;
}

public int getSelectedIndex() {
return selectedIndex;
}

public void setSelectedIndex(int selectedIndex) {
this.selectedIndex = selectedIndex;
}
}
165 changes: 165 additions & 0 deletions app/src/main/java/muon/ui/widgets/TabItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package muon.ui.widgets;

import muon.util.FontIcon;
import muon.util.IconFont;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Objects;

public class TabItem extends JComponent {
private JLabel tabIconLabel;
private JLabel tabTitle;
private JLabel tabCloseButton;
private boolean isSelected;
private boolean isStretchable, isCloseButtonHidden;
private Color selectionColor, backgroundColor, iconColor, closeButtonColor, selectionBackground, titleColor, selectedTitleColor;
private Border selectedBorder, unselectedBorder;
private FontIcon titleIcon, closeIcon;
private ActionListener tabClicked, closeClicked;

public TabItem(FontIcon titleIcon, FontIcon closeIcon,
Color selectionColor, boolean isSelected,
Color backgroundColor, boolean hideCloseButton,
Color iconColor, Color closeButtonColor,
Color selectionBackground, Color titleColor,
Color selectedTitleColor, boolean isStretchable,
ActionListener tabClicked, ActionListener closeClicked) {
super();

this.titleIcon = titleIcon;
this.closeIcon = closeIcon;
this.selectionColor = selectionColor;
this.isSelected = isSelected;
this.isStretchable = isStretchable;
this.iconColor = iconColor;
this.closeButtonColor = closeButtonColor;
this.selectionBackground = selectionBackground;
this.backgroundColor = backgroundColor;
this.isCloseButtonHidden = hideCloseButton;
this.titleColor = titleColor;
this.selectedTitleColor = selectedTitleColor;
this.selectedBorder = createBorder(selectionColor);
this.unselectedBorder = createBorder(backgroundColor);
if (Objects.nonNull(titleIcon)) {
this.tabIconLabel = new JLabel();
this.tabIconLabel.setFont(IconFont.getSharedInstance().getIconFont(18.0f));
}
this.tabTitle = new JLabel();
this.tabTitle.setMinimumSize(new Dimension(0, 0));
this.tabTitle.setFont(new Font(Font.DIALOG, Font.PLAIN, 12));
this.tabTitle.setBorder(new EmptyBorder(0, 10, 2, 10));
if (Objects.nonNull(closeIcon)) {
this.tabCloseButton = new JLabel();
this.tabCloseButton.setFont(IconFont.getSharedInstance().getIconFont(18.0f));
this.tabCloseButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (closeClicked != null) {
closeClicked.actionPerformed(new ActionEvent(TabItem.this,
TabItem.this.hashCode(),
"tab_close"));
}
}
});
}

setOpaque(true);
if (isStretchable) {
setLayout(new BorderLayout(10, 10));
add(tabIconLabel, BorderLayout.WEST);
add(tabTitle);
add(tabCloseButton, BorderLayout.EAST);
} else {
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
add(tabIconLabel);
add(tabTitle);
add(tabCloseButton);
}
setSelected(isSelected);

addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (tabClicked != null) {
tabClicked.actionPerformed(new ActionEvent(TabItem.this,
TabItem.this.hashCode(),
"tab_click"));
}
}

@Override
public void mouseEntered(MouseEvent e) {
if (isCloseButtonHidden) {
tabCloseButton.setForeground(closeButtonColor);
}
}

@Override
public void mouseExited(MouseEvent e) {
if (isCloseButtonHidden) {
tabCloseButton.setForeground(getBackground());
}
}
});
}

public void setTabTitle(String title) {
tabTitle.setText(title);
}

public void setSelected(boolean selected) {
this.isSelected = selected;
updateStyles();
}

public boolean isSelected() {
return isSelected;
}

protected void paintComponent(Graphics g) {
if (isOpaque()) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
}
}

private void updateStyles() {
if (isSelected) {
setBackground(selectionBackground);
tabTitle.setForeground(selectedTitleColor);
setBorder(selectedBorder);
} else {
setBackground(backgroundColor);
tabTitle.setForeground(titleColor);
setBorder(unselectedBorder);
}
if (tabIconLabel != null) {
tabIconLabel.setForeground(iconColor);
tabIconLabel.setText(titleIcon.getValue());
}
if (tabCloseButton != null) {
tabCloseButton.setForeground(isCloseButtonHidden ? getBackground() : closeButtonColor);
tabCloseButton.setText(closeIcon.getValue());
}
revalidate();
repaint();
}

private Border createBorder(Color color) {
return new CompoundBorder(
new MatteBorder(1, 0, 0, 0,
color),
new EmptyBorder(5, 10, 5, 10)
);
}

}
9 changes: 9 additions & 0 deletions app/src/main/java/muon/ui/widgets/TabListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package muon.ui.widgets;

public interface TabListener {
void selectionChanged(TabEvent e);

boolean tabClosing(TabEvent e);

void tabClosed(TabEvent e);
}
18 changes: 18 additions & 0 deletions app/src/main/java/muon/ui/widgets/TabSelectionEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package muon.ui.widgets;

import java.awt.event.ActionEvent;

public class TabSelectionEvent extends ActionEvent {
private int selectedIndex;
public TabSelectionEvent(Object source, int index) {
super(source, index, "tab_selection");
}

public int getSelectedIndex() {
return selectedIndex;
}

public void setSelectedIndex(int selectedIndex) {
this.selectedIndex = selectedIndex;
}
}
Loading

0 comments on commit 5ba2fe7

Please sign in to comment.