fr_shine
8 years ago
88 changed files with 2178 additions and 1751 deletions
@ -1,13 +1,14 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||||
<module type="JAVA_MODULE" version="4"> |
<module type="JAVA_MODULE" version="4"> |
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false"> |
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
||||||
<output url="file://$MODULE_DIR$/../../env/WebReport/WEB-INF/classes" /> |
<exclude-output /> |
||||||
<content url="file://$MODULE_DIR$"> |
<content url="file://$MODULE_DIR$"> |
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
||||||
</content> |
</content> |
||||||
<orderEntry type="jdk" jdkName="jdk1.8" jdkType="JavaSDK" /> |
<orderEntry type="inheritedJdk" /> |
||||||
<orderEntry type="sourceFolder" forTests="false" /> |
<orderEntry type="sourceFolder" forTests="false" /> |
||||||
<orderEntry type="module" module-name="designer_base" /> |
<orderEntry type="module" module-name="designer_base" /> |
||||||
<orderEntry type="library" name="lib" level="project" /> |
<orderEntry type="module" module-name="designer_form" /> |
||||||
|
<orderEntry type="module" module-name="designer_chart" /> |
||||||
</component> |
</component> |
||||||
</module> |
</module> |
@ -0,0 +1,41 @@ |
|||||||
|
package com.fr.design.fun; |
||||||
|
|
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.stable.fun.mark.Mutable; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 报表工具栏设计器端拓展,用于配置按钮额外属性 |
||||||
|
* Created by harry on 2016-12-23. |
||||||
|
*/ |
||||||
|
public interface ExtraButtonToolBarProvider extends Mutable { |
||||||
|
|
||||||
|
String XML_TAG = "ExtraButtonToolBarProvider"; |
||||||
|
|
||||||
|
int CURRENT_LEVEL = 1; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用于添加属性面板 |
||||||
|
* |
||||||
|
* @param centerPane 面板 |
||||||
|
*/ |
||||||
|
void updateCenterPane(JPanel centerPane); |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新界面 |
||||||
|
* |
||||||
|
* @param widget 控件 |
||||||
|
* @param card 卡片布局 |
||||||
|
* @param centerPane 面板 |
||||||
|
*/ |
||||||
|
void populate(Widget widget, CardLayout card, JPanel centerPane); |
||||||
|
|
||||||
|
/** |
||||||
|
* 保存界面设置 |
||||||
|
* |
||||||
|
* @param widget 控件 |
||||||
|
*/ |
||||||
|
void update(Widget widget); |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package com.fr.design.fun.impl; |
||||||
|
|
||||||
|
import com.fr.design.fun.ExtraButtonToolBarProvider; |
||||||
|
import com.fr.stable.fun.impl.AbstractProvider; |
||||||
|
import com.fr.stable.fun.mark.API; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by harry on 2016-12-23. |
||||||
|
*/ |
||||||
|
@API(level = ExtraButtonToolBarProvider.CURRENT_LEVEL) |
||||||
|
public abstract class AbstractExtraButtonToolBarProvider extends AbstractProvider implements ExtraButtonToolBarProvider { |
||||||
|
public int currentAPILevel() { |
||||||
|
return ExtraButtonToolBarProvider.CURRENT_LEVEL; |
||||||
|
} |
||||||
|
|
||||||
|
public String mark4Provider() { |
||||||
|
return getClass().getName(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
package com.fr.design.designer.creator.cardlayout; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.actions.FormUndoableAction; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.form.ui.CardSwitchButton; |
||||||
|
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||||
|
import com.fr.general.FRLogger; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by zhouping on 2017/2/17. |
||||||
|
*/ |
||||||
|
public class TabMoveAction extends FormUndoableAction { |
||||||
|
private XCardSwitchButton xCardSwitchButton; |
||||||
|
|
||||||
|
public TabMoveAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||||
|
super(t); |
||||||
|
this.xCardSwitchButton = xCardSwitchButton; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
|
XCardSwitchButton xCardSwitchButton = getxCardSwitchButton(); |
||||||
|
XWCardTagLayout xwCardTagLayout = xCardSwitchButton.getTagLayout(); |
||||||
|
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
||||||
|
CardSwitchButton currentButton = (CardSwitchButton) xCardSwitchButton.toData(); |
||||||
|
try { |
||||||
|
int currentIndex = currentButton.getIndex(); |
||||||
|
int maxIndex = xwCardTagLayout.getComponentCount(); |
||||||
|
XWTabFitLayout xCurrentTab = (XWTabFitLayout) xwCardLayout.getXCreator(currentIndex); |
||||||
|
WTabFitLayout currentTab = (WTabFitLayout) xCurrentTab.toData(); |
||||||
|
xwCardTagLayout.setSwitchingTab(true); |
||||||
|
|
||||||
|
changeTabIndex(xwCardTagLayout, xwCardLayout, currentIndex, maxIndex); |
||||||
|
|
||||||
|
moveTabAction(xwCardTagLayout, currentButton, xCurrentTab, currentTab); |
||||||
|
|
||||||
|
xwCardTagLayout.setSwitchingTab(false); |
||||||
|
}catch (Exception e){ |
||||||
|
xwCardTagLayout.setSwitchingTab(false); |
||||||
|
FRLogger.getLogger().error(e.getMessage()); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
private void moveTabAction(XWCardTagLayout xwCardTagLayout, CardSwitchButton currentButton, XWTabFitLayout xCurrentTab, WTabFitLayout currentTab) { |
||||||
|
int move2Index = getTabMoveIndex(currentButton); |
||||||
|
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
||||||
|
xwCardTagLayout.remove(xCardSwitchButton); |
||||||
|
xwCardTagLayout.add(xCardSwitchButton, move2Index); |
||||||
|
xwCardLayout.remove(xCurrentTab); |
||||||
|
xwCardLayout.add(xCurrentTab, move2Index); |
||||||
|
currentButton.setIndex(move2Index); |
||||||
|
currentTab.setIndex(move2Index); |
||||||
|
currentTab.setTabNameIndex(move2Index); |
||||||
|
xwCardLayout.toData().setShowIndex(move2Index); |
||||||
|
xwCardLayout.showCard(); |
||||||
|
} |
||||||
|
|
||||||
|
//改变Tab的索引号
|
||||||
|
protected void changeTabIndex(XWCardTagLayout xwCardTagLayout, XWCardLayout xwCardLayout, int currentIndex, int maxIndex) { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取tab移动的目的索引:首位,末尾,下一个,上一个 |
||||||
|
* @param currentButton 当前按钮 |
||||||
|
* @return 索引 |
||||||
|
*/ |
||||||
|
protected int getTabMoveIndex(CardSwitchButton currentButton) { |
||||||
|
return currentButton.getIndex(); |
||||||
|
} |
||||||
|
|
||||||
|
public XCardSwitchButton getxCardSwitchButton() { |
||||||
|
return xCardSwitchButton; |
||||||
|
} |
||||||
|
|
||||||
|
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
||||||
|
this.xCardSwitchButton = xCardSwitchButton; |
||||||
|
} |
||||||
|
} |
@ -1,32 +1,17 @@ |
|||||||
package com.fr.design.designer.creator.cardlayout; |
package com.fr.design.designer.creator.cardlayout; |
||||||
|
|
||||||
import com.fr.base.BaseUtils; |
|
||||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
|
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.general.IOUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by zhouping on 2017/2/9. |
* Created by zhouping on 2017/2/9. |
||||||
*/ |
*/ |
||||||
public class TabMoveCustomAction extends FormUndoableAction { |
public class TabMoveCustomAction extends TabMoveAction { |
||||||
private XCardSwitchButton xCardSwitchButton; |
|
||||||
|
|
||||||
public TabMoveCustomAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
public TabMoveCustomAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||||
super(t); |
super(t, xCardSwitchButton); |
||||||
this.setName(""); |
this.setName(""); |
||||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/refresh.png")); |
this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/control/refresh.png")); |
||||||
this.xCardSwitchButton = xCardSwitchButton; |
|
||||||
} |
} |
||||||
|
|
||||||
@Override |
|
||||||
public boolean executeActionReturnUndoRecordNeeded() { |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
public XCardSwitchButton getxCardSwitchButton() { |
|
||||||
return xCardSwitchButton; |
|
||||||
} |
|
||||||
|
|
||||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
|
||||||
this.xCardSwitchButton = xCardSwitchButton; |
|
||||||
} |
|
||||||
} |
} |
||||||
|
@ -1,64 +1,34 @@ |
|||||||
package com.fr.design.designer.creator.cardlayout; |
package com.fr.design.designer.creator.cardlayout; |
||||||
|
|
||||||
import com.fr.base.BaseUtils; |
|
||||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
|
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.form.ui.CardSwitchButton; |
import com.fr.form.ui.CardSwitchButton; |
||||||
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||||
import com.fr.general.FRLogger; |
import com.fr.general.IOUtils; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by zhouping on 2017/2/9. |
* Created by zhouping on 2017/2/9. |
||||||
*/ |
*/ |
||||||
public class TabMoveNextAction extends FormUndoableAction { |
public class TabMoveNextAction extends TabMoveAction { |
||||||
private XCardSwitchButton xCardSwitchButton; |
|
||||||
|
|
||||||
public TabMoveNextAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
public TabMoveNextAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||||
super(t); |
super(t, xCardSwitchButton); |
||||||
this.setName(Inter.getLocText("FR-Designer-Move_Tab_Next")); |
this.setName(Inter.getLocText("FR-Designer-Move_Tab_Next")); |
||||||
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/control/right.png")); |
this.setSmallIcon(IOUtils.readIcon("com/fr/design/images/control/right.png")); |
||||||
this.xCardSwitchButton = xCardSwitchButton; |
|
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public boolean executeActionReturnUndoRecordNeeded() { |
protected void changeTabIndex(XWCardTagLayout xwCardTagLayout, XWCardLayout xwCardLayout, int currentIndex, int maxIndex) { |
||||||
XWCardTagLayout xwCardTagLayout = xCardSwitchButton.getTagLayout(); |
|
||||||
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
|
||||||
CardSwitchButton currentButton = (CardSwitchButton) xCardSwitchButton.toData(); |
|
||||||
try { |
|
||||||
int currentIndex = currentButton.getIndex(); |
|
||||||
XWTabFitLayout xCurrentTab = (XWTabFitLayout) xwCardLayout.getXCreator(currentIndex); |
|
||||||
WTabFitLayout currentTab = (WTabFitLayout) xCurrentTab.toData(); |
|
||||||
xwCardTagLayout.setSwitchingTab(true); |
|
||||||
//修改下一个tab的索引号
|
//修改下一个tab的索引号
|
||||||
CardSwitchButton nextBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex + 1).toData(); |
CardSwitchButton nextBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex + 1).toData(); |
||||||
nextBtn.setIndex(currentIndex); |
nextBtn.setIndex(currentIndex); |
||||||
WTabFitLayout nextTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex + 1).toData(); |
WTabFitLayout nextTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex + 1).toData(); |
||||||
nextTab.setIndex(currentIndex); |
nextTab.setIndex(currentIndex); |
||||||
nextTab.setTabNameIndex(currentIndex); |
nextTab.setTabNameIndex(currentIndex); |
||||||
|
|
||||||
xwCardTagLayout.remove(xCardSwitchButton); |
|
||||||
xwCardTagLayout.add(xCardSwitchButton, currentIndex + 1); |
|
||||||
xwCardLayout.remove(xCurrentTab); |
|
||||||
xwCardLayout.add(xCurrentTab, currentIndex + 1); |
|
||||||
currentButton.setIndex(currentIndex + 1); |
|
||||||
currentTab.setIndex(currentIndex + 1); |
|
||||||
currentTab.setTabNameIndex(currentIndex + 1); |
|
||||||
xwCardTagLayout.setSwitchingTab(false); |
|
||||||
}catch (Exception e){ |
|
||||||
xwCardTagLayout.setSwitchingTab(false); |
|
||||||
FRLogger.getLogger().error(e.getMessage()); |
|
||||||
return false; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
} |
||||||
|
|
||||||
public XCardSwitchButton getxCardSwitchButton() { |
@Override |
||||||
return xCardSwitchButton; |
protected int getTabMoveIndex(CardSwitchButton currentButton) { |
||||||
} |
return currentButton.getIndex() + 1; |
||||||
|
|
||||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
|
||||||
this.xCardSwitchButton = xCardSwitchButton; |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,64 +1,34 @@ |
|||||||
package com.fr.design.designer.creator.cardlayout; |
package com.fr.design.designer.creator.cardlayout; |
||||||
|
|
||||||
import com.fr.base.BaseUtils; |
|
||||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
|
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.form.ui.CardSwitchButton; |
import com.fr.form.ui.CardSwitchButton; |
||||||
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||||
import com.fr.general.FRLogger; |
import com.fr.general.IOUtils; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by zhouping on 2017/2/9. |
* Created by zhouping on 2017/2/9. |
||||||
*/ |
*/ |
||||||
public class TabMovePrevAction extends FormUndoableAction { |
public class TabMovePrevAction extends TabMoveAction { |
||||||
private XCardSwitchButton xCardSwitchButton; |
|
||||||
|
|
||||||
public TabMovePrevAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
public TabMovePrevAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||||
super(t); |
super(t, xCardSwitchButton); |
||||||
this.setName(Inter.getLocText("FR-Designer-Move_Tab_Prev")); |
this.setName(Inter.getLocText("FR-Designer-Move_Tab_Prev")); |
||||||
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/control/left.png")); |
this.setSmallIcon(IOUtils.readIcon("com/fr/design/images/control/left.png")); |
||||||
this.xCardSwitchButton = xCardSwitchButton; |
|
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public boolean executeActionReturnUndoRecordNeeded() { |
protected void changeTabIndex(XWCardTagLayout xwCardTagLayout, XWCardLayout xwCardLayout, int currentIndex, int maxIndex) { |
||||||
XWCardTagLayout xwCardTagLayout = xCardSwitchButton.getTagLayout(); |
|
||||||
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
|
||||||
CardSwitchButton currentButton = (CardSwitchButton) xCardSwitchButton.toData(); |
|
||||||
try { |
|
||||||
int currentIndex = currentButton.getIndex(); |
|
||||||
XWTabFitLayout xCurrentTab = (XWTabFitLayout) xwCardLayout.getXCreator(currentIndex); |
|
||||||
WTabFitLayout currentTab = (WTabFitLayout) xCurrentTab.toData(); |
|
||||||
xwCardTagLayout.setSwitchingTab(true); |
|
||||||
//修改上一个tab的索引号
|
//修改上一个tab的索引号
|
||||||
CardSwitchButton prevBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex - 1).toData(); |
CardSwitchButton prevBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex - 1).toData(); |
||||||
prevBtn.setIndex(currentIndex); |
prevBtn.setIndex(currentIndex); |
||||||
WTabFitLayout prevTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex - 1).toData(); |
WTabFitLayout prevTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex - 1).toData(); |
||||||
prevTab.setIndex(currentIndex); |
prevTab.setIndex(currentIndex); |
||||||
prevTab.setTabNameIndex(currentIndex); |
prevTab.setTabNameIndex(currentIndex); |
||||||
|
|
||||||
xwCardTagLayout.remove(xCardSwitchButton); |
|
||||||
xwCardTagLayout.add(xCardSwitchButton, currentIndex - 1); |
|
||||||
xwCardLayout.remove(xCurrentTab); |
|
||||||
xwCardLayout.add(xCurrentTab, currentIndex - 1); |
|
||||||
currentButton.setIndex(currentIndex - 1); |
|
||||||
currentTab.setIndex(currentIndex - 1); |
|
||||||
currentTab.setTabNameIndex(currentIndex - 1); |
|
||||||
xwCardTagLayout.setSwitchingTab(false); |
|
||||||
}catch (Exception e){ |
|
||||||
xwCardTagLayout.setSwitchingTab(false); |
|
||||||
FRLogger.getLogger().error(e.getMessage()); |
|
||||||
return false; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
} |
||||||
|
|
||||||
public XCardSwitchButton getxCardSwitchButton() { |
@Override |
||||||
return xCardSwitchButton; |
protected int getTabMoveIndex(CardSwitchButton currentButton) { |
||||||
} |
return currentButton.getIndex() - 1; |
||||||
|
|
||||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
|
||||||
this.xCardSwitchButton = xCardSwitchButton; |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,267 +0,0 @@ |
|||||||
package com.fr.design.mainframe; |
|
||||||
|
|
||||||
import java.awt.Color; |
|
||||||
import java.awt.Component; |
|
||||||
import java.awt.Cursor; |
|
||||||
import java.awt.Dimension; |
|
||||||
import java.awt.event.MouseAdapter; |
|
||||||
import java.awt.event.MouseEvent; |
|
||||||
import java.util.ArrayList; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.JLabel; |
|
||||||
import javax.swing.JTable; |
|
||||||
import javax.swing.ListSelectionModel; |
|
||||||
import javax.swing.table.DefaultTableCellRenderer; |
|
||||||
import javax.swing.table.DefaultTableModel; |
|
||||||
import javax.swing.table.JTableHeader; |
|
||||||
import javax.swing.table.TableModel; |
|
||||||
|
|
||||||
import com.fr.design.designer.creator.XCreator; |
|
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
|
||||||
import com.fr.design.gui.ilable.UILabel; |
|
||||||
import com.fr.design.gui.itable.HeaderRenderer; |
|
||||||
import com.fr.form.ui.Widget; |
|
||||||
import com.fr.form.ui.container.WFitLayout; |
|
||||||
import com.fr.general.ComparatorUtils; |
|
||||||
import com.fr.general.Inter; |
|
||||||
import com.fr.stable.StringUtils; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created with IntelliJ IDEA. |
|
||||||
* User: zx |
|
||||||
* Date: 14-9-15 |
|
||||||
* Time: 下午4:52 |
|
||||||
*/ |
|
||||||
public class MobileBodyWidgetTable extends JTable { |
|
||||||
|
|
||||||
private FormDesigner designer; |
|
||||||
protected TableModel defaultmodel; |
|
||||||
private String[][] cellData; |
|
||||||
private String[] headers = {Inter.getLocText("Form-Widget_Name")}; |
|
||||||
public static final int WIDGET_TABLE_ROW_HEIGHT = 22; |
|
||||||
private UILabel moveComponent = new UILabel(); |
|
||||||
private int selectedRow = -1; |
|
||||||
private int GAP = 10; |
|
||||||
private boolean draging = false; |
|
||||||
|
|
||||||
|
|
||||||
public MobileBodyWidgetTable(FormDesigner designer) { |
|
||||||
this.designer = designer; |
|
||||||
cellData = getData(); |
|
||||||
this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT); |
|
||||||
JTableHeader header = getTableHeader(); |
|
||||||
header.setReorderingAllowed(false); |
|
||||||
header.setPreferredSize(new Dimension(0, WIDGET_TABLE_ROW_HEIGHT)); |
|
||||||
HeaderRenderer headerRenderer = new HeaderRenderer(); |
|
||||||
headerRenderer.setHorizontalAlignment(JLabel.CENTER); |
|
||||||
header.setDefaultRenderer(headerRenderer); |
|
||||||
this.setGridColor(new Color(212, 208, 200)); |
|
||||||
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
||||||
this.setColumnSelectionAllowed(false); |
|
||||||
this.setRowSelectionAllowed(false); |
|
||||||
this.setFillsViewportHeight(true); |
|
||||||
defaultmodel = new BeanTableModel(); |
|
||||||
this.setModel(defaultmodel); |
|
||||||
this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); |
|
||||||
this.repaint(); |
|
||||||
this.setDefaultRenderer(Object.class,new MobileWidgetTableCellRenderer()); |
|
||||||
refresh(); |
|
||||||
this.addMouseListener(mouseAdapter); |
|
||||||
this.addMouseMotionListener(mouseAdapter); |
|
||||||
add(moveComponent); |
|
||||||
} |
|
||||||
|
|
||||||
private MouseAdapter mouseAdapter = new MouseAdapter() { |
|
||||||
@Override |
|
||||||
public void mouseClicked(MouseEvent e) { |
|
||||||
if(getSelectedRow() != -1){ |
|
||||||
String widgetName = cellData[getSelectedRow()][0]; |
|
||||||
if (StringUtils.isNotEmpty(widgetName)){ |
|
||||||
XLayoutContainer root = getEditingDesigner().getRootComponent(); |
|
||||||
int count = root.getXCreatorCount(); |
|
||||||
for (int i = 0;i < count ;i++){ |
|
||||||
XCreator xCreator = root.getXCreator(i).getEditingChildCreator(); |
|
||||||
Widget widget = xCreator.toData(); |
|
||||||
if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) { |
|
||||||
getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator); |
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); |
|
||||||
selectedRow = getSelectedRow(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
public void mouseExited(MouseEvent e) { |
|
||||||
draging = false; |
|
||||||
moveComponent.setVisible(false); |
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void mouseMoved(MouseEvent e) { |
|
||||||
int overRow = 0; |
|
||||||
for (int i = 0;i < getRowCount();i++) { |
|
||||||
if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT){ |
|
||||||
overRow = i; |
|
||||||
} |
|
||||||
} |
|
||||||
if (overRow == getSelectedRow()) { |
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); |
|
||||||
} else { |
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void mouseDragged(MouseEvent e) { |
|
||||||
int width = getColumnModel().getColumn(0).getWidth(); |
|
||||||
if (getCursor().getType() == Cursor.MOVE_CURSOR){ |
|
||||||
draging = true; |
|
||||||
//下面这句话太重要了,拖拽过程中选中的不变
|
|
||||||
getInstance().setRowSelectionInterval(selectedRow,selectedRow); |
|
||||||
moveComponent.setText(getValueAt(getSelectedRow(), getSelectedColumn()).toString()); |
|
||||||
moveComponent.setLocation(0, e.getY() - GAP); |
|
||||||
moveComponent.setPreferredSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); |
|
||||||
moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); |
|
||||||
moveComponent.setVisible(true); |
|
||||||
moveComponent.setForeground(Color.lightGray); |
|
||||||
moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray)); |
|
||||||
} |
|
||||||
} |
|
||||||
@Override |
|
||||||
public void mouseReleased(MouseEvent e) { |
|
||||||
if(!draging){ |
|
||||||
return; |
|
||||||
} |
|
||||||
draging = false; |
|
||||||
moveComponent.setVisible(false); |
|
||||||
int toIndex = e.getY() < GAP ? 0 : (int)Math.rint((e.getY() - GAP)/WIDGET_TABLE_ROW_HEIGHT) + 1; |
|
||||||
((WFitLayout) designer.getRootComponent().toData()).adjustOrder(getSelectedRow(), toIndex); |
|
||||||
getInstance().setRowSelectionInterval(0,getRowCount() - 1); |
|
||||||
refresh(); |
|
||||||
getInstance().repaint(); |
|
||||||
designer.fireTargetModified(); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
public MobileBodyWidgetTable getInstance(){ |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public FormDesigner getEditingDesigner(){ |
|
||||||
return designer; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 刷新 |
|
||||||
*/ |
|
||||||
public void refresh(){ |
|
||||||
XCreator creator = designer.getSelectionModel().getSelection().getSelectedCreator(); |
|
||||||
cellData = getData(); |
|
||||||
if(creator != null){ |
|
||||||
String widgetName =creator.toData().getWidgetName(); |
|
||||||
int row = -1; |
|
||||||
for (int i =0; i < cellData.length;i++){ |
|
||||||
if(ComparatorUtils.equals(widgetName, cellData[i][0])){ |
|
||||||
row = i; |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
selectedRow = row; |
|
||||||
changeSelection(row,0,false,false); |
|
||||||
if(row == -1){ |
|
||||||
this.clearSelection(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private String[][] getData(){ |
|
||||||
if(designer.isFormParaDesigner()){ |
|
||||||
return new String[0][0]; |
|
||||||
} |
|
||||||
XLayoutContainer paraContainer = designer.getRootComponent(); |
|
||||||
if(paraContainer == null || !paraContainer.acceptType(WFitLayout.class)){ |
|
||||||
return new String[0][0]; |
|
||||||
} |
|
||||||
|
|
||||||
WFitLayout fitLayout = (WFitLayout) (paraContainer.toData()); |
|
||||||
ArrayList<String> strings = fitLayout.getMobileWidgetList(); |
|
||||||
String[][] widgetName = new String[strings.size()][2]; |
|
||||||
for(int i = 0;i < strings.size();i++){ |
|
||||||
widgetName[i][0] = strings.get(i); |
|
||||||
} |
|
||||||
return widgetName; |
|
||||||
} |
|
||||||
|
|
||||||
private class MobileWidgetTableCellRenderer extends DefaultTableCellRenderer { |
|
||||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, |
|
||||||
boolean hasFocus, int row, int column) { |
|
||||||
if (getCursor().getType() == Cursor.MOVE_CURSOR){ |
|
||||||
if(selectedRow > -1 && selectedRow < getRowCount()){ |
|
||||||
//拖拽过程中选中的不变
|
|
||||||
getInstance().setRowSelectionInterval(selectedRow,selectedRow); |
|
||||||
} |
|
||||||
} |
|
||||||
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public class BeanTableModel extends DefaultTableModel { |
|
||||||
public BeanTableModel() { |
|
||||||
super(cellData,headers); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int getRowCount() { |
|
||||||
return cellData.length; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int getColumnCount() { |
|
||||||
return 1; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public Object getValueAt(int row, int column) { |
|
||||||
if (row >= getRowCount() || column >= getColumnCount()) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
return cellData[row][0]; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String getColumnName(int column) { |
|
||||||
return headers[0]; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void setValueAt(Object aValue, int row, int column) { |
|
||||||
if (row >= getRowCount() || column >= getColumnCount()) { |
|
||||||
return; |
|
||||||
} |
|
||||||
if (aValue == null) { |
|
||||||
cellData[row] = null; |
|
||||||
return; |
|
||||||
} |
|
||||||
cellData[row][0] = aValue.toString(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 是否可编辑 |
|
||||||
* @param row 行号 |
|
||||||
* @param column 列号 |
|
||||||
* @return 是否可编辑 |
|
||||||
*/ |
|
||||||
public boolean isCellEditable(int row, int column) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,428 @@ |
|||||||
|
package com.fr.design.mainframe; |
||||||
|
|
||||||
|
|
||||||
|
import java.awt.BasicStroke; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.RenderingHints; |
||||||
|
import java.awt.event.FocusAdapter; |
||||||
|
import java.awt.event.FocusEvent; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.awt.geom.RoundRectangle2D; |
||||||
|
import java.util.EventObject; |
||||||
|
|
||||||
|
import javax.swing.AbstractCellEditor; |
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JTable; |
||||||
|
import javax.swing.ListSelectionModel; |
||||||
|
import javax.swing.event.DocumentEvent; |
||||||
|
import javax.swing.event.DocumentListener; |
||||||
|
import javax.swing.table.DefaultTableCellRenderer; |
||||||
|
import javax.swing.table.DefaultTableModel; |
||||||
|
import javax.swing.table.JTableHeader; |
||||||
|
import javax.swing.table.TableCellEditor; |
||||||
|
import javax.swing.table.TableColumn; |
||||||
|
import javax.swing.table.TableModel; |
||||||
|
|
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itable.GroupRenderer; |
||||||
|
import com.fr.design.gui.itable.HeaderRenderer; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWParameterLayout; |
||||||
|
import com.fr.form.ui.Label; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.form.ui.container.WParameterLayout; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* MobileParaWidgetTable主要显示参数面板容器的控件列表,与MobileWidgetTable的区别就是该表多了UITextField这一列 |
||||||
|
* Created with IntelliJ IDEA. |
||||||
|
* User: zx |
||||||
|
* Date: 14-7-9 |
||||||
|
* Time: 上午11:26 |
||||||
|
* Modified by fanglei during 2017/1/22 - 2017/2/ |
||||||
|
*/ |
||||||
|
class MobileParaWidgetTable extends JTable { |
||||||
|
|
||||||
|
private FormDesigner designer; |
||||||
|
private String[][] cellData ; |
||||||
|
private String[] headers = {Inter.getLocText("FR-Utils_Label"), Inter.getLocText("Form-Widget_Name")}; |
||||||
|
private static final int WIDGET_TABLE_ROW_HEIGHT = 22; |
||||||
|
private static final int UITEXTFIELD_WIDTH = 40; |
||||||
|
private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件
|
||||||
|
private int selectedRow = -1; |
||||||
|
private int selectedColumn = -1; |
||||||
|
private int GAP = 11; |
||||||
|
private boolean draging = false; |
||||||
|
|
||||||
|
MobileParaWidgetTable(FormDesigner designer) { |
||||||
|
this.designer = designer; |
||||||
|
this.cellData = getData(); |
||||||
|
this.setTableProperties(); |
||||||
|
this.setDefaultEditor(Object.class, new MobileCellEditor()); |
||||||
|
TableModel defaultModel = new BeanTableModel(); |
||||||
|
this.setModel(defaultModel); |
||||||
|
this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); |
||||||
|
TableColumn tc = this.getColumn(this.getColumnName(0)); |
||||||
|
tc.setPreferredWidth(UITEXTFIELD_WIDTH); |
||||||
|
this.repaint(); |
||||||
|
this.setDefaultRenderer(Object.class,new MobileWidgetTableCellRenderer()); |
||||||
|
refreshData(); |
||||||
|
this.addMouseListener(mouseAdapter); |
||||||
|
this.addMouseMotionListener(mouseAdapter); |
||||||
|
add(moveComponent); |
||||||
|
} |
||||||
|
|
||||||
|
private void setTableProperties() { |
||||||
|
JTableHeader header = getTableHeader(); |
||||||
|
header.setReorderingAllowed(false); |
||||||
|
header.setPreferredSize(new Dimension(0, WIDGET_TABLE_ROW_HEIGHT)); |
||||||
|
header.setDefaultRenderer(new HeaderRenderer()); |
||||||
|
|
||||||
|
this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT); |
||||||
|
this.setGridColor(new Color(212, 208, 200)); |
||||||
|
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
||||||
|
this.setColumnSelectionAllowed(false); |
||||||
|
this.setRowSelectionAllowed(false); |
||||||
|
this.setFillsViewportHeight(true); |
||||||
|
} |
||||||
|
|
||||||
|
private MouseAdapter mouseAdapter = new MouseAdapter() { |
||||||
|
/** |
||||||
|
* 鼠标按下时处理的事件(设置当前选中的行列) |
||||||
|
* @param e |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void mousePressed(MouseEvent e) { |
||||||
|
getInstance().setCellSelected(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标放开时处理的事件(如果是正在拖动则执行换位操作,重新绘制属性表,如果不是则什么也不做) |
||||||
|
* @param e |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void mouseReleased(MouseEvent e) { |
||||||
|
if(!draging){ |
||||||
|
return; |
||||||
|
} |
||||||
|
draging = false; |
||||||
|
moveComponent.setVisible(false); |
||||||
|
int toIndex = e.getY() < GAP ? 0 : (int)Math.rint((e.getY() - GAP)/WIDGET_TABLE_ROW_HEIGHT) + 1; |
||||||
|
//当鼠标放开时,将选中的容器调整至新的顺序
|
||||||
|
((WParameterLayout) designer.getParaComponent().toData()).adjustOrder(selectedRow, toIndex); |
||||||
|
//拿取排序后表格数据,然后重绘表格
|
||||||
|
getInstance().refreshData(); |
||||||
|
getInstance().repaint(); |
||||||
|
designer.fireTargetModified(); |
||||||
|
getInstance().setCellSelected(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置鼠标在属性表区域移动时候的事件 |
||||||
|
* @param e |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void mouseMoved(MouseEvent e) { |
||||||
|
int overColumn = e.getX() < getColumnModel().getColumn(0).getWidth() ? 0 : 1; // 判断当前鼠标在哪一列
|
||||||
|
int overRow = -1; |
||||||
|
for (int i = 0;i < getRowCount();i++) { |
||||||
|
if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT) { |
||||||
|
overRow = i; //判断当前鼠标在哪一行
|
||||||
|
} |
||||||
|
} |
||||||
|
//如果鼠标移动到当前选中的行列上面的时候,并且不能在第一列
|
||||||
|
if (overRow == selectedRow && overColumn == selectedColumn && overColumn !=0) { |
||||||
|
//把当前选中的那一列行的光标改成(除了第一列)移动样式MOVE_CURSOR
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); |
||||||
|
} else { |
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标拖动事件(如果鼠标当前是<code>MOVE_CURSOR</code>状态则执行开始拖动的代码, |
||||||
|
* 绘制一个<code>moveComponent</code>来跟随鼠标移动) |
||||||
|
* @param e |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void mouseDragged(MouseEvent e) { |
||||||
|
int width = getColumnModel().getColumn(1).getWidth(); |
||||||
|
//如果点击选中的是第二列,就可以拖动
|
||||||
|
if (selectedColumn == 1){ |
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); |
||||||
|
draging = true; |
||||||
|
moveComponent.setText(getValueAt(selectedRow, selectedColumn).toString()); |
||||||
|
moveComponent.setLocation(getColumnModel().getColumn(0).getWidth(), e.getY() - GAP); |
||||||
|
moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); |
||||||
|
moveComponent.setVisible(true); |
||||||
|
moveComponent.setForeground(Color.lightGray); |
||||||
|
moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置鼠标单击时处理的事件(单击第二列的控件列表进入控件属性表) |
||||||
|
* @param e |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void mouseClicked(MouseEvent e) { |
||||||
|
if(getSelectedRow() != -1 && getSelectedColumn() == 1){ |
||||||
|
String widgetName = cellData[getSelectedRow()][getSelectedColumn()]; |
||||||
|
if (StringUtils.isNotEmpty(widgetName)){ |
||||||
|
int count = getEditingDesigner().getParaComponent().getComponentCount(); |
||||||
|
for (int i = 0; i < count; i++){ |
||||||
|
XCreator xCreator = (XCreator)getEditingDesigner().getParaComponent().getComponent(i); |
||||||
|
Widget widget = xCreator.toData(); |
||||||
|
if (!widget.acceptType(Label.class) && ComparatorUtils.equals(widgetName,widget.getWidgetName())) { |
||||||
|
//设置选中的component,这句代码控制点击之后跳转到相应component属性表
|
||||||
|
getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 鼠标离开属性表区域事件 |
||||||
|
* @param e |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void mouseExited(MouseEvent e) { |
||||||
|
draging = false; |
||||||
|
moveComponent.setVisible(false); |
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
public MobileParaWidgetTable getInstance(){ |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
private FormDesigner getEditingDesigner(){ |
||||||
|
return designer; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置当前get到的行列的单元格为选中状态 |
||||||
|
*/ |
||||||
|
private void setCellSelected() { |
||||||
|
selectedRow = getSelectedRow(); |
||||||
|
selectedColumn = getSelectedColumn(); |
||||||
|
if (selectedRow != -1) { |
||||||
|
this.setRowSelectionInterval(selectedRow, selectedRow); |
||||||
|
} |
||||||
|
if (selectedColumn != -1) { |
||||||
|
this.setColumnSelectionInterval(selectedColumn, selectedColumn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 重新get排序后的数据 |
||||||
|
*/ |
||||||
|
public void refreshData(){ |
||||||
|
cellData = getData(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取参数面板的控件列表 |
||||||
|
* |
||||||
|
* @return String[][] 二维数组,[0][0]widgetTag, [0][1]widgetName |
||||||
|
*/ |
||||||
|
private String[][] getData(){ |
||||||
|
XLayoutContainer paraContainer = designer.getParaComponent(); |
||||||
|
if(paraContainer == null || !paraContainer.acceptType(XWParameterLayout.class)){ |
||||||
|
return new String[0][0]; |
||||||
|
} |
||||||
|
|
||||||
|
WParameterLayout para = (WParameterLayout) (paraContainer.toData()); |
||||||
|
return para.getWidgetNameTag(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义的tableRender类 |
||||||
|
*/ |
||||||
|
private class MobileWidgetTableCellRenderer extends DefaultTableCellRenderer{ |
||||||
|
@Override |
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, |
||||||
|
boolean hasFocus, int row, int column) { |
||||||
|
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
||||||
|
if (column == 0){ |
||||||
|
UITextField uiTableTextField; |
||||||
|
if (getSelectedColumn() == column && getSelectedRow() == row){ |
||||||
|
uiTableTextField = new UITableTextField(value.toString()); |
||||||
|
} else { |
||||||
|
uiTableTextField = new UITextField(value.toString()); |
||||||
|
} |
||||||
|
return uiTableTextField; |
||||||
|
} |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义的tableEditor类 |
||||||
|
*/ |
||||||
|
private class MobileCellEditor extends AbstractCellEditor implements TableCellEditor { |
||||||
|
UITableTextField uiTableTextField; |
||||||
|
MobileCellEditor(){ |
||||||
|
uiTableTextField = new UITableTextField(); |
||||||
|
uiTableTextField.addFocusListener(new FocusAdapter() { |
||||||
|
@Override |
||||||
|
public void focusLost(FocusEvent evt) { |
||||||
|
stopCellEditing(); |
||||||
|
designer.fireTargetModified(); |
||||||
|
} |
||||||
|
}); |
||||||
|
uiTableTextField.getDocument().addDocumentListener(new DocumentListener() { |
||||||
|
@Override |
||||||
|
public void insertUpdate(DocumentEvent e) { |
||||||
|
firePropertyChange(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void removeUpdate(DocumentEvent e) { |
||||||
|
firePropertyChange(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void changedUpdate(DocumentEvent e) { |
||||||
|
firePropertyChange(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* cell改变,相应的nametag改变 |
||||||
|
*/ |
||||||
|
private void firePropertyChange(){ |
||||||
|
((WParameterLayout) designer.getParaComponent().toData()).add2NameTagMap(uiTableTextField.getText(), |
||||||
|
cellData[getSelectedRow()][1]); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getCellEditorValue(){ |
||||||
|
return uiTableTextField.getText(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 双击以编辑, 表示只有双击的情况下才可以编辑 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean isCellEditable(EventObject anEvent) { |
||||||
|
return !(anEvent instanceof MouseEvent) || ((MouseEvent) anEvent).getClickCount() >= 2; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Component getTableCellEditorComponent( JTable table,Object value, |
||||||
|
boolean isSelected,int row,int column){ |
||||||
|
uiTableTextField.setText(value.toString()); |
||||||
|
return uiTableTextField; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* BeanTableModel类继承DefaultTableModel类,指定了表格的表头和内容 |
||||||
|
*/ |
||||||
|
private class BeanTableModel extends DefaultTableModel { |
||||||
|
BeanTableModel() { |
||||||
|
super(cellData, headers); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getRowCount() { |
||||||
|
return cellData.length; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getColumnCount() { |
||||||
|
return headers.length; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getValueAt(int row, int column) { |
||||||
|
if (row >= getRowCount() || column >= getColumnCount()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
Object[] rowValue = cellData[row]; |
||||||
|
if (column > -1 && column < rowValue.length) { |
||||||
|
return cellData[row][column]; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getColumnName(int column) { |
||||||
|
if (column == 0) { |
||||||
|
return headers[0]; |
||||||
|
} else { |
||||||
|
return headers[1]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void setValueAt(Object aValue, int row, int column) { |
||||||
|
if (row >= getRowCount() || column >= getColumnCount()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
if (aValue == null) { |
||||||
|
cellData[row][column] = null; |
||||||
|
return; |
||||||
|
} |
||||||
|
cellData[row][column] = aValue.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否可编辑 控件标签列可以编辑,控件名不可编辑 |
||||||
|
* @param row 行号 |
||||||
|
* @param column 列号 |
||||||
|
* @return 是否可编辑 |
||||||
|
*/ |
||||||
|
public boolean isCellEditable(int row, int column) { |
||||||
|
if(column ==1){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 继承自JTextField类,重写了编辑框的样式 |
||||||
|
*/ |
||||||
|
private class UITableTextField extends UITextField { |
||||||
|
public UITableTextField(){ |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public UITableTextField(String string){ |
||||||
|
super(string); |
||||||
|
} |
||||||
|
|
||||||
|
protected void paintBorder(Graphics g) { |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
||||||
|
if (this.isFocusOwner()) { |
||||||
|
g2d.setStroke(new BasicStroke(1.5f)); |
||||||
|
} else { |
||||||
|
g2d.setStroke(new BasicStroke(1f)); |
||||||
|
} |
||||||
|
RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, this.getWidth() - 2, this.getHeight() - 2, 4, 4); |
||||||
|
g2d.setColor(Color.orange); |
||||||
|
g2d.draw(rect); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue