Destiny.Lin
2 years ago
11 changed files with 1802 additions and 0 deletions
@ -0,0 +1,63 @@
|
||||
package com.fr.design.actions.replace; |
||||
|
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.menu.MenuKeySet; |
||||
import com.fr.design.actions.replace.ui.ITReplaceMainDialog; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.InputEvent; |
||||
import java.awt.event.KeyEvent; |
||||
|
||||
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; |
||||
|
||||
/** |
||||
* 将全局查找替换选项插入帮助菜单底部 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-08-10 |
||||
*/ |
||||
public class ITReplaceAction extends UpdateAction { |
||||
public ITReplaceAction() { |
||||
this.setMenuKeySet(IT_REPLACE); |
||||
this.setName(getMenuKeySet().getMenuName()); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setAccelerator(getMenuKeySet().getKeyStroke()); |
||||
} |
||||
|
||||
private static final MenuKeySet IT_REPLACE = new MenuKeySet() { |
||||
@Override |
||||
public char getMnemonic() { |
||||
return 'I'; |
||||
} |
||||
|
||||
@Override |
||||
public String getMenuName() { |
||||
return Toolkit.i18nText("Fine-Design_Replace_Title"); |
||||
} |
||||
|
||||
@Override |
||||
public KeyStroke getKeyStroke() { |
||||
return KeyStroke.getKeyStroke(KeyEvent.VK_F, DEFAULT_MODIFIER); |
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* 点击选项后的行为 |
||||
* |
||||
* @param event |
||||
*/ |
||||
public void actionPerformed(ActionEvent event) { |
||||
ITReplaceMainDialog mainFrame = ITReplaceMainDialog.getInstance(); |
||||
mainFrame.setVisible(true); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,113 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.stable.Constants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.plaf.basic.BasicComboBoxEditor; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionListener; |
||||
import java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* 渲染带有默认值的ComboBox |
||||
* UIComboBox中设置默认值会整体上移,需要自己重新实现一个 |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-09-02 |
||||
*/ |
||||
public class ITComboBoxEditor extends BasicComboBoxEditor { |
||||
protected UITextField textField; |
||||
private Object oldValue; |
||||
|
||||
/** |
||||
* 构造时重新设置一下TextField的上边距 |
||||
*/ |
||||
public ITComboBoxEditor() { |
||||
textField = new UITextField(){ |
||||
@Override |
||||
public Insets getInsets() { |
||||
return new Insets(4, 4, 0, 4); |
||||
} |
||||
}; |
||||
textField.setRectDirection(Constants.RIGHT); |
||||
} |
||||
|
||||
@Override |
||||
public Component getEditorComponent() { |
||||
return textField; |
||||
} |
||||
|
||||
/** |
||||
* 设置选项 |
||||
* @param anObject 选项 |
||||
*/ |
||||
@Override |
||||
public void setItem(Object anObject) { |
||||
if (anObject != null) { |
||||
|
||||
textField.setText(anObject.toString()); |
||||
oldValue = anObject; |
||||
} else { |
||||
textField.setText(StringUtils.EMPTY); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取选项 |
||||
* @return 选项 |
||||
* |
||||
*/ |
||||
@Override |
||||
public Object getItem() { |
||||
Object newValue = textField.getText(); |
||||
if (oldValue != null && !(oldValue instanceof String)) { |
||||
// The original value is not a string. Should return the value in it's
|
||||
// original type.
|
||||
if(ComparatorUtils.equals(newValue,oldValue.toString())) { |
||||
return oldValue; |
||||
} else { |
||||
// Must take the value from the textField and get the value and cast it to the new type.
|
||||
Class cls = oldValue.getClass(); |
||||
try { |
||||
Method method = cls.getMethod("valueOf", new Class[]{String.class}); |
||||
newValue = method.invoke(oldValue, new Object[]{textField.getText()}); |
||||
} catch (Exception ex) { |
||||
// Fail silently and return the newValue (a String object)
|
||||
} |
||||
} |
||||
} |
||||
return newValue; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 选择所有 |
||||
*/ |
||||
@Override |
||||
public void selectAll() { |
||||
textField.selectAll(); |
||||
textField.requestFocus(); |
||||
} |
||||
|
||||
/** |
||||
* 添加监听 |
||||
* @param l 监听 |
||||
*/ |
||||
@Override |
||||
public void addActionListener(ActionListener l) { |
||||
textField.addActionListener(l); |
||||
} |
||||
|
||||
/** |
||||
* 移除监听 |
||||
* @param l 监听 |
||||
*/ |
||||
@Override |
||||
public void removeActionListener(ActionListener l) { |
||||
textField.removeActionListener(l); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,246 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
|
||||
import com.fr.design.actions.replace.action.ShowSearchResultAction; |
||||
|
||||
import com.fr.design.actions.replace.info.FormulaInfo; |
||||
import com.fr.design.actions.replace.info.Info; |
||||
import com.fr.design.actions.replace.info.JSInfo; |
||||
import com.fr.design.actions.replace.info.WidgetInfo; |
||||
import com.fr.design.actions.replace.utils.ShowValueUtils; |
||||
import com.fr.design.data.DesignTableDataManager; |
||||
import com.fr.design.data.datapane.TableDataPaneListPane; |
||||
import com.fr.design.dialog.FineJOptionPane; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.file.TableDataConfig; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.main.impl.WorkBook; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.*; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
|
||||
/** |
||||
* 主面板 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-08-10 |
||||
*/ |
||||
public class ITReplaceMainDialog extends UIDialog { |
||||
ArrayList<? extends Info> searchResultList = new ArrayList<>(); |
||||
private static boolean ITReplaceFlag = false; |
||||
private static volatile ITReplaceMainDialog instance = null; |
||||
private static String templateID; |
||||
private static int selectCount; |
||||
private ITReplaceNorthPanel northPane; |
||||
private ITReplaceSouthPanel southPanel; |
||||
private ITReplaceWestPanel westPanel; |
||||
|
||||
private ITReplaceMainDialog() { |
||||
super(DesignerContext.getDesignerFrame()); |
||||
init(); |
||||
} |
||||
|
||||
/** |
||||
* 初始化 |
||||
*/ |
||||
public void init() { |
||||
setTitle(Toolkit.i18nText("Fine-Design_Replace_Title")); |
||||
initFrame(); |
||||
fitScreen(); |
||||
ITReplaceFlag = true; |
||||
} |
||||
|
||||
/** |
||||
* DCL |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
public static ITReplaceMainDialog getInstance() { |
||||
if (instance == null) { |
||||
synchronized (ITReplaceMainDialog.class) { |
||||
if (instance == null) { |
||||
instance = new ITReplaceMainDialog(); |
||||
} |
||||
} |
||||
} |
||||
instance.fitScreen(); |
||||
return instance; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 适配屏幕 |
||||
*/ |
||||
public void fitScreen() { |
||||
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
int height = 385; |
||||
int width = jTemplate.getWidth(); |
||||
Point point = jTemplate.getLocationOnScreen(); |
||||
setModal(false); |
||||
setMaximumSize(new Dimension(jTemplate.getWidth(), jTemplate.getHeight())); |
||||
setMinimumSize(new Dimension(jTemplate.getWidth(), 240)); |
||||
setSize(width, height); |
||||
setLocation(new Point(point.x, point.y + jTemplate.getHeight() / 2 + jTemplate.getHeight() / 2 - 385)); |
||||
|
||||
northPane.fitScreen(0, 0, jTemplate.getWidth()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 创建面板 |
||||
*/ |
||||
public void initFrame() { |
||||
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
northPane = new ITReplaceNorthPanel(); |
||||
southPanel = new ITReplaceSouthPanel(); |
||||
westPanel = new ITReplaceWestPanel(); |
||||
|
||||
northPane.fitScreen(0, 0, jTemplate.getWidth()); |
||||
|
||||
JPanel center = new JPanel(new BorderLayout()); |
||||
|
||||
northPane.getFindInputCombobox().setEditable(true); |
||||
northPane.getReplaceInputCombobox().setEditable(false); |
||||
|
||||
|
||||
((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).setPlaceholder(Toolkit.i18nText("Fine-Design_Replace_Search_Input")); |
||||
((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).setPlaceholder(Toolkit.i18nText("Fine-Design_Replace_Input")); |
||||
((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
search(); |
||||
String searchStr = ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(); |
||||
if (!StringUtils.isEmpty(searchStr)) { |
||||
((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).setEditable(true); |
||||
northPane.getReplaceInputCombobox().setEditable(true); |
||||
} else { |
||||
((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).setEditable(false); |
||||
northPane.getReplaceInputCombobox().setEditable(false); |
||||
} |
||||
} |
||||
}); |
||||
((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
replace(); |
||||
} |
||||
|
||||
|
||||
}); |
||||
center.add(northPane.getUpPanel(), BorderLayout.NORTH); |
||||
center.add(southPanel.getTableEditorPane(), BorderLayout.CENTER); |
||||
add(westPanel.getLeftJpanel(), BorderLayout.WEST); |
||||
//主体部分
|
||||
add(center, BorderLayout.CENTER); |
||||
center.setVisible(true); |
||||
} |
||||
|
||||
/** |
||||
* 替换 |
||||
*/ |
||||
private void replace() { |
||||
if (isITReplaceValid() && checkTemplateChanged(searchResultList)) { |
||||
String searchStr = ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(); |
||||
String replaceStr = ((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).getText(); |
||||
|
||||
|
||||
for (Info info : searchResultList) { |
||||
if (info.getContent().isSelected()) { |
||||
info.setValue(info, searchStr, replaceStr, info.getContent().getOperatorArray()); |
||||
ShowValueUtils.updateHighlight(info, replaceStr); |
||||
} |
||||
} |
||||
southPanel.getTableEditorPane().update(); |
||||
northPane.refreshReplaceInputComboBoxItems(); |
||||
ITTableEditorPane.getEditTable().repaint(); |
||||
HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().fireTargetModified(true); |
||||
|
||||
|
||||
} else { |
||||
Object[] options = new Object[]{Toolkit.i18nText("Fine-Design_Replace_Search_Again"), Toolkit.i18nText("Fine-Engine_Basic_Cancel")}; |
||||
int optionSelected = FineJOptionPane.showOptionDialog( |
||||
ITReplaceMainDialog.this, |
||||
Toolkit.i18nText("Fine-Design_Replace_Message"), |
||||
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.ERROR_MESSAGE, |
||||
null, |
||||
options, // 如果传null, 则按钮为 optionType 类型所表示的按钮(也就是确认对话框)
|
||||
options[0] |
||||
); |
||||
//如果选择了重新查找,则再查找一遍
|
||||
if (optionSelected == 0) { |
||||
search(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private Boolean checkTemplateChanged(ArrayList<? extends Info> searchResultList) { |
||||
for (Info info : searchResultList) { |
||||
if (!info.checkValid()) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 可行性判定(模板是否可用、是否是同个模板) |
||||
* |
||||
* @return 检查无误则返回true |
||||
*/ |
||||
public boolean isITReplaceValid() { |
||||
if (JTemplate.isValid(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate())) { |
||||
return StringUtils.equals(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget().getTemplateID(), templateID); |
||||
} else return false; |
||||
|
||||
} |
||||
|
||||
public static void setITReplaceFlag(boolean ITReplaceFlag) { |
||||
ITReplaceMainDialog.ITReplaceFlag = ITReplaceFlag; |
||||
} |
||||
|
||||
public static boolean isITReplaceFlag() { |
||||
return ITReplaceFlag; |
||||
} |
||||
|
||||
/** |
||||
* 搜索 |
||||
*/ |
||||
public void search() { |
||||
ITTableEditor itTableEditor = southPanel.getItTableEditor(); |
||||
if (JTemplate.isValid(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate())) { |
||||
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
templateID = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget().getTemplateID(); |
||||
itTableEditor.clear(); |
||||
ShowSearchResultAction searchAction = ShowSearchResultAction.match(GeneralUtils.objectToString(northPane.getFindCombobox().getSelectedItem())); |
||||
if (searchAction != null) { |
||||
searchResultList = searchAction.addMatchResult(((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(), searchAction.showSearchValue(jTemplate)); |
||||
itTableEditor.add(searchResultList); |
||||
northPane.getResultLabel().setText("<html>" + Toolkit.i18nText("Fine-Design_Replace_Search_Finish") + "<font color = 'rgb(61,153,249)'>" + searchResultList.size() + "</font>" + Toolkit.i18nText("Fine-Design_Replace_Result")); |
||||
} |
||||
itTableEditor.fireTableDataChanged(); |
||||
northPane.refreshFindInputComboBoxItems(); |
||||
} else { |
||||
//todo
|
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 检测结果是否合法 |
||||
*/ |
||||
@Override |
||||
public void checkValid() throws Exception { |
||||
} |
||||
} |
@ -0,0 +1,352 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ibutton.UIRadioButton; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
|
||||
import javax.swing.ComboBoxEditor; |
||||
import javax.swing.JCheckBox; |
||||
import javax.swing.JPanel; |
||||
import java.awt.Dimension; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
|
||||
/** |
||||
* 上面板 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-09-01 |
||||
*/ |
||||
public class ITReplaceNorthPanel { |
||||
private JPanel upPanel; |
||||
private UILabel findLabel; |
||||
private UILabel rangeLabel; |
||||
private UILabel resultLabel; |
||||
private UIComboBox findCombobox; |
||||
private UIComboBox rangeCombobox; |
||||
private JCheckBox matchRadioButton; |
||||
|
||||
private UIComboBox findInputCombobox; |
||||
private UIComboBox replaceInputCombobox; |
||||
|
||||
private UIButton replaceButton; |
||||
private UIButton searchButton; |
||||
|
||||
private static int FIND_LABEL_X, FIND_LABEL_Y, FIND_LABEL_WIDTH, FIND_LABEL_HEIGHT; |
||||
private static int FIND_COMBOBOX_X, FIND_COMBOBOX_Y, FIND_COMBOBOX_WIDTH, FIND_COMBOBOX_HEIGHT; |
||||
private static int RANGE_LABEL_X, RANGE_LABEL_Y, RANGE_LABEL_WIDTH, RANGE_LABEL_HEIGHT; |
||||
private static int RANGE_COMBOBOX_X, RANGE_COMBOBOX_Y, RANGE_COMBOBOX_WIDTH, RANGE_COMBOBOX_HEIGHT; |
||||
private static int MATCH_X, MATCH_Y, MATCH_WIDTH, MATCH_HEIGHT; |
||||
private static int RESULT_LABEL_X, RESULT_LABEL_Y, RESULT_LABEL_WIDTH, RESULT_LABEL_HEIGHT; |
||||
private static int FIND_INPUT_COMBOBOX_X, FIND_INPUT_COMBOBOX_Y, FIND_INPUT_COMBOBOX_WIDTH, FIND_INPUT_COMBOBOX_HEIGHT; |
||||
private static int REPLACE_INPUT_COMBOBOX_X, REPLACE_INPUT_COMBOBOX_Y, REPLACE_INPUT_COMBOBOX_WIDTH, REPLACE_INPUT_COMBOBOX_HEIGHT; |
||||
private static int REPLACE_BUTTON_X, REPLACE_BUTTON_Y, REPLACE_BUTTON_WIDTH, REPLACE_BUTTON_HEIGHT; |
||||
private static int SEARCH_BUTTON_X, SEARCH_BUTTON_Y, SEARCH_BUTTON_WIDTH, SEARCH_BUTTON_HEIGHT; |
||||
private static int BUTTON_GAP; |
||||
|
||||
public static ArrayList<String> findItems = new ArrayList<>(); |
||||
public static ArrayList<String> findInputItems = new ArrayList<>(); |
||||
public static ArrayList<String> replaceInputItems = new ArrayList<>(); |
||||
|
||||
static { |
||||
findItems.add(Toolkit.i18nText("Fine-Design_Basic_Cell")); |
||||
findItems.add(Toolkit.i18nText("Fine-Design_Replace_JS")); |
||||
findItems.add("SQL"); |
||||
findItems.add(Toolkit.i18nText("Fine-Design_Basic_Float_Element")); |
||||
findItems.add(Toolkit.i18nText("Fine-Design_Replace_Component")); |
||||
findItems.add(Toolkit.i18nText("Fine-Design_Basic_Widget")); |
||||
findItems.add(Toolkit.i18nText("Fine-Design_Basic_Formula")); |
||||
} |
||||
|
||||
public ITReplaceNorthPanel() { |
||||
upPanel = new JPanel(null); |
||||
|
||||
findLabel = new UILabel(Toolkit.i18nText("Fine-Design_Replace_Search_Element")); |
||||
rangeLabel = new UILabel(Toolkit.i18nText("Fine-Design_Replace_Search_Range")); |
||||
resultLabel = new UILabel(); |
||||
|
||||
String[] rangeItems = new String[]{Toolkit.i18nText("Fine-Design_Basic_Export_JS_Template_Current")}; |
||||
String[] replaceInputItems = new String[]{""}; |
||||
findCombobox = new UIComboBox(findItems.toArray()); |
||||
rangeCombobox = new UIComboBox(rangeItems); |
||||
findInputCombobox = new UIComboBox(findInputItems.toArray()) { |
||||
@Override |
||||
public void setEditor(ComboBoxEditor comboBoxEditor) { |
||||
super.setEditor(new ITComboBoxEditor()); |
||||
} |
||||
}; |
||||
replaceInputCombobox = new UIComboBox(replaceInputItems) { |
||||
@Override |
||||
public void setEditor(ComboBoxEditor comboBoxEditor) { |
||||
super.setEditor(new ITComboBoxEditor()); |
||||
} |
||||
}; |
||||
matchRadioButton = new JCheckBox(Toolkit.i18nText("Fine-Design_Replace_WildCard")); |
||||
|
||||
replaceButton = new UIButton(Toolkit.i18nText("Fine-Design_Replace_Button")); |
||||
searchButton = new UIButton(Toolkit.i18nText("Fine-Design_Search_Button")); |
||||
|
||||
setLimitSize(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getWidth()); |
||||
|
||||
upPanel.add(findLabel); |
||||
upPanel.add(rangeLabel); |
||||
upPanel.add(resultLabel); |
||||
upPanel.add(findCombobox); |
||||
upPanel.add(rangeCombobox); |
||||
upPanel.add(findInputCombobox); |
||||
upPanel.add(replaceInputCombobox); |
||||
upPanel.add(matchRadioButton); |
||||
upPanel.add(replaceButton); |
||||
upPanel.add(searchButton); |
||||
} |
||||
|
||||
/** |
||||
* 限制尺寸 |
||||
* |
||||
* @param width |
||||
*/ |
||||
public void setLimitSize(int width) { |
||||
upPanel.setMaximumSize(new Dimension(width, 161)); |
||||
upPanel.setMinimumSize(new Dimension(width, 161)); |
||||
upPanel.setPreferredSize(new Dimension(width, 161)); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 适配屏幕 |
||||
* |
||||
* @param x |
||||
* @param y |
||||
* @param templateWidth |
||||
*/ |
||||
public void fitScreen(int x, int y, int templateWidth) { |
||||
|
||||
setFindLabelBounds(x, y, templateWidth); |
||||
setRangeLabelBounds(x, y, templateWidth); |
||||
setResultLabelBounds(x, y, templateWidth); |
||||
|
||||
setFindComboboxBounds(x, y, templateWidth); |
||||
setRangeComboboxBounds(x, y, templateWidth); |
||||
setFindInputComboboxBounds(x, y, templateWidth); |
||||
setReplaceInputComboboxBounds(x, y, templateWidth); |
||||
|
||||
setUIRadioButtonBounds(x, y, templateWidth); |
||||
setReplaceButtonBounds(x, y, templateWidth); |
||||
setSearchButtonBounds(x, y, templateWidth); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* 刷新输入框 |
||||
*/ |
||||
public void refreshFindInputComboBoxItems() { |
||||
String text = ((UITextField) (this.getFindInputCombobox().getEditor().getEditorComponent())).getText(); |
||||
if(!StringUtils.isEmpty(text)){ |
||||
if (findInputItems.contains(text)) { |
||||
Collections.swap(findInputItems, 0, findInputItems.indexOf(text)); |
||||
} else { |
||||
if (findInputItems.size() >= 5) { |
||||
findInputItems.remove(4); |
||||
findInputItems.add(0, text); |
||||
} else { |
||||
findInputItems.add(0, text); |
||||
} |
||||
} |
||||
this.getFindInputCombobox().refreshBoxItems(ITReplaceNorthPanel.findInputItems); |
||||
((UITextField) (this.getFindInputCombobox().getEditor().getEditorComponent())).setText(text); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 刷新替换框 |
||||
*/ |
||||
public void refreshReplaceInputComboBoxItems(){ |
||||
String text = ((UITextField) (this.getReplaceInputCombobox().getEditor().getEditorComponent())).getText(); |
||||
if(!StringUtils.isEmpty(text)){ |
||||
if (replaceInputItems.contains(text)) { |
||||
Collections.swap(replaceInputItems, 0, replaceInputItems.indexOf(text)); |
||||
} else { |
||||
if (replaceInputItems.size() >= 5) { |
||||
replaceInputItems.remove(4); |
||||
replaceInputItems.add(0, text); |
||||
} else { |
||||
replaceInputItems.add(0, text); |
||||
} |
||||
} |
||||
this.getFindInputCombobox().refreshBoxItems(ITReplaceNorthPanel.replaceInputItems); |
||||
((UITextField) (this.getReplaceInputCombobox().getEditor().getEditorComponent())).setText(text); |
||||
} |
||||
} |
||||
|
||||
|
||||
private void setSearchButtonBounds(int x, int y, int templateWidth) { |
||||
BUTTON_GAP = templateWidth / 90; |
||||
SEARCH_BUTTON_WIDTH = templateWidth / 30; |
||||
|
||||
SEARCH_BUTTON_HEIGHT = 25; |
||||
SEARCH_BUTTON_Y = RESULT_LABEL_Y; |
||||
SEARCH_BUTTON_X = REPLACE_INPUT_COMBOBOX_X + REPLACE_INPUT_COMBOBOX_WIDTH - REPLACE_BUTTON_WIDTH * 2 - BUTTON_GAP; |
||||
searchButton.setBounds(SEARCH_BUTTON_X, SEARCH_BUTTON_Y, SEARCH_BUTTON_WIDTH, SEARCH_BUTTON_HEIGHT); |
||||
} |
||||
|
||||
private void setReplaceButtonBounds(int x, int y, int templateWidth) { |
||||
BUTTON_GAP = templateWidth / 90; |
||||
REPLACE_BUTTON_WIDTH = templateWidth / 30; |
||||
REPLACE_BUTTON_HEIGHT = 25; |
||||
REPLACE_BUTTON_Y = RESULT_LABEL_Y; |
||||
REPLACE_BUTTON_X = REPLACE_INPUT_COMBOBOX_X + REPLACE_INPUT_COMBOBOX_WIDTH - REPLACE_BUTTON_WIDTH; |
||||
replaceButton.setBounds(REPLACE_BUTTON_X, REPLACE_BUTTON_Y, REPLACE_BUTTON_WIDTH, REPLACE_BUTTON_HEIGHT); |
||||
} |
||||
|
||||
private void setReplaceInputComboboxBounds(int x, int y, int templateWidth) { |
||||
REPLACE_INPUT_COMBOBOX_X = x + templateWidth / 2 + templateWidth / 30; |
||||
REPLACE_INPUT_COMBOBOX_Y = y + 55; |
||||
REPLACE_INPUT_COMBOBOX_WIDTH = templateWidth / 3 + templateWidth / 30 * 2; |
||||
REPLACE_INPUT_COMBOBOX_HEIGHT = 25; |
||||
replaceInputCombobox.setBounds(REPLACE_INPUT_COMBOBOX_X, REPLACE_INPUT_COMBOBOX_Y, REPLACE_INPUT_COMBOBOX_WIDTH, REPLACE_INPUT_COMBOBOX_HEIGHT); |
||||
} |
||||
|
||||
private void setFindInputComboboxBounds(int x, int y, int templateWidth) { |
||||
FIND_INPUT_COMBOBOX_X = x + templateWidth / 60; |
||||
FIND_INPUT_COMBOBOX_Y = y + 55; |
||||
FIND_INPUT_COMBOBOX_WIDTH = templateWidth / 3 + templateWidth / 30 * 2; |
||||
FIND_INPUT_COMBOBOX_HEIGHT = 25; |
||||
findInputCombobox.setBounds(FIND_INPUT_COMBOBOX_X, FIND_INPUT_COMBOBOX_Y, FIND_INPUT_COMBOBOX_WIDTH, FIND_INPUT_COMBOBOX_HEIGHT); |
||||
} |
||||
|
||||
private void setUIRadioButtonBounds(int x, int y, int templateWidth) { |
||||
MATCH_X = x + templateWidth / 60; |
||||
MATCH_Y = y + 90; |
||||
MATCH_WIDTH = templateWidth; |
||||
MATCH_HEIGHT = 25; |
||||
matchRadioButton.setBounds(MATCH_X, MATCH_Y, MATCH_WIDTH, MATCH_HEIGHT); |
||||
} |
||||
|
||||
|
||||
private void setRangeComboboxBounds(int x, int y, int templateWidth) { |
||||
RANGE_COMBOBOX_X = x + templateWidth / 2 + templateWidth / 15 + templateWidth / 60; |
||||
RANGE_COMBOBOX_Y = y + 20; |
||||
RANGE_COMBOBOX_WIDTH = templateWidth / 3 + templateWidth / 60; |
||||
RANGE_COMBOBOX_HEIGHT = 25; |
||||
rangeCombobox.setBounds(RANGE_COMBOBOX_X, RANGE_COMBOBOX_Y, RANGE_COMBOBOX_WIDTH, RANGE_COMBOBOX_HEIGHT); |
||||
} |
||||
|
||||
|
||||
private void setFindComboboxBounds(int x, int y, int templateWidth) { |
||||
FIND_COMBOBOX_X = x + templateWidth / 30 * 2; |
||||
FIND_COMBOBOX_Y = y + 20; |
||||
FIND_COMBOBOX_WIDTH = templateWidth / 3 + templateWidth / 60; |
||||
FIND_COMBOBOX_HEIGHT = 25; |
||||
findCombobox.setBounds(FIND_COMBOBOX_X, FIND_COMBOBOX_Y, FIND_COMBOBOX_WIDTH, FIND_COMBOBOX_HEIGHT); |
||||
} |
||||
|
||||
|
||||
private void setResultLabelBounds(int x, int y, int templateWidth) { |
||||
RESULT_LABEL_X = FIND_LABEL_X; |
||||
RESULT_LABEL_Y = y + 125; |
||||
RESULT_LABEL_WIDTH = templateWidth; |
||||
RESULT_LABEL_HEIGHT = 25; |
||||
resultLabel.setBounds(RESULT_LABEL_X, RESULT_LABEL_Y, RESULT_LABEL_WIDTH, RESULT_LABEL_HEIGHT); |
||||
|
||||
} |
||||
|
||||
private void setRangeLabelBounds(int x, int y, int templateWidth) { |
||||
RANGE_LABEL_X = x + templateWidth / 2 + templateWidth / 30; |
||||
RANGE_LABEL_Y = y + 20; |
||||
RANGE_LABEL_WIDTH = FIND_LABEL_WIDTH; |
||||
RANGE_LABEL_HEIGHT = 25; |
||||
rangeLabel.setBounds(RANGE_LABEL_X, RANGE_LABEL_Y, RANGE_LABEL_WIDTH, RANGE_LABEL_HEIGHT); |
||||
|
||||
} |
||||
|
||||
private void setFindLabelBounds(int x, int y, int templateWidth) { |
||||
FIND_LABEL_X = x + templateWidth / 60; |
||||
FIND_LABEL_Y = y + 20; |
||||
FIND_LABEL_WIDTH = templateWidth / 20; |
||||
FIND_LABEL_HEIGHT = 25; |
||||
findLabel.setBounds(FIND_LABEL_X, FIND_LABEL_Y, FIND_LABEL_WIDTH, FIND_LABEL_HEIGHT); |
||||
} |
||||
|
||||
public JPanel getUpPanel() { |
||||
return upPanel; |
||||
} |
||||
|
||||
public void setUpPanel(JPanel upPanel) { |
||||
this.upPanel = upPanel; |
||||
} |
||||
|
||||
public UILabel getFindLabel() { |
||||
return findLabel; |
||||
} |
||||
|
||||
public void setFindLabel(UILabel findLabel) { |
||||
this.findLabel = findLabel; |
||||
} |
||||
|
||||
public UILabel getRangeLabel() { |
||||
return rangeLabel; |
||||
} |
||||
|
||||
public void setRangeLabel(UILabel rangeLabel) { |
||||
this.rangeLabel = rangeLabel; |
||||
} |
||||
|
||||
public UILabel getResultLabel() { |
||||
return resultLabel; |
||||
} |
||||
|
||||
public void setResultLabel(UILabel resultLabel) { |
||||
this.resultLabel = resultLabel; |
||||
} |
||||
|
||||
public UIComboBox getFindCombobox() { |
||||
return findCombobox; |
||||
} |
||||
|
||||
public void setFindCombobox(UIComboBox findCombobox) { |
||||
this.findCombobox = findCombobox; |
||||
} |
||||
|
||||
public UIComboBox getRangeCombobox() { |
||||
return rangeCombobox; |
||||
} |
||||
|
||||
public void setRangeCombobox(UIComboBox rangeCombobox) { |
||||
this.rangeCombobox = rangeCombobox; |
||||
} |
||||
|
||||
public JCheckBox getMatchRadioButton() { |
||||
return matchRadioButton; |
||||
} |
||||
|
||||
public void setMatchRadioButton(JCheckBox checkBox) { |
||||
this.matchRadioButton = checkBox; |
||||
} |
||||
|
||||
public UIComboBox getFindInputCombobox() { |
||||
return findInputCombobox; |
||||
} |
||||
|
||||
public void setFindInputCombobox(UIComboBox findInputCombobox) { |
||||
this.findInputCombobox = findInputCombobox; |
||||
} |
||||
|
||||
public UIComboBox getReplaceInputCombobox() { |
||||
return replaceInputCombobox; |
||||
} |
||||
|
||||
public void setReplaceInputCombobox(UIComboBox replaceInputCombobox) { |
||||
this.replaceInputCombobox = replaceInputCombobox; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
import javax.swing.RowSorter; |
||||
import javax.swing.table.TableRowSorter; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
|
||||
/** |
||||
* 下面板 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-09-05 |
||||
*/ |
||||
public class ITReplaceSouthPanel { |
||||
ITTableEditorPane tableEditorPane; |
||||
ITTableEditor itTableEditor; |
||||
|
||||
public ITReplaceSouthPanel() { |
||||
itTableEditor = new ITTableEditor(); |
||||
tableEditorPane = new ITTableEditorPane<>(itTableEditor); |
||||
RowSorter<ITTableEditor> sorter = new TableRowSorter<ITTableEditor>(itTableEditor); |
||||
tableEditorPane.getEditTable().setRowSorter(sorter); |
||||
tableEditorPane.getEditTable().setSelectionBackground(new Color(217, 235, 254)); |
||||
tableEditorPane.getEditTable().setRowHeight(tableEditorPane.getEditTable().getRowHeight() / 2 + tableEditorPane.getEditTable().getRowHeight()); |
||||
tableEditorPane.makeFace(tableEditorPane.getEditTable()); |
||||
} |
||||
|
||||
public ITTableEditorPane getTableEditorPane() { |
||||
return tableEditorPane; |
||||
} |
||||
|
||||
public void setTableEditorPane(ITTableEditorPane tableEditorPane) { |
||||
this.tableEditorPane = tableEditorPane; |
||||
} |
||||
|
||||
public ITTableEditor getItTableEditor() { |
||||
return itTableEditor; |
||||
} |
||||
|
||||
public void setItTableEditor(ITTableEditor itTableEditor) { |
||||
this.itTableEditor = itTableEditor; |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
import com.fr.design.gui.ibutton.UIToggleButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JPanel; |
||||
import java.awt.Color; |
||||
import java.awt.GridLayout; |
||||
|
||||
/** |
||||
* 左侧面板 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-09-05 |
||||
*/ |
||||
public class ITReplaceWestPanel { |
||||
JPanel leftJpanel; |
||||
|
||||
public ITReplaceWestPanel() { |
||||
|
||||
leftJpanel = new JPanel(new GridLayout(15, 1, 0, 0)); |
||||
UIToggleButton contentButton = new UIToggleButton(Toolkit.i18nText("Fine-Design_Basic_Templates_Content")); |
||||
contentButton.setSelected(true); |
||||
contentButton.setBorderPainted(false); |
||||
UIToggleButton settingButton = new UIToggleButton("//"); |
||||
settingButton.setBorderPainted(false); |
||||
leftJpanel.add(contentButton); |
||||
leftJpanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, new Color(218, 218, 221))); |
||||
leftJpanel.add(settingButton); |
||||
for (int i = 0; i < 13; i++) { |
||||
leftJpanel.add(new UILabel("")); |
||||
} |
||||
} |
||||
|
||||
public JPanel getLeftJpanel() { |
||||
return leftJpanel; |
||||
} |
||||
|
||||
public void setLeftJpanel(JPanel leftJpanel) { |
||||
this.leftJpanel = leftJpanel; |
||||
} |
||||
} |
@ -0,0 +1,102 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
import com.fr.base.TRL; |
||||
import com.fr.design.actions.replace.info.base.ITContent; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import org.omg.Messaging.SYNC_WITH_TRANSPORT; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.table.TableCellEditor; |
||||
import javax.swing.table.TableCellRenderer; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.util.ArrayList; |
||||
|
||||
import static com.fr.design.actions.replace.ui.ITTableEditorPane.getEditTable; |
||||
|
||||
/** |
||||
* 放进表格中的定位按钮 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-08-23 |
||||
*/ |
||||
public class ITTableButton extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { |
||||
|
||||
private UIButton paraButton; |
||||
|
||||
public ITTableButton() { |
||||
paraButton = new UIButton("<html><font color = 'rgb(61,153,249)'>定位</font> "); |
||||
paraButton.setVisible(true); |
||||
paraButton.setBorderPainted(false); |
||||
paraButton.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
ITContent content = (ITContent) getEditTable().getValueAt(getEditTable().getEditingRow(), 7); |
||||
if (!StringUtils.isEmpty(GeneralUtils.objectToString(content.getTrlString()))) { |
||||
ITReplaceMainDialog.setITReplaceFlag(true); |
||||
HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().navigate(new TRL(GeneralUtils.objectToString(content.getTrlString()))); |
||||
} |
||||
ITReplaceMainDialog.setITReplaceFlag(false); |
||||
} |
||||
}); |
||||
|
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取Editor的Component(编辑状态下) |
||||
* |
||||
* @param table 表格 |
||||
* @param value 传递的值 |
||||
* @param isSelected 是否选中 |
||||
* @param row 行 |
||||
* @param column 列 |
||||
* @return paraButton |
||||
*/ |
||||
@Override |
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||
return paraButton; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取Renderer的Component(正常状态下) |
||||
* |
||||
* @param table 表格 |
||||
* @param value 传递的值 |
||||
* @param isSelected 是否选中 |
||||
* @param row 行 |
||||
* @param column 列 |
||||
* @return paraButton |
||||
*/ |
||||
@Override |
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||||
return paraButton; |
||||
} |
||||
|
||||
@Override |
||||
public Object getCellEditorValue() { |
||||
return null; |
||||
} |
||||
|
||||
public UIButton getParaButton() { |
||||
return paraButton; |
||||
} |
||||
|
||||
public void setParaButton(UIButton paraButton) { |
||||
this.paraButton = paraButton; |
||||
} |
||||
} |
@ -0,0 +1,225 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
import com.fr.design.actions.replace.info.Info; |
||||
import com.fr.design.actions.replace.info.ReplaceObject; |
||||
import com.fr.design.actions.replace.info.base.ITContent; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itableeditorpane.UITableEditAction; |
||||
import com.fr.design.gui.itableeditorpane.UITableModelAdapter; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.form.ui.CheckBox; |
||||
import com.fr.function.INDEX; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
import javax.swing.*; |
||||
import java.util.ArrayList; |
||||
|
||||
/** |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-08-22 |
||||
*/ |
||||
|
||||
public class ITTableEditor extends UITableModelAdapter { |
||||
|
||||
public ITTableEditor() { |
||||
super(new String[]{ |
||||
" ", |
||||
Toolkit.i18nText("Fine-Design_Replace_Search_Content"), |
||||
Toolkit.i18nText("Fine-Design_Replace_Template_Name"), |
||||
Toolkit.i18nText("Fine-Design_Replace_Sheet_Name"), |
||||
Toolkit.i18nText("Fine-Design_Replace_Block_Name"), |
||||
Toolkit.i18nText("Fine-Design_Replace_Location"), |
||||
Toolkit.i18nText("Fine-Design_Replace_Location_Info"), |
||||
Toolkit.i18nText("Fine-Design_Replace_Operator"), |
||||
}); |
||||
|
||||
//this.createTable().getColumnModel().getColumn(4).setMaxWidth(60);
|
||||
this.setColumnClass(new Class[]{ |
||||
Boolean.class, |
||||
UILabel.class, |
||||
UILabel.class, |
||||
UILabel.class, |
||||
UILabel.class, |
||||
UILabel.class, |
||||
UILabel.class, |
||||
ITTableButton.class, |
||||
|
||||
}); |
||||
this.setDefaultEditor(ITTableButton.class, new ITTableButton()); |
||||
this.setDefaultRenderer(ITTableButton.class, new ITTableButton()); |
||||
|
||||
this.createTable().getColumnModel().getColumn(7).setMaxWidth(50); |
||||
this.createTable().getColumnModel().getColumn(0).setMaxWidth(50); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取指定单元格的值 |
||||
* |
||||
* @param rowIndex |
||||
* @param columnIndex |
||||
* @return |
||||
*/ |
||||
@Nullable |
||||
@Override |
||||
public Object getValueAt(int rowIndex, int columnIndex) { |
||||
ITContent content = (ITContent) this.getList().get(rowIndex); |
||||
ChooseIndex chooseIndex = ChooseIndex.match(columnIndex); |
||||
if (chooseIndex != null) { |
||||
return chooseIndex.returnContentObject(content); |
||||
} |
||||
return null; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 设置单元格能否编辑 |
||||
* |
||||
* @param row 行 |
||||
* @param col 列 |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public boolean isCellEditable(int row, int col) { |
||||
return col == 7 || col == 0; |
||||
} |
||||
|
||||
/** |
||||
* 创建Action |
||||
* |
||||
* @return UITableEditAction |
||||
*/ |
||||
@Override |
||||
public UITableEditAction[] createAction() { |
||||
return new UITableEditAction[0]; |
||||
} |
||||
|
||||
/** |
||||
* 添加数据 |
||||
* |
||||
* @param arrayList |
||||
*/ |
||||
public void add(ArrayList<? extends Info> arrayList) { |
||||
for (Info info : arrayList) { |
||||
addRow(info.getContent()); |
||||
fireTableDataChanged(); |
||||
} |
||||
} |
||||
|
||||
public enum ChooseIndex { |
||||
/** |
||||
* 第一列,返回选中情况 |
||||
*/ |
||||
INDEX_0(0) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return content.isSelected(); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* 第二列,展示内容 |
||||
*/ |
||||
INDEX_1(1) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return content.getShowStr(); |
||||
} |
||||
}, |
||||
/** |
||||
* 第三列,展示模板名 |
||||
*/ |
||||
INDEX_2(2) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return " " + content.getTemplateName(); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* 第四列,展示Sheet |
||||
*/ |
||||
INDEX_3(3) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return " " + content.getSheetName(); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* 第五列,展示块名、组件名 |
||||
*/ |
||||
INDEX_4(4) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return " " + content.getBlockName(); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* 第六列,展示位置 |
||||
*/ |
||||
INDEX_5(5) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return " " + content.getShowObject(); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* 第七列,展示路径 |
||||
*/ |
||||
INDEX_6(6) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return " " + content.getOtherPos(); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* 第八列,展示定位按钮 |
||||
*/ |
||||
INDEX_7(7) { |
||||
@Override |
||||
public Object returnContentObject(ITContent content) { |
||||
return content; |
||||
} |
||||
}; |
||||
|
||||
int index; |
||||
|
||||
ChooseIndex(int index) { |
||||
this.index = index; |
||||
} |
||||
|
||||
/** |
||||
* 匹配列 |
||||
* |
||||
* @param index 列序号 |
||||
* @return 选中的列 |
||||
*/ |
||||
@Nullable |
||||
public static ChooseIndex match(int index) { |
||||
ChooseIndex[] values = ChooseIndex.values(); |
||||
for (ChooseIndex value : values) { |
||||
if (value.index == index) { |
||||
return value; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 返回对应列的对应内容 |
||||
* |
||||
* @param content 存储信息的数据结构 |
||||
* @return Object |
||||
*/ |
||||
@Nullable |
||||
public Object returnContentObject(ITContent content) { |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,265 @@
|
||||
package com.fr.design.actions.replace.ui; |
||||
|
||||
import com.fr.design.actions.replace.info.base.ITContent; |
||||
import com.fr.design.border.UIRoundedBorder; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.icontainer.UIScrollPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itableeditorpane.UITableEditAction; |
||||
import com.fr.design.gui.itableeditorpane.UITableModelAdapter; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.mainframe.share.ui.base.MouseClickListener; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.table.*; |
||||
import java.awt.*; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-08-22 |
||||
*/ |
||||
public class ITTableEditorPane<T> extends BasicPane { |
||||
|
||||
public static JTable editTable; |
||||
private UITableModelAdapter<T> tableModel; |
||||
private String leftLabelName; |
||||
private JPanel buttonPane; |
||||
|
||||
public ITTableEditorPane(UITableModelAdapter<T> model) { |
||||
this.tableModel = model; |
||||
this.initComponent(model.createAction()); |
||||
//((DefaultCellEditor) editTable.getCellEditor()).setClickCountToStart(1);
|
||||
editTable.setGridColor(new Color(218, 218, 221)); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* 初始化 |
||||
* |
||||
* @param action |
||||
*/ |
||||
private void initComponent(UITableEditAction[] action) { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
JPanel pane = new JPanel(new BorderLayout(4, 4)); |
||||
this.add(pane, BorderLayout.CENTER); |
||||
UILabel l = new UILabel(leftLabelName); |
||||
editTable = tableModel.createTable(); |
||||
editTable.getTableHeader().setBackground(UIConstants.DEFAULT_BG_RULER); |
||||
editTable.addMouseListener(new MouseClickListener() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); |
||||
int col = ((JTable) e.getSource()).columnAtPoint(e.getPoint()); |
||||
if (col == 0) { |
||||
ITContent content = (ITContent) editTable.getValueAt(row, 7); |
||||
if (content.isSelected()) { |
||||
content.setSelected(false); |
||||
editTable.setValueAt(content.isSelected(), row, col); |
||||
} else { |
||||
content.setSelected(true); |
||||
editTable.setValueAt(content.isSelected(), row, col); |
||||
} |
||||
} |
||||
|
||||
} |
||||
}); |
||||
UIScrollPane scrollPane = new UIScrollPane(editTable); |
||||
scrollPane.setBorder(new UIRoundedBorder(UIConstants.TITLED_BORDER_COLOR, 1, UIConstants.ARC)); |
||||
pane.add(scrollPane, BorderLayout.CENTER); |
||||
|
||||
|
||||
} |
||||
|
||||
public UITableModelAdapter<T> getTableModel() { |
||||
return tableModel; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 表头渲染 |
||||
*/ |
||||
public static class ITHeaderRenderer implements TableCellRenderer { |
||||
JTableHeader tableHeader; |
||||
final JCheckBox selectBox; |
||||
|
||||
public ITHeaderRenderer(JTable table) { |
||||
this.tableHeader = table.getTableHeader(); |
||||
selectBox = new JCheckBox(); |
||||
selectBox.setSelected(true); |
||||
tableHeader.addMouseListener(new MouseAdapter() { |
||||
public void mouseClicked(MouseEvent e) { |
||||
if (e.getClickCount() > 0) { |
||||
//获得选中列
|
||||
int selectColumn = tableHeader.columnAtPoint(e.getPoint()); |
||||
if (selectColumn == 0) { |
||||
boolean value = !selectBox.isSelected(); |
||||
selectBox.setSelected(value); |
||||
selectAllOrNull(value); |
||||
tableHeader.repaint(); |
||||
table.repaint(); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Component getTableCellRendererComponent(JTable table, |
||||
Object value, |
||||
boolean isSelected, |
||||
boolean hasFocus, |
||||
int row, int column) { |
||||
tableHeader = table.getTableHeader(); |
||||
tableHeader.setReorderingAllowed(false); |
||||
String valueStr = (String) value; |
||||
JLabel label = new JLabel(valueStr); |
||||
label.setHorizontalAlignment(SwingConstants.LEFT); |
||||
selectBox.setHorizontalAlignment(SwingConstants.CENTER); |
||||
selectBox.setBorderPainted(true); |
||||
JComponent component = (column == 0) ? selectBox : label; |
||||
component.setForeground(tableHeader.getForeground()); |
||||
component.setBackground(tableHeader.getBackground()); |
||||
component.setFont(tableHeader.getFont()); |
||||
component.setBorder(UIManager.getBorder("TableHeader.cellBorder")); |
||||
return component; |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 设置表头属性 |
||||
* |
||||
* @param table |
||||
*/ |
||||
public static void makeFace(JTable table) { |
||||
Dimension size = table.getTableHeader().getPreferredSize(); |
||||
size.height = 26;//设置新的表头高度
|
||||
|
||||
table.getTableHeader().setBackground(new Color(232, 232, 233)); |
||||
|
||||
table.getTableHeader().setPreferredSize(size); |
||||
|
||||
table.getTableHeader().setDefaultRenderer(new ITHeaderRenderer(table)); |
||||
} |
||||
|
||||
/** |
||||
* 选中全部 |
||||
* |
||||
* @param value |
||||
*/ |
||||
public static void selectAllOrNull(Boolean value) { |
||||
for (int i = 0; i < getEditTable().getRowCount(); i++) { |
||||
((ITContent) (getEditTable().getValueAt(i, 7))).setSelected(value); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 填充数据 |
||||
* |
||||
* @param objs |
||||
*/ |
||||
public void populate(T[] objs) { |
||||
tableModel.clear(); |
||||
if (objs == null) { |
||||
return; |
||||
} |
||||
for (T obj : objs) { |
||||
tableModel.addRow(obj); |
||||
} |
||||
this.tableModel.fireTableDataChanged(); |
||||
if (objs.length > 0) { |
||||
this.editTable.getSelectionModel().setSelectionInterval(0, 0); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 更新列表内的数据 |
||||
* |
||||
* @return |
||||
*/ |
||||
public java.util.List<T> update() { |
||||
tableModel.stopCellEditing(); |
||||
return tableModel.getList(); |
||||
} |
||||
|
||||
/** |
||||
* 更新数据来源 |
||||
* |
||||
* @param list |
||||
*/ |
||||
public void update(List list) { |
||||
tableModel.stopCellEditing(); |
||||
tableModel.setList(list); |
||||
} |
||||
|
||||
/** |
||||
* 获取选中行号 |
||||
* |
||||
* @return |
||||
*/ |
||||
public int getSelectedRow() { |
||||
return this.editTable.getSelectedRow(); |
||||
} |
||||
|
||||
/** |
||||
* 获取选中列号 |
||||
* |
||||
* @return |
||||
*/ |
||||
public int getSelectedColumn() { |
||||
return this.editTable.getSelectedColumn(); |
||||
} |
||||
|
||||
/** |
||||
* 获取面板 |
||||
* |
||||
* @return |
||||
*/ |
||||
public JPanel getbuttonPane() { |
||||
return buttonPane; |
||||
} |
||||
|
||||
/** |
||||
* 停止编辑 |
||||
*/ |
||||
public void stopEditing() { |
||||
tableModel.stopCellEditing(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 设置表头是否可以改变大小 |
||||
*/ |
||||
public void setHeaderResizing(boolean resizingAllowed) { |
||||
editTable.getTableHeader().setResizingAllowed(resizingAllowed); |
||||
} |
||||
|
||||
/** |
||||
* 获取表格 |
||||
* |
||||
* @return |
||||
*/ |
||||
public static JTable getEditTable() { |
||||
return editTable; |
||||
} |
||||
|
||||
public void setEditTable(JTable editTable) { |
||||
this.editTable = editTable; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,256 @@
|
||||
package com.fr.design.actions.replace.utils; |
||||
|
||||
import com.fr.chart.chartattr.ChartCollection; |
||||
import com.fr.chart.chartglyph.ConditionAttr; |
||||
import com.fr.chart.chartglyph.ConditionCollection; |
||||
import com.fr.design.actions.replace.info.JSInfo; |
||||
import com.fr.design.actions.replace.info.base.ITContent; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.form.event.Listener; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.js.JavaScript; |
||||
import com.fr.js.JavaScriptImpl; |
||||
import com.fr.js.NameJavaScript; |
||||
import com.fr.js.NameJavaScriptGroup; |
||||
import com.fr.plugin.chart.attr.plot.VanChartPlot; |
||||
import com.fr.plugin.chart.base.AttrTooltip; |
||||
import com.fr.plugin.chart.base.VanChartHtmlLabel; |
||||
import com.fr.plugin.chart.vanchart.VanChart; |
||||
import com.fr.report.cell.Elem; |
||||
import javafx.util.Pair; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
/** |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-08-11 |
||||
*/ |
||||
public class SearchJSUtils { |
||||
|
||||
/** |
||||
* 从Listener中获取JS |
||||
*/ |
||||
public static void searchJSFromListener(ArrayList<JSInfo> jsInfos, ITContent content) { |
||||
JavaScript javaScript = ((Listener) (content.getReplaceObject())).getAction(); |
||||
if (javaScript instanceof JavaScriptImpl) { |
||||
ITContent newContent = content.copy(); |
||||
newContent.getContentObject().setJs(javaScript); |
||||
SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent)); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取HtmlLabel数组 |
||||
* |
||||
* @param collection |
||||
* @return |
||||
*/ |
||||
public static ArrayList<Pair<VanChartHtmlLabel, String>> getHtmlLabel(ChartCollection collection) { |
||||
ArrayList<Pair<VanChartHtmlLabel, String>> arrayList = new ArrayList<>(); |
||||
addHtmlLabel2Array(arrayList, collection); |
||||
return arrayList; |
||||
} |
||||
|
||||
/** |
||||
* 获取图表-样式-标签、图表-样式-提示以及图表-特效-条件显示中的HtmlLabel并加入数组 |
||||
* |
||||
* @param arrayList |
||||
* @param collection |
||||
*/ |
||||
private static void addHtmlLabel2Array(ArrayList<Pair<VanChartHtmlLabel, String>> arrayList, ChartCollection collection) { |
||||
for (int i = 0; i < collection.getChartCount(); i++) { |
||||
VanChart chart = ((VanChart) collection.getChart(i)); |
||||
int size = chart.getPlot().getConditionCollection().getConditionAttrSize(); |
||||
ConditionCollection conditionCollection = chart.getPlot().getConditionCollection(); |
||||
addAttrLabelHtmlLabel(chart, arrayList); |
||||
for (int j = 0; j < size; j++) { |
||||
searchConditionCollection(arrayList, conditionCollection.getConditionAttr(j)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 将图表-样式-标签以及图表-样式-提示中的HtmlLabel加入数组 |
||||
* |
||||
* @param chart |
||||
* @param arrayList |
||||
*/ |
||||
private static void addAttrLabelHtmlLabel(VanChart chart, ArrayList<Pair<VanChartHtmlLabel, String>> arrayList) { |
||||
VanChartPlot plot = chart.getPlot(); |
||||
addAttrToolTipCondition2Array(plot, arrayList); |
||||
if (isAttrLabelExist(plot)) { |
||||
addAttrLabelDetail2Array(plot, arrayList); |
||||
addAttrSecondLabelDetail2Array(plot, arrayList); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
private static void addAttrToolTipCondition2Array(VanChartPlot plot, ArrayList<Pair<VanChartHtmlLabel, String>> arrayList) { |
||||
if (plot.getAttrTooltipFromConditionCollection() != null && ((AttrTooltip) plot.getAttrTooltipFromConditionCollection()).isEnable() && plot.getAttrTooltipFromConditionCollection() instanceof AttrTooltip) { |
||||
arrayList.add(new Pair<>(((AttrTooltip) plot.getAttrTooltipFromConditionCollection()).getContent().getHtmlLabel(), |
||||
Toolkit.i18nText("Fine-Design_Chart_Tooltip") + "-" + Toolkit.i18nText("Fine-Design_Basic_Custom"))); |
||||
} |
||||
} |
||||
|
||||
private static void addAttrLabelDetail2Array(VanChartPlot plot, ArrayList<Pair<VanChartHtmlLabel, String>> arrayList) { |
||||
if (plot.getAttrLabelFromConditionCollection() != null |
||||
&& plot.getAttrLabelFromConditionCollection().getAttrLabelDetail() != null |
||||
&& plot.getAttrLabelFromConditionCollection().getAttrLabelDetail().getContent().getHtmlLabel() != null) { |
||||
arrayList.add(new Pair<>(plot.getAttrLabelFromConditionCollection().getAttrLabelDetail().getContent().getHtmlLabel(), Toolkit.i18nText("Fine-Design_Chart_Value_Label"))); |
||||
} |
||||
} |
||||
|
||||
private static void addAttrSecondLabelDetail2Array(VanChartPlot plot, ArrayList<Pair<VanChartHtmlLabel, String>> arrayList) { |
||||
if (plot.getAttrLabelFromConditionCollection() != null |
||||
&& plot.getAttrLabelFromConditionCollection().getSecondLabelDetail() != null |
||||
&& plot.getAttrLabelFromConditionCollection().getSecondLabelDetail().getContent().getHtmlLabel() != null) { |
||||
arrayList.add(new Pair<>(plot.getAttrLabelFromConditionCollection().getSecondLabelDetail().getContent().getHtmlLabel(), Toolkit.i18nText("Fine-Design_Chart_Category_Label"))); |
||||
} |
||||
} |
||||
|
||||
private static boolean isAttrLabelExist(VanChartPlot plot) { |
||||
return plot.getAttrLabelFromConditionCollection() != null && plot.getAttrLabelFromConditionCollection().isEnable(); |
||||
} |
||||
|
||||
/** |
||||
* 将图表-特效-条件显示中的HtmlLabel加入数组 |
||||
* |
||||
* @param arrayList |
||||
* @param conditionAttr |
||||
*/ |
||||
private static void searchConditionCollection(ArrayList<Pair<VanChartHtmlLabel, String>> arrayList, ConditionAttr conditionAttr) { |
||||
int conditionSize = conditionAttr.getDataSeriesConditionCount(); |
||||
for (int t = 0; t < conditionSize; t++) { |
||||
if (conditionAttr.getDataSeriesCondition(t) instanceof AttrTooltip) { |
||||
arrayList.add(new Pair<>(((AttrTooltip) conditionAttr.getDataSeriesCondition(t)).getContent().getHtmlLabel(), |
||||
Toolkit.i18nText("Fine-Design_Chart_Animation_Special") + "-" + Toolkit.i18nText("Fine-Design_Chart_Condition_Display"))); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取图表-特效-交互属性中的JS |
||||
* |
||||
* @param chartCollection |
||||
* @return |
||||
*/ |
||||
public static ArrayList<NameJavaScript> getNameJavaScript(ChartCollection chartCollection) { |
||||
ArrayList<NameJavaScript> nameJavaScriptArrayList = new ArrayList<>(); |
||||
for (int i = 0; i < chartCollection.getChartCount(); i++) { |
||||
VanChart chart = ((VanChart) chartCollection.getChart(i)); |
||||
NameJavaScriptGroup nameJavaScriptGroup = chart.getPlot().getHotHyperLink(); |
||||
addNameJavaScript2Array(nameJavaScriptArrayList, nameJavaScriptGroup); |
||||
|
||||
} |
||||
return nameJavaScriptArrayList; |
||||
} |
||||
|
||||
private static void addNameJavaScript2Array(ArrayList<NameJavaScript> nameJavaScriptArrayList, NameJavaScriptGroup nameJavaScriptGroup) { |
||||
if (isNameJavaScriptGroupExist(nameJavaScriptGroup)) { |
||||
for (int j = 0; j < nameJavaScriptGroup.size(); j++) { |
||||
if (nameJavaScriptGroup.getNameHyperlink(j).getJavaScript() instanceof JavaScriptImpl) { |
||||
nameJavaScriptArrayList.add(nameJavaScriptGroup.getNameHyperlink(j)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static boolean isNameJavaScriptGroupExist(NameJavaScriptGroup nameJavaScriptGroup) { |
||||
return nameJavaScriptGroup != null; |
||||
} |
||||
|
||||
/** |
||||
* 添加JSInfo到列表 |
||||
* |
||||
* @param jsInfos |
||||
* @param jsInfo |
||||
*/ |
||||
public static void addJSInfos(ArrayList<JSInfo> jsInfos, JSInfo jsInfo) { |
||||
jsInfo.setContent(jsInfo.getContent().copy()); |
||||
jsInfos.add(jsInfo); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 从HtmlLabel去获取JS |
||||
* 从图表-样式-标签以及图表-特效-条件显示获取JSInfo |
||||
* |
||||
* @param content |
||||
* @param htmlLabels |
||||
* @param jsInfos |
||||
*/ |
||||
public static void addJSInfosFromHtmlLabel(ITContent content, ArrayList<Pair<VanChartHtmlLabel, String>> htmlLabels, ArrayList<JSInfo> jsInfos) { |
||||
if (!htmlLabels.isEmpty()) { |
||||
for (Pair pair : htmlLabels) { |
||||
ITContent newContent = content.copy(); |
||||
newContent.getContentObject().setHtmlLabel((VanChartHtmlLabel) pair.getKey()); |
||||
newContent.addOtherPos(GeneralUtils.objectToString(pair.getValue())); |
||||
newContent.setReplaceObject(pair.getKey()); |
||||
SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 从NameJS类型里面拿JS |
||||
* |
||||
* @param content |
||||
* @param nameJavaScripts |
||||
* @param jsInfos |
||||
*/ |
||||
public static void addJSInfosFromNameJS(ITContent content, ArrayList<NameJavaScript> nameJavaScripts, ArrayList<JSInfo> jsInfos) { |
||||
if (!nameJavaScripts.isEmpty()) { |
||||
for (NameJavaScript nameJS : nameJavaScripts) { |
||||
ITContent newContent = content.copy(); |
||||
newContent.getContentObject().setNameJavaScript(nameJS); |
||||
newContent.setReplaceObject(nameJS); |
||||
newContent.addOtherPos(nameJS.getName()); |
||||
SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent)); |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 从超级链接里面拿JS |
||||
* |
||||
* @param elem |
||||
* @param jsInfos |
||||
* @param content |
||||
*/ |
||||
public static void addJSInfosFromHyperLink(Elem elem, ArrayList<JSInfo> jsInfos, ITContent content) { |
||||
if (elem.getNameHyperlinkGroup() != null) { |
||||
for (int j = 0; j < elem.getNameHyperlinkGroup().size(); j++) { |
||||
if ((elem.getNameHyperlinkGroup().getNameHyperlink(j).getJavaScript()) instanceof JavaScriptImpl) { |
||||
ITContent newContent = content.copy(); |
||||
newContent.getContentObject().setNameJavaScript(elem.getNameHyperlinkGroup().getNameHyperlink(j)); |
||||
newContent.addOtherPos(Toolkit.i18nText("Fine-Design_Report_Hyperlink")); |
||||
newContent.setReplaceObject(elem.getNameHyperlinkGroup().getNameHyperlink(j)); |
||||
newContent.addOtherPos(elem.getNameHyperlinkGroup().getNameHyperlink(j).getName()); |
||||
SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 从Action中拿JS |
||||
* |
||||
* @param jsInfos |
||||
* @param content |
||||
*/ |
||||
public static void selectJSAction(ArrayList<JSInfo> jsInfos, ITContent content) { |
||||
for (int i = 0; i < ((Widget) (content.getReplaceObject())).getListenerSize(); i++) { |
||||
Listener listener = ((Widget) (content.getReplaceObject())).getListener(i); |
||||
ITContent newContent = content.copy(); |
||||
newContent.getContentObject().setListener(listener); |
||||
newContent.addOtherPos(listener.getName()); |
||||
newContent.setReplaceObject(listener); |
||||
SearchJSUtils.searchJSFromListener(jsInfos, newContent); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
|
||||
package com.fr.design.actions.replace.utils; |
||||
|
||||
|
||||
import com.fr.design.actions.replace.info.DealWithInfoValue; |
||||
import com.fr.design.actions.replace.info.Info; |
||||
import com.fr.design.actions.replace.info.JSInfo; |
||||
import com.fr.third.org.apache.poi.hssf.record.formula.functions.Int; |
||||
import javafx.util.Pair; |
||||
import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* 用来处理展示内容的工具类(截取、高亮) |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-08-23 |
||||
*/ |
||||
public class ShowValueUtils { |
||||
|
||||
/** |
||||
* 获取除内容外其他一次性展示所有的内容(名称、水印...) |
||||
* |
||||
* @param str |
||||
* @param searchStr |
||||
* @return |
||||
*/ |
||||
public static String getCommonString(String str, String searchStr) { |
||||
if (StringUtils.isEmpty(searchStr)) { |
||||
return str; |
||||
} else { |
||||
return "<html><body><div><nobr>" + |
||||
replaceAll(str, searchStr, "<font color = 'rgb(61,153,249)'>" + searchStr + "</font>") + |
||||
"</nobr></div></body></html>"; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 可以替换括号的replaceAll |
||||
* |
||||
* @param str 原字符串 |
||||
* @param regex 要被替换的内容 |
||||
* @param replacement 要用来替换进去的内容 |
||||
* @return 替换后的字符串 |
||||
*/ |
||||
public static String replaceAll(String str, String regex, String replacement) { |
||||
return str.replaceAll(Pattern.quote(regex), replacement); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取匹配的字符串的位置(开始位置,结束位置) |
||||
* |
||||
* @param str 原字符串 |
||||
* @param find 要查找的内容 |
||||
* @return 存储匹配的字符串的位置的列表 |
||||
*/ |
||||
public static ArrayList<Pair<Integer, Integer>> getStringStartAndEndIndex(String str, String find) { |
||||
ArrayList<Pair<Integer, Integer>> pairs = new ArrayList<>(); |
||||
int frontLength = 0;//定义该变量用于记录匹配元素前面的长度
|
||||
StringBuffer result = new StringBuffer(); |
||||
if (StringUtils.isEmpty(find)) { |
||||
return pairs; |
||||
} |
||||
while (str.contains(find)) {//只要该str字符串中有匹配的元素,才进行以下操作
|
||||
int index = str.indexOf(find);//定义该变量用于记录匹配的元素在当前字符串的位置
|
||||
pairs.add(new Pair<>(index + frontLength, index + frontLength + find.length())); |
||||
frontLength += (index + find.length()); |
||||
str = str.substring(index + find.length());//将字符串中匹配元素的前面部分及其本身截取,留下后面的部分
|
||||
|
||||
} |
||||
return pairs; |
||||
} |
||||
|
||||
/** |
||||
* 更新高亮状态 |
||||
* |
||||
* @param info |
||||
* @param replaceStr |
||||
*/ |
||||
public static void updateHighlight(Info info, String replaceStr) { |
||||
String s = info.getInfoShowStr(info); |
||||
s = ShowValueUtils.replaceAll(s, info.getContent().getLastSearchStr(), "<font color = 'rgb(61,153,249)'>" + replaceStr + "</font>"); |
||||
info.getContent().setShowStr( |
||||
"<html><body><div><nobr>" + s + "</nobr></div></body></html>" |
||||
); |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue