|
|
@ -1,35 +1,27 @@ |
|
|
|
package com.fr.design.designer.ui; |
|
|
|
package com.fr.design.designer.ui; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.designer.beans.AdapterBus; |
|
|
|
|
|
|
|
import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter; |
|
|
|
|
|
|
|
import com.fr.design.designer.beans.events.DesignerEvent; |
|
|
|
import com.fr.design.designer.creator.XCreator; |
|
|
|
import com.fr.design.designer.creator.XCreator; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
|
|
|
|
import com.fr.design.layout.VerticalFlowLayout; |
|
|
|
import com.fr.design.mainframe.CoverReportPane; |
|
|
|
import com.fr.design.mainframe.CoverReportPane; |
|
|
|
import com.fr.design.mainframe.EditingMouseListener; |
|
|
|
import com.fr.design.mainframe.EditingMouseListener; |
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
import com.fr.general.IOUtils; |
|
|
|
import com.fr.general.IOUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import java.awt.Color; |
|
|
|
|
|
|
|
import java.awt.Component; |
|
|
|
import javax.swing.*; |
|
|
|
import java.awt.Container; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
import java.awt.Insets; |
|
|
|
|
|
|
|
import java.awt.LayoutManager; |
|
|
|
|
|
|
|
import java.awt.Rectangle; |
|
|
|
|
|
|
|
import java.awt.RenderingHints; |
|
|
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import javax.swing.AbstractButton; |
|
|
|
import java.util.ArrayList; |
|
|
|
import javax.swing.Icon; |
|
|
|
import java.util.List; |
|
|
|
import javax.swing.JButton; |
|
|
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
import javax.swing.JToggleButton; |
|
|
|
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author hades |
|
|
|
* @author hades |
|
|
@ -40,25 +32,39 @@ public class PopupControlPanel extends JPanel { |
|
|
|
|
|
|
|
|
|
|
|
private static final int ARC_VALUE = 4; |
|
|
|
private static final int ARC_VALUE = 4; |
|
|
|
private static final Color FILLED_COLOR = new Color(60, 63, 65); |
|
|
|
private static final Color FILLED_COLOR = new Color(60, 63, 65); |
|
|
|
private static final int V_GAP = 10; |
|
|
|
private static final int BUTTON_SIZE = 16; |
|
|
|
private static final int H_GAP = 2; |
|
|
|
private static final int BUTTON_MARGIN = 4; |
|
|
|
|
|
|
|
private static final int PANE_WIDTH = BUTTON_SIZE + BUTTON_MARGIN * 2; // 24
|
|
|
|
|
|
|
|
|
|
|
|
private Dimension defaultDimension = new Dimension(20, 60); |
|
|
|
private final Dimension defaultDimension = new Dimension(PANE_WIDTH, 0); |
|
|
|
private Rectangle rectangle; |
|
|
|
private Rectangle rectangle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<JComponent> buttons = new ArrayList<>(); |
|
|
|
private final JButton editButton; |
|
|
|
private final JButton editButton; |
|
|
|
private final JButton settingButton; |
|
|
|
private final JButton settingButton; |
|
|
|
private final JToggleButton toggleButton; |
|
|
|
private final JToggleButton toggleButton; |
|
|
|
private final XCreator creator; |
|
|
|
private final XCreator creator; |
|
|
|
private final UILabel firstLabel; |
|
|
|
|
|
|
|
private final UILabel secondLabel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PopupControlPanel(XCreator creator, FormDesigner designer) { |
|
|
|
public PopupControlPanel(XCreator creator, FormDesigner designer) { |
|
|
|
if (creator.isShared()) { |
|
|
|
setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0)); |
|
|
|
defaultDimension = new Dimension(20, 85); |
|
|
|
setBorder(BorderFactory.createEmptyBorder()); |
|
|
|
} |
|
|
|
|
|
|
|
setLayout(getCustomLayout()); |
|
|
|
|
|
|
|
this.creator = creator; |
|
|
|
this.creator = creator; |
|
|
|
editButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_edit.png"), Toolkit.i18nText("Fine-Design_Form_Edit_Widget")); |
|
|
|
|
|
|
|
|
|
|
|
editButton = createEditButton(designer); |
|
|
|
|
|
|
|
toggleButton = createAspectRatioLockedButton(designer); |
|
|
|
|
|
|
|
settingButton = createSettingButton(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addButton(editButton, 0); |
|
|
|
|
|
|
|
addButton(toggleButton, 1); |
|
|
|
|
|
|
|
addButton(settingButton, 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setButtonVisible(editButton, true); |
|
|
|
|
|
|
|
setButtonVisible(toggleButton, false); |
|
|
|
|
|
|
|
setButtonVisible(settingButton, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JButton createEditButton(FormDesigner designer) { |
|
|
|
|
|
|
|
JButton editButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_edit.png"), Toolkit.i18nText("Fine-Design_Form_Edit_Widget")); |
|
|
|
editButton.addMouseListener(new MouseAdapter() { |
|
|
|
editButton.addMouseListener(new MouseAdapter() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
@ -71,102 +77,99 @@ public class PopupControlPanel extends JPanel { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
settingButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_setting.png"), Toolkit.i18nText("Fine-Design_Share_Help_Settings")); |
|
|
|
return editButton; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
settingButton.addActionListener(new ActionListener() { |
|
|
|
private JToggleButton createAspectRatioLockedButton(FormDesigner designer) { |
|
|
|
|
|
|
|
JToggleButton button = new JToggleButton(IOUtils.readIcon("/com/fr/design/images/control/edit_unlock.png")); |
|
|
|
|
|
|
|
initButtonStyle(button); |
|
|
|
|
|
|
|
button.setSelectedIcon(IOUtils.readIcon("com/fr/design/images/control/edit_lock.png")); |
|
|
|
|
|
|
|
button.setToolTipText(Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio")); |
|
|
|
|
|
|
|
button.addActionListener(new ActionListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
CoverReportPane.showShareConfig(creator.toData()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
toggleButton = new JToggleButton(IOUtils.readIcon("/com/fr/design/images/control/edit_lock.png")); |
|
|
|
|
|
|
|
initButtonStyle(toggleButton); |
|
|
|
|
|
|
|
toggleButton.setSelectedIcon(IOUtils.readIcon("com/fr/design/images/control/edit_unlock.png")); |
|
|
|
|
|
|
|
toggleButton.setToolTipText(Toolkit.i18nText("Fine-Design_Form_Lock_Widget_Ratio")); |
|
|
|
|
|
|
|
toggleButton.addChangeListener(new ChangeListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
|
|
|
JToggleButton toggleBtn = (JToggleButton) e.getSource(); |
|
|
|
JToggleButton toggleBtn = (JToggleButton) e.getSource(); |
|
|
|
String toolTipText = toggleBtn.isSelected() ? Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio") : Toolkit.i18nText("Fine-Design_Form_Lock_Widget_Ratio"); |
|
|
|
String toolTipText = toggleBtn.isSelected() ? Toolkit.i18nText("Fine-Design_Form_Lock_Widget_Ratio") : Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio"); |
|
|
|
toggleBtn.setToolTipText(toolTipText); |
|
|
|
toggleBtn.setToolTipText(toolTipText); |
|
|
|
|
|
|
|
creator.toData().setAspectRatioLocked(toggleBtn.isSelected()); |
|
|
|
|
|
|
|
designer.getEditListenerTable().fireCreatorModified(creator, DesignerEvent.CREATOR_RESIZED); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
return button; |
|
|
|
firstLabel = createLabel(); |
|
|
|
|
|
|
|
secondLabel = createLabel(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add(editButton); |
|
|
|
|
|
|
|
add(toggleButton); |
|
|
|
|
|
|
|
add(settingButton); |
|
|
|
|
|
|
|
add(firstLabel); |
|
|
|
|
|
|
|
add(secondLabel); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected LayoutManager getCustomLayout() { |
|
|
|
private JButton createSettingButton() { |
|
|
|
return new LayoutManager() { |
|
|
|
JButton settingButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_setting.png"), Toolkit.i18nText("Fine-Design_Share_Help_Settings")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settingButton.addActionListener(new ActionListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void removeLayoutComponent(Component comp) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
|
|
CoverReportPane.showShareConfig(creator.toData()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return settingButton; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private void addButton(JComponent component, int index) { |
|
|
|
public Dimension preferredLayoutSize(Container parent) { |
|
|
|
buttons.add(index, component); |
|
|
|
return defaultDimension; |
|
|
|
if (index > 0) { |
|
|
|
} |
|
|
|
this.add(new SeparatorLabel(), index * 2 - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.add(component, index * 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private void setButtonVisible(JComponent component, boolean visible) { |
|
|
|
public Dimension minimumLayoutSize(Container parent) { |
|
|
|
int index = buttons.indexOf(component); |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
boolean hasVisibleButtonBeforeCurrent = false; |
|
|
|
public void layoutContainer(Container parent) { |
|
|
|
for (int i = 0; i < index; i++) { |
|
|
|
int width = parent.getPreferredSize().width; |
|
|
|
if (buttons.get(i).isVisible()) { |
|
|
|
int buttonWidth = editButton.getPreferredSize().width; |
|
|
|
hasVisibleButtonBeforeCurrent = true; |
|
|
|
int buttonHeight = editButton.getPreferredSize().height; |
|
|
|
break; |
|
|
|
int x = (width - buttonWidth) / 2; |
|
|
|
|
|
|
|
editButton.setBounds(x, V_GAP, buttonWidth, buttonHeight); |
|
|
|
|
|
|
|
firstLabel.setBounds(x, V_GAP + editButton.getHeight() + V_GAP / 2, buttonWidth, buttonHeight); |
|
|
|
|
|
|
|
toggleButton.setBounds(x, V_GAP * 2 + editButton.getHeight(), buttonWidth, buttonHeight); |
|
|
|
|
|
|
|
if (creator.isShared()) { |
|
|
|
|
|
|
|
secondLabel.setBounds(x, V_GAP * 2 + editButton.getHeight() + toggleButton.getHeight() + V_GAP / 2, buttonWidth, buttonHeight); |
|
|
|
|
|
|
|
settingButton.setBounds(x, V_GAP * 3 + editButton.getHeight() + toggleButton.getHeight(), buttonWidth, buttonHeight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
if (hasVisibleButtonBeforeCurrent) { |
|
|
|
public void addLayoutComponent(String name, Component comp) { |
|
|
|
buttons.get(index).setVisible(visible); |
|
|
|
|
|
|
|
getComponent(2 * index - 1).setVisible(visible); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 在当前按钮之前没有可见的按钮了
|
|
|
|
|
|
|
|
if (index > 0) { |
|
|
|
|
|
|
|
getComponent(2 * index - 1).setVisible(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
buttons.get(index).setVisible(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!visible) { |
|
|
|
|
|
|
|
// 如果当前按钮设置为不可见,且在当前按钮之前的其他按钮也不可见,则下一个可见按钮前无分割线
|
|
|
|
|
|
|
|
for (int i = index + 1; i < buttons.size(); i++) { |
|
|
|
|
|
|
|
if (buttons.get(i).isVisible()) { |
|
|
|
|
|
|
|
if (i > 0) { |
|
|
|
|
|
|
|
getComponent(2 * i - 1).setVisible(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JButton createNormalButton(Icon icon, String toolTipText) { |
|
|
|
private JButton createNormalButton(Icon icon, String toolTipText) { |
|
|
|
JButton button = new JButton(icon); |
|
|
|
JButton button = new JButton(icon); |
|
|
|
|
|
|
|
button.setPreferredSize(new Dimension(BUTTON_SIZE + 2 * BUTTON_MARGIN, BUTTON_SIZE + 2 * BUTTON_MARGIN)); |
|
|
|
|
|
|
|
button.setBorder(BorderFactory.createEmptyBorder(BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN)); |
|
|
|
initButtonStyle(button); |
|
|
|
initButtonStyle(button); |
|
|
|
button.setToolTipText(toolTipText); |
|
|
|
button.setToolTipText(toolTipText); |
|
|
|
return button; |
|
|
|
return button; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initButtonStyle(AbstractButton button) { |
|
|
|
private void initButtonStyle(AbstractButton button) { |
|
|
|
|
|
|
|
button.setPreferredSize(new Dimension(BUTTON_SIZE + 2 * BUTTON_MARGIN, BUTTON_SIZE + 2 * BUTTON_MARGIN)); |
|
|
|
|
|
|
|
button.setBorder(BorderFactory.createEmptyBorder(BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN)); |
|
|
|
button.setBorderPainted(false); |
|
|
|
button.setBorderPainted(false); |
|
|
|
button.setBorder(null); |
|
|
|
|
|
|
|
button.setMargin(new Insets(0, 0, 0, 0)); |
|
|
|
|
|
|
|
button.setContentAreaFilled(false); |
|
|
|
button.setContentAreaFilled(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private UILabel createLabel() { |
|
|
|
|
|
|
|
return new UILabel() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void paint(Graphics g) { |
|
|
|
|
|
|
|
super.paint(g); |
|
|
|
|
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
|
|
|
g2d.setColor(Color.WHITE); |
|
|
|
|
|
|
|
g2d.drawLine(H_GAP, 0, toggleButton.getWidth() - H_GAP, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
super.paintComponent(g); |
|
|
|
super.paintComponent(g); |
|
|
@ -188,4 +191,41 @@ public class PopupControlPanel extends JPanel { |
|
|
|
this.rectangle = rectangle; |
|
|
|
this.rectangle = rectangle; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updatePane(FormDesigner designer) { |
|
|
|
|
|
|
|
setButtonVisible(settingButton, creator.isShared()); |
|
|
|
|
|
|
|
setButtonVisible(toggleButton, AdapterBus.searchLayoutAdapter(designer, creator) instanceof FRAbsoluteLayoutAdapter); |
|
|
|
|
|
|
|
toggleButton.setSelected(creator.toData().isAspectRatioLocked()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateDimension(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateDimension() { |
|
|
|
|
|
|
|
int height = 0; |
|
|
|
|
|
|
|
for (int i = 0; i < buttons.size(); i++) { |
|
|
|
|
|
|
|
JComponent component = buttons.get(i); |
|
|
|
|
|
|
|
if (component.isVisible()) { |
|
|
|
|
|
|
|
if (i > 0) { |
|
|
|
|
|
|
|
height += 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
height += component.getHeight(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
height += 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defaultDimension.height = height; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class SeparatorLabel extends UILabel { |
|
|
|
|
|
|
|
public SeparatorLabel() { |
|
|
|
|
|
|
|
setPreferredSize(new Dimension(PANE_WIDTH, 1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void paint(Graphics g) { |
|
|
|
|
|
|
|
super.paint(g); |
|
|
|
|
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
|
|
|
g2d.setColor(Color.WHITE); |
|
|
|
|
|
|
|
g2d.drawLine(BUTTON_MARGIN, 0, getWidth() - BUTTON_MARGIN, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|