@ -1,171 +1,176 @@
|
||||
package com.fr.design.actions.server; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.Env; |
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.ModifiedTable; |
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.dav.LocalEnv; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.data.datapane.connect.ConnectionManagerPane; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrame; |
||||
import com.fr.design.menu.MenuKeySet; |
||||
import com.fr.file.DatasourceManager; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.util.HashMap; |
||||
|
||||
/** |
||||
* DatasourceList Action |
||||
*/ |
||||
public class ConnectionListAction extends UpdateAction { |
||||
private static final int BYTENUM = 1444; |
||||
|
||||
public ConnectionListAction() { |
||||
this.setMenuKeySet(DEFINE_DATA_CONNECTION); |
||||
this.setName(getMenuKeySet().getMenuKeySetName()); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/connection.png")); |
||||
} |
||||
|
||||
public static final MenuKeySet DEFINE_DATA_CONNECTION = new MenuKeySet() { |
||||
@Override |
||||
public char getMnemonic() { |
||||
return 'D'; |
||||
} |
||||
|
||||
@Override |
||||
public String getMenuName() { |
||||
return Inter.getLocText("Server-Define_Data_Connection"); |
||||
} |
||||
|
||||
@Override |
||||
public KeyStroke getKeyStroke() { |
||||
return null; |
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* 执行动作 |
||||
* |
||||
* @param evt 事件 |
||||
*/ |
||||
public void actionPerformed(ActionEvent evt) { |
||||
DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); |
||||
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
||||
final DatasourceManager backupManager = datasourceManager.getBackUpManager(); |
||||
final ConnectionManagerPane databaseManagerPane = new ConnectionManagerPane() { |
||||
public void complete() { |
||||
populate(datasourceManager); |
||||
} |
||||
|
||||
protected void renameConnection(String oldName, String newName) { |
||||
datasourceManager.getConnectionLocalModifyTable().rename(oldName, newName); |
||||
} |
||||
}; |
||||
final BasicDialog databaseListDialog = databaseManagerPane.showLargeWindow(designerFrame, null); |
||||
databaseListDialog.addDialogActionListener(new DialogActionAdapter() { |
||||
public void doOk() { |
||||
if (!databaseManagerPane.isNamePermitted()) { |
||||
databaseListDialog.setDoOKSucceed(false); |
||||
return; |
||||
} |
||||
if (!doWithDatasourceManager(datasourceManager, backupManager, databaseManagerPane, databaseListDialog)) { |
||||
//如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面
|
||||
return; |
||||
} |
||||
// marks:保存数据
|
||||
writeFile(datasourceManager); |
||||
} |
||||
|
||||
public void doCancel() { |
||||
datasourceManager.synchronizedWithServer(); |
||||
} |
||||
}); |
||||
databaseListDialog.setVisible(true); |
||||
} |
||||
|
||||
|
||||
private void writeFile(DatasourceManagerProvider datasourceManager) { |
||||
Env currentEnv = FRContext.getCurrentEnv(); |
||||
try { |
||||
boolean isSuccess = currentEnv.writeResource(datasourceManager); |
||||
if (!isSuccess) { |
||||
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
||||
} |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
||||
} |
||||
DesignerContext.getDesignerBean("databasename").refreshBeanElement(); |
||||
} |
||||
|
||||
/** |
||||
* 是否正常更新完datasourceManager |
||||
* |
||||
* @param datasourceManager |
||||
* @param databaseManagerPane |
||||
* @return |
||||
*/ |
||||
private boolean doWithDatasourceManager(DatasourceManagerProvider datasourceManager, DatasourceManager backupManager, |
||||
ConnectionManagerPane databaseManagerPane, BasicDialog databaseListDialog) { |
||||
databaseManagerPane.update(datasourceManager); |
||||
HashMap<String, Connection> modifyDetails = datasourceManager.getConnectionModifyDetails(); |
||||
modifyDetails.clear(); |
||||
Env currentEnv = FRContext.getCurrentEnv(); |
||||
ModifiedTable localModifiedTable = datasourceManager.checkConnectionModifyTable(backupManager, currentEnv.getUserID()); |
||||
boolean isFailed = false; |
||||
if (currentEnv.isSupportLocalFileOperate() && !((LocalEnv) currentEnv).isNoRemoteUser()) { |
||||
//如果是本地,并且有远程用户时则更新自己的修改表
|
||||
datasourceManager.updateSelfConnectionTotalModifiedTable(localModifiedTable, ModifiedTable.LOCAL_MODIFIER); |
||||
} else { |
||||
if (!currentEnv.isSupportLocalFileOperate()) { |
||||
//如果是远程,则去取服务器的最新的修改表,检查有没有冲突
|
||||
ModifiedTable currentServerModifyTable = currentEnv.getDataSourceModifiedTables(DatasourceManager.CONNECTION); |
||||
if (localModifiedTable.checkModifiedTableConflictWithServer(currentServerModifyTable, currentEnv.getUserID())) { |
||||
//有冲突,进行提示
|
||||
String title = Inter.getLocText(new String[]{"Select", "Single", "Setting"}); |
||||
int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), localModifiedTable.getWaringMessage(), title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||
if (returnVal == JOptionPane.YES_OPTION) { |
||||
//点击是,进行相应刷新去冲突
|
||||
datasourceManager.synchronizedWithServer(backupManager, DatasourceManager.CONNECTION); |
||||
//要是有重命名冲突的,则对详细的修改表先进行修改
|
||||
datasourceManager.doWithConnectionConflict(localModifiedTable); |
||||
localModifiedTable.removeConfilct(); |
||||
modifyDetails.clear(); |
||||
//更新面板
|
||||
databaseManagerPane.populate(datasourceManager); |
||||
} else { |
||||
//更新失败,继续停留页面
|
||||
isFailed = true; |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
//存在请重命名则不能更新
|
||||
int index = datasourceManager.isConnectionMapContainsRename(); |
||||
if (index != -1) { |
||||
isFailed = true; |
||||
databaseManagerPane.setSelectedIndex(index); |
||||
} |
||||
databaseListDialog.setDoOKSucceed(!isFailed); |
||||
//如果修改成功,则去远程端增量修改修改表
|
||||
if (!isFailed && !currentEnv.isSupportLocalFileOperate()) { |
||||
currentEnv.writeDataSourceModifiedTables(localModifiedTable, DatasourceManager.CONNECTION); |
||||
localModifiedTable.clear(); |
||||
modifyDetails.clear(); |
||||
} |
||||
return !isFailed; |
||||
} |
||||
|
||||
|
||||
public void update() { |
||||
this.setEnabled(true); |
||||
} |
||||
package com.fr.design.actions.server; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.Env; |
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.ModifiedTable; |
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.dav.LocalEnv; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.data.datapane.connect.ConnectionManagerPane; |
||||
import com.fr.design.data.datapane.connect.ConnectionShowPane; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrame; |
||||
import com.fr.design.menu.MenuKeySet; |
||||
import com.fr.file.DatasourceManager; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.util.HashMap; |
||||
|
||||
/** |
||||
* DatasourceList Action |
||||
*/ |
||||
public class ConnectionListAction extends UpdateAction { |
||||
|
||||
public ConnectionListAction() { |
||||
this.setMenuKeySet(DEFINE_DATA_CONNECTION); |
||||
this.setName(getMenuKeySet().getMenuKeySetName()); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/connection.png")); |
||||
} |
||||
|
||||
public static final MenuKeySet DEFINE_DATA_CONNECTION = new MenuKeySet() { |
||||
@Override |
||||
public char getMnemonic() { |
||||
return 'D'; |
||||
} |
||||
|
||||
@Override |
||||
public String getMenuName() { |
||||
return Inter.getLocText("Server-Define_Data_Connection"); |
||||
} |
||||
|
||||
@Override |
||||
public KeyStroke getKeyStroke() { |
||||
return null; |
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* 执行动作 |
||||
* |
||||
* @param evt 事件 |
||||
*/ |
||||
public void actionPerformed(ActionEvent evt) { |
||||
DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); |
||||
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
||||
final DatasourceManager backupManager = datasourceManager.getBackUpManager(); |
||||
final ConnectionManagerPane databaseManagerPane = new ConnectionManagerPane() { |
||||
public void complete() { |
||||
populate(datasourceManager); |
||||
} |
||||
|
||||
protected void renameConnection(String oldName, String newName) { |
||||
datasourceManager.getConnectionLocalModifyTable().rename(oldName, newName); |
||||
} |
||||
}; |
||||
final BasicDialog databaseListDialog = databaseManagerPane.showLargeWindow(designerFrame, null); |
||||
databaseListDialog.addDialogActionListener(new DialogActionAdapter() { |
||||
public void doOk() { |
||||
if (!databaseManagerPane.isNamePermitted()) { |
||||
databaseListDialog.setDoOKSucceed(false); |
||||
return; |
||||
} |
||||
if (!doWithDatasourceManager(datasourceManager, backupManager, databaseManagerPane, databaseListDialog)) { |
||||
//如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面
|
||||
return; |
||||
} |
||||
// marks:保存数据
|
||||
writeFile(datasourceManager); |
||||
} |
||||
|
||||
public void doCancel() { |
||||
datasourceManager.synchronizedWithServer(); |
||||
} |
||||
}); |
||||
databaseListDialog.setVisible(true); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @param datasourceManager |
||||
*/ |
||||
public static void writeFile(DatasourceManagerProvider datasourceManager) { |
||||
Env currentEnv = FRContext.getCurrentEnv(); |
||||
try { |
||||
boolean isSuccess = currentEnv.writeResource(datasourceManager); |
||||
if (!isSuccess) { |
||||
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
||||
} |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); |
||||
} |
||||
DesignerContext.getDesignerBean("databasename").refreshBeanElement(); |
||||
} |
||||
|
||||
/** |
||||
* 更新datasourceManager |
||||
* |
||||
* @param datasourceManager datasource管理对象 |
||||
* @param backupManager datasource管理对象备份 |
||||
* @param connectionShowPane datasource面板 |
||||
* @param databaseListDialog datasource管理对话框 |
||||
* @return boolean 是否更新成功 |
||||
*/ |
||||
public static boolean doWithDatasourceManager(DatasourceManagerProvider datasourceManager, DatasourceManager |
||||
backupManager, ConnectionShowPane connectionShowPane, BasicDialog databaseListDialog) { |
||||
connectionShowPane.update(datasourceManager); |
||||
HashMap<String, Connection> modifyDetails = datasourceManager.getConnectionModifyDetails(); |
||||
modifyDetails.clear(); |
||||
Env currentEnv = FRContext.getCurrentEnv(); |
||||
ModifiedTable localModifiedTable = datasourceManager.checkConnectionModifyTable(backupManager, currentEnv.getUserID()); |
||||
boolean isFailed = false; |
||||
if (currentEnv.isSupportLocalFileOperate() && !((LocalEnv) currentEnv).isNoRemoteUser()) { |
||||
//如果是本地,并且有远程用户时则更新自己的修改表
|
||||
datasourceManager.updateSelfConnectionTotalModifiedTable(localModifiedTable, ModifiedTable.LOCAL_MODIFIER); |
||||
} else { |
||||
if (!currentEnv.isSupportLocalFileOperate()) { |
||||
//如果是远程,则去取服务器的最新的修改表,检查有没有冲突
|
||||
ModifiedTable currentServerModifyTable = currentEnv.getDataSourceModifiedTables(DatasourceManager.CONNECTION); |
||||
if (localModifiedTable.checkModifiedTableConflictWithServer(currentServerModifyTable, currentEnv.getUserID())) { |
||||
//有冲突,进行提示
|
||||
String title = Inter.getLocText(new String[]{"Select", "Single", "Setting"}); |
||||
int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), localModifiedTable.getWaringMessage(), title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||
if (returnVal == JOptionPane.YES_OPTION) { |
||||
//点击是,进行相应刷新去冲突
|
||||
datasourceManager.synchronizedWithServer(backupManager, DatasourceManager.CONNECTION); |
||||
//要是有重命名冲突的,则对详细的修改表先进行修改
|
||||
datasourceManager.doWithConnectionConflict(localModifiedTable); |
||||
localModifiedTable.removeConfilct(); |
||||
modifyDetails.clear(); |
||||
//更新面板
|
||||
connectionShowPane.populate(datasourceManager); |
||||
} else { |
||||
//更新失败,继续停留页面
|
||||
isFailed = true; |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
//存在请重命名则不能更新
|
||||
int index = datasourceManager.isConnectionMapContainsRename(); |
||||
if (index != -1) { |
||||
isFailed = true; |
||||
connectionShowPane.setSelectedIndex(index); |
||||
} |
||||
databaseListDialog.setDoOKSucceed(!isFailed); |
||||
//如果修改成功,则去远程端增量修改修改表
|
||||
if (!isFailed && !currentEnv.isSupportLocalFileOperate()) { |
||||
currentEnv.writeDataSourceModifiedTables(localModifiedTable, DatasourceManager.CONNECTION); |
||||
localModifiedTable.clear(); |
||||
modifyDetails.clear(); |
||||
} |
||||
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; |
||||
|
||||
import com.fr.base.Env; |
||||
import com.fr.base.FRContext; |
||||
import com.fr.data.impl.AbstractDatabaseConnection; |
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.data.impl.NameDatabaseConnection; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.file.DatasourceManager; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 选择数据连接的下拉框 |
||||
* |
||||
* @editor zhou |
||||
* @since 2012-3-28下午3:02:30 |
||||
*/ |
||||
public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
||||
/** |
||||
* |
||||
*/ |
||||
private static final long serialVersionUID = 1L; |
||||
private Class<? extends Connection> cls; // 所取的Connection都是cls及其子类
|
||||
private java.util.List<String> nameList = new ArrayList<String>(); |
||||
|
||||
public ConnectionComboBoxPanel(Class<? extends Connection> cls) { |
||||
super(); |
||||
|
||||
this.cls = cls; |
||||
|
||||
// alex:添加item change监听,当改变时改变DesignerEnvManager中的最近选中的数据连接
|
||||
this.itemComboBox.addItemListener(new ItemListener() { |
||||
public void itemStateChanged(ItemEvent e) { |
||||
String selected = ConnectionComboBoxPanel.this.getSelectedItem(); |
||||
if (StringUtils.isNotBlank(selected)) { |
||||
DesignerEnvManager.getEnvManager().setRecentSelectedConnection(selected); |
||||
} |
||||
} |
||||
}); |
||||
refreshItems(); |
||||
} |
||||
|
||||
/* |
||||
* 刷新ComboBox.items |
||||
*/ |
||||
protected java.util.Iterator<String> items() { |
||||
nameList = new ArrayList<String>(); |
||||
|
||||
DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); |
||||
java.util.Iterator<String> nameIt = mgr.getConnectionNameIterator(); |
||||
while (nameIt.hasNext()) { |
||||
String conName = nameIt.next(); |
||||
Connection connection = mgr.getConnection(conName); |
||||
filterConnection(connection, conName, nameList); |
||||
} |
||||
|
||||
return nameList.iterator(); |
||||
} |
||||
|
||||
protected void filterConnection(Connection connection, String conName, List<String> nameList) { |
||||
connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); |
||||
} |
||||
|
||||
|
||||
public int getConnectionSize() { |
||||
return nameList.size(); |
||||
} |
||||
|
||||
public String getConnection(int i) { |
||||
return nameList.get(i); |
||||
} |
||||
|
||||
/* |
||||
* 弹出对话框编辑Items |
||||
*/ |
||||
protected void editItems() { |
||||
final ConnectionListPane connectionListPane = new ConnectionListPane(); |
||||
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
||||
connectionListPane.populate(datasourceManager); |
||||
BasicDialog connectionListDialog = connectionListPane.showLargeWindow( |
||||
SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), new DialogActionAdapter() { |
||||
public void doOk() { |
||||
connectionListPane.update(datasourceManager); |
||||
// marks:保存数据
|
||||
Env currentEnv = FRContext.getCurrentEnv(); |
||||
try { |
||||
currentEnv.writeResource(datasourceManager); |
||||
} catch (Exception ex) { |
||||
FRContext.getLogger().error(ex.getMessage(), ex); |
||||
} |
||||
} |
||||
}); |
||||
connectionListDialog.setVisible(true); |
||||
refreshItems(); |
||||
} |
||||
|
||||
public void populate(com.fr.data.impl.Connection connection) { |
||||
editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); |
||||
if (connection instanceof NameDatabaseConnection) { |
||||
this.setSelectedItem(((NameDatabaseConnection) connection).getName()); |
||||
} else { |
||||
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)); |
||||
} |
||||
} |
||||
} |
||||
package com.fr.design.data.datapane.connect; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.data.impl.AbstractDatabaseConnection; |
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.data.impl.NameDatabaseConnection; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.actions.server.ConnectionListAction; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.file.DatasourceManager; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.util.ArrayList; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 选择数据连接的下拉框 |
||||
* |
||||
* @editor zhou |
||||
* @since 2012-3-28下午3:02:30 |
||||
*/ |
||||
public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
||||
/** |
||||
* |
||||
*/ |
||||
private static final long serialVersionUID = 1L; |
||||
private Class<? extends Connection> cls; // 所取的Connection都是cls及其子类
|
||||
private List<String> nameList = new ArrayList<String>(); |
||||
|
||||
public ConnectionComboBoxPanel(Class<? extends Connection> cls) { |
||||
super(); |
||||
|
||||
this.cls = cls; |
||||
|
||||
// alex:添加item change监听,当改变时改变DesignerEnvManager中的最近选中的数据连接
|
||||
this.itemComboBox.addItemListener(new ItemListener() { |
||||
public void itemStateChanged(ItemEvent e) { |
||||
String selected = ConnectionComboBoxPanel.this.getSelectedItem(); |
||||
if (StringUtils.isNotBlank(selected)) { |
||||
DesignerEnvManager.getEnvManager().setRecentSelectedConnection(selected); |
||||
} |
||||
} |
||||
}); |
||||
refreshItems(); |
||||
} |
||||
|
||||
/* |
||||
* 刷新ComboBox.items |
||||
*/ |
||||
protected Iterator<String> items() { |
||||
nameList = new ArrayList<String>(); |
||||
|
||||
DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); |
||||
Iterator<String> nameIt = mgr.getConnectionNameIterator(); |
||||
while (nameIt.hasNext()) { |
||||
String conName = nameIt.next(); |
||||
Connection connection = mgr.getConnection(conName); |
||||
filterConnection(connection, conName, nameList); |
||||
} |
||||
|
||||
return nameList.iterator(); |
||||
} |
||||
|
||||
protected void filterConnection(Connection connection, String conName, List<String> nameList) { |
||||
connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); |
||||
} |
||||
|
||||
public int getConnectionSize() { |
||||
return nameList.size(); |
||||
} |
||||
|
||||
public String getConnection(int i) { |
||||
return nameList.get(i); |
||||
} |
||||
|
||||
/* |
||||
* 弹出对话框编辑Items |
||||
*/ |
||||
protected void editItems() { |
||||
final ConnectionListPane connectionListPane = new ConnectionListPane(); |
||||
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
||||
final DatasourceManager backupManager = datasourceManager.getBackUpManager(); |
||||
connectionListPane.populate(datasourceManager); |
||||
final BasicDialog connectionListDialog = connectionListPane.showLargeWindow( |
||||
SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), null); |
||||
connectionListDialog.addDialogActionListener(new DialogActionAdapter() { |
||||
public void doOk() { |
||||
if (!connectionListPane.isNamePermitted()) { |
||||
connectionListDialog.setDoOKSucceed(false); |
||||
return; |
||||
} |
||||
if (!ConnectionListAction.doWithDatasourceManager(datasourceManager, backupManager, connectionListPane, |
||||
connectionListDialog)) { |
||||
//如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面
|
||||
return; |
||||
} |
||||
// marks:保存数据
|
||||
ConnectionListAction.writeFile(datasourceManager); |
||||
} |
||||
|
||||
public void doCancel() { |
||||
datasourceManager.synchronizedWithServer(); |
||||
} |
||||
}); |
||||
connectionListDialog.setVisible(true); |
||||
refreshItems(); |
||||
} |
||||
|
||||
/** |
||||
* @param connection 数据库链接 |
||||
*/ |
||||
public void populate(Connection connection) { |
||||
editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); |
||||
if (connection instanceof NameDatabaseConnection) { |
||||
this.setSelectedItem(((NameDatabaseConnection) connection).getName()); |
||||
} else { |
||||
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; |
||||
|
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.data.impl.JDBCDatabaseConnection; |
||||
import com.fr.data.impl.JNDIDatabaseConnection; |
||||
import com.fr.design.ExtraDesignClassManager; |
||||
import com.fr.design.fun.ConnectionProvider; |
||||
import com.fr.design.gui.controlpane.JListControlPane; |
||||
import com.fr.design.gui.controlpane.NameObjectCreator; |
||||
import com.fr.design.gui.controlpane.NameableCreator; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.NameObject; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.Nameable; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.core.PropertyChangeAdapter; |
||||
|
||||
import javax.swing.*; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* Connection List Pane. |
||||
*/ |
||||
public class ConnectionListPane extends JListControlPane { |
||||
public static final String TITLE_NAME = Inter.getLocText("Server-Define_Data_Connection"); |
||||
private boolean isNamePermitted = true; |
||||
private HashMap<String, String> renameMap = new HashMap<String, String>(); |
||||
|
||||
public ConnectionListPane() { |
||||
renameMap.clear(); |
||||
this.addEditingListner(new PropertyChangeAdapter() { |
||||
public void propertyChange() { |
||||
isNamePermitted = true; |
||||
String[] allListNames = nameableList.getAllNames(); |
||||
allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; |
||||
String tempName = getEditingName(); |
||||
if (StringUtils.isEmpty(tempName)) { |
||||
String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; |
||||
String[] sign = new String[]{",", "!"}; |
||||
nameableList.stopEditing(); |
||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), Inter.getLocText(warning, sign)); |
||||
setWarnigText(editingIndex); |
||||
isNamePermitted = false; |
||||
return; |
||||
} |
||||
if (!ComparatorUtils.equals(tempName, selectedName) |
||||
&& isNameRepeted(new List[]{Arrays.asList(allListNames)}, tempName)) { |
||||
isNamePermitted = false; |
||||
nameableList.stopEditing(); |
||||
String message = Inter.getLocText(new String[]{"Utils-has_been_existed", "DashBoard-ConnectionList", "Please_Rename"}, new String[]{"", tempName + ",", "!"}); |
||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), message); |
||||
setWarnigText(editingIndex); |
||||
} |
||||
if (isNamePermitted && !ComparatorUtils.equals(tempName, selectedName)) { |
||||
rename(selectedName, tempName); |
||||
} |
||||
|
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
protected void rename(String oldName, String newName) { |
||||
if (renameMap.containsKey(selectedName)) { |
||||
renameMap.remove(selectedName); |
||||
} |
||||
renameMap.put(selectedName, newName); |
||||
} |
||||
|
||||
/** |
||||
* 名字是否允许 |
||||
* |
||||
* @return 是/否 |
||||
*/ |
||||
public boolean isNamePermitted() { |
||||
return isNamePermitted; |
||||
} |
||||
|
||||
/** |
||||
* 检查按钮可用状态 Check button enabled. |
||||
*/ |
||||
public void checkButtonEnabled() { |
||||
super.checkButtonEnabled(); |
||||
isNamePermitted = !isContainsRename(); |
||||
} |
||||
|
||||
|
||||
public HashMap<String, String> getRenameMap() { |
||||
return renameMap; |
||||
} |
||||
|
||||
/** |
||||
* 创建菜单项 |
||||
* |
||||
* @return 菜单项 |
||||
*/ |
||||
public NameableCreator[] createNameableCreators() { |
||||
NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( |
||||
"JDBC", |
||||
"/com/fr/design/images/data/source/jdbcTableData.png", |
||||
JDBCDatabaseConnection.class, |
||||
DatabaseConnectionPane.JDBC.class |
||||
), new NameObjectCreator( |
||||
"JNDI", |
||||
"/com/fr/design/images/data/source/jdbcTableData.png", |
||||
JNDIDatabaseConnection.class, |
||||
DatabaseConnectionPane.JNDI.class |
||||
)}; |
||||
Set<ConnectionProvider> pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); |
||||
for (ConnectionProvider provider : pluginCreators) { |
||||
NameObjectCreator creator = new NameObjectCreator( |
||||
provider.nameForConnection(), |
||||
provider.iconPathForConnection(), |
||||
provider.classForConnection(), |
||||
provider.appearanceForConnection() |
||||
); |
||||
creators = ArrayUtils.add(creators, creator); |
||||
} |
||||
|
||||
return creators; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return TITLE_NAME; |
||||
} |
||||
|
||||
/** |
||||
* Populate. |
||||
* |
||||
* @param datasourceManager the new datasourceManager. |
||||
*/ |
||||
public void populate(DatasourceManagerProvider datasourceManager) { |
||||
Iterator<String> nameIt = datasourceManager.getConnectionNameIterator(); |
||||
|
||||
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
||||
while (nameIt.hasNext()) { |
||||
String name = nameIt.next(); |
||||
nameObjectList.add(new NameObject(name, datasourceManager.getConnection(name))); |
||||
} |
||||
this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Update. |
||||
*/ |
||||
public void update(DatasourceManagerProvider datasourceManager) { |
||||
// Nameable[]居然不能强转成NameObject[],一定要这么写...
|
||||
Nameable[] res = this.update(); |
||||
NameObject[] res_array = new NameObject[res.length]; |
||||
java.util.Arrays.asList(res).toArray(res_array); |
||||
|
||||
datasourceManager.clearAllConnection(); |
||||
|
||||
for (int i = 0; i < res_array.length; i++) { |
||||
NameObject nameObject = res_array[i]; |
||||
datasourceManager.putConnection(nameObject.getName(), (Connection) nameObject.getObject()); |
||||
} |
||||
} |
||||
package com.fr.design.data.datapane.connect; |
||||
|
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.data.impl.JDBCDatabaseConnection; |
||||
import com.fr.data.impl.JNDIDatabaseConnection; |
||||
import com.fr.design.ExtraDesignClassManager; |
||||
import com.fr.design.fun.ConnectionProvider; |
||||
import com.fr.design.gui.controlpane.JListControlPane; |
||||
import com.fr.design.gui.controlpane.NameObjectCreator; |
||||
import com.fr.design.gui.controlpane.NameableCreator; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.NameObject; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.Nameable; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.core.PropertyChangeAdapter; |
||||
|
||||
import javax.swing.*; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* Connection List Pane. |
||||
*/ |
||||
public class ConnectionListPane extends JListControlPane implements ConnectionShowPane { |
||||
public static final String TITLE_NAME = Inter.getLocText("Server-Define_Data_Connection"); |
||||
private boolean isNamePermitted = true; |
||||
private HashMap<String, String> renameMap = new HashMap<String, String>(); |
||||
|
||||
public ConnectionListPane() { |
||||
renameMap.clear(); |
||||
this.addEditingListner(new PropertyChangeAdapter() { |
||||
public void propertyChange() { |
||||
isNamePermitted = true; |
||||
String[] allListNames = nameableList.getAllNames(); |
||||
allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; |
||||
String tempName = getEditingName(); |
||||
if (StringUtils.isEmpty(tempName)) { |
||||
String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; |
||||
String[] sign = new String[]{",", "!"}; |
||||
nameableList.stopEditing(); |
||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), Inter.getLocText(warning, sign)); |
||||
setWarnigText(editingIndex); |
||||
isNamePermitted = false; |
||||
return; |
||||
} |
||||
if (!ComparatorUtils.equals(tempName, selectedName) |
||||
&& isNameRepeted(new List[]{Arrays.asList(allListNames)}, tempName)) { |
||||
isNamePermitted = false; |
||||
nameableList.stopEditing(); |
||||
String message = Inter.getLocText(new String[]{"Utils-has_been_existed", "DashBoard-ConnectionList", "Please_Rename"}, new String[]{"", tempName + ",", "!"}); |
||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), message); |
||||
setWarnigText(editingIndex); |
||||
} |
||||
if (isNamePermitted && !ComparatorUtils.equals(tempName, selectedName)) { |
||||
rename(selectedName, tempName); |
||||
} |
||||
|
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
protected void rename(String oldName, String newName) { |
||||
if (renameMap.containsKey(selectedName)) { |
||||
renameMap.remove(selectedName); |
||||
} |
||||
renameMap.put(selectedName, newName); |
||||
} |
||||
|
||||
/** |
||||
* 名字是否允许 |
||||
* |
||||
* @return 是/否 |
||||
*/ |
||||
public boolean isNamePermitted() { |
||||
return isNamePermitted; |
||||
} |
||||
|
||||
/** |
||||
* 检查按钮可用状态 Check button enabled. |
||||
*/ |
||||
public void checkButtonEnabled() { |
||||
super.checkButtonEnabled(); |
||||
isNamePermitted = !isContainsRename(); |
||||
} |
||||
|
||||
|
||||
public HashMap<String, String> getRenameMap() { |
||||
return renameMap; |
||||
} |
||||
|
||||
/** |
||||
* 创建菜单项 |
||||
* |
||||
* @return 菜单项 |
||||
*/ |
||||
public NameableCreator[] createNameableCreators() { |
||||
NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( |
||||
"JDBC", |
||||
"/com/fr/design/images/data/source/jdbcTableData.png", |
||||
JDBCDatabaseConnection.class, |
||||
DatabaseConnectionPane.JDBC.class |
||||
), new NameObjectCreator( |
||||
"JNDI", |
||||
"/com/fr/design/images/data/source/jdbcTableData.png", |
||||
JNDIDatabaseConnection.class, |
||||
DatabaseConnectionPane.JNDI.class |
||||
)}; |
||||
Set<ConnectionProvider> pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); |
||||
for (ConnectionProvider provider : pluginCreators) { |
||||
NameObjectCreator creator = new NameObjectCreator( |
||||
provider.nameForConnection(), |
||||
provider.iconPathForConnection(), |
||||
provider.classForConnection(), |
||||
provider.appearanceForConnection() |
||||
); |
||||
creators = ArrayUtils.add(creators, creator); |
||||
} |
||||
|
||||
return creators; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return TITLE_NAME; |
||||
} |
||||
|
||||
/** |
||||
* Populate. |
||||
* |
||||
* @param datasourceManager the new datasourceManager. |
||||
*/ |
||||
public void populate(DatasourceManagerProvider datasourceManager) { |
||||
Iterator<String> nameIt = datasourceManager.getConnectionNameIterator(); |
||||
|
||||
List<NameObject> nameObjectList = new ArrayList<NameObject>(); |
||||
while (nameIt.hasNext()) { |
||||
String name = nameIt.next(); |
||||
nameObjectList.add(new NameObject(name, datasourceManager.getConnection(name))); |
||||
} |
||||
this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Update. |
||||
*/ |
||||
public void update(DatasourceManagerProvider datasourceManager) { |
||||
// Nameable[]居然不能强转成NameObject[],一定要这么写...
|
||||
Nameable[] res = this.update(); |
||||
NameObject[] res_array = new NameObject[res.length]; |
||||
java.util.Arrays.asList(res).toArray(res_array); |
||||
|
||||
datasourceManager.clearAllConnection(); |
||||
|
||||
for (int i = 0; i < res_array.length; i++) { |
||||
NameObject nameObject = res_array[i]; |
||||
datasourceManager.putConnection(nameObject.getName(), (Connection) nameObject.getObject()); |
||||
} |
||||
} |
||||
} |
@ -1,78 +1,79 @@
|
||||
package com.fr.design.data.datapane.connect; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.gui.frpane.LoadingBasicPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.util.HashMap; |
||||
|
||||
public class ConnectionManagerPane extends LoadingBasicPane { |
||||
private UITextField connectionTextField; |
||||
private ConnectionListPane connectionListPane; |
||||
|
||||
protected void initComponents(JPanel container) { |
||||
container.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
|
||||
JPanel connectionPathPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
||||
container.add(connectionPathPane, BorderLayout.NORTH); |
||||
|
||||
connectionPathPane.setBorder(BorderFactory.createEmptyBorder(6, 2, 2, 2)); |
||||
|
||||
connectionPathPane.add(new UILabel(Inter.getLocText("FR-Designer_Save_Path") + ":"), BorderLayout.WEST); |
||||
this.connectionTextField = new UITextField(); |
||||
connectionPathPane.add(connectionTextField, BorderLayout.CENTER); |
||||
this.connectionTextField.setEditable(false); |
||||
connectionListPane = new ConnectionListPane(){ |
||||
protected void rename(String oldName,String newName) { |
||||
super.rename(oldName,newName); |
||||
renameConnection(oldName,newName); |
||||
} |
||||
}; |
||||
container.add(connectionListPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("Server-Define_Data_Connection"); |
||||
} |
||||
|
||||
public HashMap<String, String> getRenameMap() { |
||||
return connectionListPane.getRenameMap(); |
||||
} |
||||
|
||||
public void populate(DatasourceManagerProvider datasourceManager) { |
||||
this.connectionTextField.setText(FRContext.getCurrentEnv().getPath() + File.separator + ProjectConstants.RESOURCES_NAME |
||||
+ File.separator + datasourceManager.fileName()); |
||||
this.connectionListPane.populate(datasourceManager); |
||||
} |
||||
|
||||
public void update(DatasourceManagerProvider datasourceManager) { |
||||
this.connectionListPane.update(datasourceManager); |
||||
} |
||||
|
||||
/** |
||||
* 设置选中项 |
||||
* |
||||
* @param index 选中项的序列号 |
||||
*/ |
||||
public void setSelectedIndex(int index) { |
||||
this.connectionListPane.setSelectedIndex(index); |
||||
} |
||||
|
||||
/** |
||||
* 名字是否允许 |
||||
* @return 允许返回true |
||||
*/ |
||||
public boolean isNamePermitted() { |
||||
return connectionListPane.isNamePermitted(); |
||||
} |
||||
|
||||
package com.fr.design.data.datapane.connect; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.gui.frpane.LoadingBasicPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.file.DatasourceManagerProvider; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.util.HashMap; |
||||
|
||||
public class ConnectionManagerPane extends LoadingBasicPane implements ConnectionShowPane { |
||||
private UITextField connectionTextField; |
||||
private ConnectionListPane connectionListPane; |
||||
|
||||
protected void initComponents(JPanel container) { |
||||
container.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
|
||||
JPanel connectionPathPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
||||
container.add(connectionPathPane, BorderLayout.NORTH); |
||||
|
||||
connectionPathPane.setBorder(BorderFactory.createEmptyBorder(6, 2, 2, 2)); |
||||
|
||||
connectionPathPane.add(new UILabel(Inter.getLocText("FR-Designer_Save_Path") + ":"), BorderLayout.WEST); |
||||
this.connectionTextField = new UITextField(); |
||||
connectionPathPane.add(connectionTextField, BorderLayout.CENTER); |
||||
this.connectionTextField.setEditable(false); |
||||
connectionListPane = new ConnectionListPane() { |
||||
protected void rename(String oldName, String newName) { |
||||
super.rename(oldName, newName); |
||||
renameConnection(oldName, newName); |
||||
} |
||||
}; |
||||
container.add(connectionListPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("Server-Define_Data_Connection"); |
||||
} |
||||
|
||||
public HashMap<String, String> getRenameMap() { |
||||
return connectionListPane.getRenameMap(); |
||||
} |
||||
|
||||
public void populate(DatasourceManagerProvider datasourceManager) { |
||||
this.connectionTextField.setText(FRContext.getCurrentEnv().getPath() + File.separator + ProjectConstants.RESOURCES_NAME |
||||
+ File.separator + datasourceManager.fileName()); |
||||
this.connectionListPane.populate(datasourceManager); |
||||
} |
||||
|
||||
public void update(DatasourceManagerProvider datasourceManager) { |
||||
this.connectionListPane.update(datasourceManager); |
||||
} |
||||
|
||||
/** |
||||
* 设置选中项 |
||||
* |
||||
* @param index 选中项的序列号 |
||||
*/ |
||||
public void setSelectedIndex(int index) { |
||||
this.connectionListPane.setSelectedIndex(index); |
||||
} |
||||
|
||||
/** |
||||
* 名字是否允许 |
||||
* |
||||
* @return 允许返回true |
||||
*/ |
||||
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; |
||||
|
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.JColorChooser; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.*; |
||||
import javax.swing.colorchooser.AbstractColorChooserPanel; |
||||
import javax.swing.colorchooser.ColorSelectionModel; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.general.Inter; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* 颜色选择器更多颜色面板 |
||||
* @author focus |
||||
* |
||||
* @author focus |
||||
*/ |
||||
public class ColorSelectDetailPane extends BasicPane{ |
||||
private static final int SELECT_PANEL_HEIGHT = 245; |
||||
// Selected color
|
||||
private Color color; |
||||
|
||||
// 颜色选择器面板
|
||||
JColorChooser selectedPanel; |
||||
|
||||
// 最近使用颜色面板
|
||||
JPanel recentUsePanel; |
||||
|
||||
// 预览
|
||||
JPanel previewPanel; |
||||
|
||||
public JColorChooser getSelectedPanel() { |
||||
return selectedPanel; |
||||
} |
||||
|
||||
public void setSelectedPanel(JColorChooser selectedPanel) { |
||||
this.selectedPanel = selectedPanel; |
||||
} |
||||
|
||||
public Color getColor() { |
||||
return color; |
||||
} |
||||
|
||||
public void setColor(Color color) { |
||||
this.color = color; |
||||
} |
||||
|
||||
public ColorSelectDetailPane() { |
||||
super(); |
||||
} |
||||
|
||||
public ColorSelectDetailPane(Color color){ |
||||
if(color == null){ |
||||
color = Color.white; |
||||
} |
||||
this.color = color; |
||||
initComponents(); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return null; |
||||
} |
||||
|
||||
protected void initComponents() { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
|
||||
// 颜色选择器面板
|
||||
selectedPanel = new JColorChooser(this.color); |
||||
selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(),SELECT_PANEL_HEIGHT)); |
||||
AbstractColorChooserPanel[] choosers = selectedPanel.getChooserPanels(); |
||||
for(int i=0;i<choosers.length;i++){ |
||||
selectedPanel.removeChooserPanel(choosers[i]); |
||||
} |
||||
selectedPanel.setPreviewPanel(new JPanel()); |
||||
|
||||
AbstractColorChooserPanel swatchChooserPanel = new SwatchChooserPanel(); |
||||
AbstractColorChooserPanel customChooserPanel = new CustomChooserPanel(); |
||||
selectedPanel.addChooserPanel(swatchChooserPanel); |
||||
selectedPanel.addChooserPanel(customChooserPanel); |
||||
this.add(selectedPanel, BorderLayout.NORTH); |
||||
|
||||
// 最近使用面板
|
||||
recentUsePanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Used")); |
||||
RecentUseColorPane recent = new RecentUseColorPane(selectedPanel); |
||||
recentUsePanel.add(recent); |
||||
|
||||
this.add(recentUsePanel,BorderLayout.CENTER); |
||||
|
||||
selectedPanel.setPreviewPanel(new JPanel()); |
||||
|
||||
// 预览
|
||||
previewPanel = FRGUIPaneFactory.createTitledBorderPaneCenter(Inter.getLocText("FR-Designer_Preview")); |
||||
final ColorChooserPreview colorChooserPreview = new ColorChooserPreview(); |
||||
ColorSelectionModel model = selectedPanel.getSelectionModel(); |
||||
model.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
ColorSelectionModel model = (ColorSelectionModel) e.getSource(); |
||||
colorChooserPreview.setMyColor(model.getSelectedColor()); |
||||
colorChooserPreview.paint(colorChooserPreview.getGraphics()); |
||||
} |
||||
}); |
||||
previewPanel.add(colorChooserPreview); |
||||
this.add(previewPanel, BorderLayout.SOUTH); |
||||
} |
||||
public class ColorSelectDetailPane extends BasicPane { |
||||
private static final int SELECT_PANEL_HEIGHT = 245; |
||||
// Selected color
|
||||
private Color color; |
||||
|
||||
// 颜色选择器面板
|
||||
private JColorChooser selectedPanel; |
||||
|
||||
// 最近使用颜色面板
|
||||
private JPanel recentUsePanel; |
||||
|
||||
// 预览
|
||||
private JPanel previewPanel; |
||||
|
||||
public JColorChooser getSelectedPanel() { |
||||
return selectedPanel; |
||||
} |
||||
|
||||
public void setSelectedPanel(JColorChooser selectedPanel) { |
||||
this.selectedPanel = selectedPanel; |
||||
} |
||||
|
||||
public Color getColor() { |
||||
return color; |
||||
} |
||||
|
||||
public void setColor(Color color) { |
||||
this.color = color; |
||||
} |
||||
|
||||
public ColorSelectDetailPane(Color color) { |
||||
if (color == null) { |
||||
color = Color.white; |
||||
} |
||||
this.color = color; |
||||
initComponents(); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return null; |
||||
} |
||||
|
||||
protected void initComponents() { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
|
||||
// 颜色选择器面板
|
||||
selectedPanel = new JColorChooser(this.color); |
||||
selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(), SELECT_PANEL_HEIGHT)); |
||||
AbstractColorChooserPanel[] choosers = selectedPanel.getChooserPanels(); |
||||
for (int i = 0; i < choosers.length; i++) { |
||||
selectedPanel.removeChooserPanel(choosers[i]); |
||||
} |
||||
selectedPanel.setPreviewPanel(new JPanel()); |
||||
|
||||
AbstractColorChooserPanel swatchChooserPanel = new SwatchChooserPanel(); |
||||
AbstractColorChooserPanel customChooserPanel = new CustomChooserPanel(); |
||||
selectedPanel.addChooserPanel(swatchChooserPanel); |
||||
selectedPanel.addChooserPanel(customChooserPanel); |
||||
this.add(selectedPanel, BorderLayout.NORTH); |
||||
|
||||
// 最近使用面板
|
||||
recentUsePanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Used")); |
||||
RecentUseColorPane recent = new RecentUseColorPane(selectedPanel); |
||||
recentUsePanel.add(recent); |
||||
|
||||
this.add(recentUsePanel, BorderLayout.CENTER); |
||||
|
||||
selectedPanel.setPreviewPanel(new JPanel()); |
||||
|
||||
// 预览
|
||||
previewPanel = FRGUIPaneFactory.createTitledBorderPaneCenter(Inter.getLocText("FR-Designer_Preview")); |
||||
final ColorChooserPreview colorChooserPreview = new ColorChooserPreview(); |
||||
ColorSelectionModel model = selectedPanel.getSelectionModel(); |
||||
model.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
ColorSelectionModel model = (ColorSelectionModel) e.getSource(); |
||||
colorChooserPreview.setMyColor(model.getSelectedColor()); |
||||
colorChooserPreview.paint(colorChooserPreview.getGraphics()); |
||||
} |
||||
}); |
||||
previewPanel.add(colorChooserPreview); |
||||
this.add(previewPanel, BorderLayout.SOUTH); |
||||
} |
||||
} |
@ -1,215 +1,205 @@
|
||||
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.constants.UIConstants; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.dialog.BasicPane; |
||||
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 |
||||
* @since 2012-5-29上午10:39:35 |
||||
*/ |
||||
public class NewColorSelectPane extends BasicPane implements ColorSelectable { |
||||
private static final long serialVersionUID = -8634152305687249392L; |
||||
|
||||
private Color color = null; // color
|
||||
// color setting action.
|
||||
private ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<ChangeListener>(); |
||||
|
||||
// 颜色选择器
|
||||
private ColorSelectDetailPane pane; |
||||
// 是否支持透明
|
||||
private boolean isSupportTransparent; |
||||
|
||||
private final static int TRANSPANENT_WINDOW_HEIGHT = 165; |
||||
private final static int WINDWO_HEIGHT = 150; |
||||
|
||||
// 最近使用颜色
|
||||
UsedColorPane usedColorPane; |
||||
|
||||
/** |
||||
* Constructor. |
||||
*/ |
||||
public NewColorSelectPane() { |
||||
this(false); |
||||
} |
||||
|
||||
/** |
||||
* Constructor. |
||||
*/ |
||||
public NewColorSelectPane(boolean isSupportTransparent) { |
||||
this.isSupportTransparent = isSupportTransparent; |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); |
||||
if (isSupportTransparent) { |
||||
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); |
||||
this.add(transpanrentButton, BorderLayout.NORTH); |
||||
transpanrentButton.addActionListener(new ActionListener() { |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
doTransparent(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// center
|
||||
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
||||
this.add(centerPane, BorderLayout.CENTER); |
||||
|
||||
// 第一行
|
||||
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); |
||||
row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7
|
||||
centerPane.add(row1Pane); |
||||
// 最近使用
|
||||
usedColorPane = new UsedColorPane(1, 8, 1, ColorSelectConfigManager.getInstance().getColors(), this, true, false); |
||||
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); |
||||
row1Pane.add(usedColorPane.getPane()); |
||||
|
||||
JPanel menuColorPane1 = new JPanel(); |
||||
centerPane.add(menuColorPane1); |
||||
|
||||
menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1)); |
||||
menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
||||
for (int i = 0; i < ColorFactory.MenuColors.length; i++) { |
||||
menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this)); |
||||
} |
||||
|
||||
centerPane.add(Box.createVerticalStrut(1)); |
||||
|
||||
// mod by anchore 16/11/16
|
||||
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() { |
||||
@Override |
||||
public void mousePressed(MouseEvent e) { |
||||
customButtonPressed(); |
||||
} |
||||
}); |
||||
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
||||
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8)); |
||||
centerPane1.add(customButton, BorderLayout.NORTH); |
||||
centerPane.add(centerPane1); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* 添加监听 |
||||
* @param 监听列表 |
||||
* Add change listener. |
||||
*/ |
||||
public void addChangeListener(ChangeListener changeListener) { |
||||
this.colorChangeListenerList.add(changeListener); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "Color"; |
||||
} |
||||
|
||||
/** |
||||
* 获取颜色 |
||||
* @return 颜色 |
||||
* Return the color. |
||||
*/ |
||||
public Color getColor() { |
||||
return color; |
||||
} |
||||
|
||||
/** |
||||
* 获取颜色 |
||||
* |
||||
* @return 颜色 |
||||
*/ |
||||
public Color getNotNoneColor() { |
||||
if (color == null) { |
||||
setColor(Color.WHITE); |
||||
return Color.WHITE; |
||||
} |
||||
return color; |
||||
} |
||||
|
||||
/** |
||||
* Set the color. |
||||
* |
||||
* @param color |
||||
* the new color. |
||||
*/ |
||||
@Override |
||||
public void setColor(Color color) { |
||||
this.color = color; |
||||
|
||||
// fire color change.
|
||||
if (!colorChangeListenerList.isEmpty()) { |
||||
ChangeEvent evt = new ChangeEvent(this); |
||||
|
||||
for (int i = 0; i < colorChangeListenerList.size(); i++) { |
||||
this.colorChangeListenerList.get(i).stateChanged(evt); |
||||
} |
||||
} |
||||
ColorSelectConfigManager.getInstance().addToColorQueue(color); |
||||
this.repaint(); |
||||
} |
||||
|
||||
/** |
||||
* 设置颜色 |
||||
* @param 颜色位置 |
||||
*/ |
||||
@Override |
||||
public void colorSetted(ColorCell colorCell) { |
||||
colorCell.repaint(); |
||||
} |
||||
|
||||
protected void doTransparent() { |
||||
setColor(null); |
||||
} |
||||
protected void customButtonPressed() { |
||||
pane = new ColorSelectDetailPane(Color.WHITE); |
||||
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if(isSupportTransparent){ |
||||
return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT); |
||||
} |
||||
return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT); |
||||
} |
||||
|
||||
/** |
||||
* 更新最近使用颜色 |
||||
* |
||||
*/ |
||||
public void updateUsedColor(){ |
||||
usedColorPane.updateUsedColor(); |
||||
} |
||||
|
||||
private static final long serialVersionUID = -8634152305687249392L; |
||||
|
||||
private Color color = null; // color
|
||||
// color setting action.
|
||||
private ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<ChangeListener>(); |
||||
|
||||
// 颜色选择器
|
||||
private ColorSelectDetailPane pane; |
||||
// 是否支持透明
|
||||
private boolean isSupportTransparent; |
||||
|
||||
private final static int TRANSPANENT_WINDOW_HEIGHT = 165; |
||||
private final static int WINDWO_HEIGHT = 150; |
||||
|
||||
// 最近使用颜色
|
||||
private UsedColorPane usedColorPane; |
||||
|
||||
/** |
||||
* Constructor. |
||||
*/ |
||||
public NewColorSelectPane() { |
||||
this(false); |
||||
} |
||||
|
||||
/** |
||||
* Constructor. |
||||
*/ |
||||
public NewColorSelectPane(boolean isSupportTransparent) { |
||||
this.isSupportTransparent = isSupportTransparent; |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); |
||||
if (isSupportTransparent) { |
||||
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); |
||||
this.add(transpanrentButton, BorderLayout.NORTH); |
||||
transpanrentButton.addActionListener(new ActionListener() { |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
doTransparent(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// center
|
||||
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
||||
this.add(centerPane, BorderLayout.CENTER); |
||||
|
||||
// 第一行
|
||||
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); |
||||
row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7
|
||||
centerPane.add(row1Pane); |
||||
// 最近使用
|
||||
usedColorPane = new UsedColorPane(1, 8, 1, this, true, false); |
||||
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); |
||||
row1Pane.add(usedColorPane.getPane()); |
||||
|
||||
JPanel menuColorPane1 = new JPanel(); |
||||
centerPane.add(menuColorPane1); |
||||
|
||||
menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1)); |
||||
menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
||||
for (int i = 0; i < ColorFactory.MenuColors.length; i++) { |
||||
menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this)); |
||||
} |
||||
|
||||
centerPane.add(Box.createVerticalStrut(1)); |
||||
|
||||
// mod by anchore 16/11/16
|
||||
UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color")); |
||||
|
||||
customButton.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mousePressed(MouseEvent e) { |
||||
customButtonPressed(); |
||||
} |
||||
}); |
||||
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
||||
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8)); |
||||
centerPane1.add(customButton, BorderLayout.NORTH); |
||||
centerPane.add(centerPane1); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 添加监听 |
||||
* |
||||
* @param 监听列表 Add change listener. |
||||
*/ |
||||
public void addChangeListener(ChangeListener changeListener) { |
||||
this.colorChangeListenerList.add(changeListener); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "Color"; |
||||
} |
||||
|
||||
/** |
||||
* 获取颜色 |
||||
* |
||||
* @return 颜色 |
||||
* Return the color. |
||||
*/ |
||||
public Color getColor() { |
||||
return color; |
||||
} |
||||
|
||||
/** |
||||
* 获取颜色 |
||||
* |
||||
* @return 颜色 |
||||
*/ |
||||
public Color getNotNoneColor() { |
||||
if (color == null) { |
||||
setColor(Color.WHITE); |
||||
return Color.WHITE; |
||||
} |
||||
return color; |
||||
} |
||||
|
||||
/** |
||||
* Set the color. |
||||
* |
||||
* @param color the new color. |
||||
*/ |
||||
@Override |
||||
public void setColor(Color color) { |
||||
this.color = color; |
||||
|
||||
// fire color change.
|
||||
if (!colorChangeListenerList.isEmpty()) { |
||||
ChangeEvent evt = new ChangeEvent(this); |
||||
|
||||
for (int i = 0; i < colorChangeListenerList.size(); i++) { |
||||
this.colorChangeListenerList.get(i).stateChanged(evt); |
||||
} |
||||
} |
||||
ColorSelectConfigManager.getInstance().addToColorQueue(color); |
||||
this.repaint(); |
||||
} |
||||
|
||||
/** |
||||
* 设置颜色 |
||||
* |
||||
* @param 颜色位置 |
||||
*/ |
||||
@Override |
||||
public void colorSetted(ColorCell colorCell) { |
||||
colorCell.repaint(); |
||||
} |
||||
|
||||
protected void doTransparent() { |
||||
setColor(null); |
||||
} |
||||
|
||||
protected void customButtonPressed() { |
||||
pane = new ColorSelectDetailPane(Color.WHITE); |
||||
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if (isSupportTransparent) { |
||||
return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT); |
||||
} |
||||
return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT); |
||||
} |
||||
|
||||
/** |
||||
* 更新最近使用颜色 |
||||
*/ |
||||
public void updateUsedColor() { |
||||
usedColorPane.updateUsedColor(); |
||||
} |
||||
|
||||
|
||||
} |
@ -1,55 +1,48 @@
|
||||
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.layout.FRGUIPaneFactory; |
||||
|
||||
public class RecentUseColorPane extends BasicPane implements ColorSelectable{ |
||||
|
||||
JColorChooser chooser; |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return null; |
||||
} |
||||
|
||||
public RecentUseColorPane() { |
||||
} |
||||
|
||||
public RecentUseColorPane(JColorChooser chooser) { |
||||
this.chooser = chooser; |
||||
|
||||
// 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()); |
||||
} |
||||
|
||||
/** |
||||
* 选中颜色 |
||||
* |
||||
* @param 颜色 |
||||
*/ |
||||
@Override |
||||
public void colorSetted(ColorCell color) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public Color getColor() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void setColor(Color color) { |
||||
chooser.getSelectionModel().setSelectedColor(color); |
||||
} |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
public class RecentUseColorPane extends BasicPane implements ColorSelectable { |
||||
|
||||
private JColorChooser chooser; |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
public RecentUseColorPane(JColorChooser chooser) { |
||||
this.chooser = chooser; |
||||
|
||||
// center
|
||||
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
||||
this.add(centerPane, BorderLayout.CENTER); |
||||
// 最近使用
|
||||
UsedColorPane pane = new UsedColorPane(2, 10, this); |
||||
centerPane.add(pane.getPane()); |
||||
} |
||||
|
||||
/** |
||||
* 选中颜色 |
||||
*/ |
||||
@Override |
||||
public void colorSetted(ColorCell color) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public Color getColor() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void setColor(Color color) { |
||||
chooser.getSelectionModel().setSelectedColor(color); |
||||
} |
||||
|
||||
} |
@ -1,119 +1,112 @@
|
||||
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.gui.ibutton.SpecialUIButton; |
||||
|
||||
public class UsedColorPane extends BasicPane{ |
||||
|
||||
public static final Color DEFAULT_COLOR = new Color(222,222,222); |
||||
|
||||
// 最近使用面板列数
|
||||
private int columns; |
||||
// 最近使用面板行数
|
||||
private int rows; |
||||
// 留白的单元格数量
|
||||
private int reserveCells; |
||||
// 是否需要取色器按钮
|
||||
private boolean needPickColorButton; |
||||
// 是否在取色时实时设定颜色
|
||||
private boolean setColorRealTime; |
||||
// 最近使用颜色
|
||||
private Object[] colors; |
||||
// 最近使用面板
|
||||
private JPanel pane; |
||||
|
||||
private ColorSelectable selectable; |
||||
|
||||
public JPanel getPane() { |
||||
return pane; |
||||
} |
||||
|
||||
public void setPane(JPanel pane) { |
||||
this.pane = pane; |
||||
} |
||||
|
||||
public UsedColorPane(){ |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 构造函数 |
||||
* |
||||
* @param rows 行 |
||||
* @param columns 列 |
||||
* @param reserveCells 留白的单元格个数 |
||||
* @param colors 最近使用的颜色 |
||||
* @param needPickColorButton 是否需要加上取色器按钮 |
||||
* @param setColorRealTime 取色器是否实时设定颜色 |
||||
*/ |
||||
public UsedColorPane(int rows,int columns,int reserveCells, Object[] colors, ColorSelectable selectable, boolean needPickColorButton, boolean setColorRealTime){ |
||||
this.columns = columns; |
||||
this.rows = rows; |
||||
this.reserveCells = reserveCells; |
||||
this.colors = colors; |
||||
this.selectable = selectable; |
||||
this.needPickColorButton = needPickColorButton; |
||||
this.setColorRealTime = setColorRealTime; |
||||
initialComponents(); |
||||
} |
||||
|
||||
public UsedColorPane(int rows,int columns, Object[] colors,ColorSelectable selectable){ |
||||
this(rows, columns, 0, colors, selectable, false, false); |
||||
} |
||||
|
||||
private void initialComponents(){ |
||||
int total = columns * rows; |
||||
JPanel panel = new JPanel(); |
||||
panel.setLayout(new GridLayout(rows,columns, 1, 1)); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
||||
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
||||
int size = colors.length; |
||||
|
||||
int i = 0; |
||||
if (needPickColorButton) { |
||||
// 取色按钮
|
||||
SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime); |
||||
panel.add(pickColorButton); |
||||
i++; |
||||
this.reserveCells += 1; |
||||
} |
||||
while (i < this.reserveCells) { |
||||
ColorCell cc = new ColorCell(DEFAULT_COLOR, selectable); |
||||
cc.setVisible(false); |
||||
panel.add(cc); |
||||
i++; |
||||
} |
||||
while (i < total) { |
||||
Color color = i < size ? colors[size-1-i]: DEFAULT_COLOR; |
||||
panel.add(new ColorCell(color == null ? DEFAULT_COLOR : color, selectable)); |
||||
i++; |
||||
} |
||||
this.pane = panel; |
||||
} |
||||
|
||||
/** |
||||
* 更新最近使用颜色 |
||||
* |
||||
*/ |
||||
public void updateUsedColor(){ |
||||
int total = columns * rows; |
||||
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
||||
int size = colors.length; |
||||
for(int i=this.reserveCells; i<total; i++){ |
||||
ColorCell cell = (ColorCell) this.pane.getComponent(i); |
||||
Color color = i < size ? colors[size-1-i]: DEFAULT_COLOR; |
||||
cell.setColor(color == null ? DEFAULT_COLOR : color); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return null; |
||||
} |
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
public class UsedColorPane extends BasicPane { |
||||
|
||||
// 默认显示颜色
|
||||
public static final Color DEFAULT_COLOR = new Color(222, 222, 222); |
||||
|
||||
// 最近使用面板列数
|
||||
private int columns; |
||||
// 最近使用面板行数
|
||||
private int rows; |
||||
// 留白的单元格数量
|
||||
private int reserveCells; |
||||
// 是否需要取色器按钮
|
||||
private boolean needPickColorButton; |
||||
// 是否在取色时实时设定颜色
|
||||
private boolean setColorRealTime; |
||||
|
||||
// 最近使用面板
|
||||
private JPanel pane; |
||||
|
||||
private ColorSelectable selectable; |
||||
|
||||
public JPanel getPane() { |
||||
return pane; |
||||
} |
||||
|
||||
public void setPane(JPanel pane) { |
||||
this.pane = pane; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 构造函数 |
||||
* |
||||
* @param rows 行 |
||||
* @param columns 列 |
||||
* @param reserveCells 留白的单元格个数 |
||||
* @param colors 最近使用的颜色 |
||||
* @param needPickColorButton 是否需要加上取色器按钮 |
||||
* @param setColorRealTime 取色器是否实时设定颜色 |
||||
*/ |
||||
public UsedColorPane(int rows, int columns, int reserveCells, ColorSelectable selectable, boolean needPickColorButton, boolean setColorRealTime) { |
||||
this.columns = columns; |
||||
this.rows = rows; |
||||
this.reserveCells = reserveCells; |
||||
this.selectable = selectable; |
||||
this.needPickColorButton = needPickColorButton; |
||||
this.setColorRealTime = setColorRealTime; |
||||
initialComponents(); |
||||
} |
||||
|
||||
public UsedColorPane(int rows, int columns, ColorSelectable selectable) { |
||||
this(rows, columns, 0, selectable, false, false); |
||||
} |
||||
|
||||
private void initialComponents() { |
||||
int total = columns * rows; |
||||
JPanel panel = new JPanel(); |
||||
panel.setLayout(new GridLayout(rows, columns, 1, 1)); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); |
||||
//最近使用颜色
|
||||
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
||||
int size = colors.length; |
||||
|
||||
int i = 0; |
||||
if (needPickColorButton) { |
||||
// 取色按钮
|
||||
SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime); |
||||
panel.add(pickColorButton); |
||||
i++; |
||||
this.reserveCells += 1; |
||||
} |
||||
while (i < this.reserveCells) { |
||||
ColorCell cc = new ColorCell(DEFAULT_COLOR, selectable); |
||||
cc.setVisible(false); |
||||
panel.add(cc); |
||||
i++; |
||||
} |
||||
while (i < total) { |
||||
Color color = i < size ? colors[size - (i - this.reserveCells) - 1] : DEFAULT_COLOR; |
||||
panel.add(new ColorCell(color == null ? DEFAULT_COLOR : color, selectable)); |
||||
i++; |
||||
} |
||||
this.pane = panel; |
||||
} |
||||
|
||||
/** |
||||
* 更新最近使用颜色 |
||||
*/ |
||||
public void updateUsedColor() { |
||||
int total = columns * rows; |
||||
Color[] colors = ColorSelectConfigManager.getInstance().getColors(); |
||||
int size = colors.length; |
||||
for (int i = this.reserveCells; i < total; i++) { |
||||
ColorCell cell = (ColorCell) this.pane.getComponent(i); |
||||
Color color = i < size ? colors[size - (i - this.reserveCells) - 1] : DEFAULT_COLOR; |
||||
cell.setColor(color == null ? DEFAULT_COLOR : color); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return null; |
||||
} |
||||
} |