帆软报表设计器源代码。
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.
 
 
 
 

171 lines
5.8 KiB

package com.fr.design.condition;
import com.fine.theme.icon.LazyIcon;
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.fr.common.annotations.Open;
import com.fr.design.actions.UpdateAction;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.log.FineLoggerFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
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.fix;
import static com.fine.swing.ui.layout.Layouts.flex;
import static com.fine.swing.ui.layout.Layouts.row;
@Open
public abstract class ConditionAttributesPane<T> extends BasicBeanPane<T> {
private static final int MAT_HEIGHT = FineUIScale.scale(120);
protected CellHighlightAddMenuDef menuDef;
protected JPanel selectedItemPane;
protected LiteConditionPane liteConditionPane;
protected Map<Class, ConditionAttrSingleConditionPane> classPaneMap = new LinkedHashMap<>();
//可用的Actions.
protected java.util.List<UpdateAction> useAbleActionList = new java.util.ArrayList<UpdateAction>();
protected JScrollPane selectedItemScrollPane = new JScrollPane() {
@Override
public Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
if (size.height > MAT_HEIGHT) {
size.height = MAT_HEIGHT;
}
return size;
}
};
protected void initComponents() {
this.setLayout(new BorderLayout());
// 选择要改变的属性.
JPanel addItemPane = new JPanel(new BorderLayout());
ToolBarDef toolbarDef = new ToolBarDef();
menuDef = new CellHighlightAddMenuDef();
menuDef.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Highlight_Click_to_Choose_Property_To_Modify"));
menuDef.setIcon(new LazyIcon("add_popup"));
toolbarDef.addShortCut(menuDef);
updateMenuDef();
UIToolbar toolBar = ToolBarDef.createJToolBar();
toolBar.setLayout(new BorderLayout());
toolBar.setBorder(new FineRoundBorder());
toolBar.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE));
toolbarDef.updateToolBar(toolBar);
addItemPane.add(toolBar, BorderLayout.WEST);
addItemPane.setBorder(new FineRoundBorder());
addItemPane.setPreferredSize(new Dimension(addItemPane.getPreferredSize().width, FineUIScale.scale(24)));
selectedItemPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
// 选中的添加Itempane
selectedItemScrollPane.setViewportView(selectedItemPane);
selectedItemScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
dealScrollPane(selectedItemScrollPane);
this.add(FineUIUtils.wrapComponentWithTitle(column(
10,
row(cell(addItemPane), flex()),
cell(selectedItemScrollPane).with(it -> it.setBorder(new FineRoundBorder())),
fix(10)
).getComponent(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Property")), BorderLayout.NORTH);
}
protected void dealScrollPane(JScrollPane scrollPane){
}
public void updateBean(T ob) {
updateMenuDef();
}
protected void updateMenuDef() {
menuDef.clearShortCuts();
for (UpdateAction ac : useAbleActionList) {
menuDef.addShortCut(ac);
}
menuDef.updateMenu();
menuDef.setEnabled(true);
}
public void checkConditionPane() {
GUICoreUtils.setEnabled(this.liteConditionPane, this.selectedItemPane.getComponentCount() >= 1);
}
public ConditionAttrSingleConditionPane createConditionAttrSingleConditionPane(Class<? extends ConditionAttrSingleConditionPane> clazz) {
try {
return clazz.newInstance();
} catch (InstantiationException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (IllegalAccessException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
protected void addAction2UseAbleActionList() {
useAbleActionList.clear();
Iterator<ConditionAttrSingleConditionPane> iterator = classPaneMap.values().iterator();
while (iterator.hasNext()) {
useAbleActionList.add(iterator.next().getHighLightConditionAction());
}
}
public void resetUseAbleActionList() {
Iterator<ConditionAttrSingleConditionPane> iterator = classPaneMap.values().iterator();
while (iterator.hasNext()) {
ConditionAttrSingleConditionPane pane = iterator.next();
if (pane.getParent() != this.selectedItemPane && !this.useAbleActionList.contains(pane.getHighLightConditionAction())) {
this.useAbleActionList.add(pane.getHighLightConditionAction());
}
}
}
public void removeConditionAttrSingleConditionPane(JComponent component) {
selectedItemPane.remove(component);
}
public void addConditionAttrSingleConditionPane(JComponent component) {
selectedItemPane.add(component);
}
public void removeUpdateActionFromUsableList(UpdateAction action) {
useAbleActionList.remove(action);
}
public void redraw() {
validate();
repaint();
}
}