diff --git a/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java b/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java index f92f7201aa..d1673d47aa 100644 --- a/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java +++ b/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java @@ -15,11 +15,12 @@ import com.fr.design.menu.ToolBarDef; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; +import com.fr.stable.StringUtils; import javax.swing.*; +import javax.swing.border.EmptyBorder; import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; +import java.awt.event.*; /** * Created by plough on 2017/7/21. @@ -313,15 +314,18 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH // 点击"编辑"按钮,弹出面板 protected class PopupEditDialog extends JDialog { private JComponent editPane; + private PopupToolPane popupToolPane; private static final int WIDTH = 570; private static final int HEIGHT = 490; - PopupEditDialog(JComponent pane) { + public PopupEditDialog(JComponent pane) { super(DesignerContext.getDesignerFrame()); setUndecorated(true); pane.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10)); this.editPane = pane; JPanel editPaneWrapper = new JPanel(new BorderLayout()); + popupToolPane = new PopupToolPane(this); + editPaneWrapper.add(popupToolPane, BorderLayout.NORTH); editPaneWrapper.add(editPane, BorderLayout.CENTER); editPaneWrapper.setBorder(BorderFactory.createLineBorder(UIConstants.POP_DIALOG_BORDER, 1)); this.getContentPane().add(editPaneWrapper, BorderLayout.CENTER); @@ -331,6 +335,10 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH initListener(); } + public void setTitle(String title) { + popupToolPane.setTitle(title); + } + private void hideDialog() { // 检查是否有子弹窗,如果有,则不隐藏 for (Window window : getOwnedWindows()) { @@ -358,4 +366,107 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH }); } } + + // 移动弹出编辑面板的工具条 + private class PopupToolPane extends JPanel { + private JDialog parentDialog; // 如果不在对话框中,值为null + private Color originColor; // 初始背景 + private JPanel contentPane; + private UILabel titleLabel; + private Point mouseDownCompCoords; // 存储按下左键的位置,移动对话框时会用到 + + private static final int MIN_X = -150; + private static final int MAX_X_SHIFT = 50; + private static final int MAX_Y_SHIFT = 50; + + private MouseListener mouseListener = new MouseAdapter() { + @Override + public void mouseExited(MouseEvent e) { + setCursor(Cursor.getDefaultCursor()); + if (mouseDownCompCoords == null) { + contentPane.setBackground(originColor); + } + repaint(); + } + @Override + public void mouseReleased(MouseEvent e) { + mouseDownCompCoords = null; + if (!getBounds().contains(e.getPoint())) { + contentPane.setBackground(originColor); + } + } + @Override + public void mousePressed(MouseEvent e) { + mouseDownCompCoords = e.getPoint(); + } + }; + + private MouseMotionListener mouseMotionListener = new MouseMotionListener() { + @Override + public void mouseMoved(MouseEvent e) { + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + contentPane.setBackground(UIConstants.POPUP_TITLE_BACKGROUND); + repaint(); + } + @Override + public void mouseDragged(MouseEvent e) { + if (mouseDownCompCoords != null) { + Point currCoords = e.getLocationOnScreen(); + int x = currCoords.x - mouseDownCompCoords.x; + int y = currCoords.y - mouseDownCompCoords.y; + //屏幕可用区域 + Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); + + int minY = screen.y; + int maxX = Toolkit.getDefaultToolkit().getScreenSize().width - MAX_X_SHIFT; + int maxY = Toolkit.getDefaultToolkit().getScreenSize().height - MAX_Y_SHIFT; + if (x < MIN_X) { + x = MIN_X; + } else if (x > maxX) { + x = maxX; + } + if (y < minY) { + y = minY; + } else if (y > maxY) { + y = maxY; + } + // 移动到屏幕边缘时,需要校正位置 + parentDialog.setLocation(x, y); + } + } + }; + + public PopupToolPane(JDialog parentDialog) { + this(StringUtils.EMPTY, parentDialog); + } + + public PopupToolPane(String title, JDialog parentDialog) { + super(); + this.parentDialog = parentDialog; + originColor = UIConstants.UI_TOOLBAR_COLOR; + + contentPane = new JPanel(); + contentPane.setBackground(originColor); + contentPane.setLayout(new BorderLayout()); + titleLabel = new UILabel(title); + contentPane.add(titleLabel, BorderLayout.WEST); + contentPane.setBorder(new EmptyBorder(5, 10, 5, 0)); + + setLayout(new BorderLayout()); + add(contentPane, BorderLayout.CENTER); + setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.TOOLBAR_BORDER_COLOR)); + + addMouseListener(mouseListener); + addMouseMotionListener(mouseMotionListener); + } + + public void setTitle(String title) { + titleLabel.setText(title); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, 25); + } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java b/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java index a148fd3b83..cd8b48d417 100644 --- a/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java +++ b/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java @@ -330,6 +330,7 @@ public abstract class UIListControlPane extends UIControlPane { nameableList.ensureIndexIsVisible(index); nameEdList.repaint(); + popupEditDialog(); } /** @@ -400,13 +401,20 @@ public abstract class UIListControlPane extends UIControlPane { } } + private void popupEditDialog() { + popupEditDialog(null); + } + protected void popupEditDialog(Point mousePos) { if (isNewStyle()) { Rectangle currentCellBounds = nameableList.getCellBounds(editingIndex, editingIndex); - if (editingIndex < 0 || !currentCellBounds.contains(mousePos)) { + if (editingIndex < 0 || (mousePos != null && !currentCellBounds.contains(mousePos))) { return; } popupEditDialog.setLocation(getPopupDialogLocation()); + if (popupEditDialog instanceof PopupEditDialog) { + ((PopupEditDialog)popupEditDialog).setTitle(getSelectedName()); + } popupEditDialog.setVisible(true); } } @@ -415,7 +423,7 @@ public abstract class UIListControlPane extends UIControlPane { Point resultPos = new Point(0, 0); Point listPos = nameableList.getLocationOnScreen(); resultPos.x = listPos.x - popupEditDialog.getWidth(); - resultPos.y = listPos.y + (editingIndex - 1) * EDIT_RANGE; + resultPos.y = listPos.y + (nameableList.getSelectedIndex() - 1) * EDIT_RANGE; // 当对象在屏幕上的位置比较靠下时,往下移动弹窗至与属性面板平齐 Window frame = DesignerContext.getDesignerFrame(); @@ -773,6 +781,7 @@ public abstract class UIListControlPane extends UIControlPane { nameableList.editItemAt(nameableList.getSelectedIndex()); } else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) { editingIndex = nameableList.getSelectedIndex(); + selectedName = nameableList.getNameAt(editingIndex); popupEditDialog(evt.getPoint()); } diff --git a/designer_base/src/com/fr/design/images/buttonicon/redo.png b/designer_base/src/com/fr/design/images/buttonicon/redo.png index f6b77b4f47..b50ad37636 100644 Binary files a/designer_base/src/com/fr/design/images/buttonicon/redo.png and b/designer_base/src/com/fr/design/images/buttonicon/redo.png differ diff --git a/designer_base/src/com/fr/design/images/buttonicon/save.png b/designer_base/src/com/fr/design/images/buttonicon/save.png index cb47c70b36..e045dda0cc 100644 Binary files a/designer_base/src/com/fr/design/images/buttonicon/save.png and b/designer_base/src/com/fr/design/images/buttonicon/save.png differ diff --git a/designer_base/src/com/fr/design/images/buttonicon/undo.png b/designer_base/src/com/fr/design/images/buttonicon/undo.png index f86a17441d..cce0180983 100644 Binary files a/designer_base/src/com/fr/design/images/buttonicon/undo.png and b/designer_base/src/com/fr/design/images/buttonicon/undo.png differ diff --git a/designer_base/src/com/fr/design/images/m_edit/copy.png b/designer_base/src/com/fr/design/images/m_edit/copy.png index 4d93d0ee5b..2b2e21fca7 100644 Binary files a/designer_base/src/com/fr/design/images/m_edit/copy.png and b/designer_base/src/com/fr/design/images/m_edit/copy.png differ diff --git a/designer_base/src/com/fr/design/images/m_edit/cut.png b/designer_base/src/com/fr/design/images/m_edit/cut.png index dded7fd3e5..adcc503078 100644 Binary files a/designer_base/src/com/fr/design/images/m_edit/cut.png and b/designer_base/src/com/fr/design/images/m_edit/cut.png differ diff --git a/designer_base/src/com/fr/design/images/m_edit/formatBrush.png b/designer_base/src/com/fr/design/images/m_edit/formatBrush.png index c821df52be..9e14785340 100644 Binary files a/designer_base/src/com/fr/design/images/m_edit/formatBrush.png and b/designer_base/src/com/fr/design/images/m_edit/formatBrush.png differ diff --git a/designer_base/src/com/fr/design/images/m_edit/paste.png b/designer_base/src/com/fr/design/images/m_edit/paste.png index 8ea606f06b..ff3651ed09 100644 Binary files a/designer_base/src/com/fr/design/images/m_edit/paste.png and b/designer_base/src/com/fr/design/images/m_edit/paste.png differ