⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swingraplablock.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {
                y += 4;
                g.setFont( FONT_INVISIBLE );
                String label = getI18n().getString( "not_visible" );
                y = drawString( g, label, y, 5, true ) + 2;
                return;
            }

            String label = getName( getReservation() );
            y = drawString( g, label, y, 2, true ) + 2;

            // If the y reaches the lowerBound "..." will be displayed
            double lowerBound = height - 11;

            if ( getBuildContext().isPersonVisible() )
            {
                g.setFont( FONT_PERSON );
                g.setColor( fg );
                Allocatable[] persons = getReservation().getPersons();
                for ( int i = 0; i < persons.length; i++ )
                {
                    if ( !getContext().isVisible( persons[i] ) )
                        continue;
                    String text = getName( persons[i] );
                    if ( y > lowerBound )
                    {
                        text = "...";
                        y -= 7;
                    }
                    y = drawString( g, text, y, 7, true );
                }
            }

            if ( getBuildContext().isResourceVisible() )
            {
                Allocatable[] resources = getReservation().getResources();
                g.setFont( FONT_RESOURCE );
                g.setColor( fg );
                for ( int i = 0; i < resources.length; i++ )
                {
                    if ( !getContext().isVisible( resources[i] ) )
                        continue;
                    String text = getName( resources[i] );
                    if ( y > lowerBound )
                    {
                        text = "...";
                        y -= 7;
                    }
                    y = drawString( g, text, y, 7, true );
                }
            }
        }

        private void setExceptionPaint( Graphics g )
        {
            Paint p = new TexturePaint( getExceptionImage(), new Rectangle( 14, 14 ) );
            ( (Graphics2D) g ).setPaint( p );
        }

        private void paintBackground( Graphics g, int width, int height, int alpha )
        {
            String[] colors = getColorsAsHex();
            double colWidth = (double) ( width - 2 ) / colors.length;
            int x = 0;
            for ( int i = 0; i < colors.length; i++ )
            {
                g.setColor( adjustColor( colors[i], alpha ) );
                g.fillRect( (int) Math.ceil( x ) + 1, 1, (int) Math.ceil( colWidth ), height - 2 );
                if ( isException() )
                {
                    setExceptionPaint( g );
                    g.fillRect( (int) Math.ceil( x ) + 1, 1, (int) Math.ceil( colWidth ), height - 2 );
                }
                x += colWidth;
            }

            //g.setColor( adjustColor( "#000000", alpha ) );
            g.setColor( linecolor );
            g.drawRoundRect( 0, 0, width - 1, height - 1, 5, 5 );
        }

        private int findBreakingSpace( char[] c, int offset, int len, int maxWidth, FontMetrics fm )
        {
            int index = -1;
            for ( int i = offset; i < offset + len; i++ )
            {
                if ( c[i] == ' ' && fm.charsWidth( c, offset, i - offset ) < maxWidth )
                    index = i;
            }
            return index;
        }

        private int findBreaking( char[] c, int offset, int len, int maxWidth, FontMetrics fm )
        {
            int index = 0;
            for ( int i = offset; i < offset + len; i++ )
            {
                if ( fm.charsWidth( c, offset, i - offset ) < maxWidth )
                    index = i;
            }
            return index - 1;
        }

        // @return the new y-coordiante below the text
        private int drawString( Graphics g, String text, int y, int indent, boolean breakLines )
        {
            FontMetrics fm = g.getFontMetrics();
            //g.setFont(new Font("SimSun",Font.PLAIN, 12));
            char[] c = text.toCharArray();
            int cWidth = getSize().width - indent;
            int height = fm.getHeight();

            int len = c.length;
            int offset = 0;
            int x = indent;
            int maxWidth = ( y >= 14 || getAppointment().getRepeating() == null || !getBuildContext()
                                                                                                     .isRepeatingVisible() )
                    ? cWidth
                    : cWidth - 12;
            if ( !breakLines )
            {
                maxWidth = maxWidth - 5;
            }
            else
            {
                while ( offset < c.length && fm.charsWidth( c, offset, len ) > maxWidth )
                {
                    int breakingSpace = findBreakingSpace( c, offset, len, maxWidth, fm );
                    //int x = bCenter ? (getSize().width - width)/2 : indent ;
                    y = y + height;
                    if ( breakingSpace > 0 && breakLines )
                    {
                        g.drawChars(c,offset,breakingSpace-offset,x,y);
                        //              System.out.println("Drawing " + new String(c,offset,breakingSpace-offset));
                        len -= breakingSpace - offset + 1;
                        offset = breakingSpace + 1;
                    }
                    else
                    {
                        int breaking = findBreaking( c, offset, len, maxWidth, fm );
                        if ( breaking > 0 )
                        {
                            g.drawChars(c,offset,breaking-offset,x,y);
                            g.drawString( "\\", fm.charsWidth( c, offset, breaking - offset ) + indent, y );
                            //  System.out.println("Drawing " + new String(c,offset,breaking-offset) + "\\");
                            len -= breaking - offset;
                            offset = breaking;
                        }
                        else
                        {
                            return y;
                        }
                    }
                    //      System.out.println("New len " + len + " new offset " + offset);
                    maxWidth = cWidth;
                }
            }
            y = y + height;
            
            g.drawChars( c, offset, len, x, y );
            //      System.out.println("Drawing rest " + new String(c,offset,len));
            return y;
        }

        public void mouseClicked( MouseEvent arg0 )
        {

        }

        public void mousePressed( MouseEvent arg0 )
        {}

        public void mouseReleased( MouseEvent evt )
        {
            Point mp = evt.getPoint();
            boolean inside = mp.x >= 0 && mp.y >= 0 && mp.x <= getWidth() && mp.y <= getHeight();
            changeLineBorder( inside && getContext().isEventSelected() );
        }

        public void mouseEntered( MouseEvent evt )
        {
            if ( ( ( evt.getModifiers() & MouseEvent.BUTTON1_MASK ) > 0 ) || !getContext().isEventSelected() )
            {
                return;
            }
            changeLineBorder( true );
        }

        public void mouseExited( MouseEvent evt )
        {
            if ( ( evt.getModifiers() & MouseEvent.BUTTON1_MASK ) > 0 )
            {
                return;
            }
            changeLineBorder( false );
        }

        public void mouseDragged( MouseEvent arg0 )
        {}

        public void mouseMoved( MouseEvent arg0 )
        {
        // TODO Auto-generated method stub

        }

        private void changeLineBorder( boolean active )
        {
            List blocks = getBuildContext().getBlocks();
            for ( Iterator it = blocks.iterator(); it.hasNext(); )
            {
                SwingRaplaBlock block = (SwingRaplaBlock) it.next();

                if ( block.getAppointment().equals( getAppointment() ) )
                {
                    block.linecolor = active ? LINECOLOR_ACTIVE : LINECOLOR_INACTIVE;
                    block.m_view.repaint();
                }
                else if ( block.getReservation().equals( getReservation() ) )
                {
                    block.linecolor = active ? LINECOLOR_SAME_RESERVATION : LINECOLOR_INACTIVE;
                    block.m_view.repaint();
                }
            }
        }

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -