📄 panel.java
字号:
if (navbarSize == 0) return; if (navbarImage == null) { navbarImage = theme.getNavbarTexture(width, navbarSize); } if(navbarImage!=null) g.drawImage(navbarImage, 0, height - navbarSize, Graphics.TOP | Graphics.LEFT); } private void drawDecorLeft(Graphics g) { // decor left not supported by this panel implementation. } private void drawDecorRight(Graphics g) { // decor right not supported by this panel implementation. } public void validate() { theme = FireScreen.getTheme(); if(showDecorations) { decorLeft = theme.decorLeft; titlebarSize = theme.decorTop; navbarSize = theme.decorBottom; decorRight = theme.decorRight; } else { decorLeft=0; titlebarSize=0; navbarSize=0; decorRight=0; } navbarImage = null; titlebarImage = null; int[] d = getPrefSize(); if (d == null) { d = getMinSize(); } width = d[0]; height = d[1]; if (container == null) { valid = true; return; } viewPortHeight = height - navbarSize - titlebarSize; viewPortWidth = width - decorLeft - decorRight; int []ps = container.getPrefSize(); if(ps!=null) // a container inside a panel must be atleast the size of the viewport { if(ps[0]<viewPortWidth) ps[0] = viewPortWidth; if(ps[1]<viewPortHeight) ps[1] = viewPortHeight; container.setPrefSize(ps[0],ps[1]); } container.validate(); // validate the container container.x = decorLeft; container.y = titlebarSize; normalVScrollLength = (NORMAL_SCROLL_PERCENT*viewPortHeight)/100; normalHScrollLength = (NORMAL_SCROLL_PERCENT*viewPortWidth)/100; fastVScrollLength = (FAST_SCROLL_PERCENT*viewPortHeight)/100; fastHScrollLength = (FAST_SCROLL_PERCENT*viewPortWidth)/100; valid = true; } /** * A Panel can have at most one container at any given time. * * @param container */ public void set(Container container) { if(container==null) throw new IllegalArgumentException("Cannot set a null container to a Panel. Use remove() instead."); if (this.container != null) this.container.parent = null; this.container = container; if (container.parent != null) { if (container.parent instanceof Container) ((Container) container.parent).remove(container); } container.parent = this; valid = false; } public Component getComponent(int i) { if(i==0) return container; else throw new ArrayIndexOutOfBoundsException("A panel has at most one container on index 0."); } public boolean remove(Component c) { if (container != c) { throw new IllegalArgumentException("Container "+c+" is not inside this panel."); } else if(container!=null) { container.parent = null; if(container.animation!=null) FireScreen.getScreen().removeAnimation(container.animation); container = null; valid = false; return true; } return false; } public int countComponents() { if(container!=null) return container.countComponents(); else return 0; } /** * * Sets the viewport position relative to the top left corner of the * container inside this panel. * * * @param x * the distance (in pixels) of the left side of the viewport from * the left side of the container * @param y * the distance (in pixels) of the top side of the viewport from * the top side of the container */ public boolean setViewPortPosition(int x, int y) { if (container == null) return false; int tx = decorLeft - container.x; int ty = titlebarSize - container.y; if (x + viewPortWidth > container.width) x = container.width - viewPortWidth; else if (x < 0) x = 0; if (y + viewPortHeight > container.height) y = container.height - viewPortHeight; else if (y < 0) y = 0; if(x==tx && y==ty) // nothing changed return false { return false; } // ok now set the correct offset to the container. container.x = decorLeft - x; container.y = titlebarSize - y; repaint(); return true; // change in the viewport position was successfull. } /** * Returns the vertical (X) coordinate of the viewport inside the innner container. * @return */ public int getViewPortPositionX() { if (container == null) return 0; return decorLeft - container.x; } /** * Returns the horizontal (Y) coordinate of the viewport inside the inner container. * @return */ public int getViewPortPositionY() { if (container == null) return 0; return titlebarSize - container.y; } /** * Returns the width of the viewport of this panel. * @return */ public int getViewPortWidth() { return viewPortWidth; } /** * Returns the height of the viewport of this panel. * @return */ public int getViewPortHeight() { return viewPortHeight; } protected void pointerDragged(int x, int y) { if (container != null) { if(dragScroll && dragX==-1 && dragY==-1) // intercept drag events end use them for navigation. { // keep the starting drag point. when the pointer is released a pointer event will be sent. dragX = x; dragY = y; } else if (x > decorLeft && x < width - decorRight && y > titlebarSize && y < height - navbarSize) { container.pointerDragged(x - container.x, y - container.y); } } super.pointerDragged(x,y); } protected void pointerPressed(int x, int y) { if (container != null) { if (x > decorLeft && x < width - decorRight && y > titlebarSize && y < height - navbarSize) { container.pointerPressed(x - container.x, y - container.y); } } super.pointerPressed(x,y); } protected void pointerReleased(int x, int y) { if(closeOnOutofBoundsPointerEvents && (x<0 || x>width || y<0 || y>height)) FireScreen.getScreen().removeComponent(this); if(container != null) { int dx = 0; int dy = 0; if(dragX!=-1 && dragY!=-1){ dx = x - dragX; dy = y - dragY; } if(dragScroll && (dx>10 || dx<-10 || dy>10 || dy<-10)) { // drag event. dx = x - dragX; dy = y - dragY; dragX=-1;dragY=-1; if(animation==null) { if(dy<-10) scrollVertically(fastVScrollLength); else if(dy>10) scrollVertically(-fastVScrollLength); else if(dx<-10) scrollHorizontally(fastHScrollLength); else if(dx>10) scrollHorizontally(-fastHScrollLength); } } else//If there is not a big dx or dy fire the event { int rightMargin = decorRight; if((scrollBarPolicy & VERTICAL_SCROLLBAR) == VERTICAL_SCROLLBAR && rightMargin<2*theme.scrollSize) { rightMargin = 2*theme.scrollSize; } if (x > decorLeft && x < width - rightMargin && y > titlebarSize && y < height - navbarSize) { container.pointerReleased(x - container.x, y - container.y); } else { if (((scrollBarPolicy & VERTICAL_SCROLLBAR) == VERTICAL_SCROLLBAR) && x > width - rightMargin && y < height - navbarSize) { // check if click is on scrollbar if (y > scrollY ) // scroll down { scrollVertically(normalVScrollLength); } else // scroll up { scrollVertically(-normalVScrollLength); } } else if (((scrollBarPolicy & HORIZONTAL_SCROLLBAR) == HORIZONTAL_SCROLLBAR) && y > (height - navbarSize-theme.scrollSize) && y < height - navbarSize + theme.scrollSize) { if (x > scrollX) { scrollHorizontally(-normalHScrollLength); } else { scrollHorizontally(normalHScrollLength); } } } } } if(pointerListener!=null) pointerListener.pointerReleased(x,y,this); } /** * Utility method to move the viewport vertically by the given number of pixels. * If the number is negative the panel will scroll up, otherwise if will scroll down. * @param pixels */ public void scrollVertically(int pixels) { if ((scrollBarPolicy & VERTICAL_SCROLLBAR) != VERTICAL_SCROLLBAR) return; int vpx = getViewPortPositionX(); int vpy = getViewPortPositionY(); setViewPortPosition(vpx,vpy+pixels); FireScreen screen = FireScreen.getScreen(); if(this.animation==null && screen.isAnimationsEnabled()) //only animate scroll if there is no other animation running on this panel. { ScrollAnimation anim = new ScrollAnimation(this,vpx,vpy,vpx,vpy+pixels); screen.registerAnimation(anim); } } /** * Utility method to move the viewport horizontally by the given number of pixels. * If the number is negative the panel will scroll right, otherwise if will scroll left. * @param pixels */ public void scrollHorizontally(int pixels) { if ((scrollBarPolicy & HORIZONTAL_SCROLLBAR) != HORIZONTAL_SCROLLBAR) return; int vpx = getViewPortPositionX(); int vpy = getViewPortPositionY(); setViewPortPosition(vpx+pixels,vpy); FireScreen screen = FireScreen.getScreen(); if(this.animation==null && screen.isAnimationsEnabled()) //only animate scroll if there is no other animation running on this panel. { ScrollAnimation anim = new ScrollAnimation(this,vpx,vpy,vpx+pixels,vpy); screen.registerAnimation(anim); } } protected void keyPressed(int keyCode) { if (container != null) container.keyPressed(keyCode); if(keyListener!=null) keyListener.keyPressed(keyCode,this); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -