forked from fanruan/design
yaohwu
5 years ago
4 changed files with 237 additions and 33 deletions
@ -0,0 +1,18 @@
|
||||
package com.fr.design.fun; |
||||
|
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
import com.fr.stable.fun.mark.Mutable; |
||||
|
||||
/** |
||||
* @author yaohwu |
||||
* created by yaohwu at 2020/4/26 15:50 |
||||
*/ |
||||
public interface CellExpandAttrProvider extends Mutable { |
||||
|
||||
String MARK_STRING = "CellExpandAttrProvider"; |
||||
|
||||
int CURRENT_LEVEL = 1; |
||||
|
||||
BasicBeanPane<TemplateCellElement> createPanel(); |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fr.design.fun.impl; |
||||
|
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.fun.CellExpandAttrProvider; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
import com.fr.stable.fun.mark.API; |
||||
|
||||
/** |
||||
* @author yaohwu |
||||
* created by yaohwu at 2020/4/26 16:08 |
||||
*/ |
||||
@API(level = CellExpandAttrProvider.CURRENT_LEVEL) |
||||
public class AbstractCellExpandAttrProvider implements CellExpandAttrProvider { |
||||
|
||||
/** |
||||
* 当前接口的API等级,用于判断是否需要升级插件 |
||||
* |
||||
* @return API等级 |
||||
*/ |
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CellExpandAttrProvider.CURRENT_LEVEL; |
||||
} |
||||
|
||||
/** |
||||
* 获取当前provider的标记(可以使用类路径保证唯一)以避免provider的重复加载 |
||||
* |
||||
* @return 当前provider的标记 |
||||
*/ |
||||
@Override |
||||
public String mark4Provider() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public BasicBeanPane<TemplateCellElement> createPanel() { |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,132 @@
|
||||
package com.fr.design.mainframe.cell.settingpane; |
||||
|
||||
import com.fr.design.ExtraDesignClassManager; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.fun.CellExpandAttrProvider; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.injectable.PluginModule; |
||||
import com.fr.plugin.manage.PluginFilter; |
||||
import com.fr.plugin.observer.PluginEvent; |
||||
import com.fr.plugin.observer.PluginEventListener; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Component; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
import static com.fr.plugin.observer.PluginEventType.AfterActive; |
||||
import static com.fr.plugin.observer.PluginEventType.AfterInstall; |
||||
import static com.fr.plugin.observer.PluginEventType.AfterRun; |
||||
import static com.fr.plugin.observer.PluginEventType.AfterStop; |
||||
import static com.fr.plugin.observer.PluginEventType.AfterUpdate; |
||||
|
||||
/** |
||||
* @author yaohwu |
||||
* created by yaohwu at 2020/4/28 10:01 |
||||
*/ |
||||
public class CellExpandExtraAttrPane extends JPanel { |
||||
|
||||
private static final double V_GAP = 5; |
||||
private static final double H_GAP = 0; |
||||
private static final int DEFAULT_COMPONENT_SIZE = 2; |
||||
|
||||
private List<BasicBeanPane<TemplateCellElement>> extras = null; |
||||
private TemplateCellElement cellElement = null; |
||||
|
||||
|
||||
private static final class Holder { |
||||
private static final CellExpandExtraAttrPane INSTANCE = new CellExpandExtraAttrPane(); |
||||
} |
||||
|
||||
static { |
||||
PluginFilter filter = new PluginFilter() { |
||||
@Override |
||||
public boolean accept(PluginContext pluginContext) { |
||||
return pluginContext.contain(PluginModule.ExtraDesign, CellExpandAttrProvider.MARK_STRING); |
||||
} |
||||
}; |
||||
PluginEventListener listener = new PluginEventListener() { |
||||
@Override |
||||
public void on(PluginEvent event) { |
||||
CellExpandExtraAttrPane.getInstance().refresh(); |
||||
} |
||||
}; |
||||
EventDispatcher.listen(AfterRun, listener, filter); |
||||
EventDispatcher.listen(AfterStop, listener, filter); |
||||
EventDispatcher.listen(AfterInstall, listener, filter); |
||||
EventDispatcher.listen(AfterUpdate, listener, filter); |
||||
EventDispatcher.listen(AfterActive, listener, filter); |
||||
EventDispatcher.listen(AfterActive, listener, filter); |
||||
} |
||||
|
||||
public static CellExpandExtraAttrPane getInstance() { |
||||
return Holder.INSTANCE; |
||||
} |
||||
|
||||
/** |
||||
* Creates a new <code>JPanel</code> with a double buffer |
||||
* and a flow layout. |
||||
*/ |
||||
private CellExpandExtraAttrPane() { |
||||
this.setBorder(null); |
||||
this.setLayout(new BorderLayout()); |
||||
} |
||||
|
||||
public void populate(TemplateCellElement cellElement) { |
||||
this.cellElement = cellElement; |
||||
if (extras != null) { |
||||
for (BasicBeanPane<TemplateCellElement> extra : extras) { |
||||
extra.populateBean(cellElement); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void update(TemplateCellElement cellElement) { |
||||
this.cellElement = cellElement; |
||||
if (extras != null) { |
||||
for (BasicBeanPane<TemplateCellElement> extra : extras) { |
||||
extra.updateBean(cellElement); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void refresh() { |
||||
this.removeAll(); |
||||
if (extras == null) { |
||||
extras = new ArrayList<>(); |
||||
} |
||||
extras.clear(); |
||||
Set<CellExpandAttrProvider> attrProviders = ExtraDesignClassManager.getInstance().getArray(CellExpandAttrProvider.MARK_STRING); |
||||
if (attrProviders != null) { |
||||
for (CellExpandAttrProvider attrProvider : attrProviders) { |
||||
BasicBeanPane<TemplateCellElement> extra = attrProvider.createPanel(); |
||||
if (extra != null) { |
||||
extras.add(extra); |
||||
} |
||||
} |
||||
} |
||||
Component[][] components = new Component[extras.size()][DEFAULT_COMPONENT_SIZE]; |
||||
|
||||
for (int i = 0; i < extras.size(); i++) { |
||||
components[i] = new Component[]{extras.get(i), null}; |
||||
} |
||||
double[] rowSize = new double[extras.size()]; |
||||
Arrays.fill(rowSize, TableLayout.PREFERRED); |
||||
double[] columnSize = {TableLayout.PREFERRED, TableLayout.FILL}; |
||||
JPanel content = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, H_GAP, V_GAP); |
||||
this.add(content, BorderLayout.CENTER); |
||||
if (this.cellElement != null) { |
||||
this.populate(cellElement); |
||||
} |
||||
this.validate(); |
||||
this.repaint(); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue