From e0a4242f0cc057fdf995fcc754d49d94f878d580 Mon Sep 17 00:00:00 2001 From: richie Date: Thu, 26 Jul 2018 11:45:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?CORE-116=20DataModel=E5=92=8CTableData?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=A7=84=E8=8C=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/utils/DesignUtils.java | 67 +------------------ 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java index 84335dd917..7082268d29 100644 --- a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java @@ -1,13 +1,9 @@ package com.fr.design.utils; import com.fr.base.BaseUtils; -import com.fr.base.EnvException; import com.fr.base.FRContext; import com.fr.base.FeedBackInfo; import com.fr.base.ServerConfig; -import com.fr.base.Utils; -import com.fr.base.remote.RemoteDeziConstants; -import com.fr.dav.DavXMLUtils; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.DesignerEnvProcessor; @@ -17,8 +13,6 @@ import com.fr.file.FileFILE; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; import com.fr.general.GeneralContext; - -import com.fr.general.http.HttpClient; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.CodeUtils; @@ -32,16 +26,12 @@ import javax.swing.*; import java.awt.*; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; import java.net.ServerSocket; import java.net.Socket; import java.net.URI; @@ -417,61 +407,6 @@ public class DesignUtils { * @throws Exception 异常 */ public static boolean sendFeedBack(FeedBackInfo feedBackInfo) throws Exception { - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把tableData写成xml文件到out - DavXMLUtils.writeXMLFeedBackInfo(feedBackInfo, out); - InputStream input = postBytes2ServerB(out.toByteArray()); - return input != null; - - } - - - private static InputStream postBytes2ServerB(byte[] bytes) throws Exception { - HttpClient client = new HttpClient("http://114.215.175.35:8080/WebReport/product_advice.jsp"); - client.asGet(); - client.setContent(bytes); - return execute4InputStream(client); - } - - - /** - * execute method之后,取返回的inputstream - */ - private static ByteArrayInputStream execute4InputStream(HttpClient client) throws Exception { - int statusCode = client.getResponseCode(); - if (statusCode != HttpURLConnection.HTTP_OK) { - throw new EnvException("Method failed: " + statusCode); - } - InputStream in = client.getResponseStream(); - if (in == null) { - return null; - } - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - Utils.copyBinaryTo(in, out); - - // 看一下传过来的byte[]是不是DesignProcessor.INVALID,如果是的话,就抛Exception - byte[] bytes = out.toByteArray(); - // carl:格式一致传中文 - String message = new String(bytes, EncodeConstants.ENCODING_UTF_8); - if (ComparatorUtils.equals(message, RemoteDeziConstants.NO_SUCH_RESOURCE)) { - return null; - } else if (ComparatorUtils.equals(message, RemoteDeziConstants.INVALID_USER)) { - throw new EnvException(RemoteDeziConstants.INVALID_USER); - } else if (ComparatorUtils.equals(message, RemoteDeziConstants.FILE_LOCKED)) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("FR-Designer_file-is-locked")); - return null; - } else if (message.startsWith(RemoteDeziConstants.RUNTIME_ERROR_PREFIX)) { - } - return new ByteArrayInputStream(bytes); - } finally { - in.close(); - out.close(); - client.release(); - } + return true; } - - } From 8be3f0b9299c94d8fed2dd982a8b54b7170eadf4 Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 26 Jul 2018 14:32:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E4=B8=A4=E4=B8=AA=E6=97=A0=E7=94=A8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/MobileParaWidgetTable.java | 418 ------------------ .../design/mainframe/MobileWidgetTable.java | 353 --------------- 2 files changed, 771 deletions(-) delete mode 100644 designer-form/src/main/java/com/fr/design/mainframe/MobileParaWidgetTable.java delete mode 100644 designer-form/src/main/java/com/fr/design/mainframe/MobileWidgetTable.java diff --git a/designer-form/src/main/java/com/fr/design/mainframe/MobileParaWidgetTable.java b/designer-form/src/main/java/com/fr/design/mainframe/MobileParaWidgetTable.java deleted file mode 100644 index e7e5089b50..0000000000 --- a/designer-form/src/main/java/com/fr/design/mainframe/MobileParaWidgetTable.java +++ /dev/null @@ -1,418 +0,0 @@ -package com.fr.design.mainframe; - - -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWParameterLayout; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itable.HeaderRenderer; -import com.fr.design.gui.itextfield.UITextField; -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; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.table.*; -import java.awt.*; -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; - -/** - * 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-Designer_Label"), Inter.getLocText("FR-Designer_Widgetname")}; - private static final int WIDGET_TABLE_ROW_HEIGHT = 22; - private static final int UITEXTFIELD_WIDTH = 0; - private static final int GAP = 11; - private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件 - private int selectedRow = -1; - private int selectedColumn = -1; - private boolean draging = false; - - private void init(FormDesigner designer) { - this.designer = designer; - this.cellData = getData(); - this.setTableProperties(); - this.setDefaultEditor(Object.class, new MobileCellEditor()); - this.setModel(new BeanTableModel()); - this.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - TableColumn tc = this.getColumn(this.getColumnName(0)); - tc.setMinWidth(UITEXTFIELD_WIDTH); - tc.setMaxWidth(UITEXTFIELD_WIDTH); - tc.setPreferredWidth(UITEXTFIELD_WIDTH); - this.repaint(); - this.setDefaultRenderer(Object.class, new MobileWidgetTableCellRenderer()); - refreshData(); - this.addMouseListener(mouseAdapter); - this.addMouseMotionListener(mouseAdapter); - } - - MobileParaWidgetTable(FormDesigner designer) { - init(designer); - 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)); - } - } - - /** - * 鼠标拖动事件(如果鼠标当前是MOVE_CURSOR状态则执行开始拖动的代码, - * 绘制一个moveComponent来跟随鼠标移动) - * @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]); - ((WParameterLayout) designer.getParaComponent().toData()).setNameTagModified(cellData[getSelectedRow()][1], - true); - } - - @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) { - return column != 1; - } - - } - - /** - * 继承自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); - } - - } -} \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/MobileWidgetTable.java b/designer-form/src/main/java/com/fr/design/mainframe/MobileWidgetTable.java deleted file mode 100644 index 982f5aad0d..0000000000 --- a/designer-form/src/main/java/com/fr/design/mainframe/MobileWidgetTable.java +++ /dev/null @@ -1,353 +0,0 @@ -package com.fr.design.mainframe; - -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.table.*; - -import com.fr.design.designer.creator.XCreator; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itable.GroupRenderer; -import com.fr.form.ui.Widget; -import com.fr.form.ui.container.*; -import com.fr.general.ComparatorUtils; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; - -/** - * MobileWidgetTable类主要显示各种容器的控件列表(body,tab,绝对布局快,不包括参数面板) - * Created with IntelliJ IDEA. - * User: zx - * Date: 14-9-15 - * Time: 下午4:52 - * Modified by fanglei at 2017/01/23 - */ -public class MobileWidgetTable extends JTable { - - private FormDesigner designer; - private String[][] cellData; - private String[] headers = {Inter.getLocText("Form-Widget_Name")}; - private static final int WIDGET_TABLE_ROW_HEIGHT = 22; - private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件 - private int selectedRow = -1; - private static final int GAP = 11; - private boolean draging = false; - private boolean collapsed = false; // 控件列表是否折叠 - - @Override - public TableCellRenderer getCellRenderer(int row, int column) { - //第一行渲染成为标题的样子 - if (row == 0) { - return new GroupRenderer(); - } - return super.getCellRenderer(row, column); - } - - - public MobileWidgetTable(FormDesigner designer) { - this.designer = designer; - cellData = getData(); - this.setTableProperties(); - TableModel defaultModel = new BeanTableModel(); - this.setModel(defaultModel); - this.repaint(); - this.setDefaultRenderer(Object.class, new DefaultTableCellRenderer()); - refreshData(); - this.addMouseListener(mouseAdapter); - this.addMouseMotionListener(mouseAdapter); - add(moveComponent); - } - - private void setTableProperties() { - JTableHeader header = getTableHeader(); - header.setReorderingAllowed(false); - header.setPreferredSize(new Dimension(0, 0)); // 隐藏表头 - GroupRenderer headerRenderer = new GroupRenderer(); - headerRenderer.setPreferredSize(new Dimension(0, 0)); //这行代码隐藏表头。因为要实现折叠效果,表头不好监听事件 - headerRenderer.setHorizontalAlignment(JLabel.LEFT); - header.setDefaultRenderer(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(false); - this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - } - - private MouseAdapter mouseAdapter = new MouseAdapter() { - /** - * 鼠标按下时处理的事件(设置当前选中的行列) - * @param e - */ - @Override - public void mousePressed(MouseEvent e) { - getInstance().setCellSelected(); - if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2) { // 如果是点击在第一行 - toggleCollapse(); - } - } - - /** - * 鼠标放开时处理的事件(如果是正在拖动则执行换位操作,重新绘制属性表,如果不是则什么也不做) - * 所谓的换行就是简单的重新拿到一次表格数据然后重新绘制表格 - * @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; - //当鼠标放开时,将选中的容器调整至新的顺序 - ((WSortLayout) designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1); - //拿取排序后表格数据,然后重绘表格 - getInstance().refreshData(); - getInstance().repaint(); - designer.fireTargetModified(); - getInstance().setCellSelected(); - } - - /** - * 设置鼠标在属性表区域移动时候的事件 - * @param e - */ - @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 == selectedRow && selectedRow > 0) { - //把当前选中的那一行的光标改成(除了第一列)移动样式MOVE_CURSOR - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - } else { - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - - /** - * 鼠标拖动事件(如果鼠标当前是MOVE_CURSOR状态则执行开始拖动的代码, - * 绘制一个moveComponent来跟随鼠标移动) - * @param e - */ - @Override - public void mouseDragged(MouseEvent e) { - int width = getColumnModel().getColumn(0).getWidth(); - //如果当前选中的行的范围是合理的话,就可以拖动 - if (selectedRow < getRowCount() && selectedRow > 0) { - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - draging = true; - moveComponent.setText(getValueAt(selectedRow, 0).toString()); - moveComponent.setLocation(0, 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 (selectedRow > 0) { - //当前点击的控件的名字 - String widgetName = cellData[selectedRow][0]; - if (StringUtils.isNotEmpty(widgetName)) { - //当前选择的容器 - XCreator selectedContainer = designer.getSelectionModel().getSelection().getSelectedCreator(); - WLayout selectedWidget = (WLayout) selectedContainer.toData(); - //当前选择的容器中的控件数量 - int count = selectedWidget.getWidgetCount(); - for (int i = 0; i < count; i++) { - XCreator xCreator = (XCreator) selectedContainer.getComponent(i); - Widget widget = xCreator.toData(); - if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) { - getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator); - } - } - } - } else if (selectedRow == 0) { // 如果是点击在第一行 - if (!e.isPopupTrigger() && e.getClickCount() > 1) { - toggleCollapse(); - } - } - } - - /** - * 鼠标离开属性表区域事件 - * @param e - */ - public void mouseExited(MouseEvent e) { - draging = false; - moveComponent.setVisible(false); - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - }; - - public MobileWidgetTable getInstance() { - return this; - } - - public FormDesigner getEditingDesigner() { - return designer; - } - - /** - * 设置当前get到的行列的单元格为选中状态 - */ - private void setCellSelected() { - selectedRow = getSelectedRow(); - if (selectedRow != -1) { - this.setRowSelectionInterval(selectedRow, selectedRow); - this.setColumnSelectionInterval(0, 0); - } - } - - /** - * 切换属性组折叠属性true/false - */ - private void toggleCollapse() { - this.setCollapsed(!this.isCollapsed()); - //这里获取表格的父控件是为了当表格被折叠了后,装表格的父控件也要相应的重新布局一下 - //比如折叠之后表格行数应该比原来的少,占用父容器空间应该小点,不重新布局父容器,表格大小不会改变 - Container parent = MobileWidgetTable.this.getParent(); - if (parent != null) { - parent.revalidate(); - } - repaint(); - } - - /** - * 重新get排序后的数据 - */ - public void refreshData() { - cellData = getData(); - } - - /** - * 获取选中控件的控件列表 - * - * @return String[][] 二维数组,[0][0]widgetName - */ - private String[][] getData() { - List mobileWidgetList = new ArrayList(); - if (designer.isFormParaDesigner()) { - return new String[0][0]; - } - - WSortLayout body = (WSortLayout) designer.getRootComponent().toData(); - - if (body == null) { - return new String[0][0]; - } - - body.setSorted(false); - - if (body.getWidgetCount() > 0 && body.getWidget(0).acceptType(WAbsoluteBodyLayout.class)) { - WAbsoluteBodyLayout absoluteBodyLayout = (WAbsoluteBodyLayout) ((WAbsoluteLayout.BoundsWidget) body.getWidget(0)).getWidget(); - mobileWidgetList = absoluteBodyLayout.getOrderedMobileWidgetList(); - } else { - mobileWidgetList = body.getOrderedMobileWidgetList(); - } - String[][] widgetName = new String[mobileWidgetList.size() + 1][1]; - widgetName[0][0] = Inter.getLocText("FR-Designer_WidgetOrder"); - for (int i = 0; i < mobileWidgetList.size(); i++) { - widgetName[i + 1][0] = mobileWidgetList.get(i); - } - - body.setSorted(true); - return widgetName; - - } - - public boolean isCollapsed() { - return collapsed; - } - - public void setCollapsed(boolean collapsed) { - this.collapsed = collapsed; - } - - /** - * 自定义的tableEditor类 - */ - public class BeanTableModel extends DefaultTableModel { - public BeanTableModel() { - super(cellData, headers); - } - - @Override - public int getRowCount() { - if (isCollapsed()) { - return 1; - } - return cellData.length; - } - - @Override - public int getColumnCount() { - return 1; - } - - - @Override - public Object getValueAt(int row, int column) { - if (row >= getRowCount() || column >= getColumnCount()) { - return null; - } - if (row == 0) { - return (isCollapsed() ? "+" : "-") + cellData[row][0]; - } - - 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; - } - - } - -} \ No newline at end of file