|
|
|
@ -1,27 +1,30 @@
|
|
|
|
|
package com.fr.quickeditor; |
|
|
|
|
|
|
|
|
|
import com.fr.design.actions.utils.DeprecatedActionManager; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.actions.UpdateAction; |
|
|
|
|
import com.fr.design.actions.core.ActionFactory; |
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
import com.fr.design.gui.iscrollbar.UIScrollBar; |
|
|
|
|
import com.fr.design.gui.itextfield.UITextField; |
|
|
|
|
import com.fr.design.layout.TableLayout; |
|
|
|
|
import com.fr.design.layout.TableLayoutHelper; |
|
|
|
|
import com.fr.design.mainframe.CellElementPropertyPane; |
|
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
|
import com.fr.design.mainframe.ElementCasePane; |
|
|
|
|
import com.fr.design.menu.MenuKeySet; |
|
|
|
|
import com.fr.design.menu.ShortCut; |
|
|
|
|
import com.fr.design.selection.QuickEditor; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.general.IOUtils; |
|
|
|
|
import com.fr.general.Inter; |
|
|
|
|
import com.fr.grid.selection.CellSelection; |
|
|
|
|
import com.fr.report.cell.TemplateCellElement; |
|
|
|
|
import com.fr.stable.ColumnRow; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.event.PopupMenuEvent; |
|
|
|
|
import javax.swing.event.PopupMenuListener; |
|
|
|
|
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.awt.event.*; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author zhou, yaoh.wu |
|
|
|
@ -30,22 +33,78 @@ import java.awt.event.MouseEvent;
|
|
|
|
|
*/ |
|
|
|
|
public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> { |
|
|
|
|
|
|
|
|
|
/*滚动条相关配置*/ |
|
|
|
|
private static final int MAXVALUE = 100; |
|
|
|
|
private static final int TITLE_HEIGHT = 50; |
|
|
|
|
private static final int MOUSE_WHEEL_SPEED = 5; |
|
|
|
|
private static final int CONTENT_PANE_WIDTH_GAP = 4; |
|
|
|
|
private static final int SCROLLBAR_WIDTH = 8; |
|
|
|
|
private int maxHeight = 280; |
|
|
|
|
/*面板配置*/ |
|
|
|
|
protected UITextField columnRowTextField; |
|
|
|
|
protected TemplateCellElement cellElement; |
|
|
|
|
private UIComboBox comboBox; |
|
|
|
|
private UpdateAction[] cellInsertActions; |
|
|
|
|
private int selectedIndex; |
|
|
|
|
private JPanel leftContentPane; |
|
|
|
|
private UIScrollBar scrollBar; |
|
|
|
|
/*占位label*/ |
|
|
|
|
protected static UILabel emptyLabel = new UILabel(); |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
emptyLabel.setPreferredSize(new Dimension(60, 20)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public CellQuickEditor() { |
|
|
|
|
|
|
|
|
|
scrollBar = new UIScrollBar(UIScrollBar.VERTICAL) { |
|
|
|
|
@Override |
|
|
|
|
public int getVisibleAmount() { |
|
|
|
|
int preferredHeight = leftContentPane.getPreferredSize().height; |
|
|
|
|
int e = MAXVALUE * (maxHeight) / preferredHeight; |
|
|
|
|
setVisibleAmount(e); |
|
|
|
|
return e; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getMaximum() { |
|
|
|
|
return MAXVALUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
scrollBar.addAdjustmentListener(new AdjustmentListener() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void adjustmentValueChanged(AdjustmentEvent e) { |
|
|
|
|
doLayout(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.addMouseWheelListener(new MouseWheelListener() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseWheelMoved(MouseWheelEvent e) { |
|
|
|
|
int value = scrollBar.getValue(); |
|
|
|
|
value += MOUSE_WHEEL_SPEED * e.getWheelRotation(); |
|
|
|
|
scrollBar.setValue(value); |
|
|
|
|
doLayout(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
double p = TableLayout.PREFERRED; |
|
|
|
|
double f = TableLayout.FILL; |
|
|
|
|
double[] columnSize = {p, f}; |
|
|
|
|
double[] rowSize = {p, p}; |
|
|
|
|
JComponent centerBody = createCenterBody(); |
|
|
|
|
centerBody.setBorder(BorderFactory.createMatteBorder(0, 10, 0, 0, this.getBackground())); |
|
|
|
|
Component[][] components = new Component[][]{ |
|
|
|
|
new Component[]{initTopContent(), null}, |
|
|
|
|
new Component[]{createCenterBody(), null} |
|
|
|
|
new Component[]{centerBody, null} |
|
|
|
|
}; |
|
|
|
|
JPanel panel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
|
|
|
|
this.setLayout(new BorderLayout()); |
|
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); |
|
|
|
|
this.add(panel, BorderLayout.CENTER); |
|
|
|
|
leftContentPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
|
|
|
|
this.setLayout(new BarLayout()); |
|
|
|
|
this.add(scrollBar); |
|
|
|
|
this.add(leftContentPane); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -58,33 +117,70 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
|
|
|
|
|
cellLabel.setPreferredSize(new Dimension(60, 20)); |
|
|
|
|
UILabel insertContentLabel = new UILabel(Inter.getLocText("HF-Insert_Content")); |
|
|
|
|
insertContentLabel.setPreferredSize(new Dimension(60, 20)); |
|
|
|
|
UIButton cellElementEditButton = initCellElementEditButton(); |
|
|
|
|
UIComboBox cellElementEditButton = initCellElementEditComboBox(); |
|
|
|
|
Component[][] components = new Component[][]{ |
|
|
|
|
new Component[]{cellLabel, columnRowTextField = initColumnRowTextField()}, |
|
|
|
|
new Component[]{insertContentLabel, cellElementEditButton}, |
|
|
|
|
}; |
|
|
|
|
JPanel topContent = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
|
|
|
|
topContent.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 15)); |
|
|
|
|
topContent.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
|
|
|
|
return topContent; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化添加按钮 |
|
|
|
|
* TODO 9.0 换成下拉菜单后原来的快捷键不好处理,先跳过。 |
|
|
|
|
* |
|
|
|
|
* @return UIButton |
|
|
|
|
*/ |
|
|
|
|
private UIButton initCellElementEditButton() { |
|
|
|
|
final UIButton cellElementEditButton = new UIButton(IOUtils.readIcon("/com/fr/design/images/buttonicon/add.png")); |
|
|
|
|
cellElementEditButton.addMouseListener(new MouseAdapter() { |
|
|
|
|
private UIComboBox initCellElementEditComboBox() { |
|
|
|
|
final String[] items = getDefaultComboBoxItems(); |
|
|
|
|
comboBox = new UIComboBox(items); |
|
|
|
|
final Object comboBoxSelected = getComboBoxSelected(); |
|
|
|
|
if (comboBoxSelected != null) { |
|
|
|
|
comboBox.setSelectedItem(((ShortCut) comboBoxSelected).getMenuKeySet().getMenuKeySetName()); |
|
|
|
|
} else { |
|
|
|
|
comboBox.setSelectedIndex(1); |
|
|
|
|
} |
|
|
|
|
comboBox.addPopupMenuListener(new PopupMenuListener() { |
|
|
|
|
@Override |
|
|
|
|
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
|
|
|
|
if (cellInsertActions == null) { |
|
|
|
|
cellInsertActions = ActionFactory.createCellInsertAction(ElementCasePane.class, tc); |
|
|
|
|
} |
|
|
|
|
// 这边重新获取是因为要根据JTemplate做一个过滤
|
|
|
|
|
ArrayList<String> arrayList = new ArrayList<String>(); |
|
|
|
|
for (UpdateAction action : cellInsertActions) { |
|
|
|
|
arrayList.add(action.getMenuKeySet().getMenuKeySetName()); |
|
|
|
|
} |
|
|
|
|
comboBox.setModel(new DefaultComboBoxModel<>(arrayList.toArray(new String[arrayList.size()]))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mousePressed(MouseEvent evt) { |
|
|
|
|
GUICoreUtils.showPopMenuWithParentWidth(DeprecatedActionManager.getCellMenu(tc).createJPopupMenu(), cellElementEditButton, 0, cellElementEditButton.getY() - 6); |
|
|
|
|
public void popupMenuCanceled(PopupMenuEvent e) { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return cellElementEditButton; |
|
|
|
|
comboBox.addActionListener(new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
selectedIndex = comboBox.getSelectedIndex(); |
|
|
|
|
cellInsertActions[selectedIndex].actionPerformed(e); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return comboBox; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String[] getDefaultComboBoxItems() { |
|
|
|
|
MenuKeySet[] cellInsertActionNames = ActionFactory.createCellInsertActionName(); |
|
|
|
|
ArrayList<String> names = new ArrayList<>(); |
|
|
|
|
for (MenuKeySet cellInsertActionName : cellInsertActionNames) { |
|
|
|
|
names.add(cellInsertActionName.getMenuKeySetName()); |
|
|
|
|
} |
|
|
|
|
return names.toArray(new String[names.size()]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -130,6 +226,14 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
|
|
|
|
|
*/ |
|
|
|
|
public abstract JComponent createCenterBody(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化下拉框中的类型 |
|
|
|
|
* |
|
|
|
|
* @return JComponent 待显示的详细信息面板 |
|
|
|
|
*/ |
|
|
|
|
public abstract Object getComboBoxSelected(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 刷新 |
|
|
|
|
*/ |
|
|
|
@ -146,4 +250,55 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
|
|
|
|
|
* 刷新详细信息 |
|
|
|
|
*/ |
|
|
|
|
protected abstract void refreshDetails(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 属性面板的滚动条和内容区域的布局管理类 |
|
|
|
|
* yaoh.wu 由于这边不能继承{@link com.fr.design.mainframe.AbstractAttrPane.BarLayout},所以冗余了一份滚动条代码进来 |
|
|
|
|
* |
|
|
|
|
* @see com.fr.design.mainframe.AbstractAttrPane.BarLayout |
|
|
|
|
*/ |
|
|
|
|
protected class BarLayout implements LayoutManager { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void addLayoutComponent(String name, Component comp) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void removeLayoutComponent(Component comp) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Dimension preferredLayoutSize(Container parent) { |
|
|
|
|
return leftContentPane.getPreferredSize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Dimension minimumLayoutSize(Container parent) { |
|
|
|
|
return leftContentPane.getMinimumSize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void layoutContainer(Container parent) { |
|
|
|
|
maxHeight = CellElementPropertyPane.getInstance().getHeight() - TITLE_HEIGHT; |
|
|
|
|
int beginY; |
|
|
|
|
if ((MAXVALUE - scrollBar.getVisibleAmount()) == 0) { |
|
|
|
|
beginY = 0; |
|
|
|
|
} else { |
|
|
|
|
int preferredHeight = leftContentPane.getPreferredSize().height; |
|
|
|
|
int value = scrollBar.getValue(); |
|
|
|
|
beginY = value * (preferredHeight - maxHeight) / (MAXVALUE - scrollBar.getVisibleAmount()); |
|
|
|
|
} |
|
|
|
|
int width = parent.getWidth(); |
|
|
|
|
int height = parent.getHeight(); |
|
|
|
|
if (leftContentPane.getPreferredSize().height > maxHeight) { |
|
|
|
|
leftContentPane.setBounds(0, -beginY, width - scrollBar.getWidth() - CONTENT_PANE_WIDTH_GAP, height + beginY); |
|
|
|
|
scrollBar.setBounds(width - scrollBar.getWidth() - 1, 0, scrollBar.getWidth(), height); |
|
|
|
|
} else { |
|
|
|
|
leftContentPane.setBounds(0, 0, width - SCROLLBAR_WIDTH - CONTENT_PANE_WIDTH_GAP, height); |
|
|
|
|
} |
|
|
|
|
leftContentPane.validate(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |