|
|
@ -1,6 +1,6 @@ |
|
|
|
package com.fr.design.gui.controlpane; |
|
|
|
package com.fr.design.gui.controlpane; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilist.ListModelElement; |
|
|
|
import com.fr.design.gui.ilist.ListModelElement; |
|
|
|
import com.fr.stable.Nameable; |
|
|
|
import com.fr.stable.Nameable; |
|
|
@ -8,7 +8,6 @@ import sun.swing.DefaultLookup; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
import javax.swing.*; |
|
|
|
import javax.swing.border.Border; |
|
|
|
import javax.swing.border.Border; |
|
|
|
import javax.swing.border.EmptyBorder; |
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.awt.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -19,18 +18,19 @@ import java.awt.*; |
|
|
|
public class UINameableListCellRenderer extends |
|
|
|
public class UINameableListCellRenderer extends |
|
|
|
JPanel implements ListCellRenderer { |
|
|
|
JPanel implements ListCellRenderer { |
|
|
|
|
|
|
|
|
|
|
|
private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1); |
|
|
|
private static final Color BORDER_COLOR = UIManager.getColor("defaultBorderColor"); |
|
|
|
private static final Border DEFAULT_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1); |
|
|
|
private static final int BUTTON_WIDTH = UIManager.getInt("List.cellRender.button.width"); |
|
|
|
private static final Color BORDER_COLOR = new Color(201, 198, 184); |
|
|
|
private static final int BUTTON_HEIGHT = UIManager.getInt("List.cellRender.button.height"); |
|
|
|
protected static Border noFocusBorder = DEFAULT_NO_FOCUS_BORDER; |
|
|
|
|
|
|
|
private static final int BUTTON_WIDTH = 25; |
|
|
|
|
|
|
|
private UILabel editButton; // "编辑按钮",实际上是一个 UILabel,由列表项(UIListControlPane)统一处理点击事件
|
|
|
|
private UILabel editButton; // "编辑按钮",实际上是一个 UILabel,由列表项(UIListControlPane)统一处理点击事件
|
|
|
|
private UILabel label; |
|
|
|
private UILabel label; |
|
|
|
private boolean isNewStyle; |
|
|
|
private boolean isNewStyle; |
|
|
|
private NameableCreator[] creators; |
|
|
|
private NameableCreator[] creators; |
|
|
|
private Color initialLabelForeground; |
|
|
|
private Color initialLabelForeground; |
|
|
|
|
|
|
|
|
|
|
|
public UINameableListCellRenderer( boolean isNewStyle, NameableCreator[] creators) { |
|
|
|
private static final Icon LIST_EDIT_ICON = new LazyIcon("tool_edit"); |
|
|
|
|
|
|
|
private static final Icon CPT_ICON = new LazyIcon("cpt_icon"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UINameableListCellRenderer(boolean isNewStyle, NameableCreator[] creators) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
this.isNewStyle = isNewStyle; |
|
|
|
this.isNewStyle = isNewStyle; |
|
|
|
this.creators = creators; |
|
|
|
this.creators = creators; |
|
|
@ -43,11 +43,11 @@ public class UINameableListCellRenderer extends |
|
|
|
private void initComponents() { |
|
|
|
private void initComponents() { |
|
|
|
editButton = new UILabel() { |
|
|
|
editButton = new UILabel() { |
|
|
|
public Dimension getPreferredSize() { |
|
|
|
public Dimension getPreferredSize() { |
|
|
|
return new Dimension(BUTTON_WIDTH, BUTTON_WIDTH); |
|
|
|
return new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
editButton.setIcon(isNewStyle ? UIConstants.LIST_EDIT_ICON : UIConstants.CPT_ICON); |
|
|
|
editButton.setIcon(isNewStyle ? LIST_EDIT_ICON : CPT_ICON); |
|
|
|
editButton.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, UIConstants.LIST_ITEM_SPLIT_LINE)); |
|
|
|
editButton.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, BORDER_COLOR)); |
|
|
|
editButton.setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
editButton.setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
label = new UILabel(); |
|
|
|
label = new UILabel(); |
|
|
|
label.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
|
|
|
label.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
|
|
@ -58,7 +58,7 @@ public class UINameableListCellRenderer extends |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Border getNoFocusBorder() { |
|
|
|
private Border getNoFocusBorder() { |
|
|
|
return BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LIST_ITEM_SPLIT_LINE); |
|
|
|
return BorderFactory.createMatteBorder(0, 0, 1, 0, BORDER_COLOR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setText(String t) { |
|
|
|
private void setText(String t) { |
|
|
@ -87,18 +87,13 @@ public class UINameableListCellRenderer extends |
|
|
|
if (isSelected) { |
|
|
|
if (isSelected) { |
|
|
|
setBackground(bg == null ? list.getSelectionBackground() : bg); |
|
|
|
setBackground(bg == null ? list.getSelectionBackground() : bg); |
|
|
|
setForeground(fg == null ? list.getSelectionForeground() : fg); |
|
|
|
setForeground(fg == null ? list.getSelectionForeground() : fg); |
|
|
|
label.setForeground(Color.WHITE); |
|
|
|
} else { |
|
|
|
if (isNewStyle) { |
|
|
|
setBackground(UIManager.getColor("List.cellRender.background")); |
|
|
|
editButton.setIcon(UIConstants.LIST_EDIT_WHITE_ICON); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
setBackground(list.getBackground()); |
|
|
|
|
|
|
|
setForeground(list.getForeground()); |
|
|
|
setForeground(list.getForeground()); |
|
|
|
label.setForeground(initialLabelForeground); |
|
|
|
label.setForeground(initialLabelForeground); |
|
|
|
if (isNewStyle) { |
|
|
|
|
|
|
|
editButton.setIcon(UIConstants.LIST_EDIT_ICON); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isNewStyle) { |
|
|
|
|
|
|
|
editButton.setIcon(LIST_EDIT_ICON); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setText((value == null) ? "" : value.toString()); |
|
|
|
setText((value == null) ? "" : value.toString()); |
|
|
@ -107,11 +102,11 @@ public class UINameableListCellRenderer extends |
|
|
|
setFont(list.getFont()); |
|
|
|
setFont(list.getFont()); |
|
|
|
|
|
|
|
|
|
|
|
if (value instanceof ListModelElement) { |
|
|
|
if (value instanceof ListModelElement) { |
|
|
|
Nameable wrappee = ((ListModelElement) value).wrapper; |
|
|
|
Nameable wrapper = ((ListModelElement) value).wrapper; |
|
|
|
this.setText(((ListModelElement) value).wrapper.getName()); |
|
|
|
this.setText(((ListModelElement) value).wrapper.getName()); |
|
|
|
|
|
|
|
|
|
|
|
for (NameableCreator creator : creators) { |
|
|
|
for (NameableCreator creator : creators) { |
|
|
|
if (creator.menuIcon() != null && creator.acceptObject2Populate(wrappee) != null) { |
|
|
|
if (creator.menuIcon() != null && creator.acceptObject2Populate(wrapper) != null) { |
|
|
|
this.setToolTipText(creator.createTooltip()); |
|
|
|
this.setToolTipText(creator.createTooltip()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|