帆软报表设计器源代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

145 lines
5.1 KiB

package com.fr.design.style.color;
import com.fine.theme.light.ui.FineRoundBorder;
import com.fine.theme.utils.FineUIScale;
import com.fine.theme.utils.FineUIUtils;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.frpane.FineTabbedPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.*;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import static com.fine.swing.ui.layout.Layouts.cell;
import static com.fine.swing.ui.layout.Layouts.column;
import static com.fine.swing.ui.layout.Layouts.flex;
import static com.fine.swing.ui.layout.Layouts.row;
import static com.fr.design.i18n.Toolkit.i18nText;
/**
* 颜色选择器更多颜色面板
*
* @author focus
*/
public class ColorSelectDetailPane extends BasicPane {
private static final int SELECT_PANEL_HEIGHT = 245;
// Selected color
private Color color;
// 颜色选择器面板
private JColorChooser selectedPanel;
// 预览
private JPanel previewPanel;
public JColorChooser getSelectedPanel() {
return selectedPanel;
}
private SwatchChooserPanel swatchChooserPanel;
private CustomChooserPanel customChooserPanel;
public void setSelectedPanel(JColorChooser selectedPanel) {
this.selectedPanel = selectedPanel;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public ColorSelectDetailPane(Color color) {
if (color == null) {
color = Color.WHITE;
}
this.color = color;
initComponents();
}
@Override
protected String title4PopupWindow() {
return i18nText("Fine-Design_Basic_Select_Color");
}
protected void initComponents() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
// 颜色选择器面板
selectedPanel = new JColorChooser(this.color);
selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(), FineUIScale.scale(SELECT_PANEL_HEIGHT)));
selectedPanel.setPreviewPanel(new JPanel());
swatchChooserPanel = new SwatchChooserPanel();
customChooserPanel = new CustomChooserPanel();
selectedPanel.setChooserPanels(new AbstractColorChooserPanel[]{customChooserPanel, swatchChooserPanel});
selectedPanel.setPreviewPanel(new JPanel());
// 预览
previewPanel = new JPanel(new BorderLayout());
final ColorChooserPreview colorChooserPreview = new ColorChooserPreview();
colorChooserPreview.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE));
ColorSelectionModel model = selectedPanel.getSelectionModel();
model.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
ColorSelectionModel model = (ColorSelectionModel) e.getSource();
colorChooserPreview.setMyColor(model.getSelectedColor());
colorChooserPreview.repaint();
}
});
previewPanel.add(row(
flex(),
column(flex(), cell(colorChooserPreview), flex()),
flex()
).getComponent());
JPanel center = initCenterPane();
center.setBorder(new ScaledEmptyBorder(10, 0, 0, 0));
add(center);
}
private FineTabbedPane buildTabbedPane() {
return FineTabbedPane.builder().withHeadRatio(0.3f)
.addTab(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"), customChooserPanel)
.addTab(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Swatch"), swatchChooserPanel).build();
}
private JPanel initCenterPane() {
// 最近使用面板
RecentUseColorPane recent = new RecentUseColorPane(selectedPanel);
UILabel label = new UILabel( i18nText("Fine-Design_Basic_Used"));
FineUIUtils.wrapBoldLabelWithUnderline(label);
FineTabbedPane tabbedPane = buildTabbedPane();
return column(
cell(tabbedPane),
column(
10,
cell(label), cell(recent),
column(
2,
cell(new UILabel(i18nText("Fine-Design_Basic_Preview"))),
cell(previewPanel).with(it -> {
it.setBorder(new FineRoundBorder());
it.setPreferredSize(new Dimension(this.getPreferredSize().width, FineUIScale.scale(120)));
it.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE));
})
)).with(it -> it.setBorder(new ScaledEmptyBorder(0, 10, 0, 10)))
).getComponent();
}
public void populate(Color color){
customChooserPanel.setColor(color);
}
}