Set up basic UI
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/* Author: Maple
|
||||
* Jan. 18 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.webclient.ui;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.webclient.Main;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
|
||||
public class TopBar extends JPanel {
|
||||
@Getter
|
||||
private MenuButton closeButton, minimizeButton, maximizeButton;
|
||||
|
||||
@Getter
|
||||
private JPanel buttonPanel;
|
||||
|
||||
private Point dragOffset;
|
||||
|
||||
public TopBar() {
|
||||
this.setPreferredSize(new Dimension(0, 40));
|
||||
|
||||
this.buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
|
||||
this.closeButton = new MenuButton("X", MenuButton.ClickAction.CLOSE);
|
||||
this.minimizeButton = new MenuButton("-", MenuButton.ClickAction.MINIMIZE);
|
||||
this.maximizeButton = new MenuButton("[]", MenuButton.ClickAction.MAXIMIZE);
|
||||
|
||||
this.buttonPanel.add(this.closeButton);
|
||||
this.buttonPanel.add(this.minimizeButton);
|
||||
this.buttonPanel.add(this.maximizeButton);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
Point mouseOnScreen = e.getLocationOnScreen();
|
||||
Point frameLocation = Main.mainFrame.getLocation();
|
||||
|
||||
dragOffset = new Point(
|
||||
mouseOnScreen.x - frameLocation.x,
|
||||
mouseOnScreen.y - frameLocation.y
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
dragOffset = null;
|
||||
}
|
||||
});
|
||||
|
||||
this.addMouseMotionListener(new MouseMotionAdapter() {
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if (dragOffset != null) {
|
||||
Point mouseOnScreen = e.getLocationOnScreen();
|
||||
|
||||
int newX = mouseOnScreen.x - dragOffset.x;
|
||||
int newY = mouseOnScreen.y - dragOffset.y;
|
||||
|
||||
Main.mainFrame.setLocation(newX, newY);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void initButtonPanel(String alignment) {
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
this.add(this.buttonPanel, alignment);
|
||||
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user