📄 oyoahautilities.java
字号:
{
return c.getForeground();
}
//- - - - - - - - - - - - - - - -
//
// GET GENERAL STATE
//
//- - - - - - - - - - - - - - - -
public static boolean getBoolean(String _s)
{
return getBoolean(_s, false);
}
public static boolean getBoolean(String _s, boolean _default)
{
Object o=UIManager.get(_s);
if(o instanceof Boolean)
{
return ((Boolean)o).booleanValue();
}
return _default;
}
public final static void loadImage(Image image)
{
loader.loadImage(image);
}
public final static Image loadImage(int[] source, int w, int h)
{
Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, source, 0, w));
loader.loadImage(image);
return image;
}
public final static OyoahaBackgroundObject getBackgroundObject(Component c)
{
return getBackgroundObject(getUIClassID(c));
}
public final static OyoahaBackgroundObject getBackgroundObject(String ui)
{
Object o = UIManager.get(ui+".backgroundObject");
if(o!=null && o instanceof OyoahaBackgroundObject)
{
return (OyoahaBackgroundObject)o;
}
return null;
}
public final static OyoahaFlash getFlash(Component c)
{
return getFlash(getUIClassID(c));
}
public final static OyoahaFlash getFlash(String ui)
{
OyoahaBackgroundObject o = null;
if(ui.equals("Slider")) //SliderTrack.backgroundObject
{
o = getBackgroundObject("SliderTrack");
}
else
if(ui.equals("ScrollBar")) //ScrollBarTrack.backgroundObject
{
o = getBackgroundObject("ScrollBarTrack");
}
else
{
o = getBackgroundObject(ui);
}
if(o!=null && o instanceof OyoahaFlash)
{
return (OyoahaFlash)o;
}
return null;
}
public final static OyoahaFlash getFlashBorder(Component c)
{
if(c instanceof JComponent)
{
Border b = ((JComponent)c).getBorder();
if(b!=null && b instanceof OyoahaFlash)
{
return (OyoahaFlash)b;
}
}
return null;
}
public final static OyoahaFlash getFlashIcon(Component c)
{
if(c instanceof AbstractButton)
{
Icon i = ((AbstractButton)c).getIcon();
if(i!=null && i instanceof OyoahaFlash)
{
return (OyoahaFlash)i;
}
}
return null;
}
public final static OyoahaBumpObject getOyoahaBumpObject()
{
Object o = UIManager.get("oyoahabump");
if(o!=null && o instanceof OyoahaBumpObject)
{
return (OyoahaBumpObject)o;
}
return null;
}
//-----------
/**
* by default rollover is enabled in OyoahaLookAndFeel
*/
public final static boolean isRolloverEnabled(Component c)
{
return isRolloverEnabled(c, oyoahaLookAndFeel.getDefaultRolloverPolicy(c));
}
public final static boolean isRolloverEnabled(Component c, boolean d)
{
return getBoolean(getUIClassID(c)+".rollover",d);
}
//- - - - - - - - - - - - - - - -
//
// SOME USEFULL PAINT ROUTINE
//
//- - - - - - - - - - - - - - - -
public final static void paintBump(Graphics g, Component c, int x, int y, int w, int h, int state, int nx, int ny)
{
//getbump for the this state
OyoahaBumpObject bump = getOyoahaBumpObject();
if(bump==null || nx==0 || ny==0)
return;
int posx = x;
int posy = y;
//check if there is enough space
if(nx>0)
{
int size = nx*bump.getWidth()+(nx-1);
if(size>w)
return;
posx += (w-size)/2;
}
else
{
//check if at least one bump can be painted
nx = 1;
int size = nx*bump.getWidth();
if(size>w)
return;
while(size<w)
{
nx++;
size = nx*bump.getWidth()+(nx-1);
}
nx--;
size = nx*bump.getWidth()+(nx-1);
posx += (w-size)/2;
}
if(ny>0)
{
int size = ny*bump.getHeight()+(ny-1);
if(size>h)
return;
posy += (h-size)/2;
}
else
{
//check if at least one bump can be painted
ny = 1;
int size = ny*bump.getHeight();
if(size>h)
return;
while(size<h)
{
ny++;
size = ny*bump.getHeight()+(ny-1);
}
ny--;
size = ny*bump.getHeight()+(ny-1);
posy += (h-size)/2;
}
//paint bump
for(int yy=0;yy<ny;yy++)
{
for(int xx=0;xx<nx;xx++)
{
bump.paint(g, c, posx+(xx*bump.getWidth())+xx, posy+(yy*bump.getHeight())+yy, state);
}
}
}
public final static void setAlphaChannel(Graphics g, Component c, float f)
{
paint.setAlphaChannel(g, c, f);
}
public final static void paintBackground(Graphics g, Component c)
{
Rectangle r = OyoahaUtilities.getFullRect(c);
paint.paintBackground(g, c, r.x, r.y, r.width, r.height, OyoahaUtilities.getBackground(c), OyoahaUtilities.getStatus(c));
}
public final static void paintBackground(Graphics g, Component c, int x, int y, int width, int height, int status)
{
paint.paintBackground(g, c, x, y, width, height, null, status);
}
public final static void paintBackground(Graphics g, Component c, int x, int y, int width, int height, Color color, int status)
{
paint.paintBackground(g, c, x, y, width, height, color, status);
}
public final static void paintColorBackground(Graphics g, Component c, int x, int y, int width, int height, Color bg, int status)
{
paint.paintColorBackground(g, c, x, y, width, height, bg, status);
}
public final static boolean isAlphaClasses(Component c)
{
/*if (c instanceof AbstractButton && !((AbstractButton)c).isBorderPainted())
{
return false;
}*/
/*if (c instanceof OyoahaButtonLikeComponent)
{
if(!((OyoahaButtonLikeComponent)c).isBorderPainted(c))
return false;
return true; //((OyoahaButtonLikeComponent)c).isAlphaClasses();
}
//ComponentUI cui = (ComponentUI)UIManager.get(OyoahaUtilities.getUIClassID(c));
ComponentUI cui = (ComponentUI)UIManager.getUI((JComponent)c);
if (cui!=null && cui instanceof OyoahaButtonLikeComponent)
{
if(!((OyoahaButtonLikeComponent)cui).isBorderPainted(c))
return false;
return true; //((OyoahaButtonLikeComponent)c).isAlphaClasses();
}
/*String ui = OyoahaUtilities.getUIClassID(c);
if (alphaClasses.containsKey(ui))
{
return ((Boolean)alphaClasses.get(ui)).booleanValue();
}*/
//return false;
OyoahaButtonLikeComponent blc = getOyoahaButtonLikeComponent(c);
if (blc!=null)
{
return blc.isBorderPainted(c);
}
return false;
}
/*public final static void forceOpaque(Component c)
{
if(!(c instanceof JComponent))
{
return;
}
/*String ui = OyoahaUtilities.getUIClassID(c);
if(alphaClasses.containsKey(ui))
{
((JComponent)c).setOpaque(!((Boolean)alphaClasses.get(ui)).booleanValue());
return;
}
alphaClasses.put(ui, new Boolean(true));
((JComponent)c).setOpaque(false);*/
//((JComponent)c).setOpaque(false);
//}
/**
*
*/
public final static OyoahaButtonLikeComponent getOyoahaButtonLikeComponent(Component c)
{
if (c instanceof OyoahaButtonLikeComponent)
{
return (OyoahaButtonLikeComponent)c;
}
if (c instanceof JComponent)
{
String ui = OyoahaUtilities.getUIClassID2(c);
if(ui==null)
return null;
Object o = UIManager.get(ui);
if(o==null || !o.toString().startsWith("com.oyoaha."))
return null;
o = UIManager.getUI((JComponent)c);
if (o!=null && o instanceof OyoahaButtonLikeComponent)
{
return (OyoahaButtonLikeComponent)o;
}
}
return null;
}
public final static void setOpaque(Component c)
{
if(!(c instanceof JComponent))
{
return;
}
//String ui = OyoahaUtilities.getUIClassID(c);
/*if(alphaClasses.containsKey(ui))
{
((JComponent)c).setOpaque(!((Boolean)alphaClasses.get(ui)).booleanValue());
return;
}*/
//Boolean bool = null;
/*Border border = ((JComponent)c).getBorder();
if(border==null || border.isBorderOpaque())
{
OyoahaBackgroundObject back = OyoahaUtilities.getBackgroundObject(c);
if(back!=null)
bool = new Boolean(!back.isOpaque());
else
bool = new Boolean(false);
}
else
if(border!=null)
{
bool = new Boolean(true);
}
else
{
bool = new Boolean(true);
}*/
/*bool = new Boolean(true);
if (!alphaClasses.containsKey(ui))
{
alphaClasses.put(ui, bool);
}*/
/*if (c instanceof OyoahaButtonLikeComponent)
{
((JComponent)c).setOpaque(false);
}
else
{
//ComponentUI cui = (ComponentUI)UIManager.get(OyoahaUtilities.getUIClassID(c));
ComponentUI cui = (ComponentUI)UIManager.getUI((JComponent)c);
if (cui!=null && cui instanceof OyoahaButtonLikeComponent)
{
((JComponent)c).setOpaque(false);
}
}*/
OyoahaButtonLikeComponent blc = getOyoahaButtonLikeComponent(c);
if (blc!=null)
{
((JComponent)c).setOpaque(false);
}
}
/**
*
*/
public final static void unsetOpaque(Component c)
{
if(c instanceof JComponent)
{
//((JComponent)c).setOpaque(isAlphaClasses(c));
((JComponent)c).setOpaque(isOpaque(c));
}
}
/**
*
*/
public final static OyoahaThemeScheme getScheme()
{
return oyoahaLookAndFeel.getOyoahaThemeScheme();
}
/****************************************/
/****************************************/
/****************************************/
/**
*
*/
protected final static OyoahaColorPool getDefaultOyoahaColorPool()
{
if(pool==null)
{
//fist try to load the specified ColorPool...
Object o = UIManager.get("OyoahaUtilities.defaultOyoahaColorPool");
if(o!=null && o instanceof OyoahaColorPool)
{
pool = (OyoahaColorPool)o;
}
else
{
pool = new OyoahaDefaultColorPool(oyoahaLookAndFeel);
}
}
return pool;
}
public final static void updateOyoahaThemeScheme(OyoahaThemeSchemeChanged changed)
{
//nothing todo
}
public final static void updateOyoahaTheme()
{
pool = null;
}
/**
*
*/
public final static Color getColor(Component c)
{
return getColor(getBackground(c), getStatus(c));
}
/**
*
*/
public final static Color getColor(Component c, int status)
{
return getColor(getBackground(c), status);
}
/**
*
*/
public final static Color getColor(Color color, int status)
{
return getDefaultOyoahaColorPool().getColor(color, status);
}
/**
*
*/
public final static Color getColor(int status)
{
if(status==BLACK)
return oyoahaLookAndFeel.getOyoahaThemeScheme().getBlack();
if(status==WHITE)
return oyoahaLookAndFeel.getOyoahaThemeScheme().getWhite();
return getDefaultOyoahaColorPool().getColor(status);
}
/**
*
*/
public final static Color getColorFromScheme(int status)
{
return oyoahaLookAndFeel.getOyoahaThemeScheme().get(status);
}
/**
*
*/
public final static Color getColor(Component c, Color bg)
{
return getColor(bg, getStatus(c));
}
/****************************************/
/****************************************/
/****************************************/
/**
*
*/
public final static void paintAScrollMosaic(Graphics g, Component c, int x, int y, int width, int height, Image i, int decalX, int decalY)
{
paint.paintAScrollMosaic(g, c, x, y, width, height, i, decalX, decalY);
}
public final static void paintAGradient(Graphics g, Component c, int x, int y, int width, int height, Color color1, Color color2, boolean horizontal, boolean vertical, int state)
{
paint.paintAGradient(g, c, x, y, width, height, color1, color2, horizontal, vertical, state);
}
/**
*
*/
public final static void paintRScrollMosaic(Graphics g, Component c, int x, int y, int width, int height, Image i, int decalX, int decalY)
{
paint.paintAScrollMosaic(g, c, x, y, width, height, i, decalX, decalY);
}
/**
*
*/
public final static void paintAMosaic(Graphics g, Component c, int x, int y, int width, int height, Image i)
{
paint.paintAMosaic(g, c, x, y, width, height, i);
}
/**
*
*/
public final static void paintRMosaic(Graphics g, Component c, int x, int y, int width, int height, Image i)
{
paint.paintRMosaic(g, c, x, y, width, height, i);
}
public final static int CENTER = 0;
public final static int TOP = 1;
public final static int TOPLEFT = 2;
public final static int LEFT = 3;
public final static int LEFTBOTTOM = 4;
public final static int BOTTOM = 5;
public final static int BOTTOMRIGHT = 6;
public final static int RIGHT = 7;
public final static int RIGHTTOP = 8;
/**
*
*/
public final static void paintAImageAt(Graphics g, Component c, int x, int y, int width, int height, Image i, int pos)
{
paint.paintAImageAt(g, c, x, y, width, height, i, pos);
}
/**
*
*/
public final static void paintAImageAt(Graphics g, Component c, int x, int y, int width, int height, Image i, int pos, int w, int h)
{
paint.paintAImageAt(g, c, x, y, width, height, i, pos, w, h);
}
/**
*
*/
public final static void paintRImageAt(Graphics g, Component c, int x, int y, int width, int height, Image i, int pos)
{
paint.paintRImageAt(g, c, x, y, width, height, i, pos);
}
/**
*
*/
public final static void paintRScaling(Graphics g, Component c, int x, int y, int width, int height, Image i)
{
paint.paintRScaling(g, c, x, y, width, height, i);
}
/**
*
*/
public final static void paintAScaling(Graphics g, Component c, int x, int y, int width, int height, Image i)
{
paint.paintAScaling(g, c, x, y, width, height, i);
}
//- - - - - - - - -
public final static String getUIClassID2(Component c)
{
if(c instanceof JComponent)
{
String ui=((JComponent)c).getUIClassID();
if(ui==null || ui=="")
return null;
return ui;
}
return null;
}
public final static String getUIClassID(Component c)
{
if(c instanceof JComponent)
{
String ui=((JComponent)c).getUIClassID();
if(ui==null || ui=="")
return "Panel";
if(ui.endsWith("UI"))
ui=ui.substring(0,ui.length()-2);
return ui;
}
return "Panel";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -