* commit 'ee78c63f92afe56ea6112748becef733305a637b': (72 commits) 国际化 无JIRA任务,国际化翻译更新 无JIRA任务,国际化翻译更新 REPORT-2626 移除国际化文件中的无效key REPORT-2626 移除国际化文件中的无效key 国际化修改 design部分第51-750个key的翻译修改 庄奇syoki 20170509 Signed-off-by: unknown <李晓丽> 国际化修改 design部分 1-50个 1901-结束部分key的翻译修改 20170508 庄奇syoki REPORT-2483 & REPORT-2484 国际化key转移;外文版的国际化文件和中文版不一致 无JIRA任务 新release合并遗漏 无任务,line separator REPORT-2537 无任务,冲突调整,release到dev 无JIRA任务,国际化,把release、master中的key合并到dev中 无JIRA任务,解决冲突 ct ct ct ct 1 ...master
@ -1,171 +1,176 @@ |
|||||||
package com.fr.design.actions.server; |
package com.fr.design.actions.server; |
||||||
|
|
||||||
import com.fr.base.BaseUtils; |
import com.fr.base.BaseUtils; |
||||||
import com.fr.base.Env; |
import com.fr.base.Env; |
||||||
import com.fr.base.FRContext; |
import com.fr.base.FRContext; |
||||||
import com.fr.base.ModifiedTable; |
import com.fr.base.ModifiedTable; |
||||||
import com.fr.data.impl.Connection; |
import com.fr.data.impl.Connection; |
||||||
import com.fr.dav.LocalEnv; |
import com.fr.dav.LocalEnv; |
||||||
import com.fr.design.actions.UpdateAction; |
import com.fr.design.actions.UpdateAction; |
||||||
import com.fr.design.data.datapane.connect.ConnectionManagerPane; |
import com.fr.design.data.datapane.connect.ConnectionManagerPane; |
||||||
import com.fr.design.dialog.BasicDialog; |
import com.fr.design.data.datapane.connect.ConnectionShowPane; |
||||||
import com.fr.design.dialog.DialogActionAdapter; |
import com.fr.design.dialog.BasicDialog; |
||||||
import com.fr.design.mainframe.DesignerContext; |
import com.fr.design.dialog.DialogActionAdapter; |
||||||
import com.fr.design.mainframe.DesignerFrame; |
import com.fr.design.mainframe.DesignerContext; |
||||||
import com.fr.design.menu.MenuKeySet; |
import com.fr.design.mainframe.DesignerFrame; |
||||||
import com.fr.file.DatasourceManager; |
import com.fr.design.menu.MenuKeySet; |
||||||
import com.fr.file.DatasourceManagerProvider; |
import com.fr.file.DatasourceManager; |
||||||
import com.fr.general.Inter; |
import com.fr.file.DatasourceManagerProvider; |
||||||
|
import com.fr.general.Inter; |
||||||
import javax.swing.*; |
|
||||||
import java.awt.event.ActionEvent; |
import javax.swing.*; |
||||||
import java.util.HashMap; |
import java.awt.event.ActionEvent; |
||||||
|
import java.util.HashMap; |
||||||
/** |
|
||||||
* DatasourceList Action |
/** |
||||||
*/ |
* DatasourceList Action |
||||||
public class ConnectionListAction extends UpdateAction { |
*/ |
||||||
private static final int BYTENUM = 1444; |
public class ConnectionListAction extends UpdateAction { |
||||||
|
|
||||||
public ConnectionListAction() { |
public ConnectionListAction() { |
||||||
this.setMenuKeySet(DEFINE_DATA_CONNECTION); |
this.setMenuKeySet(DEFINE_DATA_CONNECTION); |
||||||
this.setName(getMenuKeySet().getMenuKeySetName()); |
this.setName(getMenuKeySet().getMenuKeySetName()); |
||||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/connection.png")); |
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/connection.png")); |
||||||
} |
} |
||||||
|
|
||||||
public static final MenuKeySet DEFINE_DATA_CONNECTION = new MenuKeySet() { |
public static final MenuKeySet DEFINE_DATA_CONNECTION = new MenuKeySet() { |
||||||
@Override |
@Override |
||||||
public char getMnemonic() { |
public char getMnemonic() { |
||||||
return 'D'; |
return 'D'; |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public String getMenuName() { |
public String getMenuName() { |
||||||
return Inter.getLocText("Server-Define_Data_Connection"); |
return Inter.getLocText("Server-Define_Data_Connection"); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public KeyStroke getKeyStroke() { |
public KeyStroke getKeyStroke() { |
||||||
return null; |
return null; |
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|
||||||
/** |
/** |
||||||
* 执行动作 |
* 执行动作 |
||||||
* |
* |
||||||
* @param evt 事件 |
* @param evt 事件 |
||||||
*/ |
*/ |
||||||
public void actionPerformed(ActionEvent evt) { |
public void actionPerformed(ActionEvent evt) { |
||||||
DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); |
DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); |
||||||
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
||||||
final DatasourceManager backupManager = datasourceManager.getBackUpManager(); |
final DatasourceManager backupManager = datasourceManager.getBackUpManager(); |
||||||
final ConnectionManagerPane databaseManagerPane = new ConnectionManagerPane() { |
final ConnectionManagerPane databaseManagerPane = new ConnectionManagerPane() { |
||||||
public void complete() { |
public void complete() { |
||||||
populate(datasourceManager); |
populate(datasourceManager); |
||||||
} |
} |
||||||
|
|
||||||
protected void renameConnection(String oldName, String newName) { |
protected void renameConnection(String oldName, String newName) { |
||||||
datasourceManager.getConnectionLocalModifyTable().rename(oldName, newName); |
datasourceManager.getConnectionLocalModifyTable().rename(oldName, newName); |
||||||
} |
} |
||||||
}; |
}; |
||||||
final BasicDialog databaseListDialog = databaseManagerPane.showLargeWindow(designerFrame, null); |
final BasicDialog databaseListDialog = databaseManagerPane.showLargeWindow(designerFrame, null); |
||||||
databaseListDialog.addDialogActionListener(new DialogActionAdapter() { |
databaseListDialog.addDialogActionListener(new DialogActionAdapter() { |
||||||
public void doOk() { |
public void doOk() { |
||||||
if (!databaseManagerPane.isNamePermitted()) { |
if (!databaseManagerPane.isNamePermitted()) { |
||||||
databaseListDialog.setDoOKSucceed(false); |
databaseListDialog.setDoOKSucceed(false); |
||||||
return; |
return; |
||||||
} |
} |
||||||
if (!doWithDatasourceManager(datasourceManager, backupManager, databaseManagerPane, databaseListDialog)) { |
if (!doWithDatasourceManager(datasourceManager, backupManager, databaseManagerPane, databaseListDialog)) { |
||||||
//如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面
|
//如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面
|
||||||
return; |
return; |
||||||
} |
} |
||||||
// marks:保存数据
|
// marks:保存数据
|
||||||
writeFile(datasourceManager); |
writeFile(datasourceManager); |
||||||
} |
} |
||||||
|
|
||||||
public void doCancel() { |
public void doCancel() { |
||||||
datasourceManager.synchronizedWithServer(); |
datasourceManager.synchronizedWithServer(); |
||||||
} |
} |
||||||
}); |
}); |
||||||
databaseListDialog.setVisible(true); |
databaseListDialog.setVisible(true); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
private void writeFile(DatasourceManagerProvider datasourceManager) { |
/** |
||||||
Env currentEnv = FRContext.getCurrentEnv(); |
* @param datasourceManager |
||||||
try { |
*/ |
||||||
boolean isSuccess = currentEnv.writeResource(datasourceManager); |
public static void writeFile(DatasourceManagerProvider datasourceManager) { |
||||||
if (!isSuccess) { |
Env currentEnv = FRContext.getCurrentEnv(); |
||||||
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
try { |
||||||
} |
boolean isSuccess = currentEnv.writeResource(datasourceManager); |
||||||
} catch (Exception e) { |
if (!isSuccess) { |
||||||
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
||||||
} |
} |
||||||
DesignerContext.getDesignerBean("databasename").refreshBeanElement(); |
} catch (Exception e) { |
||||||
} |
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
||||||
|
} |
||||||
/** |
DesignerContext.getDesignerBean("databasename").refreshBeanElement(); |
||||||
* 是否正常更新完datasourceManager |
} |
||||||
* |
|
||||||
* @param datasourceManager |
/** |
||||||
* @param databaseManagerPane |
* 更新datasourceManager |
||||||
* @return |
* |
||||||
*/ |
* @param datasourceManager datasource管理对象 |
||||||
private boolean doWithDatasourceManager(DatasourceManagerProvider datasourceManager, DatasourceManager backupManager, |
* @param backupManager datasource管理对象备份 |
||||||
ConnectionManagerPane databaseManagerPane, BasicDialog databaseListDialog) { |
* @param connectionShowPane datasource面板 |
||||||
databaseManagerPane.update(datasourceManager); |
* @param databaseListDialog datasource管理对话框 |
||||||
HashMap<String, Connection> modifyDetails = datasourceManager.getConnectionModifyDetails(); |
* @return boolean 是否更新成功 |
||||||
modifyDetails.clear(); |
*/ |
||||||
Env currentEnv = FRContext.getCurrentEnv(); |
public static boolean doWithDatasourceManager(DatasourceManagerProvider datasourceManager, DatasourceManager |
||||||
ModifiedTable localModifiedTable = datasourceManager.checkConnectionModifyTable(backupManager, currentEnv.getUserID()); |
backupManager, ConnectionShowPane connectionShowPane, BasicDialog databaseListDialog) { |
||||||
boolean isFailed = false; |
connectionShowPane.update(datasourceManager); |
||||||
if (currentEnv.isSupportLocalFileOperate() && !((LocalEnv) currentEnv).isNoRemoteUser()) { |
HashMap<String, Connection> modifyDetails = datasourceManager.getConnectionModifyDetails(); |
||||||
//如果是本地,并且有远程用户时则更新自己的修改表
|
modifyDetails.clear(); |
||||||
datasourceManager.updateSelfConnectionTotalModifiedTable(localModifiedTable, ModifiedTable.LOCAL_MODIFIER); |
Env currentEnv = FRContext.getCurrentEnv(); |
||||||
} else { |
ModifiedTable localModifiedTable = datasourceManager.checkConnectionModifyTable(backupManager, currentEnv.getUserID()); |
||||||
if (!currentEnv.isSupportLocalFileOperate()) { |
boolean isFailed = false; |
||||||
//如果是远程,则去取服务器的最新的修改表,检查有没有冲突
|
if (currentEnv.isSupportLocalFileOperate() && !((LocalEnv) currentEnv).isNoRemoteUser()) { |
||||||
ModifiedTable currentServerModifyTable = currentEnv.getDataSourceModifiedTables(DatasourceManager.CONNECTION); |
//如果是本地,并且有远程用户时则更新自己的修改表
|
||||||
if (localModifiedTable.checkModifiedTableConflictWithServer(currentServerModifyTable, currentEnv.getUserID())) { |
datasourceManager.updateSelfConnectionTotalModifiedTable(localModifiedTable, ModifiedTable.LOCAL_MODIFIER); |
||||||
//有冲突,进行提示
|
} else { |
||||||
String title = Inter.getLocText(new String[]{"Select", "Single", "Setting"}); |
if (!currentEnv.isSupportLocalFileOperate()) { |
||||||
int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), localModifiedTable.getWaringMessage(), title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
//如果是远程,则去取服务器的最新的修改表,检查有没有冲突
|
||||||
if (returnVal == JOptionPane.YES_OPTION) { |
ModifiedTable currentServerModifyTable = currentEnv.getDataSourceModifiedTables(DatasourceManager.CONNECTION); |
||||||
//点击是,进行相应刷新去冲突
|
if (localModifiedTable.checkModifiedTableConflictWithServer(currentServerModifyTable, currentEnv.getUserID())) { |
||||||
datasourceManager.synchronizedWithServer(backupManager, DatasourceManager.CONNECTION); |
//有冲突,进行提示
|
||||||
//要是有重命名冲突的,则对详细的修改表先进行修改
|
String title = Inter.getLocText(new String[]{"Select", "Single", "Setting"}); |
||||||
datasourceManager.doWithConnectionConflict(localModifiedTable); |
int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), localModifiedTable.getWaringMessage(), title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||||
localModifiedTable.removeConfilct(); |
if (returnVal == JOptionPane.YES_OPTION) { |
||||||
modifyDetails.clear(); |
//点击是,进行相应刷新去冲突
|
||||||
//更新面板
|
datasourceManager.synchronizedWithServer(backupManager, DatasourceManager.CONNECTION); |
||||||
databaseManagerPane.populate(datasourceManager); |
//要是有重命名冲突的,则对详细的修改表先进行修改
|
||||||
} else { |
datasourceManager.doWithConnectionConflict(localModifiedTable); |
||||||
//更新失败,继续停留页面
|
localModifiedTable.removeConfilct(); |
||||||
isFailed = true; |
modifyDetails.clear(); |
||||||
} |
//更新面板
|
||||||
|
connectionShowPane.populate(datasourceManager); |
||||||
} |
} else { |
||||||
} |
//更新失败,继续停留页面
|
||||||
} |
isFailed = true; |
||||||
//存在请重命名则不能更新
|
} |
||||||
int index = datasourceManager.isConnectionMapContainsRename(); |
|
||||||
if (index != -1) { |
} |
||||||
isFailed = true; |
} |
||||||
databaseManagerPane.setSelectedIndex(index); |
} |
||||||
} |
//存在请重命名则不能更新
|
||||||
databaseListDialog.setDoOKSucceed(!isFailed); |
int index = datasourceManager.isConnectionMapContainsRename(); |
||||||
//如果修改成功,则去远程端增量修改修改表
|
if (index != -1) { |
||||||
if (!isFailed && !currentEnv.isSupportLocalFileOperate()) { |
isFailed = true; |
||||||
currentEnv.writeDataSourceModifiedTables(localModifiedTable, DatasourceManager.CONNECTION); |
connectionShowPane.setSelectedIndex(index); |
||||||
localModifiedTable.clear(); |
} |
||||||
modifyDetails.clear(); |
databaseListDialog.setDoOKSucceed(!isFailed); |
||||||
} |
//如果修改成功,则去远程端增量修改修改表
|
||||||
return !isFailed; |
if (!isFailed && !currentEnv.isSupportLocalFileOperate()) { |
||||||
} |
currentEnv.writeDataSourceModifiedTables(localModifiedTable, DatasourceManager.CONNECTION); |
||||||
|
localModifiedTable.clear(); |
||||||
|
modifyDetails.clear(); |
||||||
public void update() { |
} |
||||||
this.setEnabled(true); |
return !isFailed; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
|
public void update() { |
||||||
|
this.setEnabled(true); |
||||||
|
} |
||||||
} |
} |
@ -1,45 +0,0 @@ |
|||||||
package com.fr.design.beans.location; |
|
||||||
|
|
||||||
import com.fr.base.BaseUtils; |
|
||||||
import com.fr.design.gui.ibutton.UIButton; |
|
||||||
import com.fr.design.icon.IconPathConstants; |
|
||||||
import com.fr.general.Inter; |
|
||||||
|
|
||||||
import javax.swing.*; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by zhouping on 2016/7/24. |
|
||||||
*/ |
|
||||||
public class WidgetForbidWindow extends JWindow { |
|
||||||
|
|
||||||
private static final int WIDTH = 150; |
|
||||||
private static final int HEIGHT = 20; |
|
||||||
|
|
||||||
private UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Widgets_Intersects"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); |
|
||||||
|
|
||||||
/** |
|
||||||
* 构造函数 |
|
||||||
*/ |
|
||||||
public WidgetForbidWindow() { |
|
||||||
this.add(promptButton); |
|
||||||
this.setSize(WIDTH, HEIGHT); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 在指定位置显示窗口, 默认将window的中心点放到指定位置上 |
|
||||||
* |
|
||||||
* @param x x坐标 |
|
||||||
* @param y y坐标 |
|
||||||
*/ |
|
||||||
public void showWindow(int x, int y) { |
|
||||||
this.setLocation(x - WIDTH / 2, y - HEIGHT / 2); |
|
||||||
this.setVisible(true); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 隐藏当前窗口 |
|
||||||
*/ |
|
||||||
public void hideWindow() { |
|
||||||
this.setVisible(false); |
|
||||||
} |
|
||||||
} |
|
@ -1,128 +1,140 @@ |
|||||||
package com.fr.design.data.datapane.connect; |
package com.fr.design.data.datapane.connect; |
||||||
|
|
||||||
import com.fr.base.Env; |
import com.fr.base.FRContext; |
||||||
import com.fr.base.FRContext; |
import com.fr.data.impl.AbstractDatabaseConnection; |
||||||
import com.fr.data.impl.AbstractDatabaseConnection; |
import com.fr.data.impl.Connection; |
||||||
import com.fr.data.impl.Connection; |
import com.fr.data.impl.NameDatabaseConnection; |
||||||
import com.fr.data.impl.NameDatabaseConnection; |
import com.fr.design.DesignerEnvManager; |
||||||
import com.fr.design.DesignerEnvManager; |
import com.fr.design.actions.server.ConnectionListAction; |
||||||
import com.fr.design.dialog.BasicDialog; |
import com.fr.design.dialog.BasicDialog; |
||||||
import com.fr.design.dialog.DialogActionAdapter; |
import com.fr.design.dialog.DialogActionAdapter; |
||||||
import com.fr.file.DatasourceManager; |
import com.fr.file.DatasourceManager; |
||||||
import com.fr.file.DatasourceManagerProvider; |
import com.fr.file.DatasourceManagerProvider; |
||||||
import com.fr.general.ComparatorUtils; |
import com.fr.general.ComparatorUtils; |
||||||
import com.fr.stable.StringUtils; |
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
import javax.swing.*; |
import javax.swing.*; |
||||||
import java.awt.event.ItemEvent; |
import java.awt.event.ItemEvent; |
||||||
import java.awt.event.ItemListener; |
import java.awt.event.ItemListener; |
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
import java.util.List; |
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
/** |
|
||||||
* 选择数据连接的下拉框 |
/** |
||||||
* |
* 选择数据连接的下拉框 |
||||||
* @editor zhou |
* |
||||||
* @since 2012-3-28下午3:02:30 |
* @editor zhou |
||||||
*/ |
* @since 2012-3-28下午3:02:30 |
||||||
public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
*/ |
||||||
/** |
public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
||||||
* |
/** |
||||||
*/ |
* |
||||||
private static final long serialVersionUID = 1L; |
*/ |
||||||
private Class<? extends Connection> cls; // 所取的Connection都是cls及其子类
|
private static final long serialVersionUID = 1L; |
||||||
private java.util.List<String> nameList = new ArrayList<String>(); |
private Class<? extends Connection> cls; // 所取的Connection都是cls及其子类
|
||||||
|
private List<String> nameList = new ArrayList<String>(); |
||||||
public ConnectionComboBoxPanel(Class<? extends Connection> cls) { |
|
||||||
super(); |
public ConnectionComboBoxPanel(Class<? extends Connection> cls) { |
||||||
|
super(); |
||||||
this.cls = cls; |
|
||||||
|
this.cls = cls; |
||||||
// alex:添加item change监听,当改变时改变DesignerEnvManager中的最近选中的数据连接
|
|
||||||
this.itemComboBox.addItemListener(new ItemListener() { |
// alex:添加item change监听,当改变时改变DesignerEnvManager中的最近选中的数据连接
|
||||||
public void itemStateChanged(ItemEvent e) { |
this.itemComboBox.addItemListener(new ItemListener() { |
||||||
String selected = ConnectionComboBoxPanel.this.getSelectedItem(); |
public void itemStateChanged(ItemEvent e) { |
||||||
if (StringUtils.isNotBlank(selected)) { |
String selected = ConnectionComboBoxPanel.this.getSelectedItem(); |
||||||
DesignerEnvManager.getEnvManager().setRecentSelectedConnection(selected); |
if (StringUtils.isNotBlank(selected)) { |
||||||
} |
DesignerEnvManager.getEnvManager().setRecentSelectedConnection(selected); |
||||||
} |
} |
||||||
}); |
} |
||||||
refreshItems(); |
}); |
||||||
} |
refreshItems(); |
||||||
|
} |
||||||
/* |
|
||||||
* 刷新ComboBox.items |
/* |
||||||
*/ |
* 刷新ComboBox.items |
||||||
protected java.util.Iterator<String> items() { |
*/ |
||||||
nameList = new ArrayList<String>(); |
protected Iterator<String> items() { |
||||||
|
nameList = new ArrayList<String>(); |
||||||
DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); |
|
||||||
java.util.Iterator<String> nameIt = mgr.getConnectionNameIterator(); |
DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); |
||||||
while (nameIt.hasNext()) { |
Iterator<String> nameIt = mgr.getConnectionNameIterator(); |
||||||
String conName = nameIt.next(); |
while (nameIt.hasNext()) { |
||||||
Connection connection = mgr.getConnection(conName); |
String conName = nameIt.next(); |
||||||
filterConnection(connection, conName, nameList); |
Connection connection = mgr.getConnection(conName); |
||||||
} |
filterConnection(connection, conName, nameList); |
||||||
|
} |
||||||
return nameList.iterator(); |
|
||||||
} |
return nameList.iterator(); |
||||||
|
} |
||||||
protected void filterConnection(Connection connection, String conName, List<String> nameList) { |
|
||||||
connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); |
protected void filterConnection(Connection connection, String conName, List<String> nameList) { |
||||||
} |
connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); |
||||||
|
} |
||||||
|
|
||||||
public int getConnectionSize() { |
public int getConnectionSize() { |
||||||
return nameList.size(); |
return nameList.size(); |
||||||
} |
} |
||||||
|
|
||||||
public String getConnection(int i) { |
public String getConnection(int i) { |
||||||
return nameList.get(i); |
return nameList.get(i); |
||||||
} |
} |
||||||
|
|
||||||
/* |
/* |
||||||
* 弹出对话框编辑Items |
* 弹出对话框编辑Items |
||||||
*/ |
*/ |
||||||
protected void editItems() { |
protected void editItems() { |
||||||
final ConnectionListPane connectionListPane = new ConnectionListPane(); |
final ConnectionListPane connectionListPane = new ConnectionListPane(); |
||||||
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
||||||
connectionListPane.populate(datasourceManager); |
final DatasourceManager backupManager = datasourceManager.getBackUpManager(); |
||||||
BasicDialog connectionListDialog = connectionListPane.showLargeWindow( |
connectionListPane.populate(datasourceManager); |
||||||
SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), new DialogActionAdapter() { |
final BasicDialog connectionListDialog = connectionListPane.showLargeWindow( |
||||||
public void doOk() { |
SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), null); |
||||||
connectionListPane.update(datasourceManager); |
connectionListDialog.addDialogActionListener(new DialogActionAdapter() { |
||||||
// marks:保存数据
|
public void doOk() { |
||||||
Env currentEnv = FRContext.getCurrentEnv(); |
if (!connectionListPane.isNamePermitted()) { |
||||||
try { |
connectionListDialog.setDoOKSucceed(false); |
||||||
currentEnv.writeResource(datasourceManager); |
return; |
||||||
} catch (Exception ex) { |
} |
||||||
FRContext.getLogger().error(ex.getMessage(), ex); |
if (!ConnectionListAction.doWithDatasourceManager(datasourceManager, backupManager, connectionListPane, |
||||||
} |
connectionListDialog)) { |
||||||
} |
//如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面
|
||||||
}); |
return; |
||||||
connectionListDialog.setVisible(true); |
} |
||||||
refreshItems(); |
// marks:保存数据
|
||||||
} |
ConnectionListAction.writeFile(datasourceManager); |
||||||
|
} |
||||||
public void populate(com.fr.data.impl.Connection connection) { |
|
||||||
editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); |
public void doCancel() { |
||||||
if (connection instanceof NameDatabaseConnection) { |
datasourceManager.synchronizedWithServer(); |
||||||
this.setSelectedItem(((NameDatabaseConnection) connection).getName()); |
} |
||||||
} else { |
}); |
||||||
String s = DesignerEnvManager.getEnvManager().getRecentSelectedConnection(); |
connectionListDialog.setVisible(true); |
||||||
if (StringUtils.isNotBlank(s)) { |
refreshItems(); |
||||||
for (int i = 0; i < this.getConnectionSize(); i++) { |
} |
||||||
String t = this.getConnection(i); |
|
||||||
if (ComparatorUtils.equals(s, t)) { |
/** |
||||||
this.setSelectedItem(s); |
* @param connection 数据库链接 |
||||||
break; |
*/ |
||||||
} |
public void populate(Connection connection) { |
||||||
} |
editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); |
||||||
} |
if (connection instanceof NameDatabaseConnection) { |
||||||
// alex:如果这个ComboBox还是没有选中,那么选中第一个
|
this.setSelectedItem(((NameDatabaseConnection) connection).getName()); |
||||||
if (StringUtils.isBlank(this.getSelectedItem()) && this.getConnectionSize() > 0) { |
} else { |
||||||
this.setSelectedItem(this.getConnection(0)); |
String s = DesignerEnvManager.getEnvManager().getRecentSelectedConnection(); |
||||||
} |
if (StringUtils.isNotBlank(s)) { |
||||||
} |
for (int i = 0; i < this.getConnectionSize(); i++) { |
||||||
} |
String t = this.getConnection(i); |
||||||
|
if (ComparatorUtils.equals(s, t)) { |
||||||
|
this.setSelectedItem(s); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// alex:如果这个ComboBox还是没有选中,那么选中第一个
|
||||||
|
if (StringUtils.isBlank(this.getSelectedItem()) && this.getConnectionSize() > 0) { |
||||||
|
this.setSelectedItem(this.getConnection(0)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
@ -1,163 +1,163 @@ |
|||||||
package com.fr.design.data.datapane.connect; |
package com.fr.design.data.datapane.connect; |
||||||
|
|
||||||
import com.fr.data.impl.Connection; |
import com.fr.data.impl.Connection; |
||||||
import com.fr.data.impl.JDBCDatabaseConnection; |
import com.fr.data.impl.JDBCDatabaseConnection; |
||||||
import com.fr.data.impl.JNDIDatabaseConnection; |
import com.fr.data.impl.JNDIDatabaseConnection; |
||||||
import com.fr.design.ExtraDesignClassManager; |
import com.fr.design.ExtraDesignClassManager; |
||||||
import com.fr.design.fun.ConnectionProvider; |
import com.fr.design.fun.ConnectionProvider; |
||||||
import com.fr.design.gui.controlpane.JListControlPane; |
import com.fr.design.gui.controlpane.JListControlPane; |
||||||
import com.fr.design.gui.controlpane.NameObjectCreator; |
import com.fr.design.gui.controlpane.NameObjectCreator; |
||||||
import com.fr.design.gui.controlpane.NameableCreator; |
import com.fr.design.gui.controlpane.NameableCreator; |
||||||
import com.fr.file.DatasourceManagerProvider; |
import com.fr.file.DatasourceManagerProvider; |
||||||
import com.fr.general.ComparatorUtils; |
import com.fr.general.ComparatorUtils; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
import com.fr.general.NameObject; |
import com.fr.general.NameObject; |
||||||
import com.fr.stable.ArrayUtils; |
import com.fr.stable.ArrayUtils; |
||||||
import com.fr.stable.Nameable; |
import com.fr.stable.Nameable; |
||||||
import com.fr.stable.StringUtils; |
import com.fr.stable.StringUtils; |
||||||
import com.fr.stable.core.PropertyChangeAdapter; |
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
import javax.swing.*; |
import javax.swing.*; |
||||||
import java.util.*; |
import java.util.*; |
||||||
|
|
||||||
/** |
/** |
||||||
* Connection List Pane. |
* Connection List Pane. |
||||||
*/ |
*/ |
||||||
public class ConnectionListPane extends JListControlPane { |
public class ConnectionListPane extends JListControlPane implements ConnectionShowPane { |
||||||
public static final String TITLE_NAME = Inter.getLocText("Server-Define_Data_Connection"); |
public static final String TITLE_NAME = Inter.getLocText("Server-Define_Data_Connection"); |
||||||
private boolean isNamePermitted = true; |
private boolean isNamePermitted = true; |
||||||
private HashMap<String, String> renameMap = new HashMap<String, String>(); |
private HashMap<String, String> renameMap = new HashMap<String, String>(); |
||||||
|
|
||||||
public ConnectionListPane() { |
public ConnectionListPane() { |
||||||
renameMap.clear(); |
renameMap.clear(); |
||||||
this.addEditingListner(new PropertyChangeAdapter() { |
this.addEditingListner(new PropertyChangeAdapter() { |
||||||
public void propertyChange() { |
public void propertyChange() { |
||||||
isNamePermitted = true; |
isNamePermitted = true; |
||||||
String[] allListNames = nameableList.getAllNames(); |
String[] allListNames = nameableList.getAllNames(); |
||||||
allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; |
allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; |
||||||
String tempName = getEditingName(); |
String tempName = getEditingName(); |
||||||
if (StringUtils.isEmpty(tempName)) { |
if (StringUtils.isEmpty(tempName)) { |
||||||
String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; |
String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; |
||||||
String[] sign = new String[]{",", "!"}; |
String[] sign = new String[]{",", "!"}; |
||||||
nameableList.stopEditing(); |
nameableList.stopEditing(); |
||||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), Inter.getLocText(warning, sign)); |
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), Inter.getLocText(warning, sign)); |
||||||
setWarnigText(editingIndex); |
setWarnigText(editingIndex); |
||||||
isNamePermitted = false; |
isNamePermitted = false; |
||||||
return; |
return; |
||||||
} |
} |
||||||
if (!ComparatorUtils.equals(tempName, selectedName) |
if (!ComparatorUtils.equals(tempName, selectedName) |
||||||
&& isNameRepeted(new List[]{Arrays.asList(allListNames)}, tempName)) { |
&& isNameRepeted(new List[]{Arrays.asList(allListNames)}, tempName)) { |
||||||
isNamePermitted = false; |
isNamePermitted = false; |
||||||
nameableList.stopEditing(); |
nameableList.stopEditing(); |
||||||
String message = Inter.getLocText(new String[]{"Utils-has_been_existed", "DashBoard-ConnectionList", "Please_Rename"}, new String[]{"", tempName + ",", "!"}); |
String message = Inter.getLocText(new String[]{"Utils-has_been_existed", "DashBoard-ConnectionList", "Please_Rename"}, new String[]{"", tempName + ",", "!"}); |
||||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), message); |
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), message); |
||||||
setWarnigText(editingIndex); |
setWarnigText(editingIndex); |
||||||
} |
} |
||||||
if (isNamePermitted && !ComparatorUtils.equals(tempName, selectedName)) { |
if (isNamePermitted && !ComparatorUtils.equals(tempName, selectedName)) { |
||||||
rename(selectedName, tempName); |
rename(selectedName, tempName); |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
protected void rename(String oldName, String newName) { |
protected void rename(String oldName, String newName) { |
||||||
if (renameMap.containsKey(selectedName)) { |
if (renameMap.containsKey(selectedName)) { |
||||||
renameMap.remove(selectedName); |
renameMap.remove(selectedName); |
||||||
} |
} |
||||||
renameMap.put(selectedName, newName); |
renameMap.put(selectedName, newName); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 名字是否允许 |
* 名字是否允许 |
||||||
* |
* |
||||||
* @return 是/否 |
* @return 是/否 |
||||||
*/ |
*/ |
||||||
public boolean isNamePermitted() { |
public boolean isNamePermitted() { |
||||||
return isNamePermitted; |
return isNamePermitted; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 检查按钮可用状态 Check button enabled. |
* 检查按钮可用状态 Check button enabled. |
||||||
*/ |
*/ |
||||||
public void checkButtonEnabled() { |
public void checkButtonEnabled() { |
||||||
super.checkButtonEnabled(); |
super.checkButtonEnabled(); |
||||||
isNamePermitted = !isContainsRename(); |
isNamePermitted = !isContainsRename(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
public HashMap<String, String> getRenameMap() { |
public HashMap<String, String> getRenameMap() { |
||||||
return renameMap; |
return renameMap; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 创建菜单项 |
* 创建菜单项 |
||||||
* |
* |
||||||
* @return 菜单项 |
* @return 菜单项 |
||||||
*/ |
*/ |
||||||
public NameableCreator[] createNameableCreators() { |
public NameableCreator[] createNameableCreators() { |
||||||
NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( |
NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( |
||||||
"JDBC", |
"JDBC", |
||||||
"/com/fr/design/images/data/source/jdbcTableData.png", |
"/com/fr/design/images/data/source/jdbcTableData.png", |
||||||
JDBCDatabaseConnection.class, |
JDBCDatabaseConnection.class, |
||||||
DatabaseConnectionPane.JDBC.class |
DatabaseConnectionPane.JDBC.class |
||||||
), new NameObjectCreator( |
), new NameObjectCreator( |
||||||
"JNDI", |
"JNDI", |
||||||
"/com/fr/design/images/data/source/jdbcTableData.png", |
"/com/fr/design/images/data/source/jdbcTableData.png", |
||||||
JNDIDatabaseConnection.class, |
JNDIDatabaseConnection.class, |
||||||
DatabaseConnectionPane.JNDI.class |
DatabaseConnectionPane.JNDI.class |
||||||
)}; |
)}; |
||||||
Set<ConnectionProvider> pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); |
Set<ConnectionProvider> pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); |
||||||
for (ConnectionProvider provider : pluginCreators) { |
for (ConnectionProvider provider : pluginCreators) { |
||||||
NameObjectCreator creator = new NameObjectCreator( |
NameObjectCreator creator = new NameObjectCreator( |
||||||
provider.nameForConnection(), |
provider.nameForConnection(), |
||||||
provider.iconPathForConnection(), |
provider.iconPathForConnection(), |
||||||
provider.classForConnection(), |
provider.classForConnection(), |
||||||
provider.appearanceForConnection() |
provider.appearanceForConnection() |
||||||
); |
); |
||||||
creators = ArrayUtils.add(creators, creator); |
creators = ArrayUtils.add(creators, creator); |
||||||
} |
} |
||||||
|
|
||||||
return creators; |
return creators; |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
protected String title4PopupWindow() { |
protected String title4PopupWindow() { |
||||||
return TITLE_NAME; |
return TITLE_NAME; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Populate. |
* Populate. |
||||||
* |
* |
||||||
* @param datasourceManager the new datasourceManager. |
* @param datasourceManager the new datasourceManager. |
||||||
*/ |
*/ |
||||||
public void populate(DatasourceManagerProvider datasourceManager) { |
public void populate(DatasourceManagerProvider datasourceManager) { |
||||||
Iterator<String> nameIt = datasourceManager.getConnectionNameIterator(); |
Iterator<String> nameIt = datasourceManager.getConnectionNameIterator(); |
||||||
|
|
||||||
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
||||||
while (nameIt.hasNext()) { |
while (nameIt.hasNext()) { |
||||||
String name = nameIt.next(); |
String name = nameIt.next(); |
||||||
nameObjectList.add(new NameObject(name, datasourceManager.getConnection(name))); |
nameObjectList.add(new NameObject(name, datasourceManager.getConnection(name))); |
||||||
} |
} |
||||||
this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Update. |
* Update. |
||||||
*/ |
*/ |
||||||
public void update(DatasourceManagerProvider datasourceManager) { |
public void update(DatasourceManagerProvider datasourceManager) { |
||||||
// Nameable[]居然不能强转成NameObject[],一定要这么写...
|
// Nameable[]居然不能强转成NameObject[],一定要这么写...
|
||||||
Nameable[] res = this.update(); |
Nameable[] res = this.update(); |
||||||
NameObject[] res_array = new NameObject[res.length]; |
NameObject[] res_array = new NameObject[res.length]; |
||||||
java.util.Arrays.asList(res).toArray(res_array); |
java.util.Arrays.asList(res).toArray(res_array); |
||||||
|
|
||||||
datasourceManager.clearAllConnection(); |
datasourceManager.clearAllConnection(); |
||||||
|
|
||||||
for (int i = 0; i < res_array.length; i++) { |
for (int i = 0; i < res_array.length; i++) { |
||||||
NameObject nameObject = res_array[i]; |
NameObject nameObject = res_array[i]; |
||||||
datasourceManager.putConnection(nameObject.getName(), (Connection) nameObject.getObject()); |
datasourceManager.putConnection(nameObject.getName(), (Connection) nameObject.getObject()); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
@ -1,78 +1,79 @@ |
|||||||
package com.fr.design.data.datapane.connect; |
package com.fr.design.data.datapane.connect; |
||||||
|
|
||||||
import com.fr.base.FRContext; |
import com.fr.base.FRContext; |
||||||
import com.fr.design.gui.frpane.LoadingBasicPane; |
import com.fr.design.gui.frpane.LoadingBasicPane; |
||||||
import com.fr.design.gui.ilable.UILabel; |
import com.fr.design.gui.ilable.UILabel; |
||||||
import com.fr.design.gui.itextfield.UITextField; |
import com.fr.design.gui.itextfield.UITextField; |
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
import com.fr.file.DatasourceManagerProvider; |
import com.fr.file.DatasourceManagerProvider; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
import com.fr.stable.project.ProjectConstants; |
import com.fr.stable.project.ProjectConstants; |
||||||
|
|
||||||
import javax.swing.*; |
import javax.swing.*; |
||||||
import java.awt.*; |
import java.awt.*; |
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.util.HashMap; |
import java.util.HashMap; |
||||||
|
|
||||||
public class ConnectionManagerPane extends LoadingBasicPane { |
public class ConnectionManagerPane extends LoadingBasicPane implements ConnectionShowPane { |
||||||
private UITextField connectionTextField; |
private UITextField connectionTextField; |
||||||
private ConnectionListPane connectionListPane; |
private ConnectionListPane connectionListPane; |
||||||
|
|
||||||
protected void initComponents(JPanel container) { |
protected void initComponents(JPanel container) { |
||||||
container.setLayout(FRGUIPaneFactory.createBorderLayout()); |
container.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
|
||||||
JPanel connectionPathPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
JPanel connectionPathPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
||||||
container.add(connectionPathPane, BorderLayout.NORTH); |
container.add(connectionPathPane, BorderLayout.NORTH); |
||||||
|
|
||||||
connectionPathPane.setBorder(BorderFactory.createEmptyBorder(6, 2, 2, 2)); |
connectionPathPane.setBorder(BorderFactory.createEmptyBorder(6, 2, 2, 2)); |
||||||
|
|
||||||
connectionPathPane.add(new UILabel(Inter.getLocText("FR-Designer_Save_Path") + ":"), BorderLayout.WEST); |
connectionPathPane.add(new UILabel(Inter.getLocText("FR-Designer_Save_Path") + ":"), BorderLayout.WEST); |
||||||
this.connectionTextField = new UITextField(); |
this.connectionTextField = new UITextField(); |
||||||
connectionPathPane.add(connectionTextField, BorderLayout.CENTER); |
connectionPathPane.add(connectionTextField, BorderLayout.CENTER); |
||||||
this.connectionTextField.setEditable(false); |
this.connectionTextField.setEditable(false); |
||||||
connectionListPane = new ConnectionListPane(){ |
connectionListPane = new ConnectionListPane() { |
||||||
protected void rename(String oldName,String newName) { |
protected void rename(String oldName, String newName) { |
||||||
super.rename(oldName,newName); |
super.rename(oldName, newName); |
||||||
renameConnection(oldName,newName); |
renameConnection(oldName, newName); |
||||||
} |
} |
||||||
}; |
}; |
||||||
container.add(connectionListPane, BorderLayout.CENTER); |
container.add(connectionListPane, BorderLayout.CENTER); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
protected String title4PopupWindow() { |
protected String title4PopupWindow() { |
||||||
return Inter.getLocText("Server-Define_Data_Connection"); |
return Inter.getLocText("Server-Define_Data_Connection"); |
||||||
} |
} |
||||||
|
|
||||||
public HashMap<String, String> getRenameMap() { |
public HashMap<String, String> getRenameMap() { |
||||||
return connectionListPane.getRenameMap(); |
return connectionListPane.getRenameMap(); |
||||||
} |
} |
||||||
|
|
||||||
public void populate(DatasourceManagerProvider datasourceManager) { |
public void populate(DatasourceManagerProvider datasourceManager) { |
||||||
this.connectionTextField.setText(FRContext.getCurrentEnv().getPath() + File.separator + ProjectConstants.RESOURCES_NAME |
this.connectionTextField.setText(FRContext.getCurrentEnv().getPath() + File.separator + ProjectConstants.RESOURCES_NAME |
||||||
+ File.separator + datasourceManager.fileName()); |
+ File.separator + datasourceManager.fileName()); |
||||||
this.connectionListPane.populate(datasourceManager); |
this.connectionListPane.populate(datasourceManager); |
||||||
} |
} |
||||||
|
|
||||||
public void update(DatasourceManagerProvider datasourceManager) { |
public void update(DatasourceManagerProvider datasourceManager) { |
||||||
this.connectionListPane.update(datasourceManager); |
this.connectionListPane.update(datasourceManager); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置选中项 |
* 设置选中项 |
||||||
* |
* |
||||||
* @param index 选中项的序列号 |
* @param index 选中项的序列号 |
||||||
*/ |
*/ |
||||||
public void setSelectedIndex(int index) { |
public void setSelectedIndex(int index) { |
||||||
this.connectionListPane.setSelectedIndex(index); |
this.connectionListPane.setSelectedIndex(index); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 名字是否允许 |
* 名字是否允许 |
||||||
* @return 允许返回true |
* |
||||||
*/ |
* @return 允许返回true |
||||||
public boolean isNamePermitted() { |
*/ |
||||||
return connectionListPane.isNamePermitted(); |
public boolean isNamePermitted() { |
||||||
} |
return connectionListPane.isNamePermitted(); |
||||||
|
} |
||||||
|
|
||||||
} |
} |
@ -0,0 +1,15 @@ |
|||||||
|
package com.fr.design.data.datapane.connect; |
||||||
|
|
||||||
|
import com.fr.file.DatasourceManagerProvider; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by yaoh.wu on 2017/4/22. |
||||||
|
* 数据链接显示面板 |
||||||
|
*/ |
||||||
|
public interface ConnectionShowPane { |
||||||
|
void update(DatasourceManagerProvider datasourceManager); |
||||||
|
|
||||||
|
void populate(DatasourceManagerProvider datasourceManager); |
||||||
|
|
||||||
|
void setSelectedIndex(int index); |
||||||
|
} |
After Width: | Height: | Size: 248 B |
After Width: | Height: | Size: 250 B |
After Width: | Height: | Size: 264 B |
After Width: | Height: | Size: 264 B |
After Width: | Height: | Size: 265 B |
After Width: | Height: | Size: 257 B |
After Width: | Height: | Size: 272 B |
After Width: | Height: | Size: 273 B |
@ -1,112 +1,104 @@ |
|||||||
package com.fr.design.style.color; |
package com.fr.design.style.color; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
import com.fr.design.dialog.BasicPane; |
||||||
import java.awt.Color; |
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
import java.awt.Dimension; |
import com.fr.general.Inter; |
||||||
|
|
||||||
import javax.swing.JColorChooser; |
import javax.swing.*; |
||||||
import javax.swing.JPanel; |
|
||||||
import javax.swing.colorchooser.AbstractColorChooserPanel; |
import javax.swing.colorchooser.AbstractColorChooserPanel; |
||||||
import javax.swing.colorchooser.ColorSelectionModel; |
import javax.swing.colorchooser.ColorSelectionModel; |
||||||
import javax.swing.event.ChangeEvent; |
import javax.swing.event.ChangeEvent; |
||||||
import javax.swing.event.ChangeListener; |
import javax.swing.event.ChangeListener; |
||||||
|
import java.awt.*; |
||||||
import com.fr.design.dialog.BasicPane; |
|
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
|
||||||
import com.fr.general.Inter; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 颜色选择器更多颜色面板 |
* 颜色选择器更多颜色面板 |
||||||
* @author focus |
|
||||||
* |
* |
||||||
|
* @author focus |
||||||
*/ |
*/ |
||||||
public class ColorSelectDetailPane extends BasicPane{ |
public class ColorSelectDetailPane extends BasicPane { |
||||||
private static final int SELECT_PANEL_HEIGHT = 245; |
private static final int SELECT_PANEL_HEIGHT = 245; |
||||||
// Selected color
|
// Selected color
|
||||||
private Color color; |
private Color color; |
||||||
|
|
||||||
// 颜色选择器面板
|
// 颜色选择器面板
|
||||||
JColorChooser selectedPanel; |
private JColorChooser selectedPanel; |
||||||
|
|
||||||
// 最近使用颜色面板
|
// 最近使用颜色面板
|
||||||
JPanel recentUsePanel; |
private JPanel recentUsePanel; |
||||||
|
|
||||||
// 预览
|
// 预览
|
||||||
JPanel previewPanel; |
private JPanel previewPanel; |
||||||
|
|
||||||
public JColorChooser getSelectedPanel() { |
public JColorChooser getSelectedPanel() { |
||||||
return selectedPanel; |
return selectedPanel; |
||||||
} |
} |
||||||
|
|
||||||
public void setSelectedPanel(JColorChooser selectedPanel) { |
public void setSelectedPanel(JColorChooser selectedPanel) { |
||||||
this.selectedPanel = selectedPanel; |
this.selectedPanel = selectedPanel; |
||||||
} |
} |
||||||
|
|
||||||
public Color getColor() { |
public Color getColor() { |
||||||
return color; |
return color; |
||||||
} |
} |
||||||
|
|
||||||
public void setColor(Color color) { |
public void setColor(Color color) { |
||||||
this.color = color; |
this.color = color; |
||||||
} |
} |
||||||
|
|
||||||
public ColorSelectDetailPane() { |
public ColorSelectDetailPane(Color color) { |
||||||
super(); |
if (color == null) { |
||||||
} |
color = Color.white; |
||||||
|
} |
||||||
public ColorSelectDetailPane(Color color){ |
this.color = color; |
||||||
if(color == null){ |
initComponents(); |
||||||
color = Color.white; |
} |
||||||
} |
|
||||||
this.color = color; |
@Override |
||||||
initComponents(); |
protected String title4PopupWindow() { |
||||||
} |
return null; |
||||||
|
} |
||||||
@Override |
|
||||||
protected String title4PopupWindow() { |
protected void initComponents() { |
||||||
return null; |
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
} |
|
||||||
|
// 颜色选择器面板
|
||||||
protected void initComponents() { |
selectedPanel = new JColorChooser(this.color); |
||||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(), SELECT_PANEL_HEIGHT)); |
||||||
|
AbstractColorChooserPanel[] choosers = selectedPanel.getChooserPanels(); |
||||||
// 颜色选择器面板
|
for (int i = 0; i < choosers.length; i++) { |
||||||
selectedPanel = new JColorChooser(this.color); |
selectedPanel.removeChooserPanel(choosers[i]); |
||||||
selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(),SELECT_PANEL_HEIGHT)); |
} |
||||||
AbstractColorChooserPanel[] choosers = selectedPanel.getChooserPanels(); |
selectedPanel.setPreviewPanel(new JPanel()); |
||||||
for(int i=0;i<choosers.length;i++){ |
|
||||||
selectedPanel.removeChooserPanel(choosers[i]); |
AbstractColorChooserPanel swatchChooserPanel = new SwatchChooserPanel(); |
||||||
} |
AbstractColorChooserPanel customChooserPanel = new CustomChooserPanel(); |
||||||
selectedPanel.setPreviewPanel(new JPanel()); |
selectedPanel.addChooserPanel(swatchChooserPanel); |
||||||
|
selectedPanel.addChooserPanel(customChooserPanel); |
||||||
AbstractColorChooserPanel swatchChooserPanel = new SwatchChooserPanel(); |
this.add(selectedPanel, BorderLayout.NORTH); |
||||||
AbstractColorChooserPanel customChooserPanel = new CustomChooserPanel(); |
|
||||||
selectedPanel.addChooserPanel(swatchChooserPanel); |
// 最近使用面板
|
||||||
selectedPanel.addChooserPanel(customChooserPanel); |
recentUsePanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Used")); |
||||||
this.add(selectedPanel, BorderLayout.NORTH); |
RecentUseColorPane recent = new RecentUseColorPane(selectedPanel); |
||||||
|
recentUsePanel.add(recent); |
||||||
// 最近使用面板
|
|
||||||
recentUsePanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Used")); |
this.add(recentUsePanel, BorderLayout.CENTER); |
||||||
RecentUseColorPane recent = new RecentUseColorPane(selectedPanel); |
|
||||||
recentUsePanel.add(recent); |
selectedPanel.setPreviewPanel(new JPanel()); |
||||||
|
|
||||||
this.add(recentUsePanel,BorderLayout.CENTER); |
// 预览
|
||||||
|
previewPanel = FRGUIPaneFactory.createTitledBorderPaneCenter(Inter.getLocText("FR-Designer_Preview")); |
||||||
selectedPanel.setPreviewPanel(new JPanel()); |
final ColorChooserPreview colorChooserPreview = new ColorChooserPreview(); |
||||||
|
ColorSelectionModel model = selectedPanel.getSelectionModel(); |
||||||
// 预览
|
model.addChangeListener(new ChangeListener() { |
||||||
previewPanel = FRGUIPaneFactory.createTitledBorderPaneCenter(Inter.getLocText("FR-Designer_Preview")); |
@Override |
||||||
final ColorChooserPreview colorChooserPreview = new ColorChooserPreview(); |
public void stateChanged(ChangeEvent e) { |
||||||
ColorSelectionModel model = selectedPanel.getSelectionModel(); |
ColorSelectionModel model = (ColorSelectionModel) e.getSource(); |
||||||
model.addChangeListener(new ChangeListener() { |
colorChooserPreview.setMyColor(model.getSelectedColor()); |
||||||
@Override |
colorChooserPreview.paint(colorChooserPreview.getGraphics()); |
||||||
public void stateChanged(ChangeEvent e) { |
} |
||||||
ColorSelectionModel model = (ColorSelectionModel) e.getSource(); |
}); |
||||||
colorChooserPreview.setMyColor(model.getSelectedColor()); |
previewPanel.add(colorChooserPreview); |
||||||
colorChooserPreview.paint(colorChooserPreview.getGraphics()); |
this.add(previewPanel, BorderLayout.SOUTH); |
||||||
} |
} |
||||||
}); |
|
||||||
previewPanel.add(colorChooserPreview); |
|
||||||
this.add(previewPanel, BorderLayout.SOUTH); |
|
||||||
} |
|
||||||
} |
} |
@ -1,215 +1,205 @@ |
|||||||
package com.fr.design.style.color; |
package com.fr.design.style.color; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
|
||||||
import java.awt.Color; |
|
||||||
import java.awt.Cursor; |
|
||||||
import java.awt.Dimension; |
|
||||||
import java.awt.GridLayout; |
|
||||||
import java.awt.event.ActionEvent; |
|
||||||
import java.awt.event.ActionListener; |
|
||||||
import java.awt.event.MouseAdapter; |
|
||||||
import java.awt.event.MouseEvent; |
|
||||||
import java.util.ArrayList; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.Box; |
|
||||||
import javax.swing.JPanel; |
|
||||||
import javax.swing.event.ChangeEvent; |
|
||||||
import javax.swing.event.ChangeListener; |
|
||||||
|
|
||||||
import com.fr.design.constants.UIConstants; |
|
||||||
import com.fr.design.border.UIRoundedBorder; |
import com.fr.design.border.UIRoundedBorder; |
||||||
|
import com.fr.design.constants.UIConstants; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
import com.fr.design.gui.ibutton.UIButton; |
import com.fr.design.gui.ibutton.UIButton; |
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
import com.fr.design.mainframe.DesignerContext; |
import com.fr.design.mainframe.DesignerContext; |
||||||
import com.fr.design.dialog.BasicPane; |
|
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import javax.swing.event.ChangeEvent; |
||||||
|
import javax.swing.event.ChangeListener; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* |
|
||||||
* @author zhou |
* @author zhou |
||||||
* @since 2012-5-29上午10:39:35 |
* @since 2012-5-29上午10:39:35 |
||||||
*/ |
*/ |
||||||
public class NewColorSelectPane extends BasicPane implements ColorSelectable { |
public class NewColorSelectPane extends BasicPane implements ColorSelectable { |
||||||
private static final long serialVersionUID = -8634152305687249392L; |
private static final long serialVersionUID = -8634152305687249392L; |
||||||
|
|
||||||
private Color color = null; // color
|
private Color color = null; // color
|
||||||
// color setting action.
|
// color setting action.
|
||||||
private ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<ChangeListener>(); |
private ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<ChangeListener>(); |
||||||
|
|
||||||
// 颜色选择器
|
// 颜色选择器
|
||||||
private ColorSelectDetailPane pane; |
private ColorSelectDetailPane pane; |
||||||
// 是否支持透明
|
// 是否支持透明
|
||||||
private boolean isSupportTransparent; |
private boolean isSupportTransparent; |
||||||
|
|
||||||
private final static int TRANSPANENT_WINDOW_HEIGHT = 165; |
private final static int TRANSPANENT_WINDOW_HEIGHT = 165; |
||||||
private final static int WINDWO_HEIGHT = 150; |
private final static int WINDWO_HEIGHT = 150; |
||||||
|
|
||||||
// 最近使用颜色
|
// 最近使用颜色
|
||||||
UsedColorPane usedColorPane; |
private UsedColorPane usedColorPane; |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor. |
* Constructor. |
||||||
*/ |
*/ |
||||||
public NewColorSelectPane() { |
public NewColorSelectPane() { |
||||||
this(false); |
this(false); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor. |
* Constructor. |
||||||
*/ |
*/ |
||||||
public NewColorSelectPane(boolean isSupportTransparent) { |
public NewColorSelectPane(boolean isSupportTransparent) { |
||||||
this.isSupportTransparent = isSupportTransparent; |
this.isSupportTransparent = isSupportTransparent; |
||||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); |
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); |
||||||
if (isSupportTransparent) { |
if (isSupportTransparent) { |
||||||
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); |
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); |
||||||
this.add(transpanrentButton, BorderLayout.NORTH); |
this.add(transpanrentButton, BorderLayout.NORTH); |
||||||
transpanrentButton.addActionListener(new ActionListener() { |
transpanrentButton.addActionListener(new ActionListener() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
||||||
doTransparent(); |
doTransparent(); |
||||||
} |
} |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
|
||||||
// center
|
// center
|
||||||
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
||||||
this.add(centerPane, BorderLayout.CENTER); |
this.add(centerPane, BorderLayout.CENTER); |
||||||
|
|
||||||
// 第一行
|
// 第一行
|
||||||
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||||
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); |
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); |
||||||
row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7
|
row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7
|
||||||
centerPane.add(row1Pane); |
centerPane.add(row1Pane); |
||||||
// 最近使用
|
// 最近使用
|
||||||
usedColorPane = new UsedColorPane(1, 8, 1, ColorSelectConfigManager.getInstance().getColors(), this, true, false); |
usedColorPane = new UsedColorPane(1, 8, 1, this, true, false); |
||||||
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); |
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); |
||||||
row1Pane.add(usedColorPane.getPane()); |
row1Pane.add(usedColorPane.getPane()); |
||||||
|
|
||||||
JPanel menuColorPane1 = new JPanel(); |
JPanel menuColorPane1 = new JPanel(); |
||||||
centerPane.add(menuColorPane1); |
centerPane.add(menuColorPane1); |
||||||
|
|
||||||
menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1)); |
menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1)); |
||||||
menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
||||||
for (int i = 0; i < ColorFactory.MenuColors.length; i++) { |
for (int i = 0; i < ColorFactory.MenuColors.length; i++) { |
||||||
menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this)); |
menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this)); |
||||||
} |
} |
||||||
|
|
||||||
centerPane.add(Box.createVerticalStrut(1)); |
centerPane.add(Box.createVerticalStrut(1)); |
||||||
|
|
||||||
// mod by anchore 16/11/16
|
// mod by anchore 16/11/16
|
||||||
UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color")); |
UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color")); |
||||||
//UIButton customButton = new UIButton(Inter.getLocText(new String[]{"More", "Color"}) + "...");
|
|
||||||
|
customButton.addMouseListener(new MouseAdapter() { |
||||||
customButton.addMouseListener(new MouseAdapter() { |
@Override |
||||||
@Override |
public void mousePressed(MouseEvent e) { |
||||||
public void mousePressed(MouseEvent e) { |
customButtonPressed(); |
||||||
customButtonPressed(); |
} |
||||||
} |
}); |
||||||
}); |
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
||||||
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8)); |
||||||
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8)); |
centerPane1.add(customButton, BorderLayout.NORTH); |
||||||
centerPane1.add(customButton, BorderLayout.NORTH); |
centerPane.add(centerPane1); |
||||||
centerPane.add(centerPane1); |
} |
||||||
} |
|
||||||
|
|
||||||
|
/** |
||||||
|
* 添加监听 |
||||||
/** |
* |
||||||
* 添加监听 |
* @param 监听列表 Add change listener. |
||||||
* @param 监听列表 |
*/ |
||||||
* Add change listener. |
public void addChangeListener(ChangeListener changeListener) { |
||||||
*/ |
this.colorChangeListenerList.add(changeListener); |
||||||
public void addChangeListener(ChangeListener changeListener) { |
} |
||||||
this.colorChangeListenerList.add(changeListener); |
|
||||||
} |
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
@Override |
return "Color"; |
||||||
protected String title4PopupWindow() { |
} |
||||||
return "Color"; |
|
||||||
} |
/** |
||||||
|
* 获取颜色 |
||||||
/** |
* |
||||||
* 获取颜色 |
* @return 颜色 |
||||||
* @return 颜色 |
* Return the color. |
||||||
* Return the color. |
*/ |
||||||
*/ |
public Color getColor() { |
||||||
public Color getColor() { |
return color; |
||||||
return color; |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* 获取颜色 |
||||||
* 获取颜色 |
* |
||||||
* |
* @return 颜色 |
||||||
* @return 颜色 |
*/ |
||||||
*/ |
public Color getNotNoneColor() { |
||||||
public Color getNotNoneColor() { |
if (color == null) { |
||||||
if (color == null) { |
setColor(Color.WHITE); |
||||||
setColor(Color.WHITE); |
return Color.WHITE; |
||||||
return Color.WHITE; |
} |
||||||
} |
return color; |
||||||
return color; |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Set the color. |
||||||
* Set the color. |
* |
||||||
* |
* @param color the new color. |
||||||
* @param color |
*/ |
||||||
* the new color. |
@Override |
||||||
*/ |
public void setColor(Color color) { |
||||||
@Override |
this.color = color; |
||||||
public void setColor(Color color) { |
|
||||||
this.color = color; |
// fire color change.
|
||||||
|
if (!colorChangeListenerList.isEmpty()) { |
||||||
// fire color change.
|
ChangeEvent evt = new ChangeEvent(this); |
||||||
if (!colorChangeListenerList.isEmpty()) { |
|
||||||
ChangeEvent evt = new ChangeEvent(this); |
for (int i = 0; i < colorChangeListenerList.size(); i++) { |
||||||
|
this.colorChangeListenerList.get(i).stateChanged(evt); |
||||||
for (int i = 0; i < colorChangeListenerList.size(); i++) { |
} |
||||||
this.colorChangeListenerList.get(i).stateChanged(evt); |
} |
||||||
} |
ColorSelectConfigManager.getInstance().addToColorQueue(color); |
||||||
} |
this.repaint(); |
||||||
ColorSelectConfigManager.getInstance().addToColorQueue(color); |
} |
||||||
this.repaint(); |
|
||||||
} |
/** |
||||||
|
* 设置颜色 |
||||||
/** |
* |
||||||
* 设置颜色 |
* @param 颜色位置 |
||||||
* @param 颜色位置 |
*/ |
||||||
*/ |
@Override |
||||||
@Override |
public void colorSetted(ColorCell colorCell) { |
||||||
public void colorSetted(ColorCell colorCell) { |
colorCell.repaint(); |
||||||
colorCell.repaint(); |
} |
||||||
} |
|
||||||
|
protected void doTransparent() { |
||||||
protected void doTransparent() { |
setColor(null); |
||||||
setColor(null); |
} |
||||||
} |
|
||||||
protected void customButtonPressed() { |
protected void customButtonPressed() { |
||||||
pane = new ColorSelectDetailPane(Color.WHITE); |
pane = new ColorSelectDetailPane(Color.WHITE); |
||||||
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); |
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public Dimension getPreferredSize() { |
public Dimension getPreferredSize() { |
||||||
if(isSupportTransparent){ |
if (isSupportTransparent) { |
||||||
return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT); |
return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT); |
||||||
} |
} |
||||||
return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT); |
return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 更新最近使用颜色 |
* 更新最近使用颜色 |
||||||
* |
*/ |
||||||
*/ |
public void updateUsedColor() { |
||||||
public void updateUsedColor(){ |
usedColorPane.updateUsedColor(); |
||||||
usedColorPane.updateUsedColor(); |
} |
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
} |
@ -1,55 +1,48 @@ |
|||||||
package com.fr.design.style.color; |
package com.fr.design.style.color; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
|
||||||
import java.awt.Color; |
|
||||||
|
|
||||||
import javax.swing.JColorChooser; |
|
||||||
import javax.swing.JPanel; |
|
||||||
|
|
||||||
import com.fr.design.dialog.BasicPane; |
import com.fr.design.dialog.BasicPane; |
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
|
||||||
public class RecentUseColorPane extends BasicPane implements ColorSelectable{ |
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
JColorChooser chooser; |
|
||||||
|
public class RecentUseColorPane extends BasicPane implements ColorSelectable { |
||||||
@Override |
|
||||||
protected String title4PopupWindow() { |
private JColorChooser chooser; |
||||||
return null; |
|
||||||
} |
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
public RecentUseColorPane() { |
return null; |
||||||
} |
} |
||||||
|
|
||||||
public RecentUseColorPane(JColorChooser chooser) { |
|
||||||
this.chooser = chooser; |
public RecentUseColorPane(JColorChooser chooser) { |
||||||
|
this.chooser = chooser; |
||||||
// center
|
|
||||||
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
// center
|
||||||
this.add(centerPane, BorderLayout.CENTER); |
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
||||||
// 最近使用
|
this.add(centerPane, BorderLayout.CENTER); |
||||||
UsedColorPane pane = new UsedColorPane(2, 10, ColorSelectConfigManager.getInstance().getColors(),this); |
// 最近使用
|
||||||
centerPane.add(pane.getPane()); |
UsedColorPane pane = new UsedColorPane(2, 10, this); |
||||||
} |
centerPane.add(pane.getPane()); |
||||||
|
} |
||||||
/** |
|
||||||
* 选中颜色 |
/** |
||||||
* |
* 选中颜色 |
||||||
* @param 颜色 |
*/ |
||||||
*/ |
@Override |
||||||
@Override |
public void colorSetted(ColorCell color) { |
||||||
public void colorSetted(ColorCell color) { |
|
||||||
|
} |
||||||
} |
|
||||||
|
@Override |
||||||
@Override |
public Color getColor() { |
||||||
public Color getColor() { |
return null; |
||||||
return null; |
} |
||||||
} |
|
||||||
|
@Override |
||||||
@Override |
public void setColor(Color color) { |
||||||
public void setColor(Color color) { |
chooser.getSelectionModel().setSelectedColor(color); |
||||||
chooser.getSelectionModel().setSelectedColor(color); |
} |
||||||
} |
|
||||||
|
|
||||||
} |
} |
@ -1,119 +1,112 @@ |
|||||||
package com.fr.design.style.color; |
package com.fr.design.style.color; |
||||||
|
|
||||||
import java.awt.Color; |
|
||||||
import java.awt.GridLayout; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.JPanel; |
|
||||||
|
|
||||||
import com.fr.design.dialog.BasicPane; |
import com.fr.design.dialog.BasicPane; |
||||||
import com.fr.design.gui.ibutton.SpecialUIButton; |
import com.fr.design.gui.ibutton.SpecialUIButton; |
||||||
|
|
||||||
public class UsedColorPane extends BasicPane{ |
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
public static final Color DEFAULT_COLOR = new Color(222,222,222); |
|
||||||
|
public class UsedColorPane extends BasicPane { |
||||||
// 最近使用面板列数
|
|
||||||
private int columns; |
// 默认显示颜色
|
||||||
// 最近使用面板行数
|
public static final Color DEFAULT_COLOR = new Color(222, 222, 222); |
||||||
private int rows; |
|
||||||
// 留白的单元格数量
|
// 最近使用面板列数
|
||||||
private int reserveCells; |
private int columns; |
||||||
// 是否需要取色器按钮
|
// 最近使用面板行数
|
||||||
private boolean needPickColorButton; |
private int rows; |
||||||
// 是否在取色时实时设定颜色
|
// 留白的单元格数量
|
||||||
private boolean setColorRealTime; |
private int reserveCells; |
||||||
// 最近使用颜色
|
// 是否需要取色器按钮
|
||||||
private Object[] colors; |
private boolean needPickColorButton; |
||||||
// 最近使用面板
|
// 是否在取色时实时设定颜色
|
||||||
private JPanel pane; |
private boolean setColorRealTime; |
||||||
|
|
||||||
private ColorSelectable selectable; |
// 最近使用面板
|
||||||
|
private JPanel pane; |
||||||
public JPanel getPane() { |
|
||||||
return pane; |
private ColorSelectable selectable; |
||||||
} |
|
||||||
|
public JPanel getPane() { |
||||||
public void setPane(JPanel pane) { |
return pane; |
||||||
this.pane = pane; |
} |
||||||
} |
|
||||||
|
public void setPane(JPanel pane) { |
||||||
public UsedColorPane(){ |
this.pane = pane; |
||||||
|
} |
||||||
} |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 构造函数 |
* 构造函数 |
||||||
* |
* |
||||||
* @param rows 行 |
* @param rows 行 |
||||||
* @param columns 列 |
* @param columns 列 |
||||||
* @param reserveCells 留白的单元格个数 |
* @param reserveCells 留白的单元格个数 |
||||||
* @param colors 最近使用的颜色 |
* @param colors 最近使用的颜色 |
||||||
* @param needPickColorButton 是否需要加上取色器按钮 |
* @param needPickColorButton 是否需要加上取色器按钮 |
||||||
* @param setColorRealTime 取色器是否实时设定颜色 |
* @param setColorRealTime 取色器是否实时设定颜色 |
||||||
*/ |
*/ |
||||||
public UsedColorPane(int rows,int columns,int reserveCells, Object[] colors, ColorSelectable selectable, boolean needPickColorButton, boolean setColorRealTime){ |
public UsedColorPane(int rows, int columns, int reserveCells, ColorSelectable selectable, boolean needPickColorButton, boolean setColorRealTime) { |
||||||
this.columns = columns; |
this.columns = columns; |
||||||
this.rows = rows; |
this.rows = rows; |
||||||
this.reserveCells = reserveCells; |
this.reserveCells = reserveCells; |
||||||
this.colors = colors; |
this.selectable = selectable; |
||||||
this.selectable = selectable; |
this.needPickColorButton = needPickColorButton; |
||||||
this.needPickColorButton = needPickColorButton; |
this.setColorRealTime = setColorRealTime; |
||||||
this.setColorRealTime = setColorRealTime; |
initialComponents(); |
||||||
initialComponents(); |
} |
||||||
} |
|
||||||
|
public UsedColorPane(int rows, int columns, ColorSelectable selectable) { |
||||||
public UsedColorPane(int rows,int columns, Object[] colors,ColorSelectable selectable){ |
this(rows, columns, 0, selectable, false, false); |
||||||
this(rows, columns, 0, colors, selectable, false, false); |
} |
||||||
} |
|
||||||
|
private void initialComponents() { |
||||||
private void initialComponents(){ |
int total = columns * rows; |
||||||
int total = columns * rows; |
JPanel panel = new JPanel(); |
||||||
JPanel panel = new JPanel(); |
panel.setLayout(new GridLayout(rows, columns, 1, 1)); |
||||||
panel.setLayout(new GridLayout(rows,columns, 1, 1)); |
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
||||||
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
//最近使用颜色
|
||||||
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
||||||
int size = colors.length; |
int size = colors.length; |
||||||
|
|
||||||
int i = 0; |
int i = 0; |
||||||
if (needPickColorButton) { |
if (needPickColorButton) { |
||||||
// 取色按钮
|
// 取色按钮
|
||||||
SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime); |
SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime); |
||||||
panel.add(pickColorButton); |
panel.add(pickColorButton); |
||||||
i++; |
i++; |
||||||
this.reserveCells += 1; |
this.reserveCells += 1; |
||||||
} |
} |
||||||
while (i < this.reserveCells) { |
while (i < this.reserveCells) { |
||||||
ColorCell cc = new ColorCell(DEFAULT_COLOR, selectable); |
ColorCell cc = new ColorCell(DEFAULT_COLOR, selectable); |
||||||
cc.setVisible(false); |
cc.setVisible(false); |
||||||
panel.add(cc); |
panel.add(cc); |
||||||
i++; |
i++; |
||||||
} |
} |
||||||
while (i < total) { |
while (i < total) { |
||||||
Color color = i < size ? colors[size-1-i]: DEFAULT_COLOR; |
Color color = i < size ? colors[size - (i - this.reserveCells) - 1] : DEFAULT_COLOR; |
||||||
panel.add(new ColorCell(color == null ? DEFAULT_COLOR : color, selectable)); |
panel.add(new ColorCell(color == null ? DEFAULT_COLOR : color, selectable)); |
||||||
i++; |
i++; |
||||||
} |
} |
||||||
this.pane = panel; |
this.pane = panel; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 更新最近使用颜色 |
* 更新最近使用颜色 |
||||||
* |
*/ |
||||||
*/ |
public void updateUsedColor() { |
||||||
public void updateUsedColor(){ |
int total = columns * rows; |
||||||
int total = columns * rows; |
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
||||||
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
int size = colors.length; |
||||||
int size = colors.length; |
for (int i = this.reserveCells; i < total; i++) { |
||||||
for(int i=this.reserveCells; i<total; i++){ |
ColorCell cell = (ColorCell) this.pane.getComponent(i); |
||||||
ColorCell cell = (ColorCell) this.pane.getComponent(i); |
Color color = i < size ? colors[size - (i - this.reserveCells) - 1] : DEFAULT_COLOR; |
||||||
Color color = i < size ? colors[size-1-i]: DEFAULT_COLOR; |
cell.setColor(color == null ? DEFAULT_COLOR : color); |
||||||
cell.setColor(color == null ? DEFAULT_COLOR : color); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
@Override |
||||||
@Override |
protected String title4PopupWindow() { |
||||||
protected String title4PopupWindow() { |
return null; |
||||||
return null; |
} |
||||||
} |
|
||||||
} |
} |
@ -1,346 +1,341 @@ |
|||||||
package com.fr.design.designer.beans.adapters.layout; |
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
import com.fr.design.beans.GroupModel; |
import com.fr.design.beans.GroupModel; |
||||||
import com.fr.design.designer.beans.ConstraintsGroupModel; |
import com.fr.design.designer.beans.ConstraintsGroupModel; |
||||||
import com.fr.design.designer.beans.HoverPainter; |
import com.fr.design.designer.beans.HoverPainter; |
||||||
import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter; |
import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter; |
||||||
import com.fr.design.designer.creator.*; |
import com.fr.design.designer.creator.*; |
||||||
import com.fr.design.designer.properties.BoundsGroupModel; |
import com.fr.design.designer.properties.BoundsGroupModel; |
||||||
import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; |
import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; |
||||||
import com.fr.design.utils.ComponentUtils; |
import com.fr.design.utils.ComponentUtils; |
||||||
import com.fr.design.utils.gui.LayoutUtils; |
import com.fr.design.utils.gui.LayoutUtils; |
||||||
import com.fr.form.ui.container.WAbsoluteLayout; |
import com.fr.form.ui.container.WAbsoluteLayout; |
||||||
import com.fr.general.ComparatorUtils; |
import com.fr.general.ComparatorUtils; |
||||||
import com.fr.general.FRLogger; |
import com.fr.general.FRLogger; |
||||||
|
|
||||||
import java.awt.*; |
import java.awt.*; |
||||||
|
|
||||||
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { |
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { |
||||||
//是不是添加到父容器上
|
//是不是添加到父容器上
|
||||||
private boolean isAdd2ParentLayout = false; |
private boolean isAdd2ParentLayout = false; |
||||||
private HoverPainter painter; |
private HoverPainter painter; |
||||||
|
|
||||||
public FRAbsoluteLayoutAdapter(XLayoutContainer container) { |
public FRAbsoluteLayoutAdapter(XLayoutContainer container) { |
||||||
super(container); |
super(container); |
||||||
painter = new FRAbsoluteLayoutPainter(container); |
painter = new FRAbsoluteLayoutPainter(container); |
||||||
initMinSize(); |
initMinSize(); |
||||||
} |
} |
||||||
|
|
||||||
private void initMinSize() { |
private void initMinSize() { |
||||||
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; |
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; |
||||||
minWidth = layout.getActualMinWidth(); |
minWidth = layout.getActualMinWidth(); |
||||||
minHeight = layout.getActualMinHeight(); |
minHeight = layout.getActualMinHeight(); |
||||||
actualVal = layout.getAcualInterval(); |
actualVal = layout.getAcualInterval(); |
||||||
margin = layout.toData().getMargin(); |
margin = layout.toData().getMargin(); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public HoverPainter getPainter() { |
public HoverPainter getPainter() { |
||||||
return painter; |
return painter; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 是否能在指定位置添加组件 |
* 是否能在指定位置添加组件 |
||||||
* |
* @param creator 组件 |
||||||
* @param creator 组件 |
* @param x 坐标x |
||||||
* @param x 坐标x |
* @param y 坐标y |
||||||
* @param y 坐标y |
* @return 能则返回true |
||||||
* @return 能则返回true |
*/ |
||||||
*/ |
//这个地方的逻辑非常复杂,
|
||||||
//这个地方的逻辑非常复杂,
|
// 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围,
|
||||||
// 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围,
|
// 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套)
|
||||||
// 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套)
|
// 3.当前绝对布局可编辑,那么控件添加
|
||||||
// 3.当前绝对布局可编辑,那么控件添加
|
@Override |
||||||
@Override |
public boolean accept(XCreator creator, int x, int y) { |
||||||
public boolean accept(XCreator creator, int x, int y) { |
Component comp = container.getComponentAt(x, y); |
||||||
Component comp = container.getComponentAt(x, y); |
//布局控件要先判断是不是可编辑
|
||||||
//布局控件要先判断是不是可编辑
|
//可以编辑,按原有逻辑判断
|
||||||
//可以编辑,按原有逻辑判断
|
//不可编辑,当成一整个控件处理
|
||||||
//不可编辑,当成一整个控件处理
|
if (comp == null){ |
||||||
if (comp == null) { |
return false; |
||||||
return false; |
} |
||||||
} |
//参数面板内的组件不允许拖往绝对布局中
|
||||||
//参数面板内的组件不允许拖往绝对布局中
|
if (creator.getParent() != null && ((XCreator)creator.getParent()).acceptType(XWParameterLayout.class)){ |
||||||
if (creator.getParent() != null && ((XCreator) creator.getParent()).acceptType(XWParameterLayout.class)) { |
Rectangle rec = creator.getBounds(); |
||||||
Rectangle rec = creator.getBounds(); |
rec.y = creator.getParent().getHeight() - rec.height; |
||||||
rec.y = creator.getParent().getHeight() - rec.height; |
creator.setBounds(rec); |
||||||
creator.setBounds(rec); |
return false; |
||||||
return false; |
} |
||||||
} |
//判断下组件能不能拖入绝对布局
|
||||||
//判断组件能不能拖入绝对布局
|
if (!creator.canEnterIntoAbsolutePane()){ |
||||||
if (!creator.canEnterIntoAbsolutePane()) { |
return false; |
||||||
return false; |
} |
||||||
} |
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout(); |
||||||
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator) comp).getTopLayout(); |
if(topLayout != null){ |
||||||
if (topLayout != null) { |
if (topLayout.isEditable()){ |
||||||
if (topLayout.isEditable()) { |
return topLayoutAccept(creator, x, y); |
||||||
return topLayoutAccept(creator, x, y); |
} |
||||||
} |
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局
|
||||||
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局
|
else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { |
||||||
else if (((XLayoutContainer) topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { |
return false; |
||||||
return false; |
} else { |
||||||
} else { |
return acceptWidget(x, y); |
||||||
return acceptWidget(x, y); |
} |
||||||
} |
} else { |
||||||
} else { |
FRLogger.getLogger().error("top layout is null!"); |
||||||
FRLogger.getLogger().error("top layout is null!"); |
} |
||||||
} |
|
||||||
|
return false; |
||||||
return false; |
} |
||||||
} |
|
||||||
|
//topLayout假如可以编辑的话就往里面添加组件
|
||||||
//topLayout假如可以编辑的话就往里面添加组件
|
private boolean topLayoutAccept(XCreator creator, int x, int y) { |
||||||
private boolean topLayoutAccept(XCreator creator, int x, int y) { |
//允许组件重叠,可以不判断有没有和当前控件重叠
|
||||||
//允许组件重叠,可以不判断有没有和当前控件重叠
|
//先计算当前控件的位置
|
||||||
//先计算当前控件的位置
|
int creatorX, creatorY; |
||||||
int creatorX, creatorY; |
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { |
||||||
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { |
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); |
||||||
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); |
creatorX = creatorRectangle.x; |
||||||
creatorX = creatorRectangle.x; |
creatorY = creatorRectangle.y; |
||||||
creatorY = creatorRectangle.y; |
} else { |
||||||
} else { |
//这边计算得到的组件其实位置是正确的,
|
||||||
//这边计算得到的组件其实位置是正确的,
|
//因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的,
|
||||||
//因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的,
|
// 例如高度为21,那么就是+10-10;
|
||||||
// 例如高度为21,那么就是+10-10;
|
// 高度为20,那么就是+10-10; 没区别
|
||||||
// 高度为20,那么就是+10-10; 没区别
|
int w = creator.getWidth() / 2; |
||||||
int w = creator.getWidth() / 2; |
int h = creator.getHeight() / 2; |
||||||
int h = creator.getHeight() / 2; |
creatorX = x - w; |
||||||
creatorX = x - w; |
creatorY = y - h; |
||||||
creatorY = y - h; |
} |
||||||
} |
if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { |
||||||
if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { |
return false; |
||||||
return false; |
} |
||||||
} |
if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()){ |
||||||
if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()) { |
return false; |
||||||
return false; |
} |
||||||
} |
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() |
||||||
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() |
&& creator.getWidth() <= container.getWidth(); |
||||||
&& creator.getWidth() <= container.getWidth(); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* 判断是否鼠标在组件的三等分区域,如果组件在布局管理器中间,上下左右都可能会三等分 |
||||||
* 判断是否鼠标在组件的三等分区域,如果组件在布局管理器中间,上下左右都可能会三等分 |
* @param parentComp 鼠标所在区域的组件 |
||||||
* |
* @param x 坐标x |
||||||
* @param parentComp 鼠标所在区域的组件 |
* @param y 坐标y |
||||||
* @param x 坐标x |
* @return 是则返回true |
||||||
* @param y 坐标y |
*/ |
||||||
* @return 是则返回true |
public boolean isTrisectionArea(Component parentComp, int x, int y) { |
||||||
*/ |
XCreator creator = (XCreator)parentComp; |
||||||
public boolean isTrisectionArea(Component parentComp, int x, int y) { |
trisectAreaDirect = 0; |
||||||
XCreator creator = (XCreator) parentComp; |
if (container.getComponentCount()<=1) { |
||||||
trisectAreaDirect = 0; |
return false; |
||||||
if (container.getComponentCount() <= 1) { |
} |
||||||
return false; |
int maxWidth = parentComp.getWidth(); |
||||||
} |
int maxHeight = parentComp.getHeight(); |
||||||
int maxWidth = parentComp.getWidth(); |
int xL = parentComp.getX(); |
||||||
int maxHeight = parentComp.getHeight(); |
int yL = parentComp.getY(); |
||||||
int xL = parentComp.getX(); |
// 组件宽高的十分之一和默认值取大
|
||||||
int yL = parentComp.getY(); |
int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); |
||||||
// 组件宽高的十分之一和默认值取大
|
int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); |
||||||
int minRangeWidth = Math.max(maxWidth / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); |
if(y<yL+minRangeHeight ) { |
||||||
int minRangeHeight = Math.max(maxHeight / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); |
// 在组件上侧三等分
|
||||||
if (y < yL + minRangeHeight) { |
trisectAreaDirect = COMP_TOP; |
||||||
// 在组件上侧三等分
|
} else if(y>yL+maxHeight-minRangeHeight) { |
||||||
trisectAreaDirect = COMP_TOP; |
// 在组件下侧三等分
|
||||||
} else if (y > yL + maxHeight - minRangeHeight) { |
trisectAreaDirect = COMP_BOTTOM; |
||||||
// 在组件下侧三等分
|
} else if (x<xL+minRangeWidth) { |
||||||
trisectAreaDirect = COMP_BOTTOM; |
// 在组件左侧三等分
|
||||||
} else if (x < xL + minRangeWidth) { |
trisectAreaDirect = COMP_LEFT; |
||||||
// 在组件左侧三等分
|
} else if(x>xL+maxWidth-minRangeWidth) { |
||||||
trisectAreaDirect = COMP_LEFT; |
// 在组件右侧三等分
|
||||||
} else if (x > xL + maxWidth - minRangeWidth) { |
trisectAreaDirect = COMP_RIGHT; |
||||||
// 在组件右侧三等分
|
} |
||||||
trisectAreaDirect = COMP_RIGHT; |
// tab布局的边界特殊处理,不进行三等分
|
||||||
} |
if(!creator.getTargetChildrenList().isEmpty()){ |
||||||
// tab布局的边界特殊处理,不进行三等分
|
return false; |
||||||
if (!creator.getTargetChildrenList().isEmpty()) { |
} |
||||||
return false; |
|
||||||
} |
return !ComparatorUtils.equals(trisectAreaDirect, 0); |
||||||
|
} |
||||||
return !ComparatorUtils.equals(trisectAreaDirect, 0); |
|
||||||
} |
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围
|
||||||
|
private boolean acceptWidget(int x, int y) { |
||||||
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围
|
isFindRelatedComps = false; |
||||||
private boolean acceptWidget(int x, int y) { |
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
|
||||||
isFindRelatedComps = false; |
Component comp = container.getComponentAt(x, y); |
||||||
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
|
//如果当前处于边缘地带, 那么就把他贴到父容器上
|
||||||
Component comp = container.getComponentAt(x, y); |
XLayoutContainer parent = container.findNearestFit(); |
||||||
//如果当前处于边缘地带, 那么就把他贴到父容器上
|
container = parent != null ? parent : container; |
||||||
XLayoutContainer parent = container.findNearestFit(); |
isAdd2ParentLayout = true; |
||||||
container = parent != null ? parent : container; |
|
||||||
isAdd2ParentLayout = true; |
int componentHeight = comp.getHeight(); |
||||||
|
int componentWidth = comp.getWidth(); |
||||||
int componentHeight = comp.getHeight(); |
//上半部分高度
|
||||||
int componentWidth = comp.getWidth(); |
int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY(); |
||||||
//上半部分高度
|
//下半部分高度
|
||||||
int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY(); |
int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY(); |
||||||
//下半部分高度
|
|
||||||
int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY(); |
if (isCrossPointArea(comp, x, y)) { |
||||||
|
return canAcceptWhileCrossPoint(comp, x, y); |
||||||
if (isCrossPointArea(comp, x, y)) { |
} |
||||||
return canAcceptWhileCrossPoint(comp, x, y); |
|
||||||
} |
if (isTrisectionArea(comp, x, y)) { |
||||||
|
return canAcceptWhileTrisection(comp, x, y); |
||||||
if (isTrisectionArea(comp, x, y)) { |
} |
||||||
return canAcceptWhileTrisection(comp, x, y); |
|
||||||
} |
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal; |
||||||
|
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal; |
||||||
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal; |
return y > upHeight && y < downHeight ? horizonValid : verticalValid; |
||||||
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal; |
} |
||||||
return y > upHeight && y < downHeight ? horizonValid : verticalValid; |
|
||||||
} |
/** |
||||||
|
* 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 |
||||||
/** |
* addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 |
||||||
* 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 |
* |
||||||
* addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 |
* @param creator 被添加的新组件 |
||||||
* |
* @param x 添加的位置x,该位置是相对于container的 |
||||||
* @param creator 被添加的新组件 |
* @param y 添加的位置y,该位置是相对于container的 |
||||||
* @param x 添加的位置x,该位置是相对于container的 |
* @return 是否添加成功,成功返回true,否则false |
||||||
* @param y 添加的位置y,该位置是相对于container的 |
*/ |
||||||
* @return 是否添加成功,成功返回true,否则false |
@Override |
||||||
*/ |
public boolean addBean(XCreator creator, int x, int y) { |
||||||
@Override |
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
public boolean addBean(XCreator creator, int x, int y) { |
|
||||||
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
int posX = x + rect.x; |
||||||
|
int posY = y + rect.y; |
||||||
int posX = x + rect.x; |
if (!accept(creator, x, y)) { |
||||||
int posY = y + rect.y; |
return false; |
||||||
if (!accept(creator, x, y)) { |
} |
||||||
return false; |
addComp(creator, posX, posY); |
||||||
} |
((XWidgetCreator) creator).recalculateChildrenSize(); |
||||||
addComp(creator, posX, posY); |
return true; |
||||||
((XWidgetCreator) creator).recalculateChildrenSize(); |
} |
||||||
return true; |
|
||||||
} |
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
@Override |
if(!isAdd2ParentLayout) { |
||||||
protected void addComp(XCreator creator, int x, int y) { |
Rectangle r = ComponentUtils.getRelativeBounds(container); |
||||||
if (!isAdd2ParentLayout) { |
x = x - r.x; |
||||||
Rectangle r = ComponentUtils.getRelativeBounds(container); |
y = y - r.y; |
||||||
x = x - r.x; |
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { |
||||||
y = y - r.y; |
|
||||||
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { |
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); |
||||||
|
x = creatorRectangle.x - r.x; |
||||||
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); |
y = creatorRectangle.y - r.y; |
||||||
x = creatorRectangle.x - r.x; |
} else { |
||||||
y = creatorRectangle.y - r.y; |
int w = creator.getWidth() / 2; |
||||||
} else { |
int h = creator.getHeight() / 2; |
||||||
int w = creator.getWidth() / 2; |
x = x - w; |
||||||
int h = creator.getHeight() / 2; |
y = y - h; |
||||||
x = x - w; |
} |
||||||
y = y - h; |
fix(creator, x, y); |
||||||
} |
|
||||||
fix(creator, x, y); |
if (creator.hasTitleStyle()) { |
||||||
|
addParentCreator(creator); |
||||||
if (creator.hasTitleStyle()) { |
} else { |
||||||
addParentCreator(creator); |
container.add(creator, creator.toData().getWidgetName(),0); |
||||||
} else { |
} |
||||||
container.add(creator, creator.toData().getWidgetName(), 0); |
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; |
||||||
} |
layout.updateBoundsWidget(creator); |
||||||
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; |
updateCreatorBackBound(); |
||||||
layout.updateBoundsWidget(creator); |
LayoutUtils.layoutRootContainer(container); |
||||||
updateCreatorBackBound(); |
}else{ |
||||||
LayoutUtils.layoutRootContainer(container); |
fixAbsolute(creator, x, y); |
||||||
} else { |
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { |
||||||
fixAbsolute(creator, x, y); |
addParentCreator(creator); |
||||||
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { |
} else { |
||||||
addParentCreator(creator); |
container.add(creator, creator.toData().getWidgetName(),0); |
||||||
} else { |
} |
||||||
container.add(creator, creator.toData().getWidgetName(), 0); |
XWFitLayout layout = (XWFitLayout) container; |
||||||
} |
// 更新对应的BoundsWidget
|
||||||
XWFitLayout layout = (XWFitLayout) container; |
layout.updateBoundsWidget(); |
||||||
// 更新对应的BoundsWidget
|
updateCreatorBackBound(); |
||||||
layout.updateBoundsWidget(); |
} |
||||||
updateCreatorBackBound(); |
} |
||||||
} |
|
||||||
} |
private void updateCreatorBackBound() { |
||||||
|
for (int i=0,size=container.getComponentCount(); i<size; i++) { |
||||||
private void updateCreatorBackBound() { |
XCreator creator = (XCreator) container.getComponent(i); |
||||||
for (int i = 0, size = container.getComponentCount(); i < size; i++) { |
creator.updateChildBound(minHeight); |
||||||
XCreator creator = (XCreator) container.getComponent(i); |
creator.setBackupBound(creator.getBounds()); |
||||||
creator.updateChildBound(minHeight); |
} |
||||||
creator.setBackupBound(creator.getBounds()); |
} |
||||||
} |
|
||||||
} |
private void addParentCreator(XCreator child) { |
||||||
|
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); |
||||||
private void addParentCreator(XCreator child) { |
container.add(parentPanel, child.toData().getWidgetName(),0); |
||||||
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); |
} |
||||||
container.add(parentPanel, child.toData().getWidgetName(), 0); |
|
||||||
} |
/** |
||||||
|
* 新拖入组件时,计算调整其他关联组件位置大小 |
||||||
/** |
* @param child 新拖入的组件 |
||||||
* 新拖入组件时,计算调整其他关联组件位置大小 |
* @param x 鼠标所在x坐标 |
||||||
* |
* @param y 鼠标所在y坐标 |
||||||
* @param child 新拖入的组件 |
*/ |
||||||
* @param x 鼠标所在x坐标 |
private void fixAbsolute(XCreator child, int x, int y) { |
||||||
* @param y 鼠标所在y坐标 |
Component parentComp = container.getComponentAt(x, y); |
||||||
*/ |
if (container.getComponentCount()==0){ |
||||||
private void fixAbsolute(XCreator child, int x, int y) { |
child.setLocation(0, 0); |
||||||
Component parentComp = container.getComponentAt(x, y); |
child.setSize(parentComp.getWidth(), parentComp.getHeight()); |
||||||
if (container.getComponentCount() == 0) { |
} else if(isCrossPointArea(parentComp, x, y)){ |
||||||
child.setLocation(0, 0); |
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
|
||||||
child.setSize(parentComp.getWidth(), parentComp.getHeight()); |
fixCrossPointArea(parentComp, child, x, y); |
||||||
} else if (isCrossPointArea(parentComp, x, y)) { |
return; |
||||||
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
|
} else if (isTrisectionArea(parentComp, x, y)) { |
||||||
fixCrossPointArea(parentComp, child, x, y); |
// 在边界三等分区域,就不再和组件二等分了
|
||||||
return; |
fixTrisect(parentComp, child, x, y); |
||||||
} else if (isTrisectionArea(parentComp, x, y)) { |
return; |
||||||
// 在边界三等分区域,就不再和组件二等分了
|
} else{ |
||||||
fixTrisect(parentComp, child, x, y); |
fixHalve(parentComp, child, x, y); |
||||||
return; |
} |
||||||
} else { |
} |
||||||
fixHalve(parentComp, child, x, y); |
|
||||||
} |
/** |
||||||
} |
* 组件拖拽后调整大小 |
||||||
|
* @param creator 组件 |
||||||
/** |
*/ |
||||||
* 组件拖拽后调整大小 |
@Override |
||||||
* |
public void fix(XCreator creator) { |
||||||
* @param creator 组件 |
WAbsoluteLayout wabs = (WAbsoluteLayout)container.toData(); |
||||||
*/ |
fix(creator,creator.getX(),creator.getY()); |
||||||
@Override |
wabs.setBounds(creator.toData(),creator.getBounds()); |
||||||
public void fix(XCreator creator) { |
|
||||||
WAbsoluteLayout wabs = (WAbsoluteLayout) container.toData(); |
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; |
||||||
fix(creator, creator.getX(), creator.getY()); |
layout.updateBoundsWidget(creator); |
||||||
wabs.setBounds(creator.toData(), creator.getBounds()); |
} |
||||||
|
|
||||||
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; |
/** |
||||||
layout.updateBoundsWidget(creator); |
* 调整组件大小到合适尺寸位置 |
||||||
} |
* @param creator 组件 |
||||||
|
* @param x 坐标x |
||||||
/** |
* @param y 坐标y |
||||||
* 调整组件大小到合适尺寸位置 |
*/ |
||||||
* |
public void fix(XCreator creator ,int x, int y) { |
||||||
* @param creator 组件 |
int height = creator.getHeight(); |
||||||
* @param x 坐标x |
int width = creator.getWidth(); |
||||||
* @param y 坐标y |
if (x < 0) { |
||||||
*/ |
x = container.getX(); |
||||||
public void fix(XCreator creator, int x, int y) { |
} else if (x + creator.getWidth() > container.getWidth()) { |
||||||
int height = creator.getHeight(); |
x = container.getWidth() - width; |
||||||
int width = creator.getWidth(); |
} |
||||||
if (x < 0) { |
|
||||||
x = container.getX(); |
if (y < 0) { |
||||||
} else if (x + creator.getWidth() > container.getWidth()) { |
y = container.getY(); |
||||||
x = container.getWidth() - width; |
} else if (y + creator.getHeight() > container.getHeight()) { |
||||||
} |
y = container.getHeight() - height; |
||||||
|
} |
||||||
if (y < 0) { |
|
||||||
y = container.getY(); |
creator.setBounds(x, y, width, height); |
||||||
} else if (y + creator.getHeight() > container.getHeight()) { |
} |
||||||
y = container.getHeight() - height; |
|
||||||
} |
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
creator.setBounds(x, y, width, height); |
return new BoundsGroupModel((XWAbsoluteLayout)container, creator); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
public GroupModel getLayoutProperties() { |
||||||
return new BoundsGroupModel((XWAbsoluteLayout) container, creator); |
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; |
||||||
} |
return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); |
||||||
|
} |
||||||
@Override |
|
||||||
public GroupModel getLayoutProperties() { |
|
||||||
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; |
|
||||||
return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); |
|
||||||
} |
|
||||||
} |
} |
@ -1,141 +1,141 @@ |
|||||||
package com.fr.design.designer.beans.models; |
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
import java.awt.Rectangle; |
import java.awt.Rectangle; |
||||||
|
|
||||||
import com.fr.design.designer.creator.XWAbsoluteLayout; |
import com.fr.design.designer.creator.XWAbsoluteLayout; |
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.design.designer.beans.AdapterBus; |
import com.fr.design.designer.beans.AdapterBus; |
||||||
import com.fr.design.designer.beans.ComponentAdapter; |
import com.fr.design.designer.beans.ComponentAdapter; |
||||||
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; |
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; |
||||||
import com.fr.design.designer.creator.XCreator; |
import com.fr.design.designer.creator.XCreator; |
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
import com.fr.design.designer.creator.XWParameterLayout; |
import com.fr.design.designer.creator.XWParameterLayout; |
||||||
import com.fr.design.utils.ComponentUtils; |
import com.fr.design.utils.ComponentUtils; |
||||||
import com.fr.general.ComparatorUtils; |
import com.fr.general.ComparatorUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* 添加状态下的model |
* 添加状态下的model |
||||||
*/ |
*/ |
||||||
public class AddingModel { |
public class AddingModel { |
||||||
|
|
||||||
// 当前要添加的组件
|
// 当前要添加的组件
|
||||||
private XCreator creator; |
private XCreator creator; |
||||||
// 记录当前鼠标的位置信息
|
// 记录当前鼠标的位置信息
|
||||||
private int currentX; |
private int currentX; |
||||||
private int currentY; |
private int currentY; |
||||||
private boolean added; |
private boolean added; |
||||||
|
|
||||||
public AddingModel(FormDesigner designer, XCreator xCreator) { |
public AddingModel(FormDesigner designer, XCreator xCreator) { |
||||||
String creatorName = getXCreatorName(designer, xCreator); |
String creatorName = getXCreatorName(designer, xCreator); |
||||||
this.creator = xCreator; |
this.creator = xCreator; |
||||||
instantiateCreator(designer, creatorName); |
instantiateCreator(designer, creatorName); |
||||||
// 初始的时候隐藏该组件的图标
|
// 初始的时候隐藏该组件的图标
|
||||||
currentY = -this.creator.getWidth(); |
currentY = -this.creator.getWidth(); |
||||||
currentX = -this.creator.getHeight(); |
currentX = -this.creator.getHeight(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 待说明 |
* 待说明 |
||||||
* |
* |
||||||
* @param designer 设计器 |
* @param designer 设计器 |
||||||
* @param creatorName 组件名 |
* @param creatorName 组件名 |
||||||
*/ |
*/ |
||||||
public void instantiateCreator(FormDesigner designer, String creatorName) { |
public void instantiateCreator(FormDesigner designer, String creatorName) { |
||||||
creator.toData().setWidgetName(creatorName); |
creator.toData().setWidgetName(creatorName); |
||||||
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); |
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); |
||||||
adapter.initialize(); |
adapter.initialize(); |
||||||
creator.addNotify(); |
creator.addNotify(); |
||||||
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); |
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); |
||||||
} |
} |
||||||
|
|
||||||
public AddingModel(XCreator xCreator, int x, int y) { |
public AddingModel(XCreator xCreator, int x, int y) { |
||||||
this.creator = xCreator; |
this.creator = xCreator; |
||||||
this.creator.backupCurrentSize(); |
this.creator.backupCurrentSize(); |
||||||
this.creator.backupParent(); |
this.creator.backupParent(); |
||||||
this.creator.setSize(xCreator.initEditorSize()); |
this.creator.setSize(xCreator.initEditorSize()); |
||||||
currentX = x - (xCreator.getWidth() / 2); |
currentX = x - (xCreator.getWidth() / 2); |
||||||
currentY = y - (xCreator.getHeight() / 2); |
currentY = y - (xCreator.getHeight() / 2); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 隐藏当前组件的图标 |
* 隐藏当前组件的图标 |
||||||
*/ |
*/ |
||||||
public void reset() { |
public void reset() { |
||||||
currentX = -this.creator.getWidth(); |
currentX = -this.creator.getWidth(); |
||||||
currentY = -this.creator.getHeight(); |
currentY = -this.creator.getHeight(); |
||||||
} |
} |
||||||
|
|
||||||
public String getXCreatorName(FormDesigner designer, XCreator x) { |
public String getXCreatorName(FormDesigner designer, XCreator x) { |
||||||
String def = x.createDefaultName(); |
String def = x.createDefaultName(); |
||||||
if (x.acceptType(XWParameterLayout.class)) { |
if (x.acceptType(XWParameterLayout.class)) { |
||||||
return def; |
return def; |
||||||
} |
} |
||||||
int i = 0; |
int i = 0; |
||||||
while (designer.getTarget().isNameExist(def + i)) { |
while (designer.getTarget().isNameExist(def + i)) { |
||||||
i++; |
i++; |
||||||
} |
} |
||||||
return def + i; |
return def + i; |
||||||
} |
} |
||||||
|
|
||||||
public int getCurrentX() { |
public int getCurrentX() { |
||||||
return currentX; |
return currentX; |
||||||
} |
} |
||||||
|
|
||||||
public int getCurrentY() { |
public int getCurrentY() { |
||||||
return currentY; |
return currentY; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* 移动组件图标到鼠标事件发生的位置 |
* 移动组件图标到鼠标事件发生的位置 |
||||||
* |
* |
||||||
* @param x 坐标 |
* @param x 坐标 |
||||||
* @param y 坐标 |
* @param y 坐标 |
||||||
*/ |
*/ |
||||||
public void moveTo(int x, int y) { |
public void moveTo(int x, int y) { |
||||||
currentX = x - (this.creator.getWidth() / 2); |
currentX = x - (this.creator.getWidth() / 2); |
||||||
currentY = y - (this.creator.getHeight() / 2); |
currentY = y - (this.creator.getHeight() / 2); |
||||||
} |
} |
||||||
|
|
||||||
public XCreator getXCreator() { |
public XCreator getXCreator() { |
||||||
return this.creator; |
return this.creator; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 当前组件是否已经添加到某个容器中 |
* 当前组件是否已经添加到某个容器中 |
||||||
* |
* |
||||||
* @return 是返回true |
* @return 是返回true |
||||||
*/ |
*/ |
||||||
public boolean isCreatorAdded() { |
public boolean isCreatorAdded() { |
||||||
return added; |
return added; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 加入容器 |
* 加入容器 |
||||||
* |
* |
||||||
* @param designer 设计器 |
* @param designer 设计器 |
||||||
* @param container 容器 |
* @param container 容器 |
||||||
* @param x 坐标 |
* @param x 坐标 |
||||||
* @param y 坐标 |
* @param y 坐标 |
||||||
* @return 成功返回true |
* @return 成功返回true |
||||||
*/ |
*/ |
||||||
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { |
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { |
||||||
//考虑不同布局嵌套的情况,获取顶层容器
|
//考虑不同布局嵌套的情况,获取顶层容器
|
||||||
XLayoutContainer xLayoutContainer = container.getTopLayout(); |
XLayoutContainer xLayoutContainer = container.getTopLayout(); |
||||||
if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) { |
if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) { |
||||||
container = xLayoutContainer; |
container = xLayoutContainer; |
||||||
} |
} |
||||||
|
|
||||||
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) { |
if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) { |
||||||
added = container.getLayoutAdapter().addBean(creator, |
added = container.getLayoutAdapter().addBean(creator, |
||||||
x + designer.getArea().getHorizontalValue(), |
x + designer.getArea().getHorizontalValue(), |
||||||
y + designer.getArea().getVerticalValue()); |
y + designer.getArea().getVerticalValue()); |
||||||
return added; |
return added; |
||||||
} |
} |
||||||
added = container.getLayoutAdapter().addBean(creator, |
added = container.getLayoutAdapter().addBean(creator, |
||||||
x + designer.getArea().getHorizontalValue() - rect.x, |
x + designer.getArea().getHorizontalValue() - rect.x, |
||||||
y + designer.getArea().getVerticalValue() - rect.y); |
y + designer.getArea().getVerticalValue() - rect.y); |
||||||
return added; |
return added; |
||||||
} |
} |
||||||
} |
} |
@ -1,476 +1,476 @@ |
|||||||
package com.fr.design.designer.beans.models; |
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
import com.fr.design.beans.location.Absorptionline; |
import com.fr.design.beans.location.Absorptionline; |
||||||
import com.fr.design.designer.beans.AdapterBus; |
import com.fr.design.designer.beans.AdapterBus; |
||||||
import com.fr.design.designer.beans.HoverPainter; |
import com.fr.design.designer.beans.HoverPainter; |
||||||
import com.fr.design.designer.beans.LayoutAdapter; |
import com.fr.design.designer.beans.LayoutAdapter; |
||||||
import com.fr.design.designer.beans.events.DesignerEvent; |
import com.fr.design.designer.beans.events.DesignerEvent; |
||||||
import com.fr.design.designer.beans.location.Direction; |
import com.fr.design.designer.beans.location.Direction; |
||||||
import com.fr.design.designer.beans.location.Location; |
import com.fr.design.designer.beans.location.Location; |
||||||
import com.fr.design.designer.creator.*; |
import com.fr.design.designer.creator.*; |
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.design.mainframe.FormSelectionUtils; |
import com.fr.design.mainframe.FormSelectionUtils; |
||||||
import com.fr.design.utils.ComponentUtils; |
import com.fr.design.utils.ComponentUtils; |
||||||
|
|
||||||
import java.awt.*; |
import java.awt.*; |
||||||
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
|
|
||||||
/** |
/** |
||||||
* 普通模式下的状态model |
* 普通模式下的状态model |
||||||
*/ |
*/ |
||||||
public class StateModel { |
public class StateModel { |
||||||
// 对应的selection model
|
// 对应的selection model
|
||||||
|
|
||||||
private SelectionModel selectionModel; |
private SelectionModel selectionModel; |
||||||
// 当前鼠标进入拖拽区域的位置类型
|
// 当前鼠标进入拖拽区域的位置类型
|
||||||
private Direction driection; |
private Direction driection; |
||||||
|
|
||||||
// 当前拖拽的起始位置
|
// 当前拖拽的起始位置
|
||||||
private int currentX; |
private int currentX; |
||||||
private int currentY; |
private int currentY; |
||||||
|
|
||||||
//拖拽组件原始位置大小备份
|
//拖拽组件原始位置大小备份
|
||||||
private Rectangle selectedPositionBackup; |
private Rectangle selectedPositionBackup; |
||||||
|
|
||||||
private Point startPoint = new Point(); |
private Point startPoint = new Point(); |
||||||
private Point currentPoint = new Point(); |
private Point currentPoint = new Point(); |
||||||
|
|
||||||
private Absorptionline lineInX; |
private Absorptionline lineInX; |
||||||
private Absorptionline lineInY; |
private Absorptionline lineInY; |
||||||
//等距线
|
//等距线
|
||||||
private Absorptionline lineEquidistant; |
private Absorptionline lineEquidistant; |
||||||
|
|
||||||
// 当前是否处于拖拽选择状态
|
// 当前是否处于拖拽选择状态
|
||||||
private boolean selecting; |
private boolean selecting; |
||||||
private boolean dragging; |
private boolean dragging; |
||||||
|
|
||||||
private boolean addable; |
private boolean addable; |
||||||
|
|
||||||
private FormDesigner designer; |
private FormDesigner designer; |
||||||
|
|
||||||
public StateModel(FormDesigner designer) { |
public StateModel(FormDesigner designer) { |
||||||
this.designer = designer; |
this.designer = designer; |
||||||
selectionModel = designer.getSelectionModel(); |
selectionModel = designer.getSelectionModel(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 返回direction |
* 返回direction |
||||||
* |
* |
||||||
* @return direction方向 |
* @return direction方向 |
||||||
*/ |
*/ |
||||||
public Direction getDirection() { |
public Direction getDirection() { |
||||||
return driection; |
return driection; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 是否有组件正被选中 |
* 是否有组件正被选中 |
||||||
* |
* |
||||||
* @return true 如果至少一个组件被选中 |
* @return true 如果至少一个组件被选中 |
||||||
*/ |
*/ |
||||||
public boolean isSelecting() { |
public boolean isSelecting() { |
||||||
return selecting; |
return selecting; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 是否能拖拽 |
* 是否能拖拽 |
||||||
* |
* |
||||||
* @return 非outer且选中为空 |
* @return 非outer且选中为空 |
||||||
*/ |
*/ |
||||||
public boolean dragable() { |
public boolean dragable() { |
||||||
return ((driection != Location.outer) && !selecting); |
return ((driection != Location.outer) && !selecting); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 拖拽中是否可以转换为添加模式: |
* 拖拽中是否可以转换为添加模式: |
||||||
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
||||||
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
||||||
*/ |
*/ |
||||||
private void checkAddable(MouseEvent e) { |
private void checkAddable(MouseEvent e) { |
||||||
addable = false; |
addable = false; |
||||||
designer.setPainter(null); |
designer.setPainter(null); |
||||||
|
|
||||||
if (driection != Location.inner) { |
if (driection != Location.inner) { |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
||||||
if (creatorContainer != null && creatorContainer != container |
if (creatorContainer != null && creatorContainer != container |
||||||
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
designer.setPainter(painter); |
designer.setPainter(painter); |
||||||
if (painter != null) { |
if (painter != null) { |
||||||
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
rect.x -= designer.getArea().getHorizontalValue(); |
rect.x -= designer.getArea().getHorizontalValue(); |
||||||
rect.y -= designer.getArea().getVerticalValue(); |
rect.y -= designer.getArea().getVerticalValue(); |
||||||
painter.setRenderingBounds(rect); |
painter.setRenderingBounds(rect); |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
painter.setCreator(creator); |
painter.setCreator(creator); |
||||||
} |
} |
||||||
addable = true; |
addable = true; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* @param container 容器 |
* @param container 容器 |
||||||
* @param mouseX 鼠标释放位置X |
* @param mouseX 鼠标释放位置X |
||||||
* @param mouseY 鼠标释放位置Y |
* @param mouseY 鼠标释放位置Y |
||||||
* @return 是否成功 |
* @return 是否成功 |
||||||
*/ |
*/ |
||||||
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { |
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { |
||||||
LayoutAdapter adapter = container.getLayoutAdapter(); |
LayoutAdapter adapter = container.getLayoutAdapter(); |
||||||
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); |
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); |
||||||
if (selectionModel.getSelection().size() == 1) { |
if (selectionModel.getSelection().size() == 1) { |
||||||
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), |
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), |
||||||
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
} |
} |
||||||
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
||||||
adapter.addBean(creator, |
adapter.addBean(creator, |
||||||
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
} |
} |
||||||
return true; |
return true; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* @param mouseReleasedX 鼠标释放位置X |
* @param mouseReleasedX 鼠标释放位置X |
||||||
* @param mouseReleasedY 鼠标释放位置Y |
* @param mouseReleasedY 鼠标释放位置Y |
||||||
*/ |
*/ |
||||||
private void adding(int mouseReleasedX, int mouseReleasedY) { |
private void adding(int mouseReleasedX, int mouseReleasedY) { |
||||||
// 当前鼠标所在的组件
|
// 当前鼠标所在的组件
|
||||||
XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators()); |
XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators()); |
||||||
|
|
||||||
// 获取该组件所在的焦点容器
|
// 获取该组件所在的焦点容器
|
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
||||||
|
|
||||||
boolean success = false; |
boolean success = false; |
||||||
|
|
||||||
if (container != null) { |
if (container != null) { |
||||||
// 如果是容器,则调用其acceptComponent接受组件
|
// 如果是容器,则调用其acceptComponent接受组件
|
||||||
success = addBean(container, mouseReleasedX, mouseReleasedY); |
success = addBean(container, mouseReleasedX, mouseReleasedY); |
||||||
} |
} |
||||||
|
|
||||||
if (success) { |
if (success) { |
||||||
FormSelectionUtils.rebuildSelection(designer); |
FormSelectionUtils.rebuildSelection(designer); |
||||||
designer.getEditListenerTable().fireCreatorModified( |
designer.getEditListenerTable().fireCreatorModified( |
||||||
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
||||||
} else { |
} else { |
||||||
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); |
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); |
||||||
Toolkit.getDefaultToolkit().beep(); |
Toolkit.getDefaultToolkit().beep(); |
||||||
} |
} |
||||||
// 取消提示
|
// 取消提示
|
||||||
designer.setPainter(null); |
designer.setPainter(null); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 是否拖拽 |
* 是否拖拽 |
||||||
* |
* |
||||||
* @return dragging状态 |
* @return dragging状态 |
||||||
*/ |
*/ |
||||||
public boolean isDragging() { |
public boolean isDragging() { |
||||||
return dragging; |
return dragging; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 是否可以开始画线 |
* 是否可以开始画线 |
||||||
* |
* |
||||||
* @return startPoint不为空返回true |
* @return startPoint不为空返回true |
||||||
*/ |
*/ |
||||||
public boolean prepareForDrawLining() { |
public boolean prepareForDrawLining() { |
||||||
return startPoint != null; |
return startPoint != null; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置开始位置 |
* 设置开始位置 |
||||||
* |
* |
||||||
* @param p point位置 |
* @param p point位置 |
||||||
*/ |
*/ |
||||||
public void setStartPoint(Point p) { |
public void setStartPoint(Point p) { |
||||||
this.startPoint = p; |
this.startPoint = p; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 返回开始位置 |
* 返回开始位置 |
||||||
* |
* |
||||||
* @return 点位置 |
* @return 点位置 |
||||||
*/ |
*/ |
||||||
public Point getStartPoint() { |
public Point getStartPoint() { |
||||||
return startPoint; |
return startPoint; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 返回当前点位置 |
* 返回当前点位置 |
||||||
* |
* |
||||||
* @return 点位置 |
* @return 点位置 |
||||||
*/ |
*/ |
||||||
public Point getEndPoint() { |
public Point getEndPoint() { |
||||||
return currentPoint; |
return currentPoint; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 当前选中组件 |
* 当前选中组件 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void startSelecting(MouseEvent e) { |
public void startSelecting(MouseEvent e) { |
||||||
selecting = true; |
selecting = true; |
||||||
selectionModel.setHotspotBounds(new Rectangle()); |
selectionModel.setHotspotBounds(new Rectangle()); |
||||||
currentX = getMouseXY(e).x; |
currentX = getMouseXY(e).x; |
||||||
currentY = getMouseXY(e).y; |
currentY = getMouseXY(e).y; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 当前鼠标的xy |
* 当前鼠标的xy |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void startResizing(MouseEvent e) { |
public void startResizing(MouseEvent e) { |
||||||
if (!selectionModel.getSelection().isEmpty()) { |
if (!selectionModel.getSelection().isEmpty()) { |
||||||
driection.backupBounds(designer); |
driection.backupBounds(designer); |
||||||
} |
} |
||||||
currentX = getMouseXY(e).x; |
currentX = getMouseXY(e).x; |
||||||
currentY = getMouseXY(e).y; |
currentY = getMouseXY(e).y; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 起始点开始DrawLine |
* 起始点开始DrawLine |
||||||
* |
* |
||||||
* @param p 点位置 |
* @param p 点位置 |
||||||
*/ |
*/ |
||||||
public void startDrawLine(Point p) { |
public void startDrawLine(Point p) { |
||||||
this.startPoint = p; |
this.startPoint = p; |
||||||
if (p != null) { |
if (p != null) { |
||||||
try { |
try { |
||||||
designer.setCursor(XConnector.connectorCursor); |
designer.setCursor(XConnector.connectorCursor); |
||||||
} catch (Exception e) { |
} catch (Exception e) { |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 鼠标释放时所在的区域及圈中的组件 |
* 鼠标释放时所在的区域及圈中的组件 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void selectCreators(MouseEvent e) { |
public void selectCreators(MouseEvent e) { |
||||||
int x = getMouseXY(e).x; |
int x = getMouseXY(e).x; |
||||||
int y = getMouseXY(e).y; |
int y = getMouseXY(e).y; |
||||||
|
|
||||||
Rectangle bounds = createCurrentBounds(x, y); |
Rectangle bounds = createCurrentBounds(x, y); |
||||||
|
|
||||||
if ((x != currentX) || (y != currentY)) { |
if ((x != currentX) || (y != currentY)) { |
||||||
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
||||||
} |
} |
||||||
selectionModel.setHotspotBounds(null); |
selectionModel.setHotspotBounds(null); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 画所在区域线 |
* 画所在区域线 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void drawLine(MouseEvent e) { |
public void drawLine(MouseEvent e) { |
||||||
designer.getDrawLineHelper().setDrawLine(true); |
designer.getDrawLineHelper().setDrawLine(true); |
||||||
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
||||||
if (p != null) { |
if (p != null) { |
||||||
currentPoint = p; |
currentPoint = p; |
||||||
} else { |
} else { |
||||||
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
||||||
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private Rectangle createCurrentBounds(int x, int y) { |
private Rectangle createCurrentBounds(int x, int y) { |
||||||
Rectangle bounds = new Rectangle(); |
Rectangle bounds = new Rectangle(); |
||||||
|
|
||||||
bounds.x = Math.min(x, currentX); |
bounds.x = Math.min(x, currentX); |
||||||
bounds.y = Math.min(y, currentY); |
bounds.y = Math.min(y, currentY); |
||||||
bounds.width = Math.max(x, currentX) - bounds.x; |
bounds.width = Math.max(x, currentX) - bounds.x; |
||||||
bounds.height = Math.max(y, currentY) - bounds.y; |
bounds.height = Math.max(y, currentY) - bounds.y; |
||||||
|
|
||||||
return bounds; |
return bounds; |
||||||
} |
} |
||||||
|
|
||||||
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
||||||
ArrayList<XCreator> creators = new ArrayList<>(); |
ArrayList<XCreator> creators = new ArrayList<>(); |
||||||
|
|
||||||
if (!root.isVisible() && !designer.isRoot(root)) { |
if (!root.isVisible() && !designer.isRoot(root)) { |
||||||
return creators; |
return creators; |
||||||
} |
} |
||||||
|
|
||||||
if (root instanceof XLayoutContainer) { |
if (root instanceof XLayoutContainer) { |
||||||
XLayoutContainer container = (XLayoutContainer) root; |
XLayoutContainer container = (XLayoutContainer) root; |
||||||
int count = container.getXCreatorCount(); |
int count = container.getXCreatorCount(); |
||||||
Rectangle clipped = new Rectangle(selection); |
Rectangle clipped = new Rectangle(selection); |
||||||
|
|
||||||
for (int i = count - 1; i >= 0; i--) { |
for (int i = count - 1; i >= 0; i--) { |
||||||
XCreator child = container.getXCreator(i); |
XCreator child = container.getXCreator(i); |
||||||
|
|
||||||
if (selection.contains(child.getBounds())) { |
if (selection.contains(child.getBounds())) { |
||||||
creators.add(child); |
creators.add(child); |
||||||
} else { |
} else { |
||||||
clipped.x = selection.x - child.getX(); |
clipped.x = selection.x - child.getX(); |
||||||
clipped.y = selection.y - child.getY(); |
clipped.y = selection.y - child.getY(); |
||||||
creators.addAll(getHotspotCreators(clipped, child)); |
creators.addAll(getHotspotCreators(clipped, child)); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return creators; |
return creators; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* 重置model |
* 重置model |
||||||
*/ |
*/ |
||||||
public void resetModel() { |
public void resetModel() { |
||||||
dragging = false; |
dragging = false; |
||||||
selecting = false; |
selecting = false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 重置 |
* 重置 |
||||||
*/ |
*/ |
||||||
public void reset() { |
public void reset() { |
||||||
driection = Location.outer; |
driection = Location.outer; |
||||||
dragging = false; |
dragging = false; |
||||||
selecting = false; |
selecting = false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 取消拖拽 |
* 取消拖拽 |
||||||
*/ |
*/ |
||||||
public void draggingCancel() { |
public void draggingCancel() { |
||||||
designer.repaint(); |
designer.repaint(); |
||||||
reset(); |
reset(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置可拉伸方向 |
* 设置可拉伸方向 |
||||||
* |
* |
||||||
* @param dir 拉伸方向 |
* @param dir 拉伸方向 |
||||||
*/ |
*/ |
||||||
public void setDirection(Direction dir) { |
public void setDirection(Direction dir) { |
||||||
if (driection != dir) { |
if (driection != dir) { |
||||||
this.driection = dir; |
this.driection = dir; |
||||||
driection.updateCursor(designer); |
driection.updateCursor(designer); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* x吸附线赋值 |
* x吸附线赋值 |
||||||
* |
* |
||||||
* @param line 线 |
* @param line 线 |
||||||
*/ |
*/ |
||||||
public void setXAbsorptionline(Absorptionline line) { |
public void setXAbsorptionline(Absorptionline line) { |
||||||
this.lineInX = line; |
this.lineInX = line; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* y吸附线赋值 |
* y吸附线赋值 |
||||||
* |
* |
||||||
* @param line 线 |
* @param line 线 |
||||||
*/ |
*/ |
||||||
public void setYAbsorptionline(Absorptionline line) { |
public void setYAbsorptionline(Absorptionline line) { |
||||||
this.lineInY = line; |
this.lineInY = line; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 等距线赋值 |
* 等距线赋值 |
||||||
* |
* |
||||||
* @param line 线 |
* @param line 线 |
||||||
*/ |
*/ |
||||||
public void setEquidistantLine(Absorptionline line) { |
public void setEquidistantLine(Absorptionline line) { |
||||||
this.lineEquidistant = line; |
this.lineEquidistant = line; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 画吸附线 |
* 画吸附线 |
||||||
* |
* |
||||||
* @param g Graphics类 |
* @param g Graphics类 |
||||||
*/ |
*/ |
||||||
public void paintAbsorptionline(Graphics g) { |
public void paintAbsorptionline(Graphics g) { |
||||||
if (lineInX != null) { |
if (lineInX != null) { |
||||||
lineInX.paint(g, designer.getArea()); |
lineInX.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
if (lineInY != null) { |
if (lineInY != null) { |
||||||
lineInY.paint(g, designer.getArea()); |
lineInY.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
if (lineEquidistant != null) { |
if (lineEquidistant != null) { |
||||||
lineEquidistant.paint(g, designer.getArea()); |
lineEquidistant.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 拖拽 |
* 拖拽 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void dragging(MouseEvent e) { |
public void dragging(MouseEvent e) { |
||||||
//进入dragging状态时备份组件大小和位置
|
//进入dragging状态时备份组件大小和位置
|
||||||
if (!dragging) { |
if (!dragging) { |
||||||
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); |
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); |
||||||
} |
} |
||||||
checkAddable(e); |
checkAddable(e); |
||||||
setDependLinePainter(e); |
setDependLinePainter(e); |
||||||
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); |
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); |
||||||
this.dragging = true; |
this.dragging = true; |
||||||
} |
} |
||||||
|
|
||||||
// 拖拽时画依附线用到的painter
|
// 拖拽时画依附线用到的painter
|
||||||
private void setDependLinePainter(MouseEvent e) { |
private void setDependLinePainter(MouseEvent e) { |
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
designer.setPainter(painter); |
designer.setPainter(painter); |
||||||
if (painter != null) { |
if (painter != null) { |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
painter.setCreator(creator); |
painter.setCreator(creator); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 释放捕获 |
* 释放捕获 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void releaseDragging(MouseEvent e) { |
public void releaseDragging(MouseEvent e) { |
||||||
this.dragging = false; |
this.dragging = false; |
||||||
if (addable) { |
if (addable) { |
||||||
adding(e.getX(), e.getY()); |
adding(e.getX(), e.getY()); |
||||||
} else if (!selectionModel.getSelection().isEmpty()) { |
} else if (!selectionModel.getSelection().isEmpty()) { |
||||||
selectionModel.releaseDragging(); |
selectionModel.releaseDragging(); |
||||||
} |
} |
||||||
designer.repaint(); |
designer.repaint(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 改变选择区域 |
* 改变选择区域 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void changeSelection(MouseEvent e) { |
public void changeSelection(MouseEvent e) { |
||||||
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
||||||
selectionModel.setHotspotBounds(bounds); |
selectionModel.setHotspotBounds(bounds); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 返回鼠标所在的x、y 考虑滚动条的值 |
* 返回鼠标所在的x、y 考虑滚动条的值 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
* @return xy值 |
* @return xy值 |
||||||
*/ |
*/ |
||||||
public Point getMouseXY(MouseEvent e) { |
public Point getMouseXY(MouseEvent e) { |
||||||
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
||||||
+ designer.getArea().getVerticalValue()); |
+ designer.getArea().getVerticalValue()); |
||||||
return p1; |
return p1; |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
@ -1,96 +1,96 @@ |
|||||||
package com.fr.design.designer.beans.painters; |
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
import java.awt.Color; |
import java.awt.Color; |
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
import java.awt.Graphics2D; |
import java.awt.Graphics2D; |
||||||
import java.awt.Point; |
import java.awt.Point; |
||||||
import java.awt.Rectangle; |
import java.awt.Rectangle; |
||||||
import java.awt.Stroke; |
import java.awt.Stroke; |
||||||
|
|
||||||
import com.fr.design.designer.beans.HoverPainter; |
import com.fr.design.designer.beans.HoverPainter; |
||||||
import com.fr.design.designer.creator.XCreator; |
import com.fr.design.designer.creator.XCreator; |
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
import com.fr.design.form.util.XCreatorConstants; |
import com.fr.design.form.util.XCreatorConstants; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
|
|
||||||
public abstract class AbstractPainter implements HoverPainter { |
public abstract class AbstractPainter implements HoverPainter { |
||||||
|
|
||||||
protected Point hotspot; |
protected Point hotspot; |
||||||
protected Rectangle hotspot_bounds; |
protected Rectangle hotspot_bounds; |
||||||
protected XLayoutContainer container; |
protected XLayoutContainer container; |
||||||
protected XCreator creator; |
protected XCreator creator; |
||||||
|
|
||||||
/** |
/** |
||||||
* 构造函数 |
* 构造函数 |
||||||
* |
* |
||||||
* @param container 容器 |
* @param container 容器 |
||||||
*/ |
*/ |
||||||
public AbstractPainter(XLayoutContainer container) { |
public AbstractPainter(XLayoutContainer container) { |
||||||
this.container = container; |
this.container = container; |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void setHotspot(Point p) { |
public void setHotspot(Point p) { |
||||||
hotspot = p; |
hotspot = p; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 画初始区域 |
* 画初始区域 |
||||||
* |
* |
||||||
* @param g 画图类 |
* @param g 画图类 |
||||||
* @param startX 起始x位置 |
* @param startX 起始x位置 |
||||||
* @param startY 起始y位置 |
* @param startY 起始y位置 |
||||||
*/ |
*/ |
||||||
public void paint(Graphics g, int startX, int startY) { |
public void paint(Graphics g, int startX, int startY) { |
||||||
if (hotspot_bounds != null) { |
if (hotspot_bounds != null) { |
||||||
drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false); |
drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 设置边界 |
* 设置边界 |
||||||
* |
* |
||||||
* @param rect 位置 |
* @param rect 位置 |
||||||
*/ |
*/ |
||||||
@Override |
@Override |
||||||
public void setRenderingBounds(Rectangle rect) { |
public void setRenderingBounds(Rectangle rect) { |
||||||
hotspot_bounds = rect; |
hotspot_bounds = rect; |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void setCreator(XCreator component) { |
public void setCreator(XCreator component) { |
||||||
this.creator = component; |
this.creator = component; |
||||||
} |
} |
||||||
|
|
||||||
protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { |
protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { |
||||||
Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; |
Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; |
||||||
drawHotspot(g, x, y, width, height, bColor, accept, false); |
drawHotspot(g, x, y, width, height, bColor, accept, false); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 自适应布局那边渲染提示,要画整个背景,不是画边框 |
* 自适应布局那边渲染提示,要画整个背景,不是画边框 |
||||||
*/ |
*/ |
||||||
protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) { |
protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) { |
||||||
drawHotspot(g, x, y, width, height, bColor, accept, true); |
drawHotspot(g, x, y, width, height, bColor, accept, true); |
||||||
} |
} |
||||||
|
|
||||||
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { |
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { |
||||||
Graphics2D g2d = (Graphics2D) g; |
Graphics2D g2d = (Graphics2D) g; |
||||||
Color color = g2d.getColor(); |
Color color = g2d.getColor(); |
||||||
Stroke backup = g2d.getStroke(); |
Stroke backup = g2d.getStroke(); |
||||||
// 设置线条的样式
|
// 设置线条的样式
|
||||||
g2d.setStroke(XCreatorConstants.STROKE); |
g2d.setStroke(XCreatorConstants.STROKE); |
||||||
g2d.setColor(bColor); |
g2d.setColor(bColor); |
||||||
if (!accept) { |
if (!accept) { |
||||||
g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2); |
g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2); |
||||||
} else if (drawBackground) { |
} else if (drawBackground) { |
||||||
g2d.fillRect(x, y, width, height); |
g2d.fillRect(x, y, width, height); |
||||||
} else { |
} else { |
||||||
g2d.drawRect(x, y, width, height); |
g2d.drawRect(x, y, width, height); |
||||||
} |
} |
||||||
g2d.setStroke(backup); |
g2d.setStroke(backup); |
||||||
g2d.setColor(color); |
g2d.setColor(color); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
} |
} |