175 changed files with 3938 additions and 1557 deletions
@ -0,0 +1,102 @@
|
||||
package com.fr.design.report.mobile; |
||||
|
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.designer.IntervalConstants; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.general.Inter; |
||||
import com.fr.report.mobile.ElementCaseMobileAttr; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* Created by plough on 2018/1/8. |
||||
*/ |
||||
public class ReportMobileTemplateSettingsPane extends BasicBeanPane<ElementCaseMobileAttr> { |
||||
|
||||
private UICheckBox mobileCanvasSizeCheck; // 设置为手机模版画布大小
|
||||
|
||||
public ReportMobileTemplateSettingsPane() { |
||||
this.initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
JPanel borderPane = FRGUIPaneFactory.createTitledBorderPane(this.title4PopupWindow()); |
||||
|
||||
JPanel contentPane = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||
contentPane.setBorder(BorderFactory.createEmptyBorder(0, IntervalConstants.INTERVAL_L2, 0, 0)); |
||||
|
||||
contentPane.add(getMobileCanvasSizeCheckPane(), BorderLayout.CENTER); |
||||
|
||||
borderPane.add(contentPane); |
||||
this.add(borderPane); |
||||
} |
||||
|
||||
private JPanel getMobileCanvasSizeCheckPane() { |
||||
JPanel panel = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||
mobileCanvasSizeCheck = new UICheckBox(Inter.getLocText("FR-Designer_Set_Mobile_Canvas_Size")); |
||||
panel.add(mobileCanvasSizeCheck, BorderLayout.NORTH); |
||||
panel.add(getCanvasDescPane(), BorderLayout.CENTER); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, 0, IntervalConstants.INTERVAL_L6, 0)); |
||||
return panel; |
||||
} |
||||
|
||||
private JPanel getCanvasDescPane() { |
||||
|
||||
UILabel desc1 = createDescLabel(Inter.getLocText("FR-Designer_Mobile_Screen_Match_Desc")); |
||||
UILabel desc2 = createDescLabel(Inter.getLocText("FR-Designer_Mobile_Screen_Zoom_In_Desc")); |
||||
UILabel desc3 = createDescLabel(Inter.getLocText("FR-Designer_Mobile_Screen_Zoom_Out_Desc")); |
||||
|
||||
double f = TableLayout.FILL; |
||||
double p = TableLayout.PREFERRED; |
||||
double[] rowSize = {p, p, p, p}; |
||||
double[] columnSize = {p, f}; |
||||
int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{desc1, null}, |
||||
new Component[]{desc2, null}, |
||||
new Component[]{desc3, null} |
||||
}; |
||||
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_W0, IntervalConstants.INTERVAL_L1); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L7, IntervalConstants.INTERVAL_W4, IntervalConstants.INTERVAL_L1, 0)); |
||||
return panel; |
||||
} |
||||
|
||||
private UILabel createDescLabel(String desc) { |
||||
UILabel label = new UILabel(desc); |
||||
label.setForeground(Color.gray); |
||||
return label; |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(ElementCaseMobileAttr ob) { |
||||
if (ob == null) { |
||||
ob = new ElementCaseMobileAttr(); |
||||
} |
||||
mobileCanvasSizeCheck.setSelected(ob.isMobileCanvasSize()); |
||||
} |
||||
|
||||
@Override |
||||
public ElementCaseMobileAttr updateBean() { |
||||
ElementCaseMobileAttr mobileAttr = new ElementCaseMobileAttr(); |
||||
mobileAttr.setMobileCanvasSize(mobileCanvasSizeCheck.isSelected()); |
||||
return mobileAttr; |
||||
} |
||||
|
||||
@Override |
||||
public void updateBean(ElementCaseMobileAttr mobileAttr) { |
||||
if(mobileAttr != null) { |
||||
mobileAttr.setMobileCanvasSize(mobileCanvasSizeCheck.isSelected()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer_Template_Settings"); |
||||
} |
||||
} |
@ -1 +1 @@
|
||||
package com.fr.design.actions;
import com.fr.base.BaseUtils;
import com.fr.design.constants.UIConstants;
import com.fr.design.menu.KeySetUtils;
import com.fr.design.roleAuthority.ReportAndFSManagePane;
import com.fr.design.roleAuthority.RolesAlreadyEditedPane;
import com.fr.design.designer.TargetComponent;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.*;
/**
* Author : daisy
* Date: 13-8-30
* Time: 上午10:12
*/
public class AllowAuthorityEditAction extends TemplateComponentAction {
public AllowAuthorityEditAction(TargetComponent t) {
super(t);
this.setMenuKeySet(KeySetUtils.ALLOW_AUTHORITY_EDIT);
this.setName(getMenuKeySet().getMenuName());
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/allow_authority_edit.png"));
}
/**
* 撤销
*/
public void prepare4Undo() {
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().iniAuthorityUndoState();
}
/**
* 执行动作
*
* @return 是否执行成功
*/
public boolean executeActionReturnUndoRecordNeeded() {
TargetComponent tc = getEditingComponent();
if (tc == null) {
return false;
}
cleanAuthorityCondition();
//进入时是格式刷则取消格式刷
if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) {
tc.cancelFormat();
}
BaseUtils.setAuthorityEditing(true);
ReportAndFSManagePane.getInstance().refreshDockingView();
RolesAlreadyEditedPane.getInstance().refreshDockingView();
WestRegionContainerPane.getInstance().replaceDownPane(ReportAndFSManagePane.getInstance());
DesignerContext.getDesignerFrame().setCloseMode(UIConstants.CLOSE_OF_AUTHORITY);
DesignerContext.getDesignerFrame().resetToolkitByPlus(tc.getToolBarMenuDockPlus());
DesignerContext.getDesignerFrame().needToAddAuhtorityPaint();
EastRegionContainerPane.getInstance().switchMode(EastRegionContainerPane.PropertyMode.AUTHORITY_EDITION);
EastRegionContainerPane.getInstance().replaceAuthorityEditionPane(tc.getEastUpPane());
DesignerContext.getDesignerFrame().refreshDottedLine();
EastRegionContainerPane.getInstance().replaceConfiguredRolesPane(RolesAlreadyEditedPane.getInstance());
EastRegionContainerPane.getInstance().removeParameterPane();
//画虚线
return true;
}
/**
* 进入权限编辑之前将权限编辑界面重置一下工具栏
*/
private void cleanAuthorityCondition() {
java.util.List<JTemplate<?, ?>> opendedTemplate = HistoryTemplateListPane.getInstance().getHistoryList();
for (int i = 0; i < opendedTemplate.size(); i++) {
opendedTemplate.get(i).cleanAuthorityUndo();
}
}
} |
||||
package com.fr.design.actions;
import com.fr.base.BaseUtils;
import com.fr.base.vcs.DesignerMode;
import com.fr.design.constants.UIConstants;
import com.fr.design.menu.KeySetUtils;
import com.fr.design.roleAuthority.ReportAndFSManagePane;
import com.fr.design.roleAuthority.RolesAlreadyEditedPane;
import com.fr.design.designer.TargetComponent;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.*;
/**
* Author : daisy
* Date: 13-8-30
* Time: 上午10:12
*/
public class AllowAuthorityEditAction extends TemplateComponentAction {
public AllowAuthorityEditAction(TargetComponent t) {
super(t);
this.setMenuKeySet(KeySetUtils.ALLOW_AUTHORITY_EDIT);
this.setName(getMenuKeySet().getMenuName());
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/allow_authority_edit.png"));
}
/**
* 撤销
*/
public void prepare4Undo() {
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().iniAuthorityUndoState();
}
/**
* 执行动作
*
* @return 是否执行成功
*/
public boolean executeActionReturnUndoRecordNeeded() {
TargetComponent tc = getEditingComponent();
if (tc == null) {
return false;
}
cleanAuthorityCondition();
//进入时是格式刷则取消格式刷
if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) {
tc.cancelFormat();
}
DesignerMode.setMode(DesignerMode.AUTHORITY);
ReportAndFSManagePane.getInstance().refreshDockingView();
RolesAlreadyEditedPane.getInstance().refreshDockingView();
WestRegionContainerPane.getInstance().replaceDownPane(ReportAndFSManagePane.getInstance());
DesignerContext.getDesignerFrame().setCloseMode(UIConstants.CLOSE_OF_AUTHORITY);
DesignerContext.getDesignerFrame().resetToolkitByPlus(tc.getToolBarMenuDockPlus());
DesignerContext.getDesignerFrame().needToAddAuhtorityPaint();
EastRegionContainerPane.getInstance().switchMode(EastRegionContainerPane.PropertyMode.AUTHORITY_EDITION);
EastRegionContainerPane.getInstance().replaceAuthorityEditionPane(tc.getEastUpPane());
DesignerContext.getDesignerFrame().refreshDottedLine();
EastRegionContainerPane.getInstance().replaceConfiguredRolesPane(RolesAlreadyEditedPane.getInstance());
EastRegionContainerPane.getInstance().removeParameterPane();
//画虚线
return true;
}
/**
* 进入权限编辑之前将权限编辑界面重置一下工具栏
*/
private void cleanAuthorityCondition() {
java.util.List<JTemplate<?, ?>> opendedTemplate = HistoryTemplateListPane.getInstance().getHistoryList();
for (int i = 0; i < opendedTemplate.size(); i++) {
opendedTemplate.get(i).cleanAuthorityUndo();
}
}
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.design.event; |
||||
|
||||
import java.util.EventListener; |
||||
|
||||
/** |
||||
* Created by plough on 2018/1/19. |
||||
*/ |
||||
public interface DesignerOpenedListener extends EventListener { |
||||
/** |
||||
* Invoked when the target of the listener has changed the rpt content. |
||||
*/ |
||||
public void designerOpened(); |
||||
} |
@ -0,0 +1,467 @@
|
||||
package com.fr.design.gui.controlpane; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.icontainer.UIScrollPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ilist.ListModelElement; |
||||
import com.fr.design.gui.ilist.UIList; |
||||
import com.fr.design.gui.itoolbar.UIToolBarUI; |
||||
import com.fr.design.gui.itoolbar.UIToolbar; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.menu.ShortCut; |
||||
import com.fr.design.menu.ToolBarDef; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.Nameable; |
||||
import com.fr.stable.StringUtils; |
||||
import sun.swing.DefaultLookup; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.border.Border; |
||||
import javax.swing.event.ListSelectionEvent; |
||||
import javax.swing.event.ListSelectionListener; |
||||
import java.awt.*; |
||||
import java.awt.event.*; |
||||
import java.util.Arrays; |
||||
import java.util.Comparator; |
||||
|
||||
/** |
||||
* 简单列表面板 |
||||
* Created by plough on 2018/2/1. |
||||
*/ |
||||
public class UISimpleListControlPane extends BasicPane { |
||||
public static final String LIST_NAME = "UISimpleControl_List"; |
||||
|
||||
protected UIList nameList; |
||||
protected String selectedName; |
||||
private ShortCut4JControlPane[] shorts; |
||||
private ToolBarDef toolbarDef; |
||||
private UIToolbar toolBar; |
||||
|
||||
public UISimpleListControlPane() { |
||||
initComponentPane(); |
||||
} |
||||
|
||||
public ShortCut4JControlPane[] getShorts() { |
||||
return shorts; |
||||
} |
||||
|
||||
protected void initComponentPane() { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
this.add(getContentPane(), BorderLayout.CENTER); |
||||
this.checkButtonEnabled(); |
||||
} |
||||
|
||||
protected JPanel getContentPane() { |
||||
JPanel contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
|
||||
JPanel listPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
initListPane(listPane); |
||||
contentPane.add(listPane, BorderLayout.CENTER); |
||||
|
||||
shorts = this.createShortcuts(); |
||||
if (ArrayUtils.isEmpty(shorts)) { |
||||
return contentPane; |
||||
} |
||||
|
||||
toolbarDef = new ToolBarDef(); |
||||
for (ShortCut4JControlPane sj : shorts) { |
||||
toolbarDef.addShortCut(sj.getShortCut()); |
||||
} |
||||
toolBar = ToolBarDef.createJToolBar(); |
||||
toolBar.setUI(new UIToolBarUI(){ |
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
Graphics2D g2 = (Graphics2D) g; |
||||
g2.setColor(Color.WHITE); |
||||
g2.fillRect(0, 0, c.getWidth(), c.getHeight()); |
||||
} |
||||
}); |
||||
toolbarDef.updateToolBar(toolBar); |
||||
// 封装一层,加边框
|
||||
JPanel toolBarPane = new JPanel(new BorderLayout()); |
||||
toolBarPane.add(toolBar, BorderLayout.CENTER); |
||||
toolBarPane.setBorder(BorderFactory.createMatteBorder(1, 1, 0, 1, UIConstants.RULER_LINE_COLOR)); |
||||
|
||||
listPane.add(toolBarPane, BorderLayout.NORTH); |
||||
|
||||
return contentPane; |
||||
} |
||||
|
||||
protected ShortCut4JControlPane[] createShortcuts() { |
||||
return new ShortCut4JControlPane[]{ |
||||
moveUpItemShortCut(), |
||||
moveDownItemShortCut(), |
||||
sortItemShortCut(), |
||||
}; |
||||
} |
||||
|
||||
protected void initListPane(JPanel listPane) { |
||||
nameList = createJNameList(); |
||||
nameList.setName(LIST_NAME); |
||||
nameList.setSelectionBackground(UIConstants.ATTRIBUTE_PRESS); |
||||
listPane.add(new UIScrollPane(nameList), BorderLayout.CENTER); |
||||
|
||||
|
||||
nameList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
||||
nameList.addMouseListener(listMouseListener); |
||||
nameList.addListSelectionListener(new ListSelectionListener() { |
||||
public void valueChanged(ListSelectionEvent evt) { |
||||
// richie:避免多次update和populate大大降低效率
|
||||
if (!evt.getValueIsAdjusting()) { |
||||
UISimpleListControlPane.this.checkButtonEnabled(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public UIList createJNameList() { |
||||
UIList nameList = new UIList(new DefaultListModel()) { |
||||
@Override |
||||
public int locationToIndex(Point location) { |
||||
int index = super.locationToIndex(location); |
||||
if (index != -1 && !getCellBounds(index, index).contains(location)) { |
||||
return -1; |
||||
} |
||||
else { |
||||
return index; |
||||
} |
||||
} |
||||
}; |
||||
nameList.setCellRenderer(new NameableListCellRenderer(this)); |
||||
return nameList; |
||||
} |
||||
|
||||
protected ShortCut4JControlPane moveUpItemShortCut() { |
||||
return new NormalEnableShortCut(new MoveUpItemAction()); |
||||
} |
||||
|
||||
protected ShortCut4JControlPane moveDownItemShortCut() { |
||||
return new NormalEnableShortCut(new MoveDownItemAction()); |
||||
} |
||||
|
||||
protected ShortCut4JControlPane sortItemShortCut() { |
||||
return new NormalEnableShortCut(new SortItemAction()); |
||||
} |
||||
|
||||
public Nameable[] update() { |
||||
java.util.List<Nameable> res = new java.util.ArrayList<Nameable>(); |
||||
DefaultListModel listModel = (DefaultListModel) this.nameList.getModel(); |
||||
for (int i = 0, len = listModel.getSize(); i < len; i++) { |
||||
res.add(((ListModelElement) listModel.getElementAt(i)).wrapper); |
||||
} |
||||
|
||||
return res.toArray(new Nameable[res.size()]); |
||||
} |
||||
|
||||
public void populate(Nameable[] nameableArray) { |
||||
DefaultListModel listModel = (DefaultListModel) this.nameList.getModel(); |
||||
listModel.removeAllElements(); |
||||
if (ArrayUtils.isEmpty(nameableArray)) { |
||||
return; |
||||
} |
||||
|
||||
listModel.setSize(nameableArray.length); |
||||
for (int i = 0; i < nameableArray.length; i++) { |
||||
listModel.set(i, new ListModelElement(nameableArray[i])); |
||||
} |
||||
if (listModel.size() > 0 || this.nameList.getSelectedIndex() != 0) { |
||||
this.nameList.setSelectedIndex(0); |
||||
} |
||||
this.checkButtonEnabled(); |
||||
} |
||||
|
||||
/** |
||||
* 根据name,选中UINameEdList中的item |
||||
*/ |
||||
public void setSelectedName(String name) { |
||||
DefaultListModel listModel = (DefaultListModel) this.nameList.getModel(); |
||||
for (int i = 0, len = listModel.getSize(); i < len; i++) { |
||||
Nameable item = ((ListModelElement) listModel.getElementAt(i)).wrapper; |
||||
if (ComparatorUtils.equals(name, item.getName())) { |
||||
this.nameList.setSelectedIndex(i); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取选中的名字 |
||||
*/ |
||||
public String getSelectedName() { |
||||
ListModelElement el = (ListModelElement) this.nameList.getSelectedValue(); |
||||
|
||||
return el == null ? null : el.wrapper.getName(); |
||||
} |
||||
|
||||
protected DefaultListModel getModel() { |
||||
return (DefaultListModel) this.nameList.getModel(); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return null; |
||||
} |
||||
|
||||
/* |
||||
* 上移Item |
||||
*/ |
||||
private class MoveUpItemAction extends UpdateAction { |
||||
public MoveUpItemAction() { |
||||
this.setName(Inter.getLocText("Utils-Move_Up")); |
||||
this.setMnemonic('U'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/design/images/control/up.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
int selectedIndex = nameList.getSelectedIndex(); |
||||
if (selectedIndex == -1) { |
||||
return; |
||||
} |
||||
|
||||
// 上移
|
||||
if (selectedIndex > 0) { |
||||
DefaultListModel listModel = (DefaultListModel) nameList.getModel(); |
||||
|
||||
Object prevObj = listModel.get(selectedIndex - 1); |
||||
Object currentObj = listModel.get(selectedIndex); |
||||
listModel.set(selectedIndex - 1, currentObj); |
||||
listModel.set(selectedIndex, prevObj); |
||||
|
||||
nameList.setSelectedIndex(selectedIndex - 1); |
||||
nameList.ensureIndexIsVisible(selectedIndex - 1); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* 下移Item |
||||
*/ |
||||
private class MoveDownItemAction extends UpdateAction { |
||||
public MoveDownItemAction() { |
||||
this.setName(Inter.getLocText("Utils-Move_Down")); |
||||
this.setMnemonic('D'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/design/images/control/down.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
int selectedIndex = nameList.getSelectedIndex(); |
||||
if (selectedIndex == -1) { |
||||
return; |
||||
} |
||||
|
||||
if (selectedIndex < nameList.getModel().getSize() - 1) { |
||||
DefaultListModel listModel = (DefaultListModel) nameList.getModel(); |
||||
|
||||
Object nextObj = listModel.get(selectedIndex + 1); |
||||
Object currentObj = listModel.get(selectedIndex); |
||||
listModel.set(selectedIndex + 1, currentObj); |
||||
listModel.set(selectedIndex, nextObj); |
||||
|
||||
nameList.setSelectedIndex(selectedIndex + 1); |
||||
nameList.ensureIndexIsVisible(selectedIndex + 1); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private class SortItemAction extends UpdateAction { |
||||
private boolean isAtoZ = false; |
||||
|
||||
public SortItemAction() { |
||||
this.setName(Inter.getLocText("FR-Action_Sort")); |
||||
this.setMnemonic('S'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/design/images/control/sortAsc.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
// p:选中的值.
|
||||
Object selectedValue = nameList.getSelectedValue(); |
||||
|
||||
DefaultListModel listModel = (DefaultListModel) nameList.getModel(); |
||||
if (listModel.getSize() <= 0) { |
||||
return; |
||||
} |
||||
Nameable[] nameableArray = new Nameable[listModel.getSize()]; |
||||
|
||||
for (int i = 0; i < listModel.getSize(); i++) { |
||||
nameableArray[i] = ((ListModelElement) listModel.getElementAt(i)).wrapper; |
||||
} |
||||
|
||||
// p:排序.
|
||||
if (isAtoZ) { // 升序
|
||||
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() { |
||||
@Override |
||||
public int compare(Nameable o1, Nameable o2) { |
||||
return ComparatorUtils.compare(o2.getName(), o1.getName()); |
||||
} |
||||
}; |
||||
isAtoZ = !isAtoZ; |
||||
Arrays.sort(nameableArray, nameableComparator); |
||||
} else { // 降序
|
||||
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() { |
||||
@Override |
||||
public int compare(Nameable o1, Nameable o2) { |
||||
return ComparatorUtils.compare(o1.getName(), o2 |
||||
.getName()); |
||||
} |
||||
}; |
||||
isAtoZ = !isAtoZ; |
||||
Arrays.sort(nameableArray, nameableComparator); |
||||
} |
||||
|
||||
for (int i = 0; i < nameableArray.length; i++) { |
||||
listModel.set(i, new ListModelElement(nameableArray[i])); |
||||
} |
||||
|
||||
// p:需要选中以前的那个值.
|
||||
if (selectedValue != null) { |
||||
nameList.setSelectedValue(selectedValue, true); |
||||
} |
||||
|
||||
checkButtonEnabled(); |
||||
// p:需要repaint.
|
||||
nameList.repaint(); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* UIList的鼠标事件 |
||||
*/ |
||||
private MouseListener listMouseListener = new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
JList list = (JList) e.getSource(); |
||||
if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown() |
||||
&& !isMenuShortcutKeyDown(e)) { |
||||
list.clearSelection(); |
||||
} |
||||
} |
||||
|
||||
private boolean isMenuShortcutKeyDown(InputEvent event) { |
||||
return (event.getModifiers() & Toolkit.getDefaultToolkit() |
||||
.getMenuShortcutKeyMask()) != 0; |
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* 检查按钮可用状态 Check button enabled. |
||||
*/ |
||||
public void checkButtonEnabled() { |
||||
for (ShortCut4JControlPane sj : getShorts()) { |
||||
sj.checkEnable(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置选中项 |
||||
* |
||||
* @param index 选中项的序列号 |
||||
*/ |
||||
public void setSelectedIndex(int index) { |
||||
nameList.setSelectedIndex(index); |
||||
} |
||||
|
||||
|
||||
public class NormalEnableShortCut extends ShortCut4JControlPane { |
||||
public NormalEnableShortCut(ShortCut shortCut) { |
||||
this.shortCut = shortCut; |
||||
} |
||||
|
||||
/** |
||||
* 检查是否可用 |
||||
*/ |
||||
@Override |
||||
public void checkEnable() { |
||||
this.shortCut.setEnabled(getModel() |
||||
.getSize() > 0 |
||||
&& UISimpleListControlPane.this.nameList.getSelectedIndex() != -1); |
||||
} |
||||
} |
||||
|
||||
|
||||
private class NameableListCellRenderer extends |
||||
JPanel implements ListCellRenderer { |
||||
|
||||
private UILabel label; |
||||
private UISimpleListControlPane listControlPane; |
||||
private Color initialLabelForeground; |
||||
|
||||
public NameableListCellRenderer(UISimpleListControlPane listControlPane) { |
||||
super(); |
||||
this.listControlPane = listControlPane; |
||||
initComponents(); |
||||
setOpaque(true); |
||||
setBorder(getNoFocusBorder()); |
||||
setName("List.cellRenderer"); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
label = new UILabel(); |
||||
label.setBorder(BorderFactory.createEmptyBorder(3, 10, 3, 0)); |
||||
initialLabelForeground = label.getForeground(); |
||||
this.setLayout(new BorderLayout()); |
||||
this.add(label, BorderLayout.CENTER); |
||||
} |
||||
|
||||
private Border getNoFocusBorder() { |
||||
return BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LIST_ITEM_SPLIT_LINE); |
||||
} |
||||
|
||||
private void setText(String t) { |
||||
label.setText(t); |
||||
} |
||||
|
||||
@Override |
||||
public Component getListCellRendererComponent(JList list, Object value, |
||||
int index, boolean isSelected, boolean cellHasFocus) { |
||||
setComponentOrientation(list.getComponentOrientation()); |
||||
|
||||
Color bg = null; |
||||
Color fg = null; |
||||
|
||||
JList.DropLocation dropLocation = list.getDropLocation(); |
||||
if (dropLocation != null |
||||
&& !dropLocation.isInsert() |
||||
&& dropLocation.getIndex() == index) { |
||||
|
||||
bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground"); |
||||
fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground"); |
||||
|
||||
isSelected = true; |
||||
} |
||||
|
||||
if (isSelected) { |
||||
setBackground(bg == null ? list.getSelectionBackground() : bg); |
||||
setForeground(fg == null ? list.getSelectionForeground() : fg); |
||||
label.setForeground(Color.WHITE); |
||||
} |
||||
else { |
||||
setBackground(list.getBackground()); |
||||
setForeground(list.getForeground()); |
||||
label.setForeground(initialLabelForeground); |
||||
} |
||||
|
||||
setText((value == null) ? StringUtils.EMPTY : value.toString()); |
||||
|
||||
setEnabled(list.isEnabled()); |
||||
setFont(list.getFont()); |
||||
|
||||
if (value instanceof ListModelElement) { |
||||
Nameable wrappee = ((ListModelElement) value).wrapper; |
||||
this.setText(wrappee.getName()); |
||||
} |
||||
|
||||
return this; |
||||
} |
||||
} |
||||
} |
@ -1,211 +1,192 @@
|
||||
/* |
||||
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||
*/ |
||||
package com.fr.design.gui.icombobox; |
||||
|
||||
import java.awt.Dimension; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.DocumentEvent; |
||||
import javax.swing.event.DocumentListener; |
||||
import javax.swing.event.PopupMenuEvent; |
||||
import javax.swing.event.PopupMenuListener; |
||||
import javax.swing.plaf.basic.BasicComboPopup; |
||||
|
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* @author richer |
||||
* @since 6.5.5 创建于2011-6-15 延迟加载的下拉框 |
||||
*/ |
||||
public abstract class LazyComboBox extends UIComboBox implements PopupMenuListener { |
||||
protected boolean loaded = false; |
||||
private List<EventListener> ls = new ArrayList<EventListener>(); |
||||
private Object initialSelected = null; |
||||
private static final int NUM=80; |
||||
|
||||
public static final Object PENDING = new Object() { |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return Inter.getLocText("Loading") + "..."; |
||||
} |
||||
}; |
||||
|
||||
public LazyComboBox() { |
||||
super(); |
||||
this.setEditor(new FilterComboBoxEditor()); |
||||
addPopupMenuListener(this); |
||||
// updateUI();
|
||||
} |
||||
|
||||
public void setLoaded(boolean loaded) { |
||||
this.loaded = loaded; |
||||
} |
||||
|
||||
public abstract Object[] load(); |
||||
|
||||
public void setSelectedItem(Object anObject) { |
||||
initialSelected = anObject; |
||||
if (loaded) { |
||||
super.setSelectedItem(anObject); |
||||
} else { |
||||
|
||||
setModel(new DefaultComboBoxModel(new Object[] { anObject })); |
||||
super.setSelectedItem(anObject); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 通过调用该方法,在点击下拉框按钮之前就加载好数据,不需要出现loading了 |
||||
*/ |
||||
public void loadInstant() { |
||||
setLoaded(true); |
||||
loadList(); |
||||
} |
||||
|
||||
@Override |
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
||||
if (loaded) { |
||||
return; |
||||
} |
||||
DefaultComboBoxModel loadingModel = new DefaultComboBoxModel(new String[]{"", Inter.getLocText("Loading") + "..."}); |
||||
LazyComboBox.this.setModel(loadingModel); |
||||
new SwingWorker<Void, Void>() { |
||||
|
||||
@Override |
||||
protected Void doInBackground() throws Exception { |
||||
final Object selectedObj = getSelectedItem(); |
||||
loadList(); |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void done() { |
||||
LazyComboBox.this.updateUI(); |
||||
LazyComboBox.this.fireEvent(); |
||||
LazyComboBox.this.showPopup(); |
||||
} |
||||
|
||||
}.execute(); |
||||
|
||||
|
||||
} |
||||
|
||||
/** |
||||
* 计算加载下拉列表 |
||||
*/ |
||||
public void loadList() { |
||||
DefaultComboBoxModel model = new DefaultComboBoxModel(load()); |
||||
model.setSelectedItem(initialSelected); |
||||
LazyComboBox.this.setModel(model); |
||||
LazyComboBox.this.selectedItemReminder = initialSelected ; |
||||
loaded = true; |
||||
} |
||||
|
||||
@Override |
||||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void popupMenuCanceled(PopupMenuEvent e) { |
||||
|
||||
} |
||||
|
||||
public void addClickListener(EventListener l) { |
||||
if (ls == null) { |
||||
ls = new ArrayList<LazyComboBox.EventListener>(); |
||||
} |
||||
ls.add(l); |
||||
} |
||||
|
||||
public void fireEvent() { |
||||
for (int i = 0, n = ls.size(); i < n; i++) { |
||||
ls.get(i).fireEvent(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
Dimension dim = super.getPreferredSize(); |
||||
dim.width = NUM; |
||||
return dim; |
||||
} |
||||
|
||||
private static class LazyPopMenu extends BasicComboPopup { |
||||
|
||||
public LazyPopMenu(final JComboBox combo) { |
||||
super(combo); |
||||
LazyComboBox comboc = (LazyComboBox) combo; |
||||
comboc.addClickListener(new EventListener() { |
||||
|
||||
@Override |
||||
public void fireEvent() { |
||||
LazyPopMenu.this.show(); |
||||
combo.showPopup(); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
private interface EventListener { |
||||
void fireEvent(); |
||||
} |
||||
|
||||
class FilterComboBoxEditor extends UIComboBoxEditor implements DocumentListener { |
||||
private Object item; |
||||
private volatile boolean filtering = false; |
||||
private volatile boolean setting = false; |
||||
|
||||
public FilterComboBoxEditor() { |
||||
super(); |
||||
textField.getDocument().addDocumentListener(this); |
||||
} |
||||
|
||||
public void setItem(Object item) { |
||||
if (filtering) { |
||||
return; |
||||
} |
||||
this.item = item; |
||||
|
||||
this.setting = true; |
||||
textField.setSetting(true); |
||||
String newText = (item == null) ? "" : item.toString(); |
||||
textField.setText(newText); |
||||
textField.setSetting(false); |
||||
this.setting = false; |
||||
} |
||||
|
||||
public Object getItem() { |
||||
return this.item; |
||||
} |
||||
|
||||
public void insertUpdate(DocumentEvent e) { |
||||
handleChange(); |
||||
} |
||||
|
||||
public void removeUpdate(DocumentEvent e) { |
||||
handleChange(); |
||||
} |
||||
|
||||
public void changedUpdate(DocumentEvent e) { |
||||
handleChange(); |
||||
} |
||||
|
||||
protected void handleChange() { |
||||
if (setting) { |
||||
return; |
||||
} |
||||
filtering = true; |
||||
String xx = textField.getText(); |
||||
LazyComboBox.this.setSelectedItem(xx); |
||||
this.item = textField.getText(); |
||||
|
||||
setPopupVisible(true); |
||||
filtering = false; |
||||
} |
||||
} |
||||
/* |
||||
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||
*/ |
||||
package com.fr.design.gui.icombobox; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.DefaultComboBoxModel; |
||||
import javax.swing.SwingWorker; |
||||
import javax.swing.event.DocumentEvent; |
||||
import javax.swing.event.DocumentListener; |
||||
import javax.swing.event.PopupMenuEvent; |
||||
import javax.swing.event.PopupMenuListener; |
||||
import java.awt.Dimension; |
||||
import java.util.concurrent.ExecutionException; |
||||
|
||||
/** |
||||
* @author richer |
||||
* @version 2018年2月6日14点43分 by @yaoh.wu |
||||
* @since 6.5.5 创建于2011-6-15 延迟加载的下拉框 |
||||
*/ |
||||
public abstract class LazyComboBox extends UIComboBox implements PopupMenuListener { |
||||
|
||||
private static final int NUM = 80; |
||||
private static final String[] PENDING_CONTENT = new String[]{"", Inter.getLocText("Loading") + "..."}; |
||||
|
||||
/** |
||||
* 是否加载完成 |
||||
*/ |
||||
protected boolean loaded = false; |
||||
|
||||
/** |
||||
* 初始化选项 |
||||
*/ |
||||
private Object initialSelected = null; |
||||
|
||||
|
||||
protected LazyComboBox() { |
||||
super(); |
||||
this.setEditor(new FilterComboBoxEditor()); |
||||
addPopupMenuListener(this); |
||||
} |
||||
|
||||
public void setLoaded(boolean loaded) { |
||||
this.loaded = loaded; |
||||
} |
||||
|
||||
/** |
||||
* 加载下拉框中的选项 |
||||
* |
||||
* @return 下拉框中的选项 |
||||
*/ |
||||
public abstract Object[] load(); |
||||
|
||||
@Override |
||||
public void setSelectedItem(Object anObject) { |
||||
initialSelected = anObject; |
||||
if (loaded) { |
||||
super.setSelectedItem(anObject); |
||||
} else { |
||||
this.setModel(new DefaultComboBoxModel<>(new Object[]{anObject})); |
||||
super.setSelectedItem(anObject); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
||||
if (loaded) { |
||||
return; |
||||
} |
||||
DefaultComboBoxModel<String> loadingModel = new DefaultComboBoxModel<>(PENDING_CONTENT); |
||||
this.setModel(loadingModel); |
||||
new SwingWorker<Object[], Void>() { |
||||
|
||||
@Override |
||||
protected Object[] doInBackground() { |
||||
return load(); |
||||
} |
||||
|
||||
@Override |
||||
public void done() { |
||||
try { |
||||
LazyComboBox.this.loadList(get()); |
||||
} catch (InterruptedException | ExecutionException exception) { |
||||
FRLogger.getLogger().debug(exception.getMessage()); |
||||
} |
||||
LazyComboBox.this.showPopup(); |
||||
} |
||||
}.execute(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 加载下拉列表 |
||||
*/ |
||||
public void loadList() { |
||||
DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<>(load()); |
||||
model.setSelectedItem(initialSelected); |
||||
this.setModel(model); |
||||
this.selectedItemReminder = initialSelected; |
||||
loaded = true; |
||||
} |
||||
|
||||
/** |
||||
* 加载下拉列表 |
||||
* |
||||
* @param contents 下拉列表内容 |
||||
*/ |
||||
private void loadList(Object[] contents) { |
||||
DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<>(contents); |
||||
model.setSelectedItem(initialSelected); |
||||
this.setModel(model); |
||||
this.selectedItemReminder = initialSelected; |
||||
loaded = true; |
||||
} |
||||
|
||||
@Override |
||||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void popupMenuCanceled(PopupMenuEvent e) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
Dimension dim = super.getPreferredSize(); |
||||
dim.width = NUM; |
||||
return dim; |
||||
} |
||||
|
||||
class FilterComboBoxEditor extends UIComboBoxEditor implements DocumentListener { |
||||
private Object item; |
||||
private volatile boolean filtering = false; |
||||
private volatile boolean setting = false; |
||||
|
||||
public FilterComboBoxEditor() { |
||||
super(); |
||||
textField.getDocument().addDocumentListener(this); |
||||
} |
||||
|
||||
@Override |
||||
public void setItem(Object item) { |
||||
if (filtering) { |
||||
return; |
||||
} |
||||
this.item = item; |
||||
this.setting = true; |
||||
textField.setSetting(true); |
||||
String newText = (item == null) ? "" : item.toString(); |
||||
textField.setText(newText); |
||||
textField.setSetting(false); |
||||
this.setting = false; |
||||
} |
||||
|
||||
@Override |
||||
public Object getItem() { |
||||
return this.item; |
||||
} |
||||
|
||||
@Override |
||||
public void insertUpdate(DocumentEvent e) { |
||||
handleChange(); |
||||
} |
||||
|
||||
@Override |
||||
public void removeUpdate(DocumentEvent e) { |
||||
handleChange(); |
||||
} |
||||
|
||||
@Override |
||||
public void changedUpdate(DocumentEvent e) { |
||||
handleChange(); |
||||
} |
||||
|
||||
void handleChange() { |
||||
if (setting) { |
||||
return; |
||||
} |
||||
filtering = true; |
||||
String xx = textField.getText(); |
||||
LazyComboBox.this.setSelectedItem(xx); |
||||
this.item = textField.getText(); |
||||
|
||||
setPopupVisible(true); |
||||
filtering = false; |
||||
} |
||||
} |
||||
} |
@ -1,214 +1,198 @@
|
||||
package com.fr.design.gui.icombobox; |
||||
|
||||
import com.fr.design.event.GlobalNameListener; |
||||
import com.fr.design.event.GlobalNameObserver; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.plaf.ComboBoxUI; |
||||
import javax.swing.plaf.basic.ComboPopup; |
||||
import java.awt.*; |
||||
import java.awt.event.FocusAdapter; |
||||
import java.awt.event.FocusEvent; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.util.Vector; |
||||
|
||||
/** |
||||
* august:非常beautiful的ComboBox,不支持编辑状态. 内容过长时,鼠标移动过去会有ToolTips,不会有横向滚动条 |
||||
* 假如支持编辑,因为UIComboBox的TextField 的绘制 并不是靠Renderer来控制 , |
||||
* 它会通过paintCurrentValueBackground()来绘制背景, |
||||
* 然后通过paintCurrentValue(),去绘制UIComboBox里显示的值。所考虑情况比现在复杂多多多多多了,所以暂时不支持 |
||||
* 另外,项的内容最好不要有图标 |
||||
* |
||||
* @author zhou |
||||
* @since 2012-5-9下午3:18:58 |
||||
*/ |
||||
public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObserver { |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
private static final int SIZE = 20; |
||||
|
||||
private static final int SIZE5 = 5; |
||||
|
||||
protected UIObserverListener uiObserverListener; |
||||
|
||||
private String comboBoxName = ""; |
||||
|
||||
private GlobalNameListener globalNameListener = null; |
||||
|
||||
public UIComboBox() { |
||||
super(); |
||||
init(); |
||||
} |
||||
|
||||
public UIComboBox(ComboBoxModel model) { |
||||
super(model); |
||||
init(); |
||||
} |
||||
|
||||
public UIComboBox(Object[] items) { |
||||
super(items); |
||||
init(); |
||||
} |
||||
|
||||
public UIComboBox(Vector<?> items) { |
||||
super(items); |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
setOpaque(false); |
||||
setUI(getUIComboBoxUI()); |
||||
setRenderer(new UIComboBoxRenderer()); |
||||
setEditor(new UIComboBoxEditor()); |
||||
initListener(); |
||||
} |
||||
|
||||
protected void initListener() { |
||||
if (shouldResponseChangeListener()) { |
||||
this.addFocusListener(new FocusAdapter() { |
||||
@Override |
||||
public void focusGained(FocusEvent e) { |
||||
fireSetGlobalName(); |
||||
} |
||||
}); |
||||
this.addItemListener(new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
if (uiObserverListener == null) { |
||||
return; |
||||
} |
||||
fireSetGlobalName(); |
||||
if (e.getStateChange() == ItemEvent.SELECTED) { |
||||
uiObserverListener.doChange(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
protected void fireSetGlobalName() { |
||||
if (globalNameListener != null && shouldResponseNameListener()) { |
||||
globalNameListener.setGlobalName(comboBoxName); |
||||
} |
||||
} |
||||
|
||||
|
||||
protected ComboBoxUI getUIComboBoxUI() { |
||||
return new UIComboBoxUI(); |
||||
} |
||||
|
||||
/** |
||||
* 只允许设置为UIComboBoxRenderer,所以要继承UIComboBoxRenderer |
||||
*/ |
||||
@Override |
||||
public void setRenderer(ListCellRenderer aRenderer) { |
||||
if (aRenderer instanceof UIComboBoxRenderer) { |
||||
super.setRenderer(aRenderer); |
||||
} else { |
||||
//throw new IllegalArgumentException("Must be UIComboBoxRenderer");
|
||||
} |
||||
} |
||||
|
||||
protected ComboPopup createPopup() { |
||||
return null; |
||||
} |
||||
|
||||
public void setGlobalName(String name) { |
||||
comboBoxName = name; |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(super.getPreferredSize().width + SIZE5, SIZE);//加5的原因在于:render里,每一个项前面了空了一格,要多几像素
|
||||
} |
||||
|
||||
/** |
||||
* 鼠标进入事件 |
||||
*/ |
||||
public void mouseEnterEvent() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 鼠标离开事件 |
||||
*/ |
||||
public void mouseExitEvent() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
public void updateUI() { |
||||
setUI(getUIComboBoxUI()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
uiObserverListener = listener; |
||||
} |
||||
|
||||
public void removeChangeListener(){ |
||||
uiObserverListener = null; |
||||
} |
||||
|
||||
public UIObserverListener getUiObserverListener(){ |
||||
return uiObserverListener; |
||||
} |
||||
|
||||
/** |
||||
* @return |
||||
*/ |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
public void registerNameListener(GlobalNameListener listener) { |
||||
globalNameListener = listener; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return |
||||
*/ |
||||
public boolean shouldResponseNameListener() { |
||||
return true; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @param args |
||||
*/ |
||||
public static void main(String... args) { |
||||
LayoutManager layoutManager = null; |
||||
JFrame jf = new JFrame("test"); |
||||
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
JPanel content = (JPanel) jf.getContentPane(); |
||||
content.setLayout(layoutManager); |
||||
UIComboBox bb = new UIComboBox(new String[]{"", "jerry", "kunsnat", "richer"}); |
||||
bb.setEditable(true); |
||||
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height); |
||||
content.add(bb); |
||||
GUICoreUtils.centerWindow(jf); |
||||
jf.setSize(400, 400); |
||||
jf.setVisible(true); |
||||
} |
||||
|
||||
|
||||
package com.fr.design.gui.icombobox; |
||||
|
||||
import com.fr.design.event.GlobalNameListener; |
||||
import com.fr.design.event.GlobalNameObserver; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
|
||||
import javax.swing.ComboBoxModel; |
||||
import javax.swing.JComboBox; |
||||
import javax.swing.ListCellRenderer; |
||||
import javax.swing.plaf.ComboBoxUI; |
||||
import javax.swing.plaf.basic.ComboPopup; |
||||
import java.awt.Dimension; |
||||
import java.awt.event.FocusAdapter; |
||||
import java.awt.event.FocusEvent; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.util.Vector; |
||||
|
||||
/** |
||||
* august:非常beautiful的ComboBox,不支持编辑状态. 内容过长时,鼠标移动过去会有ToolTips,不会有横向滚动条 |
||||
* 假如支持编辑,因为UIComboBox的TextField 的绘制 并不是靠Renderer来控制 , |
||||
* 它会通过paintCurrentValueBackground()来绘制背景, |
||||
* 然后通过paintCurrentValue(),去绘制UIComboBox里显示的值。所考虑情况比现在复杂多多多多多了,所以暂时不支持 |
||||
* 另外,项的内容最好不要有图标 |
||||
* |
||||
* @author zhou |
||||
* @since 2012-5-9下午3:18:58 |
||||
*/ |
||||
public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObserver { |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
private static final int SIZE = 20; |
||||
|
||||
private static final int SIZE5 = 5; |
||||
|
||||
protected UIObserverListener uiObserverListener; |
||||
|
||||
private String comboBoxName = ""; |
||||
|
||||
private GlobalNameListener globalNameListener = null; |
||||
|
||||
public UIComboBox() { |
||||
super(); |
||||
init(); |
||||
} |
||||
|
||||
public UIComboBox(ComboBoxModel model) { |
||||
super(model); |
||||
init(); |
||||
} |
||||
|
||||
public UIComboBox(Object[] items) { |
||||
super(items); |
||||
init(); |
||||
} |
||||
|
||||
public UIComboBox(Vector<?> items) { |
||||
super(items); |
||||
init(); |
||||
} |
||||
|
||||
private void init() { |
||||
setOpaque(false); |
||||
setUI(getUIComboBoxUI()); |
||||
setRenderer(new UIComboBoxRenderer()); |
||||
setEditor(new UIComboBoxEditor()); |
||||
initListener(); |
||||
} |
||||
|
||||
protected void initListener() { |
||||
if (shouldResponseChangeListener()) { |
||||
this.addFocusListener(new FocusAdapter() { |
||||
@Override |
||||
public void focusGained(FocusEvent e) { |
||||
fireSetGlobalName(); |
||||
} |
||||
}); |
||||
this.addItemListener(new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
if (uiObserverListener == null) { |
||||
return; |
||||
} |
||||
fireSetGlobalName(); |
||||
if (e.getStateChange() == ItemEvent.SELECTED) { |
||||
uiObserverListener.doChange(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
protected void fireSetGlobalName() { |
||||
if (globalNameListener != null && shouldResponseNameListener()) { |
||||
globalNameListener.setGlobalName(comboBoxName); |
||||
} |
||||
} |
||||
|
||||
|
||||
protected ComboBoxUI getUIComboBoxUI() { |
||||
return new UIComboBoxUI(); |
||||
} |
||||
|
||||
/** |
||||
* 只允许设置为UIComboBoxRenderer,所以要继承UIComboBoxRenderer |
||||
*/ |
||||
@Override |
||||
public void setRenderer(ListCellRenderer aRenderer) { |
||||
if (aRenderer instanceof UIComboBoxRenderer) { |
||||
super.setRenderer(aRenderer); |
||||
} |
||||
} |
||||
|
||||
protected ComboPopup createPopup() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void setGlobalName(String name) { |
||||
comboBoxName = name; |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
//加5的原因在于:render里,每一个项前面了空了一格,要多几像素
|
||||
return new Dimension(super.getPreferredSize().width + SIZE5, SIZE); |
||||
} |
||||
|
||||
/** |
||||
* 鼠标进入事件 |
||||
*/ |
||||
public void mouseEnterEvent() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 鼠标离开事件 |
||||
*/ |
||||
public void mouseExitEvent() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@Override |
||||
public void updateUI() { |
||||
setUI(getUIComboBoxUI()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
@Override |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
uiObserverListener = listener; |
||||
} |
||||
|
||||
public void removeChangeListener() { |
||||
uiObserverListener = null; |
||||
} |
||||
|
||||
public UIObserverListener getUiObserverListener() { |
||||
return uiObserverListener; |
||||
} |
||||
|
||||
/** |
||||
* @return 是否响应变更事件 |
||||
*/ |
||||
@Override |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @param listener 观察者监听事件 |
||||
*/ |
||||
@Override |
||||
public void registerNameListener(GlobalNameListener listener) { |
||||
globalNameListener = listener; |
||||
} |
||||
|
||||
/** |
||||
* @return 是否响应名称事件 |
||||
*/ |
||||
@Override |
||||
public boolean shouldResponseNameListener() { |
||||
return true; |
||||
} |
||||
|
||||
|
||||
} |
@ -1 +1,36 @@
|
||||
package com.fr.design.icon;
/**
* Created by IntelliJ IDEA.
* Author : Richer
* Version: 6.5.6
* Date: 12-12-18
* Time: 上午9:42
* 用于保存所有图标路径的类
*/
public class IconPathConstants {
private IconPathConstants() {
}
public static final String ADD_POPMENU_ICON_PATH = "/com/fr/design/images/control/addPopup.png";
public static final String DS_ICON_PATH = "/com/fr/design/images/data/datasource.png";
public static final String CLASS_TD_ICON_PATH = "/com/fr/design/images/data/source/classTableData.png";
public static final String EMB_TD_ICON_PATH = "/com/fr/design/images/data/dataTable.png";
public static final String DS_RELATION_TD_ICON_PATH = "/com/fr/design/images/data/multi.png";
public static final String FILE_TD_ICON_PATH = "/com/fr/design/images/data/file.png";
public static final String DS_TREE_TD_ICON_PATH = "/com/fr/design/images/data/tree.png";
public static final String DS_QUERY_ICON_PATH = "/com/fr/design/images/data/database.png";
public static final String PREVIEW_ICON_PATH = "/com/fr/design/images/m_file/preview.png";
public static final String TD_EDIT_ICON_PATH = "/com/fr/design/images/control/edit.png";
public static final String TD_EL_SHARE_HELP_ICON_PATH = "/com/fr/design/images/control/help_open.png";
public static final String TD_EL_SHARE_CLOSE_ICON_PATH = "/com/fr/design/images/control/help_close.png";
public static final String TD_REMOVE_ICON_PATH = "/com/fr/design/images/control/tab/remove.png";
public static final String TD_CONNECTION_ICON_PATH = "/com/fr/design/images/m_web/connection.png";
public static final String SP_SHOW_ICON_PATH = "/com/fr/design/images/data/store_procedure.png";
public static final String STD_SHOW_ICON_PATH = "/com/fr/design/images/data/dock/serverdatabase.png";
public static final String XMLA_ICON_PATH = "/com/fr/design/images/data/cube.png";
public static final String FORBID_ICON_PATH = "/com/fr/web/images/form/forbid.png";
} |
||||
package com.fr.design.icon; |
||||
|
||||
/** |
||||
* Created by IntelliJ IDEA. |
||||
* Author : Richer |
||||
* Version: 6.5.6 |
||||
* Date: 12-12-18 |
||||
* Time: 上午9:42 |
||||
* 用于保存所有图标路径的类 |
||||
*/ |
||||
public class IconPathConstants { |
||||
private IconPathConstants() { |
||||
|
||||
} |
||||
|
||||
public static final String ADD_POPMENU_ICON_PATH = "/com/fr/design/images/control/addPopup.png"; |
||||
|
||||
public static final String DS_ICON_PATH = "/com/fr/design/images/data/datasource.png"; |
||||
public static final String CLASS_TD_ICON_PATH = "/com/fr/design/images/data/source/classTableData.png"; |
||||
public static final String EMB_TD_ICON_PATH = "/com/fr/design/images/data/dataTable.png"; |
||||
public static final String DS_RELATION_TD_ICON_PATH = "/com/fr/design/images/data/multi.png"; |
||||
public static final String FILE_TD_ICON_PATH = "/com/fr/design/images/data/file.png"; |
||||
public static final String DS_TREE_TD_ICON_PATH = "/com/fr/design/images/data/tree.png"; |
||||
public static final String DS_QUERY_ICON_PATH = "/com/fr/design/images/data/database.png"; |
||||
public static final String PREVIEW_ICON_PATH = "/com/fr/design/images/m_file/preview.png"; |
||||
public static final String TD_EDIT_ICON_PATH = "/com/fr/design/images/control/edit.png"; |
||||
public static final String TD_EL_SHARE_HELP_ICON_PATH = "/com/fr/design/images/control/help_open.png"; |
||||
public static final String TD_EL_SHARE_CLOSE_ICON_PATH = "/com/fr/design/images/control/help_close.png"; |
||||
public static final String TD_REMOVE_ICON_PATH = "/com/fr/design/images/control/tab/remove.png"; |
||||
public static final String TD_CONNECTION_ICON_PATH = "/com/fr/design/images/m_web/connection.png"; |
||||
public static final String SP_SHOW_ICON_PATH = "/com/fr/design/images/data/store_procedure.png"; |
||||
public static final String STD_SHOW_ICON_PATH = "/com/fr/design/images/data/dock/serverdatabase.png"; |
||||
public static final String XMLA_ICON_PATH = "/com/fr/design/images/data/cube.png"; |
||||
public static final String FORBID_ICON_PATH = "/com/fr/web/images/form/forbid.png"; |
||||
public static final String EDIT_ICON_PATH = "/com/fr/design/images/control/newEdit.png"; |
||||
} |
Before Width: | Height: | Size: 306 B After Width: | Height: | Size: 321 B |
Before Width: | Height: | Size: 232 B After Width: | Height: | Size: 203 B |
After Width: | Height: | Size: 442 B |
@ -0,0 +1,17 @@
|
||||
package com.fr.design.mainframe.widget.accessibles; |
||||
|
||||
import com.fr.design.style.background.BackgroundButtonPane; |
||||
import com.fr.design.style.background.BackgroundCardSwitchButtonPane; |
||||
/** |
||||
* @author kerry |
||||
* @date 2018/1/29 |
||||
*/ |
||||
public class AccessibleTabBackgroundEditor extends AccessibleImgBackgroundEditor { |
||||
public AccessibleTabBackgroundEditor() { |
||||
super(); |
||||
} |
||||
@Override |
||||
protected BackgroundButtonPane initBackgroundPane(){ |
||||
return new BackgroundCardSwitchButtonPane(); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.fr.design.mainframe.widget.accessibles; |
||||
|
||||
import com.fr.base.background.ColorBackground; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.mainframe.widget.wrappers.BackgroundWrapper; |
||||
import com.fr.design.style.background.BackgroundTabPane; |
||||
import com.fr.general.Background; |
||||
|
||||
import javax.swing.SwingUtilities; |
||||
import java.awt.Dimension; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/1/17 |
||||
*/ |
||||
public class AccessibleTabPaneBackgroundEditor extends UneditableAccessibleEditor { |
||||
private BackgroundTabPane choosePane; |
||||
|
||||
public AccessibleTabPaneBackgroundEditor() { |
||||
super(new BackgroundWrapper()); |
||||
} |
||||
|
||||
@Override |
||||
protected void showEditorPane() { |
||||
choosePane = new BackgroundTabPane(); |
||||
choosePane.setPreferredSize(new Dimension(600, 400)); |
||||
BasicDialog dlg = choosePane.showWindow(SwingUtilities.getWindowAncestor(this)); |
||||
dlg.addDialogActionListener(new DialogActionAdapter() { |
||||
|
||||
@Override |
||||
public void doOk() { |
||||
setValue(choosePane.update()); |
||||
fireStateChanged(); |
||||
} |
||||
}); |
||||
choosePane.populate(getValue() instanceof Background ? (Background) getValue() : new ColorBackground()); |
||||
dlg.setVisible(true); |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.design.style.background; |
||||
|
||||
import com.fr.base.background.ColorBackground; |
||||
import com.fr.base.background.GradientBackground; |
||||
import com.fr.base.background.ImageBackground; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.style.background.gradient.GradientBackgroundPane; |
||||
import com.fr.design.style.background.impl.ColorBackgroundPane; |
||||
import com.fr.design.style.background.impl.ImageBackgroundPane; |
||||
import com.fr.design.style.background.impl.NullBackgroundPane; |
||||
import com.fr.general.Background; |
||||
import com.fr.general.Inter; |
||||
|
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/1/29 |
||||
*/ |
||||
public class BackgroundCardSwitchButtonPane extends BackgroundButtonPane { |
||||
|
||||
private static Map<Class<? extends Background>, BackgroundUIWrapper> cardSwitchButton = new LinkedHashMap<>(); |
||||
|
||||
static { |
||||
registerCardSwitchBtnBackground(cardSwitchButton); |
||||
} |
||||
|
||||
|
||||
private static void registerCardSwitchBtnBackground(Map<Class<? extends Background>, BackgroundUIWrapper> map) { |
||||
map.put(ColorBackground.class, BackgroundUIWrapper.create() |
||||
.setType(ColorBackgroundPane.class).setTitle(Inter.getLocText("FR-Designer_Background_Color"))); |
||||
map.put(ImageBackground.class, BackgroundUIWrapper.create() |
||||
.setType(ImageBackgroundPane.class).setTitle(Inter.getLocText("FR-Designer_Background_Image"))); |
||||
map.put(GradientBackground.class, BackgroundUIWrapper.create() |
||||
.setType(GradientBackgroundPane.class).setTitle(Inter.getLocText("FR-Designer_Background_Gradient_Color"))); |
||||
|
||||
} |
||||
|
||||
public BackgroundCardSwitchButtonPane() { |
||||
super(); |
||||
} |
||||
|
||||
@Override |
||||
protected void initTabPane() { |
||||
int index = 0; |
||||
for (Class<? extends Background> key : cardSwitchButton.keySet()) { |
||||
BackgroundUIWrapper wrapper = cardSwitchButton.get(key); |
||||
wrapper.setIndex(index++); |
||||
tabbedPane.addTab(Inter.getLocText(wrapper.getTitle()), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected BackgroundUIWrapper getBackgroundUIWrapper(Background background) { |
||||
return cardSwitchButton.get(background == null ? null : background.getClass()); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected BackgroundDetailPane getTabItemPane(Background background, int index) { |
||||
BackgroundDetailPane quickPane = cacheMap.get(index); |
||||
if (quickPane == null) { |
||||
BackgroundUIWrapper uiWrapper = getBackgroundUIWrapper(background); |
||||
quickPane = BackgroundFactory.createByWrapper(uiWrapper); |
||||
quickPane.addChangeListener(backgroundChangeListener); |
||||
cacheMap.put(index, quickPane); |
||||
} |
||||
tabbedPane.setComponentAt(index, quickPane); |
||||
tabbedPane.setSelectedIndex(index); |
||||
return quickPane; |
||||
} |
||||
|
||||
@Override |
||||
protected BackgroundDetailPane getTabItemPaneByIndex(int index) { |
||||
BackgroundDetailPane quickPane = cacheMap.get(index); |
||||
if (quickPane == null) { |
||||
quickPane = createDetailPaneByIndex(index); |
||||
tabbedPane.setComponentAt(index, quickPane); |
||||
cacheMap.put(index, quickPane); |
||||
quickPane.addChangeListener(backgroundChangeListener); |
||||
} |
||||
return quickPane; |
||||
} |
||||
|
||||
public BackgroundDetailPane createDetailPaneByIndex(int index) { |
||||
for (BackgroundUIWrapper wrapper : cardSwitchButton.values()) { |
||||
if (wrapper.getIndex() == index) { |
||||
return BackgroundFactory.createByWrapper(wrapper); |
||||
} |
||||
} |
||||
return new NullBackgroundPane(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,88 @@
|
||||
package com.fr.design.style.background; |
||||
|
||||
import com.fr.base.background.ColorBackground; |
||||
import com.fr.base.background.GradientBackground; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.style.background.gradient.GradientBackgroundPane; |
||||
import com.fr.design.style.background.impl.ColorBackgroundPane; |
||||
import com.fr.design.style.background.impl.NullBackgroundPane; |
||||
import com.fr.general.Background; |
||||
import com.fr.general.Inter; |
||||
|
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/1/17 |
||||
*/ |
||||
public class BackgroundTabPane extends BackgroundPane { |
||||
|
||||
private static Map<Class<? extends Background>, BackgroundUIWrapper> tabpane = new LinkedHashMap<>(); |
||||
|
||||
static { |
||||
registerTabpaneBackground(tabpane); |
||||
} |
||||
|
||||
|
||||
private static void registerTabpaneBackground(Map<Class<? extends Background>, BackgroundUIWrapper> map) { |
||||
map.put(null, BackgroundUIWrapper.create() |
||||
.setType(NullBackgroundPane.class).setTitle(Inter.getLocText("FR-Designer_Background_Null"))); |
||||
map.put(ColorBackground.class, BackgroundUIWrapper.create() |
||||
.setType(ColorBackgroundPane.class).setTitle(Inter.getLocText("FR-Designer_Background_Color"))); |
||||
map.put(GradientBackground.class, BackgroundUIWrapper.create() |
||||
.setType(GradientBackgroundPane.class).setTitle(Inter.getLocText("FR-Designer_Background_Gradient_Color"))); |
||||
|
||||
} |
||||
|
||||
public BackgroundTabPane() { |
||||
super(); |
||||
} |
||||
|
||||
protected void initTabPane() { |
||||
int index = 0; |
||||
for (Class<? extends Background> key : tabpane.keySet()) { |
||||
BackgroundUIWrapper wrapper = tabpane.get(key); |
||||
wrapper.setIndex(index++); |
||||
tabbedPane.addTab(Inter.getLocText(wrapper.getTitle()), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); |
||||
} |
||||
} |
||||
|
||||
protected BackgroundUIWrapper getBackgroundUIWrapper(Background background) { |
||||
return tabpane.get(background == null ? null : background.getClass()); |
||||
} |
||||
|
||||
protected BackgroundDetailPane getTabItemPane(Background background, int index) { |
||||
BackgroundDetailPane quickPane = cacheMap.get(index); |
||||
if (quickPane == null) { |
||||
BackgroundUIWrapper uiWrapper = getBackgroundUIWrapper(background); |
||||
quickPane = BackgroundFactory.createByWrapper(uiWrapper); |
||||
quickPane.addChangeListener(backgroundChangeListener); |
||||
cacheMap.put(index, quickPane); |
||||
} |
||||
tabbedPane.setComponentAt(index, quickPane); |
||||
tabbedPane.setSelectedIndex(index); |
||||
return quickPane; |
||||
} |
||||
|
||||
protected BackgroundDetailPane getTabItemPaneByIndex(int index) { |
||||
BackgroundDetailPane quickPane = cacheMap.get(index); |
||||
if (quickPane == null) { |
||||
quickPane = createDetailPaneByIndex(index); |
||||
tabbedPane.setComponentAt(index, quickPane); |
||||
cacheMap.put(index, quickPane); |
||||
quickPane.addChangeListener(backgroundChangeListener); |
||||
} |
||||
return quickPane; |
||||
} |
||||
|
||||
public BackgroundDetailPane createDetailPaneByIndex(int index) { |
||||
for (BackgroundUIWrapper wrapper : tabpane.values()) { |
||||
if (wrapper.getIndex() == index) { |
||||
return BackgroundFactory.createByWrapper(wrapper); |
||||
} |
||||
} |
||||
return new NullBackgroundPane(); |
||||
} |
||||
|
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue