superman
3 weeks ago
8 changed files with 31 additions and 470 deletions
@ -1,28 +0,0 @@
|
||||
package com.fr.design.gui.imenu; |
||||
|
||||
import com.fr.design.editlock.EditLockUtils; |
||||
|
||||
import javax.swing.JMenuItem; |
||||
import java.awt.Graphics; |
||||
import java.awt.Rectangle; |
||||
|
||||
/** |
||||
* @author Yvan |
||||
* @version 10.0 |
||||
* Created by Yvan on 2021/1/20 |
||||
*/ |
||||
public class UILockMenuItemUI extends UIMenuItemUI{ |
||||
|
||||
@Override |
||||
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { |
||||
super.paintText(g, menuItem, textRect, text); |
||||
// 除了绘制text之外,还需要画一下锁定图标
|
||||
UILockMenuItem lockMenuItem = (UILockMenuItem) menuItem; |
||||
// if (EditLockUtils.isLocked(lockMenuItem.getLockItem())) {
|
||||
int width = menuItem.getWidth(); |
||||
int height = menuItem.getHeight(); |
||||
g.drawImage(EditLockUtils.LOCKED_IMAGE, (int) Math.round(width * 0.9), (int) Math.round(height * 0.1), 16, 16, null); |
||||
// }
|
||||
|
||||
} |
||||
} |
@ -1,221 +0,0 @@
|
||||
package com.fr.design.cell.bar; |
||||
|
||||
import com.fr.design.gui.iscrollbar.UISBChooser; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.plaf.basic.BasicScrollBarUI; |
||||
import java.awt.*; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* Created by IntelliJ IDEA. |
||||
* Author : daisy |
||||
* Version: 6.5.6 |
||||
* Date: 13-12-30 |
||||
* Time: 下午2:28 |
||||
*/ |
||||
public class DynamicScrollBarUI extends BasicScrollBarUI { |
||||
|
||||
|
||||
private boolean isRollover = false; |
||||
//是否
|
||||
private boolean wasRollover = false; |
||||
|
||||
|
||||
public DynamicScrollBarUI() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 是否可见 |
||||
* @return 可见返回true |
||||
*/ |
||||
public boolean isThumbVisible() { |
||||
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { |
||||
return getThumbBounds().height > 0; |
||||
} else { |
||||
return getThumbBounds().width > 0; |
||||
} |
||||
} |
||||
|
||||
public void paintThumb(Graphics g, JComponent c, Rectangle t) { |
||||
// super.paintThumb(g,c,t);
|
||||
paintXP(g, t); |
||||
} |
||||
|
||||
private void paintXP(Graphics g, Rectangle t) { |
||||
Color c = null; |
||||
if (isDragging && isRollover) { |
||||
c = ScrollBarUIConstant.PRESS_SCROLL_BAR_COLOR; |
||||
} else if (isRollover) { |
||||
c = ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR; |
||||
} else { |
||||
c = ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR; |
||||
} |
||||
|
||||
g.setColor(c); |
||||
|
||||
int xs = t.x + 1; |
||||
int ys = t.y + 1; |
||||
int x2 = t.x + t.width - 1; |
||||
int y2 = t.y + t.height - 1; |
||||
|
||||
paintScrollBar(g, xs, ys, x2, y2, t); |
||||
|
||||
// draw Grip
|
||||
// if (t.height < 11) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
|
||||
// drawVertical(t, y2, g, c);
|
||||
// } else {
|
||||
// drawHrizontal(t, x2, g, c);
|
||||
// }
|
||||
} |
||||
|
||||
|
||||
private void drawHrizontal(Rectangle t, int x2, Graphics g, Color c) { |
||||
int x1 = t.x + (t.width) / 2 - 4; |
||||
x2 = Math.min(x1 + 8, t.x + t.width - 5); |
||||
|
||||
int x = x1 + 1; |
||||
// we take only saturation & brightness and apply them
|
||||
// to the background color (normal/rollover/pressed)
|
||||
g.setColor(UISBChooser.getAdjustedColor(c, 0, 71)); |
||||
while (x < x2) { |
||||
g.drawLine(x, 5, x, 11); |
||||
x += 2; |
||||
} |
||||
|
||||
x = x1; |
||||
g.setColor(UISBChooser.getAdjustedColor(c, 0, -13)); |
||||
while (x < x2) { |
||||
g.drawLine(x, 6, x, 12); |
||||
x += 2; |
||||
} |
||||
} |
||||
|
||||
private void drawVertical(Rectangle t, int y2, Graphics g, Color c) { |
||||
int y1 = t.y + (t.height) / 2 - 4; |
||||
y2 = Math.min(y1 + 8, t.y + t.height - 5); |
||||
|
||||
int y = y1; |
||||
// we take only saturation & brightness and apply them
|
||||
// to the background color (normal/rollover/pressed)
|
||||
g.setColor(UISBChooser.getAdjustedColor(c, 0, 71)); |
||||
while (y < y2) { |
||||
g.drawLine(5, y, 11, y); |
||||
y += 2; |
||||
} |
||||
|
||||
y = y1 + 1; |
||||
g.setColor(UISBChooser.getAdjustedColor(c, 0, -13)); |
||||
while (y < y2) { |
||||
g.drawLine(6, y, 12, y); |
||||
y += 2; |
||||
} |
||||
} |
||||
|
||||
private void paintScrollBar(Graphics g, int xs, int ys, int x2, int y2, Rectangle t) { |
||||
switch (scrollbar.getOrientation()) { |
||||
//harry: 垂直滚动条和水平滚动条的画法分开。
|
||||
case JScrollBar.VERTICAL: |
||||
Graphics2D g2 = (Graphics2D) g; |
||||
GradientPaint scrollBarBg = null; |
||||
if (isRollover) { |
||||
scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR, x2, ys, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR); |
||||
} else { |
||||
scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR, x2, ys, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR); |
||||
} |
||||
g2.setPaint(scrollBarBg); |
||||
g2.fillRoundRect(xs, ys, t.width - 2, t.height - 2, 0, 0); |
||||
break; |
||||
case JScrollBar.HORIZONTAL: |
||||
Graphics2D g2H = (Graphics2D) g; |
||||
if (isRollover) { |
||||
scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR, xs, y2, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR); |
||||
} else { |
||||
scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR, xs, y2, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR); |
||||
} |
||||
g2H.setPaint(scrollBarBg); |
||||
g2H.fillRoundRect(xs, ys, t.width - 2, t.height - 2, 0, 0); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
|
||||
protected JButton createDecreaseButton(int orientation) { |
||||
return new DynamicScrollButton(orientation, this); |
||||
} |
||||
|
||||
/** |
||||
* Creates the increase button of the scrollbar. |
||||
* |
||||
* @param orientation The button's orientation. |
||||
* @return The created button. |
||||
*/ |
||||
protected JButton createIncreaseButton(int orientation) { |
||||
return new DynamicScrollButton(orientation, this); |
||||
} |
||||
|
||||
protected TrackListener createTrackListener() { |
||||
return new ScrollBarTrackListener(); |
||||
} |
||||
|
||||
|
||||
private class ScrollBarTrackListener extends BasicScrollBarUI.TrackListener { |
||||
public void mouseReleased(MouseEvent e) { |
||||
super.mouseReleased(e); |
||||
scrollbar.repaint(); |
||||
} |
||||
|
||||
public void mousePressed(MouseEvent e) { |
||||
super.mousePressed(e); |
||||
scrollbar.repaint(); |
||||
} |
||||
|
||||
public void mouseEntered(MouseEvent e) { |
||||
isRollover = false; |
||||
wasRollover = false; |
||||
if (getThumbBounds().contains(e.getPoint())) { |
||||
isRollover = true; |
||||
wasRollover = isRollover; |
||||
scrollbar.repaint(); |
||||
} |
||||
} |
||||
|
||||
public void mouseExited(MouseEvent e) { |
||||
isRollover = false; |
||||
if (isRollover != wasRollover) { |
||||
wasRollover = isRollover; |
||||
scrollbar.repaint(); |
||||
} |
||||
} |
||||
|
||||
public void mouseDragged(MouseEvent e) { |
||||
if (getThumbBounds().contains(e.getPoint())) { |
||||
isDragging = true; |
||||
} |
||||
super.mouseDragged(e); |
||||
} |
||||
|
||||
public void mouseMoved(MouseEvent e) { |
||||
if (getThumbBounds().contains(e.getPoint())) { |
||||
isRollover = true; |
||||
if (isRollover != wasRollover) { |
||||
scrollbar.repaint(); |
||||
wasRollover = isRollover; |
||||
} |
||||
} else { |
||||
isRollover = false; |
||||
if (isRollover != wasRollover) { |
||||
scrollbar.repaint(); |
||||
wasRollover = isRollover; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -1,180 +0,0 @@
|
||||
package com.fr.design.cell.bar; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.utils.SvgDrawUtils; |
||||
import com.fr.general.ComparatorUtils; |
||||
|
||||
import javax.swing.SwingConstants; |
||||
import javax.swing.plaf.basic.BasicArrowButton; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import java.awt.GradientPaint; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Image; |
||||
import java.awt.Insets; |
||||
import java.awt.image.BufferedImage; |
||||
import java.util.HashMap; |
||||
|
||||
/** |
||||
* Created by IntelliJ IDEA. |
||||
* Author : daisy |
||||
* Version: 6.5.6 |
||||
* Date: 13-12-30 |
||||
* Time: 下午3:22 |
||||
*/ |
||||
public class DynamicScrollButton extends BasicArrowButton { |
||||
|
||||
|
||||
private DynamicScrollBarUI scrollbarUI; |
||||
|
||||
|
||||
static HashMap cache = new HashMap(); |
||||
|
||||
private Dimension buttonSize = new Dimension(17, 17); |
||||
|
||||
public DynamicScrollButton(int direction, DynamicScrollBarUI scrollbarUI) { |
||||
super(direction); |
||||
|
||||
this.scrollbarUI = scrollbarUI; |
||||
setBorder(null); |
||||
setRolloverEnabled(true); |
||||
setMargin(new Insets(0, 0, 0, 0)); |
||||
setSize(buttonSize); |
||||
} |
||||
|
||||
public void paint(Graphics g) { |
||||
Color c = null; |
||||
|
||||
if (!scrollbarUI.isThumbVisible()) { |
||||
c = ScrollBarUIConstant.DISABLE_SCROLL_BAR_COLOR; |
||||
} else if (getModel().isPressed()) { |
||||
c = ScrollBarUIConstant.PRESS_SCROLL_BAR_COLOR; |
||||
} else if (getModel().isRollover()) { |
||||
c = ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR; |
||||
} else { |
||||
c = ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR; |
||||
} |
||||
|
||||
g.setColor(c); |
||||
paintButton(g, getSize(), c); |
||||
if (!scrollbarUI.isThumbVisible()) { |
||||
g.setColor(ScrollBarUIConstant.ARROW_DISABLED_COLOR); |
||||
} else { |
||||
g.setColor(ScrollBarUIConstant.SCROLL_ARROW_COLOR); |
||||
} |
||||
|
||||
paintArrow(g, getSize()); |
||||
} |
||||
|
||||
|
||||
private void paintArrow(Graphics g, Dimension size) { |
||||
SvgDrawUtils.beforeDraw((Graphics2D) g); |
||||
switch (direction) { |
||||
case SwingConstants.NORTH: |
||||
g.drawImage(UIConstants.ARROW_NORTH, 0, 0, this); |
||||
break; |
||||
case SwingConstants.SOUTH: |
||||
g.drawImage(UIConstants.ARROW_SOUTH, 0, 0, this); |
||||
break; |
||||
case SwingConstants.EAST: |
||||
g.drawImage(UIConstants.ARROW_EAST, 0, 0, this); |
||||
break; |
||||
case SwingConstants.WEST: |
||||
g.drawImage(UIConstants.ARROW_WEST, 0, 0, this); |
||||
break; |
||||
} |
||||
SvgDrawUtils.afterDraw((Graphics2D) g); |
||||
} |
||||
|
||||
|
||||
private void paintButton(Graphics g, Dimension size, Color c) { |
||||
boolean enabled = scrollbarUI.isThumbVisible(); |
||||
boolean pressed = getModel().isPressed(); |
||||
boolean rollover = getModel().isRollover(); |
||||
ScrollButtonKey key = new ScrollButtonKey( |
||||
(direction == NORTH || direction == SOUTH), |
||||
c, pressed, enabled, rollover); |
||||
Object value = cache.get(key); |
||||
if (value != null) { |
||||
// image was cached - paint image and return
|
||||
g.drawImage((Image) value, 0, 0, this); |
||||
return; |
||||
} |
||||
Image img = new BufferedImage(17, 17, BufferedImage.TYPE_INT_ARGB); |
||||
Graphics imgGraphics = img.getGraphics(); |
||||
switch (direction) { |
||||
case EAST: |
||||
case WEST: |
||||
case NORTH: |
||||
case SOUTH: |
||||
Color a = ScrollBarUIConstant.SCROLL_BORDER_COLOR; |
||||
Graphics2D g2 = (Graphics2D) imgGraphics; |
||||
GradientPaint scrollBarBg = null; |
||||
if (!scrollbarUI.isThumbVisible()) { |
||||
scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR); |
||||
} else if (getModel().isPressed()) { |
||||
scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR); |
||||
} else if (getModel().isRollover()) { |
||||
scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR); |
||||
} else { |
||||
scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR); |
||||
} |
||||
//GradientPaint scrollBarHight = new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 0.5f), 0, 7, new Color(1.0f, 1.0f, 1.0f, 0.2f));
|
||||
g2.setPaint(scrollBarBg); |
||||
g2.fillRoundRect(1, 1, 16, 16, 0, 0); |
||||
break; |
||||
} |
||||
// dispose of image graphics
|
||||
imgGraphics.dispose(); |
||||
// draw the image
|
||||
g.drawImage(img, 0, 0, this); |
||||
// add the image to the cache
|
||||
cache.put(key, img); |
||||
} |
||||
|
||||
static class ScrollButtonKey { |
||||
|
||||
private boolean vertical; |
||||
private Color c; |
||||
private boolean pressed; |
||||
private boolean enabled; |
||||
private boolean rollover; |
||||
|
||||
ScrollButtonKey(boolean vertical, Color c, |
||||
boolean pressed, boolean enabled, boolean rollover) { |
||||
this.vertical = vertical; |
||||
this.c = c; |
||||
this.pressed = pressed; |
||||
this.enabled = enabled; |
||||
this.rollover = rollover; |
||||
} |
||||
|
||||
public boolean equals(Object o) { |
||||
if (o == null) { |
||||
return false; |
||||
} |
||||
if (!(o instanceof ScrollButtonKey)) { |
||||
return false; |
||||
} |
||||
|
||||
ScrollButtonKey other = (ScrollButtonKey) o; |
||||
|
||||
return vertical == other.vertical && |
||||
pressed == other.pressed && |
||||
enabled == other.enabled && |
||||
rollover == other.rollover && |
||||
ComparatorUtils.equals(c, other.c); |
||||
|
||||
} |
||||
|
||||
public int hashCode() { |
||||
return c.hashCode() * |
||||
(pressed ? 1 : 2) * |
||||
(enabled ? 4 : 8) * |
||||
(rollover ? 16 : 32) * |
||||
(vertical ? 64 : 128); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue