forked from fanruan/design
kuangshuai
3 years ago
51 changed files with 571 additions and 223 deletions
@ -0,0 +1,47 @@
|
||||
package com.fr.design.gui.frpane; |
||||
|
||||
import java.awt.Component; |
||||
import java.awt.Container; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/9/17 |
||||
*/ |
||||
public class AttributeChangeUtils { |
||||
private static AbstractAttrNoScrollPane findNearestAttrNoScrollPaneAncestor(Component c) { |
||||
for(Container p = c.getParent(); p != null; p = p.getParent()) { |
||||
if (p instanceof AbstractAttrNoScrollPane) { |
||||
return (AbstractAttrNoScrollPane) p; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static void changeComposedUI(Component composedComponent, boolean fireMiddleStateChanged, UIChangeAction action) { |
||||
AbstractAttrNoScrollPane attrPane = findNearestAttrNoScrollPaneAncestor(composedComponent); |
||||
boolean oldAutoFire = true; |
||||
|
||||
if (!fireMiddleStateChanged) { |
||||
// 禁止属性面板自动处理属性更新
|
||||
if (attrPane != null) { |
||||
oldAutoFire = attrPane.isAutoFireAttributesChanged(); |
||||
attrPane.setAutoFireAttributesChanged(false); |
||||
} |
||||
} |
||||
|
||||
// 更新UI
|
||||
action.changeComposedUI(); |
||||
|
||||
if (!fireMiddleStateChanged) { |
||||
// 恢复属性面板自动处理属性更新
|
||||
if (attrPane != null) { |
||||
attrPane.setAutoFireAttributesChanged(oldAutoFire); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public interface UIChangeAction { |
||||
void changeComposedUI(); |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.fr.design.mainframe.share.ui.actions; |
||||
|
||||
import com.fr.design.gui.imenu.UIMenuItem; |
||||
import com.fr.design.mainframe.share.ui.constants.ColorConstants; |
||||
import com.fr.general.IOUtils; |
||||
|
||||
import javax.swing.Action; |
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.Icon; |
||||
import java.awt.Graphics; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/10/19 |
||||
*/ |
||||
public class LoadingMenuItem extends UIMenuItem { |
||||
private boolean loading = false; |
||||
|
||||
private final Icon profileIcon = IOUtils.readIcon("/com/fr/design/form/images/loading.gif"); |
||||
|
||||
public LoadingMenuItem(Action action) { |
||||
super(action); |
||||
setOpaque(true); |
||||
setBackground(ColorConstants.BACKGROUND); |
||||
setUI(new SharedComponentActionMenuItemUI(false)); |
||||
} |
||||
|
||||
public void startLoading() { |
||||
loading = true; |
||||
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20)); |
||||
revalidate(); |
||||
repaint(); |
||||
} |
||||
|
||||
public void stopLoading() { |
||||
loading = false; |
||||
setBorder(BorderFactory.createEmptyBorder()); |
||||
revalidate(); |
||||
repaint(); |
||||
} |
||||
|
||||
@Override |
||||
protected void paintBorder(Graphics g) { |
||||
super.paintBorder(g); |
||||
if (loading) { |
||||
profileIcon.paintIcon(this, g, getWidth() - 20, 0); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.fr.design.mainframe.share.ui.actions; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.gui.imenu.UIMenuItemUI; |
||||
import com.fr.design.utils.gui.GUIPaintUtils; |
||||
import com.fr.stable.Constants; |
||||
|
||||
import javax.swing.ButtonModel; |
||||
import javax.swing.JMenu; |
||||
import javax.swing.JMenuItem; |
||||
import javax.swing.MenuSelectionManager; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/10/18 |
||||
*/ |
||||
public class SharedComponentActionMenuItemUI extends UIMenuItemUI { |
||||
|
||||
private final boolean autoClosePopup; |
||||
|
||||
public SharedComponentActionMenuItemUI(boolean autoClosePopup) { |
||||
this.autoClosePopup = autoClosePopup; |
||||
} |
||||
|
||||
public SharedComponentActionMenuItemUI() { |
||||
this(true); |
||||
} |
||||
|
||||
@Override |
||||
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { |
||||
ButtonModel model = menuItem.getModel(); |
||||
Color oldColor = g.getColor(); |
||||
int menuWidth = menuItem.getWidth(); |
||||
int menuHeight = menuItem.getHeight(); |
||||
|
||||
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
||||
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 0); |
||||
} |
||||
|
||||
g.setColor(oldColor); |
||||
} |
||||
|
||||
@Override |
||||
protected void doClick(MenuSelectionManager msm) { |
||||
if (autoClosePopup) { |
||||
super.doClick(msm); |
||||
} else { |
||||
menuItem.doClick(0); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.fr.design.mainframe.share.ui.constants; |
||||
|
||||
import java.awt.Color; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/10/19 |
||||
*/ |
||||
public class ColorConstants { |
||||
public static final Color BACKGROUND = new Color(0xF0F0F1); |
||||
} |
After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 10 KiB |
Loading…
Reference in new issue