@ -0,0 +1,98 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.utils.FineUIStyle; |
||||
import com.formdev.flatlaf.ui.FlatTableHeaderUI; |
||||
import com.fr.stable.StringUtils; |
||||
import sun.swing.DefaultLookup; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JComponent; |
||||
import javax.swing.JTable; |
||||
import javax.swing.SwingConstants; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.border.Border; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import javax.swing.plaf.UIResource; |
||||
import javax.swing.table.DefaultTableCellRenderer; |
||||
import javax.swing.table.JTableHeader; |
||||
import java.awt.Component; |
||||
import java.awt.Graphics; |
||||
|
||||
/** |
||||
* 应用于 JTable 的UI |
||||
* |
||||
* @author lemon |
||||
* @since |
||||
* Created on |
||||
*/ |
||||
public class FineTableHeaderUI extends FlatTableHeaderUI { |
||||
|
||||
@Override |
||||
public void installUI(JComponent c) { |
||||
super.installUI(c); |
||||
JTableHeader header = (JTableHeader) c; |
||||
header.setDefaultRenderer(new TableHeaderRenderer()); |
||||
JTable table = header.getTable(); |
||||
|
||||
FineUIStyle.setStyle(table, FineUIStyle.DEFAULT_TABLE); |
||||
table.getTableHeader().getTable().setDefaultRenderer(Object.class, new TableRenderer()); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
super.paint(g, c); |
||||
} |
||||
|
||||
/** |
||||
* 表头 render |
||||
*/ |
||||
public static class TableHeaderRenderer extends DefaultTableCellRenderer implements UIResource { |
||||
public TableHeaderRenderer() { |
||||
} |
||||
|
||||
@Override |
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||||
Border border = DefaultLookup.getBorder(this, this.ui, "TableHeader.cellBorder"); |
||||
this.setText(value == null ? "" : value.toString()); |
||||
this.setHorizontalAlignment(SwingConstants.LEFT); |
||||
this.setBorder(border); |
||||
return this; |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* UI |
||||
* @param c |
||||
* @return |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineTableHeaderUI(); |
||||
} |
||||
|
||||
/** |
||||
* 表身 render |
||||
*/ |
||||
public static class TableRenderer extends DefaultTableCellRenderer { |
||||
public TableRenderer() { |
||||
setHorizontalAlignment(SwingConstants.LEFT); |
||||
} |
||||
|
||||
@Override |
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||||
Border border; |
||||
if (column == table.getColumnCount() - 1) { |
||||
border = BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor")), |
||||
UIManager.getBorder("Table.cellNoFocusBorder")); |
||||
} else { |
||||
border = BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")), |
||||
UIManager.getBorder("Table.cellNoFocusBorder")); |
||||
} |
||||
setBackground(UIManager.getColor("Table.background")); |
||||
setText(value == null ? StringUtils.BLANK : String.valueOf(value)); |
||||
setBorder(border); |
||||
return this; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.formdev.flatlaf.ui.FlatScrollBarUI; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.JTable; |
||||
import java.awt.Graphics; |
||||
import java.awt.Rectangle; |
||||
|
||||
/** |
||||
* 应用于 JTable 的垂直滚动条UI |
||||
* |
||||
* @author lemon |
||||
* @since |
||||
* Created on 2024/08/11 |
||||
*/ |
||||
public class FineTableScrollBarPaneUI extends FlatScrollBarUI { |
||||
|
||||
private final JTable table; |
||||
|
||||
public FineTableScrollBarPaneUI(JTable table) { |
||||
this.table = table; |
||||
} |
||||
|
||||
@Override |
||||
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { |
||||
super.paintTrack(g, c, trackBounds); |
||||
} |
||||
|
||||
@Override |
||||
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { |
||||
// 确保滚动条滑块不会超过表头区域
|
||||
Rectangle headerRect = table.getTableHeader().getBounds(); |
||||
int headerHeight = headerRect.height; |
||||
thumbBounds.y = Math.max(thumbBounds.y, headerHeight); |
||||
|
||||
super.paintThumb(g, c, thumbBounds); |
||||
} |
||||
|
||||
} |
@ -1 +1 @@
|
||||
package com.fr.design.mainframe;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.iscrollbar.UIScrollBar;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Path2D;
/**
* Author : daisy
* Date: 13-9-11
* Time: 上午10:14
*/
public class DottedLine extends JPanel {
public static final int HEIGHT = 3;
private static final int BLUE_WIDTH = 12;//蓝色线长度,白色线长度是其半
private int direction = UIScrollBar.HORIZONTAL;
public DottedLine(int direction, int width) {
//水平方向的虚线框
if (direction == UIScrollBar.HORIZONTAL) {
this.setPreferredSize(new Dimension(width, HEIGHT));
} else {
this.setPreferredSize(new Dimension(HEIGHT, width));
}
this.direction = direction;
this.setBackground(new Color(255, 255, 255));//设置白色背景
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
//如果是水平方向的
if (direction == UIScrollBar.HORIZONTAL) {
paintHorizontal(g2d);
} else {
paintVertical(g2d);
}
}
private void paintHorizontal(Graphics2D g2d) {
int totalWidth = getWidth();
int paintX = 0;
while (paintX < totalWidth) {
int endX = paintX + BLUE_WIDTH;
if (endX > totalWidth) {
endX = totalWidth;
}
int[] x = new int[]{paintX, endX, endX, paintX, paintX};
int[] y = new int[]{0, 0, HEIGHT, HEIGHT, 0};
paintBlueArea(g2d, x, y);
paintX += BLUE_WIDTH + BLUE_WIDTH / 2;
}
}
private void paintVertical(Graphics2D g2d) {
int totalHeight = getHeight();
int paintY = 0;
while (paintY < totalHeight) {
int endY = paintY + BLUE_WIDTH;
if (endY > totalHeight) {
endY = totalHeight;
}
int[] x = new int[]{0, HEIGHT, HEIGHT, 0, 0};
int[] y = new int[]{paintY, paintY, endY, endY, paintY};
paintBlueArea(g2d, x, y);
paintY += BLUE_WIDTH + BLUE_WIDTH / 2;
}
}
private void paintBlueArea(Graphics2D g2d, int[] x, int[] y) {
g2d.setPaint(UIConstants.DOTTED_LINE_COLOR);
GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length);
generalPath.moveTo(x[0], y[0]);
for (int index = 1; index < x.length; index++) {
generalPath.lineTo(x[index], y[index]);
}
generalPath.closePath();
g2d.fill(generalPath);
}
} |
||||
package com.fr.design.mainframe;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.iscrollbar.UIScrollBar;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Path2D;
/**
* Author : daisy
* Date: 13-9-11
* Time: 上午10:14
*/
public class DottedLine extends JPanel {
public static final int HEIGHT = 3;
private static final int BLUE_WIDTH = 12;//蓝色线长度,白色线长度是其半
private int direction = UIScrollBar.HORIZONTAL;
public DottedLine(int direction, int width) {
//水平方向的虚线框
if (direction == UIScrollBar.HORIZONTAL) {
this.setPreferredSize(new Dimension(width, HEIGHT));
} else {
this.setPreferredSize(new Dimension(HEIGHT, width));
}
this.direction = direction;
this.setBackground(new Color(255, 255, 255));//设置白色背景
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
//如果是水平方向的
if (direction == UIScrollBar.HORIZONTAL) {
paintHorizontal(g2d);
} else {
paintVertical(g2d);
}
}
private void paintHorizontal(Graphics2D g2d) {
int totalWidth = getWidth();
int paintX = 0;
while (paintX < totalWidth) {
int endX = paintX + BLUE_WIDTH;
if (endX > totalWidth) {
endX = totalWidth;
}
int[] x = new int[]{paintX, endX, endX, paintX, paintX};
int[] y = new int[]{0, 0, HEIGHT, HEIGHT, 0};
paintBlueArea(g2d, x, y);
paintX += BLUE_WIDTH + BLUE_WIDTH / 2;
}
}
private void paintVertical(Graphics2D g2d) {
int totalHeight = getHeight();
int paintY = 0;
while (paintY < totalHeight) {
int endY = paintY + BLUE_WIDTH;
if (endY > totalHeight) {
endY = totalHeight;
}
int[] x = new int[]{0, HEIGHT, HEIGHT, 0, 0};
int[] y = new int[]{paintY, paintY, endY, endY, paintY};
paintBlueArea(g2d, x, y);
paintY += BLUE_WIDTH + BLUE_WIDTH / 2;
}
}
private void paintBlueArea(Graphics2D g2d, int[] x, int[] y) {
g2d.setPaint(FlatUIUtils.getUIColor("DottedLine.defaultColor", new Color(37,118,239,1)));
GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length);
generalPath.moveTo(x[0], y[0]);
for (int index = 1; index < x.length; index++) {
generalPath.lineTo(x[index], y[index]);
}
generalPath.closePath();
g2d.fill(generalPath);
}
} |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 693 B |
After Width: | Height: | Size: 696 B |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 910 B |
After Width: | Height: | Size: 910 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 896 B |
After Width: | Height: | Size: 896 B |
After Width: | Height: | Size: 894 B |
After Width: | Height: | Size: 894 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 915 B |
After Width: | Height: | Size: 915 B |
After Width: | Height: | Size: 852 B |
After Width: | Height: | Size: 852 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.1 KiB |