Destiny.Lin
2 months ago
51 changed files with 981 additions and 673 deletions
@ -0,0 +1,59 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
import com.fr.design.gui.date.UICalendarPanel; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.border.LineBorder; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import javax.swing.plaf.PanelUI; |
||||
import java.awt.Color; |
||||
|
||||
|
||||
/** |
||||
* {@link UICalendarPanel} 的 UI 样式 |
||||
* |
||||
* @author lemon |
||||
* @since 12.0 |
||||
* Created on 2024/09/22 |
||||
*/ |
||||
public class FineCalendarPaneUI extends PanelUI { |
||||
protected Color defaultBackground; |
||||
|
||||
/** |
||||
* @param shared |
||||
* @since 2 |
||||
*/ |
||||
protected FineCalendarPaneUI() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* 创建UI |
||||
* |
||||
* @param c 组件 |
||||
* @return ComponentUI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return FlatUIUtils.createSharedUI(FineCalendarPaneUI.class, FineCalendarPaneUI::new); |
||||
} |
||||
|
||||
/** |
||||
* @param c the component where this UI delegate is being installed |
||||
*/ |
||||
public void installUI(JComponent c) { |
||||
super.installUI(c); |
||||
defaultBackground = UIManager.getColor("Calendar.background"); |
||||
|
||||
//renderer this
|
||||
c.setBackground(defaultBackground); |
||||
c.setBorder(new LineBorder(FlatUIUtils.getUIColor("defaultBorderColor", Color.BLACK))); |
||||
} |
||||
|
||||
@Override |
||||
public void uninstallUI(JComponent c) { |
||||
super.uninstallUI(c); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,140 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.formdev.flatlaf.ui.FlatLabelUI; |
||||
import com.formdev.flatlaf.ui.FlatRoundBorder; |
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
import com.fr.design.gui.date.UIDayLabel; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.FontMetrics; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
|
||||
/** |
||||
* {@link UIDayLabel} 的 UI 样式 |
||||
* |
||||
* @author lemon |
||||
* @since 12.0 |
||||
* Created on 2024/09/22 |
||||
*/ |
||||
public class FineDayLabelUI extends FlatLabelUI { |
||||
protected Color defaultBackground; |
||||
protected Color selectedBackground; |
||||
protected Color hoverBackground; |
||||
protected Color pressedBackground; |
||||
protected Color otherMonthForeground; |
||||
|
||||
protected int arc; |
||||
|
||||
/** |
||||
* @since 2 |
||||
*/ |
||||
protected FineDayLabelUI() { |
||||
super(false); |
||||
} |
||||
|
||||
/** |
||||
* 创建UI |
||||
* |
||||
* @param c 组件 |
||||
* @return ComponentUI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return FlatUIUtils.createSharedUI(FineDayLabelUI.class, FineDayLabelUI::new); |
||||
} |
||||
|
||||
/** |
||||
* @param c the component where this UI delegate is being installed |
||||
*/ |
||||
public void installUI(JComponent c) { |
||||
super.installUI(c); |
||||
selectedBackground = UIManager.getColor("Calendar.day.selectedBackground"); |
||||
hoverBackground = UIManager.getColor("Calendar.day.hoverBackground"); |
||||
pressedBackground = UIManager.getColor("Calendar.day.pressedBackground"); |
||||
defaultBackground = UIManager.getColor("Calendar.background"); |
||||
otherMonthForeground = UIManager.getColor("Calendar.dayOtherMonth.foreground"); |
||||
|
||||
arc = UIManager.getInt("Calendar.day.arc"); |
||||
} |
||||
|
||||
@Override |
||||
public void uninstallUI(JComponent c) { |
||||
super.uninstallUI(c); |
||||
} |
||||
|
||||
/** |
||||
* UICalendarPanel paint, 目前只对 {@link UIDayLabel} 样式自定义,其余使用默认样式 |
||||
* |
||||
* @param g the <code>Graphics</code> context in which to paint |
||||
* @param c the component being painted; |
||||
* this argument is often ignored, |
||||
* but might be used if the UI object is stateless |
||||
* and shared by multiple components |
||||
*/ |
||||
public void paint(Graphics g, JComponent c) { |
||||
super.paint(g, c); |
||||
if (c instanceof UIDayLabel) { |
||||
paintDayLabel((UIDayLabel) c); |
||||
} |
||||
} |
||||
|
||||
private void paintDayLabel(UIDayLabel label) { |
||||
if (!label.isSmallLabel()) { |
||||
label.setBackground(getBackgroundColor(label)); |
||||
return; |
||||
} |
||||
|
||||
label.setBorder(new DayLabelRoundedBorder()); |
||||
|
||||
if (!label.isCurrentMonth()) { |
||||
label.setForeground(otherMonthForeground); |
||||
} |
||||
} |
||||
|
||||
private Color getBackgroundColor(UIDayLabel dayLabel) { |
||||
if (dayLabel.isSelected()) { |
||||
return selectedBackground; |
||||
} |
||||
if (dayLabel.isHovered()) { |
||||
return hoverBackground; |
||||
} |
||||
if (dayLabel.isPressed()) { |
||||
return pressedBackground; |
||||
} |
||||
return defaultBackground; |
||||
} |
||||
|
||||
/** |
||||
* {@link UIDayLabel} 的 border 样式 |
||||
*/ |
||||
private class DayLabelRoundedBorder extends FlatRoundBorder { |
||||
|
||||
public DayLabelRoundedBorder() { |
||||
} |
||||
|
||||
@Override |
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
||||
Graphics2D g2 = (Graphics2D) g.create(); |
||||
|
||||
try { |
||||
FlatUIUtils.setRenderingHints(g2); |
||||
g2.setColor(getBackgroundColor((UIDayLabel) c)); |
||||
g2.fillRoundRect(0, 0, width, height, arc, arc); |
||||
|
||||
// 避免文字被背景色覆盖
|
||||
UIDayLabel dayLabel = (UIDayLabel) c; |
||||
g2.setColor(dayLabel.getForeground()); |
||||
FontMetrics metrics = g2.getFontMetrics(dayLabel.getFont()); |
||||
int x1 = (width - metrics.stringWidth(dayLabel.getText())) / 2; |
||||
int y1 = ((height - metrics.getHeight()) / 2) + metrics.getAscent(); |
||||
g2.drawString(dayLabel.getText(), x1, y1); |
||||
} finally { |
||||
g2.dispose(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
|
||||
package com.fr.design.mainframe.toolbar; |
||||
|
||||
import com.fanruan.gui.UiInspector; |
||||
import com.fine.theme.light.ui.laf.FineDarkLaf; |
||||
import com.fine.theme.light.ui.laf.FineLightLaf; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.gui.UILookAndFeel; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.menu.MenuDef; |
||||
import com.fr.design.remote.ui.debug.RemoteDesignNetWorkAction; |
||||
|
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* 调试模式菜单 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/9/24 |
||||
*/ |
||||
public class DebugModeMenuDef extends MenuDef { |
||||
|
||||
public DebugModeMenuDef() { |
||||
super("Debug"); |
||||
addLookAndFeelMenu(); |
||||
addRemotePane(); |
||||
} |
||||
|
||||
private void addUIInspect() { |
||||
this.addShortCut(new UpdateAction() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
new UiInspector().showInspector(DesignerContext.getDesignerFrame()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void addLookAndFeelMenu() { |
||||
MenuDef lookAndFeel = new MenuDef("Look And Feel", 'L'); |
||||
lookAndFeel.addShortCut( |
||||
new LookAndFeelAction(new FineLightLaf()), |
||||
new LookAndFeelAction(new FineDarkLaf()), |
||||
new LookAndFeelAction(new UILookAndFeel()) |
||||
); |
||||
this.addShortCut(lookAndFeel); |
||||
} |
||||
|
||||
private void addRemotePane() { |
||||
this.addShortCut(new RemoteDesignNetWorkAction()); |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.fr.design.remote.ui.debug; |
||||
|
||||
import com.fine.theme.utils.FineUIScale; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrame; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.workspace.WorkContext; |
||||
|
||||
import javax.swing.JDialog; |
||||
import java.awt.Dimension; |
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* 远程设计网络调试 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/9/24 |
||||
*/ |
||||
public class RemoteDesignNetWorkAction extends UpdateAction { |
||||
public static final String TITLE = "Remote Design NetWork"; |
||||
|
||||
public RemoteDesignNetWorkAction() { |
||||
setName(TITLE); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (WorkContext.getCurrent().isLocal()) { |
||||
return; |
||||
} |
||||
JDialog jDialog = new JDialog(DesignerContext.getDesignerFrame(), TITLE); |
||||
jDialog.setSize(calculatePaneDimension()); |
||||
jDialog.add(new RemoteDesignNetWorkTablePane()); |
||||
GUICoreUtils.centerWindow(jDialog); |
||||
jDialog.setVisible(true); |
||||
} |
||||
|
||||
private static Dimension calculatePaneDimension() { |
||||
DesignerFrame parent = DesignerContext.getDesignerFrame(); |
||||
return new Dimension((int) (FineUIScale.unscale(parent.getWidth()) * 0.8), |
||||
(int) (FineUIScale.unscale(parent.getHeight()) * 0.6)); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,109 @@
|
||||
package com.fr.design.remote.ui.debug; |
||||
|
||||
import com.fanruan.workplace.http.debug.RequestInfo; |
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
||||
import com.fr.event.Event; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.event.Listener; |
||||
import com.fr.workspace.WorkContext; |
||||
|
||||
import javax.swing.JPanel; |
||||
import javax.swing.JScrollPane; |
||||
import javax.swing.JTable; |
||||
import javax.swing.table.DefaultTableModel; |
||||
import javax.swing.table.TableCellRenderer; |
||||
import javax.swing.table.TableColumn; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Component; |
||||
import java.text.DecimalFormat; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
|
||||
import static com.fanruan.workplace.http.debug.RemoteDesignDebugEvent.REMOTE_HTTP_REQUEST; |
||||
|
||||
/** |
||||
* 远程设计网络调试面板 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/9/24 |
||||
*/ |
||||
public class RemoteDesignNetWorkTablePane extends JPanel { |
||||
private static final int K = 1024; |
||||
private static final int TWO = 2; |
||||
private JTable uiTable; |
||||
private DefaultTableModel model; |
||||
|
||||
public RemoteDesignNetWorkTablePane() { |
||||
setLayout(new BorderLayout()); |
||||
setBorder(new ScaledEmptyBorder(10, 10, 10, 10)); |
||||
initComponent(); |
||||
initListener(); |
||||
} |
||||
|
||||
private void initComponent() { |
||||
model = new DefaultTableModel(); |
||||
model.addColumn("status"); |
||||
model.addColumn("time"); |
||||
model.addColumn("path"); |
||||
model.addColumn("cost"); |
||||
model.addColumn("request size"); |
||||
model.addColumn("response size"); |
||||
model.addColumn("request"); |
||||
model.addColumn("response"); |
||||
uiTable = new JTable(model); |
||||
add(new JScrollPane(uiTable), BorderLayout.CENTER); |
||||
} |
||||
|
||||
private void initListener() { |
||||
EventDispatcher.listen(REMOTE_HTTP_REQUEST, new Listener<RequestInfo>() { |
||||
@Override |
||||
public void on(Event event, RequestInfo requestInfo) { |
||||
model.addRow(new Object[]{ |
||||
requestInfo.getStatus(), |
||||
dateFormat(requestInfo.getDate()), |
||||
requestInfo.getPath().substring(WorkContext.getCurrent().getPath().length() - 1), |
||||
requestInfo.getConsume() + "ms", |
||||
simpleSize(requestInfo.getRequestSize()), |
||||
simpleSize(requestInfo.getResponseSize()), |
||||
requestInfo.getSendBody(), |
||||
requestInfo.getReturnBody(), |
||||
}); |
||||
adjustColumnWidths(uiTable); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private static void adjustColumnWidths(JTable table) { |
||||
for (int column = 0; column < table.getColumnCount() - TWO; column++) { |
||||
TableColumn tableColumn = table.getColumnModel().getColumn(column); |
||||
int preferredWidth = 20; |
||||
int maxWidth = tableColumn.getMaxWidth(); |
||||
tableColumn.setMinWidth(0); |
||||
// 从最后一行来调整大小
|
||||
int row = table.getRowCount() - 1; |
||||
TableCellRenderer cellRenderer = table.getCellRenderer(row, column); |
||||
Component component = table.prepareRenderer(cellRenderer, row, column); |
||||
int width = component.getPreferredSize().width + table.getIntercellSpacing().width; |
||||
preferredWidth = Math.max(preferredWidth, Math.min(width, maxWidth)); |
||||
tableColumn.setPreferredWidth(preferredWidth); |
||||
} |
||||
} |
||||
|
||||
private static String dateFormat(Date date) { |
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
return dateFormat.format(date); |
||||
} |
||||
|
||||
private static String simpleSize(long bytes) { |
||||
if (bytes < 0) { |
||||
return bytes + ""; |
||||
} else if (bytes < K) { |
||||
return bytes + " B"; |
||||
} else { |
||||
DecimalFormat df = new DecimalFormat("#.00"); |
||||
return df.format((float) bytes / K) + " K"; |
||||
} |
||||
} |
||||
|
||||
} |
After Width: | Height: | Size: 413 B |
After Width: | Height: | Size: 413 B |
File diff suppressed because one or more lines are too long
@ -0,0 +1,32 @@
|
||||
package com.fr.design.gui.storybook.components; |
||||
|
||||
import com.fine.theme.light.ui.FineRoundBorder; |
||||
import com.fr.design.gui.date.UICalendarPanel; |
||||
import com.fr.design.gui.date.UIDatePicker; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.storybook.StoryBoard; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.util.Date; |
||||
|
||||
import static com.fine.swing.ui.layout.Layouts.*; |
||||
|
||||
public class UICalendarPaneStoryBoard extends StoryBoard { |
||||
public UICalendarPaneStoryBoard() { |
||||
super("日期控件"); |
||||
UICalendarPanel calendarPanel = new UICalendarPanel(true); |
||||
calendarPanel.setSelectedDate(new Date()); |
||||
add( |
||||
cell(new UILabel("日期下拉框")).with(this::h3), |
||||
row(cell(new UIDatePicker(2)).with(this::setFixSize), flex()), |
||||
cell(new UILabel("日期")).with(this::h3), |
||||
row(cell(calendarPanel), flex()) |
||||
); |
||||
} |
||||
|
||||
private void setFixSize(JComponent component) { |
||||
component.setPreferredSize(new Dimension(240, component.getHeight())); |
||||
component.setBorder(new FineRoundBorder()); |
||||
} |
||||
} |
Loading…
Reference in new issue