📄 xpstyle.java
字号:
margin = ((AbstractButton)c).getMargin(); } else if (c instanceof JToolBar) { margin = ((JToolBar)c).getMargin(); } else if (c instanceof JTextComponent) { margin = ((JTextComponent)c).getMargin(); } insets.top = (margin != null? margin.top : 0) + borderInsets.top; insets.left = (margin != null? margin.left : 0) + borderInsets.left; insets.bottom = (margin != null? margin.bottom : 0) + borderInsets.bottom; insets.right = (margin != null? margin.right : 0) + borderInsets.right; return insets; } } private class XPEmptyBorder extends EmptyBorder implements UIResource { XPEmptyBorder(Insets m) { super(m.top+2, m.left+2, m.bottom+2, m.right+2); } public Insets getBorderInsets(Component c) { return getBorderInsets(c, getBorderInsets()); } public Insets getBorderInsets(Component c, Insets insets) { insets = super.getBorderInsets(c, insets); Insets margin = null; if (c instanceof AbstractButton) { Insets m = ((AbstractButton)c).getMargin(); // if this is a toolbar button then ignore getMargin() // and subtract the padding added by the constructor if(c.getParent() instanceof JToolBar && ! (c instanceof JRadioButton) && ! (c instanceof JCheckBox) && m instanceof InsetsUIResource) { insets.top -= 2; insets.left -= 2; insets.bottom -= 2; insets.right -= 2; } else { margin = m; } } else if (c instanceof JToolBar) { margin = ((JToolBar)c).getMargin(); } else if (c instanceof JTextComponent) { margin = ((JTextComponent)c).getMargin(); } if (margin != null) { insets.top = margin.top + 2; insets.left = margin.left + 2; insets.bottom = margin.bottom + 2; insets.right = margin.right + 2; } return insets; } } boolean isSkinDefined(Component c, Part part) { return (part.getValue() == 0) || ThemeReader.isThemePartDefined( part.getControlName(c), part.getValue(), 0); } /** Get a <code>Skin</code> object from the current style * for a named part (component type) * * @param part a <code>Part</code> * @return a <code>Skin</code> object */ synchronized Skin getSkin(Component c, Part part) { assert isSkinDefined(c, part) : "part " + part + " is not defined"; return new Skin(c, part, null); } long getThemeTransitionDuration(Component c, Part part, State stateFrom, State stateTo, Prop prop) { return ThemeReader.getThemeTransitionDuration(part.getControlName(c), part.getValue(), State.getValue(part, stateFrom), State.getValue(part, stateTo), (prop != null) ? prop.getValue() : 0); } /** A class which encapsulates attributes for a given part * (component type) and which provides methods for painting backgrounds * and glyphs */ static class Skin { final Component component; final Part part; final State state; private final String string; private Dimension size = null; Skin(Component component, Part part) { this(component, part, null); } Skin(Part part, State state) { this(null, part, state); } Skin(Component component, Part part, State state) { this.component = component; this.part = part; this.state = state; String str = part.getControlName(component) +"." + part.name(); if (state != null) { str += "("+state.name()+")"; } string = str; } Insets getContentMargin() { // This is only called by WindowsTableHeaderUI so far. return ThemeReader.getThemeMargins(part.getControlName(null), part.getValue(), 0, Prop.SIZINGMARGINS.getValue()); } private int getWidth(State state) { if (size == null) { size = getPartSize(part, state); } return size.width; } int getWidth() { return getWidth((state != null) ? state : State.NORMAL); } private int getHeight(State state) { if (size == null) { size = getPartSize(part, state); } return size.height; } int getHeight() { return getHeight((state != null) ? state : State.NORMAL); } public String toString() { return string; } public boolean equals(Object obj) { return (obj instanceof Skin && ((Skin)obj).string.equals(string)); } public int hashCode() { return string.hashCode(); } /** Paint a skin at x, y. * * @param g the graphics context to use for painting * @param dx the destination <i>x</i> coordinate * @param dy the destination <i>y</i> coordinate * @param state which state to paint */ void paintSkin(Graphics g, int dx, int dy, State state) { if (state == null) { state = this.state; } paintSkin(g, dx, dy, getWidth(state), getHeight(state), state); } /** Paint a skin in an area defined by a rectangle. * * @param g the graphics context to use for painting * @param r a <code>Rectangle</code> defining the area to fill, * may cause the image to be stretched or tiled * @param state which state to paint */ void paintSkin(Graphics g, Rectangle r, State state) { paintSkin(g, r.x, r.y, r.width, r.height, state); } /** Paint a skin at a defined position and size * This method supports animation. * * @param g the graphics context to use for painting * @param dx the destination <i>x</i> coordinate * @param dy the destination <i>y</i> coordinate * @param dw the width of the area to fill, may cause * the image to be stretched or tiled * @param dh the height of the area to fill, may cause * the image to be stretched or tiled * @param state which state to paint */ void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state) { if (ThemeReader.isGetThemeTransitionDurationDefined() && component instanceof JComponent && SwingUtilities.getAncestorOfClass(CellRendererPane.class, component) == null) { AnimationController.paintSkin((JComponent) component, this, g, dx, dy, dw, dh, state); } else { paintSkinRaw(g, dx, dy, dw, dh, state); } } /** Paint a skin at a defined position and size. This method * does not trigger animation. It is needed for the animation * support. * * @param g the graphics context to use for painting * @param dx the destination <i>x</i> coordinate. * @param dy the destination <i>y</i> coordinate. * @param dw the width of the area to fill, may cause * the image to be stretched or tiled * @param dh the height of the area to fill, may cause * the image to be stretched or tiled * @param state which state to paint */ void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, State state) { skinPainter.paint(null, g, dx, dy, dw, dh, this, state); } /** Paint a skin at a defined position and size * * @param g the graphics context to use for painting * @param dx the destination <i>x</i> coordinate * @param dy the destination <i>y</i> coordinate * @param dw the width of the area to fill, may cause * the image to be stretched or tiled * @param dh the height of the area to fill, may cause * the image to be stretched or tiled * @param state which state to paint * @param borderFill should test if the component uses a border fill and skip painting if it is */ void paintSkin(Graphics g, int dx, int dy, int dw, int dh, State state, boolean borderFill) { if(borderFill && "borderfill".equals(getTypeEnumName(component, part, state, Prop.BGTYPE))) { return; } skinPainter.paint(null, g, dx, dy, dw, dh, this, state); } } private static class SkinPainter extends CachedPainter { SkinPainter() { super(30); flush(); } public void flush() { super.flush(); } protected void paintToImage(Component c, Image image, Graphics g, int w, int h, Object[] args) { CachingSurfaceManager csm = null; boolean accEnabled = false; Skin skin = (Skin)args[0]; Part part = skin.part; State state = (State)args[1]; if (state == null) { state = skin.state; } if (c == null) { c = skin.component; } BufferedImage bi = (BufferedImage)image; // Getting the DataBuffer for an image (as it's done below) defeats // possible future acceleration. // Calling setLocalAccelerationEnabled on that image's surface // manager re-enables it. SurfaceManager sm = SurfaceManager.getManager(bi); if (sm instanceof CachingSurfaceManager) { csm = (CachingSurfaceManager)sm; accEnabled = csm.isLocalAccelerationEnabled(); } WritableRaster raster = bi.getRaster(); DataBufferInt buffer = (DataBufferInt)raster.getDataBuffer(); ThemeReader.paintBackground(buffer.getData(), part.getControlName(c), part.getValue(), State.getValue(part, state), 0, 0, w, h, w); if (csm != null && accEnabled != csm.isLocalAccelerationEnabled()) { csm.setLocalAccelerationEnabled(accEnabled); csm.rasterChanged(); } } protected Image createImage(Component c, int w, int h, GraphicsConfiguration config, Object[] args) { return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); } } static class GlyphButton extends JButton { private Skin skin; public GlyphButton(Component parent, Part part) { XPStyle xp = getXP(); skin = xp.getSkin(parent, part); setBorder(null); setContentAreaFilled(false); setMinimumSize(new Dimension(5, 5)); setPreferredSize(new Dimension(16, 16)); setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); } public boolean isFocusTraversable() { return false; } protected State getState() { State state = State.NORMAL; if (!isEnabled()) { state = State.DISABLED; } else if (getModel().isPressed()) { state = State.PRESSED; } else if (getModel().isRollover()) { state = State.HOT; } return state; } public void paintComponent(Graphics g) { Dimension d = getSize(); skin.paintSkin(g, 0, 0, d.width, d.height, getState()); } public void setPart(Component parent, Part part) { XPStyle xp = getXP(); skin = xp.getSkin(parent, part); revalidate(); repaint(); } protected void paintBorder(Graphics g) { } } // Private constructor private XPStyle() { flatMenus = getSysBoolean(Prop.FLATMENUS); colorMap = new HashMap<String, Color>(); borderMap = new HashMap<String, Border>(); // Note: All further access to the maps must be synchronized } private boolean getBoolean(Component c, Part part, State state, Prop prop) { return ThemeReader.getBoolean(part.getControlName(c), part.getValue(), State.getValue(part, state), prop.getValue()); } static Dimension getPartSize(Part part, State state) { return ThemeReader.getPartSize(part.getControlName(null), part.getValue(), State.getValue(part, state)); } private static boolean getSysBoolean(Prop prop) { // We can use any widget name here, I guess. return ThemeReader.getSysBoolean("window", prop.getValue()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -