Browse Source

无jira任务 代码质量

newui
jinsihou 10 months ago
parent
commit
1d8c8816ec
  1. 36
      designer-base/src/main/java/com/fr/design/foldablepane/HeaderPane.java

36
designer-base/src/main/java/com/fr/design/foldablepane/HeaderPane.java

@ -6,29 +6,20 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
/**
* Created by MoMeak on 2017/7/5.
*/
public class HeaderPane extends JPanel {
private static final long serialVersionUID = 1L;
private final Insets defaultInsets = new Insets(0, 6, 0, 6);
private final int defaultWidth = 248;
private final int defaultHeight = 24;
private int headWidth;
private int headHeight;
private Color bgColor;
private boolean isShow;
private boolean isPressed = false;
private String title;
@ -39,6 +30,7 @@ public class HeaderPane extends JPanel {
public void setPressed(boolean pressed) {
this.isPressed = pressed;
}
public void setShow(boolean isShow) {
this.isShow = isShow;
}
@ -47,14 +39,6 @@ public class HeaderPane extends JPanel {
this.title = title;
}
public void setHeadWidth(int headwidth) {
this.headWidth = headwidth;
}
public void setheadHeight(int headHeight) {
this.headHeight = headHeight;
}
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
@ -75,15 +59,17 @@ public class HeaderPane extends JPanel {
g2d.setFont(getFont());
g2d.setPaint(getForeground());
g2d.setComposite(AlphaComposite.SrcOver.derive((float) getForeground().getAlpha() / 255));
g2d.setComposite(AlphaComposite.SrcOver.derive( getForeground().getAlpha() / 255f));
FontMetrics metrics = g2d.getFontMetrics();
int ascent = metrics.getAscent();
int descent = metrics.getDescent();
double titleY = (double) (getHeight() - (ascent + descent)) / 2 + ascent;
float titleX = triangleDown.getIconWidth()
+ FineUIScale.scale(UIManager.getInt("ExpandablePane.HeaderPane.hGap"));
float titleY = (getHeight() - (ascent + descent)) / 2.0f + ascent;
FlatUIUtils.setRenderingHints(g2d);
g2d.drawString(this.title, triangleDown.getIconWidth() + FineUIScale.scale(UIManager.getInt("ExpandablePane.HeaderPane.hGap")), (int) titleY);
g2d.drawString(this.title, titleX, titleY);
g2d.dispose();
}
@ -101,14 +87,4 @@ public class HeaderPane extends JPanel {
this.title = title;
}
public static void main(String[] args) {
JFrame mainFrame = new JFrame("UI Demo - Gloomyfish");
mainFrame.getContentPane().setLayout(new BorderLayout());
mainFrame.getContentPane().add(new HeaderPane(Color.black, "基本", 24), BorderLayout.CENTER);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.pack();
mainFrame.setSize(300, 400);
mainFrame.setVisible(true);
}
}

Loading…
Cancel
Save