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

📄 thebox.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    else
                    	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));                	
    
                    //do the ticker stuff
                    Functions.Ticker(tText, tIndex, 1, tY, cw - 1, g, Graphics.TOP | Graphics.LEFT);
                    tIndex = (short) ((tIndex + 1) % tText.length());
                    return;
                }
            }
    
            // screen parameters
            int screenHeight = getHeight();
            int screenWidth = getWidth();
            if (Settings.fontSize == Settings.FONT_NORMAL)
            	g.setFont(Font.getDefaultFont());
            else
            	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));

            int fontHeight = g.getFont().getHeight();
            
            //fill the screen with white color
            g.setColor(0x00ffffff); // white color
            g.fillRect(0, 0, screenWidth, screenHeight);
    
    
            if (isBusy()) {
                paintIsBusy();
                return;
            }
    
            //synchronization saves us from crashing, when the storage is being modified in another thread(ie deleting)
            //so the size of storage is changed and we may take an element that is out of array index
            synchronized (storage) {
                final int size = storage.getSize();
                  //System.out.println( "DEBUG TheBox.paint() - storage size: " + storage.getSize() );
                  // vertical coordinate where to start painting
                int actItem = 0;    // actually painted item
                if (Settings.fontSize == Settings.FONT_NORMAL) {
                	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); //set font size for box's headline
                } else {
                	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE)); //set font size for box's headline            	
                }
    
                // -3 because of headline's spacing
                actItem = getActuallyPaintedItem(g, g.getFont().getHeight() - 3, fontHeight, screenHeight);
                if (pageJump != 0) {
                    cur = actItem;
                    pageJump = 0;
                }
    
                //headline: for example the folder name and number of currently 
                // selected message
                int y = g.getFont().getHeight() + 3;
                printTitle(g);
    
                // paint messages
                while (y < screenHeight && actItem < size) {
                      //System.out.println("DEBUG TheBox.paint() - actItem: " + actItem);
                    //MessageHeader mail = (MessageHeader) storage.getMessageAt( size - actItem - 1 );
                    MessageHeader mail = storage.getMessageAt( actItem );
                    if ( mail.isEmpty() ) {
                        if ( actItem == cur) {
                            empties += (direction)?1:-1;
                            cur = moveCurrent(cur, direction);
                            printTitle(g);
                        }
                    	++actItem;
                    	continue;
                    }

                    if (actItem == cur) { //fill the selected item's background
                        g.setColor(121, 111, 255);
                        g.fillRect(0, y, screenWidth, 2 * fontHeight);
                        g.setColor(255, 255, 255);
                    } else {
                        g.setColor(0x00000000);
                    }

                      // horizontal coordinate where to start painting
                    int x = 1;

                    if (storage instanceof ThreadedEmails) {
                        ThreadedEmails tm = (ThreadedEmails)storage;
                        int level = tm.getLevel( mail.getThreadingMessageID() );
                          // we want to indent only first 10 levels because 
                          //   there is not enought space for message left
                        level = Math.min(level, 10);
                        x += ( 5 * level );
                    }

                    //icons
                    drawIcons(mail, g, x, y);
                    x += 12;
                    //has attachments
                    if (mail.messageFormat == MessageHeader.FRT_MULTI) {
                        g.drawImage(imAttch, x - 3, y + 3, Graphics.TOP | Graphics.LEFT);
                        x += 4;
                    }
                    //is flagged
                    if (mail.flagged) {
                    	g.drawImage(imFlagged, x - 3, y, Graphics.TOP | Graphics.LEFT);
                    	x += 12;
                    }
    
                    // subject
                    String newSbj = mail.getSubject().length() == 0 ? Lang.get(Lang.TB_NO_SUBJECT) : mail.getSubject();
                    if (g.getFont().stringWidth(newSbj) > screenWidth - x - 1) {	//does it fit to the display?				
                        newSbj = Functions.cutString(newSbj, 0, screenWidth - x - 1 - g.getFont().stringWidth(".."), g).trim() + "..";
                    }
                    g.drawString(newSbj, x + 1, y, Graphics.TOP | Graphics.LEFT);
    
    
                    y += fontHeight;
                    
                    // paint header details
                    y = headerDetailsPainter.paint(g, mail, actItem == cur, 
                        new ScreenParameters(fontHeight, screenWidth, y));
                    
                    // paint items below header details
                    y = belowHeaderDetailsPainter.paint(g, mail, actItem == cur, 
                        new ScreenParameters(fontHeight, screenWidth, y));
                    
                    // paint the line separating each mail
                    g.setColor(228, 228, 228);
                    g.drawLine(0, y, screenWidth, y);
                    ++y;
                    ++actItem;
                } // while
            } // synchronized
        } catch (Throwable t) {
            System.err.println("ERROR - TheBox.paint()");
            t.printStackTrace();
        }
    }
    
    protected class HeaderDetailsPainter implements MessagePartPainter {

        public int getHeight(Graphics g, boolean isMailSelected) {
            if (!isMailSelected) {
                return 0;
            } else {
                Font font = g.getFont();
                if (Settings.fontSize == Settings.FONT_NORMAL)
                	g.setFont(Font.getDefaultFont());
                else
                	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
                int messageFontHeight = g.getFont().getHeight();
                g.setFont(font);

                return (isMailSelected) ? messageFontHeight + 1 : messageFontHeight;
            }
        }

        /**
         * Paints header details. Called by method paint.
         * Paints all header details on single line. If the line is too long, uses
         * ticker to scroll through the line.
         * This implementation paints header details only if the mail is currently
         * selected. See parameter isMailSelected.
         * 
         * @param g the graphics object used for painting.
         * @param mail the mail which header details will be painted
         * @param isMailSelected true if the mail which header details are painted is
         *  currently selected.
         * @param screenParameters the parameters of the screen
         * @return vertical (y) position on the screen where next item can be painted
         */
        public int paint(Graphics g, MessageHeader mail, boolean isMailSelected, ScreenParameters screenParameters) {
            if (!isMailSelected) {
                return screenParameters.actYPosition;
            } else {

                int screenWidth = screenParameters.screenWidth;
                int y = screenParameters.actYPosition;
                int fontHeight = screenParameters.defaultFontHeight;

                if (Settings.fontSize == Settings.FONT_NORMAL)
                	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
                else
                	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));                	
                
                //Build the string which will be shown below
                //message header
                String info = (TheBox.this == getMujMail().getInBox()) ? 
                		Lang.get(Lang.ML_FROM) + " " + mail.getFrom() + " " + 
                		mail.getRecipients() + " " +
                		Lang.get(Lang.ML_MAIL_ACCOUNT) + " " + mail.getAccountID() 
                		: mail.getRecipients();
                		
                //add size to the info string
                info = mail.getSize() < 1024 ? info + "  " + Lang.get(Lang.ML_SIZE) + " " + mail.getSize() + "B" : info + "  " + Lang.get(Lang.ML_SIZE) + " " + mail.getSize() / 1024 + "kB";
                //display time, depending if its today or not, 86400000 = 24*60*60*1000
                if (System.currentTimeMillis() / 86400000 == mail.getTime() / 86400000) {
                    info = info + "  " + Lang.get(Lang.ML_TIME) + " " + mail.getShortTimeStr();
                } else {
                    info = info + "  " + Lang.get(Lang.ML_TIME) + " " + mail.getTimeStr().substring(5, 11);
                }

                //does it fit in?	
                if (tickerEnabled && g.getFont().stringWidth(info) > screenWidth - 1) {
                    if (tickerTimer == null) { //lets init the ticker																			
                        StringBuffer bf = new StringBuffer(info);
                        short space = (short) (screenWidth / (2 * g.getFont().charWidth(' ')));
                        for (short i = 0; i < space; i++) //lets fill it with half of screen of spaces
                        {
                            bf.append(' ');
                        }
                        tText = bf.toString();
                        info = Functions.cutString(info, 0, screenWidth - 1, g);
                        g.drawString(info, 1, y, Graphics.TOP | Graphics.LEFT);
                        tickerTimer = new Timer();
                        tY = y;
                        tickerTimer.schedule(new Ticker(), 100, 100);
                    }
                } else {
                    g.drawString(info, 1, y, Graphics.TOP | Graphics.LEFT);
                }

                y += fontHeight;
                if (Settings.fontSize == Settings.FONT_NORMAL)
                	g.setFont(Font.getDefaultFont());
                else
                	g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));

                return y;
            }
        }
        
        
    }

    /**
     * Interface for objects used to paint parts of messages while painting
     * the list of messages from this box.
     * Such objects are used in method paint of the class TheBox.
     * To change the way of painting of given part, redefine method setXXXPainter()
     * in the descendant of the class TheBox and set to variable used to paint
     * given message part another object implementing this interface.
     */
    protected interface MessagePartPainter {
        /** Dummy instance - does not paint anything. */
        public static final MessagePartPainter DEFAULT_PAINTER = new DefaultPainter();
        
        /**
         * Gets the height of this message part.
         * @param g the graphics object used for painting.
         * @param isMailSelected true if this mail is currently selected.
         * @return the height of this message part
         */
        public int getHeight(Graphics g, boolean isMailSelected);
        
        /**
         * Paints given message part.
         * 
         * @param g the graphics object used for painting.
         * @param mail the mail which part is painted
         * @param isMailSelected true if this mail is currently selected.
         * @param screenParameters the parameters of the screen
         * @return vertical (y) position on the screen where next item can be painted
         */
        public int paint(Graphics g, MessageHeader mail, boolean isMailSelected, ScreenParameters screenParameters);
        
        /**
         * Default implementation that does not paint anything.
         */
        public static class DefaultPainter implements MessagePartPainter {

            public int getHeight(Graphics g, boolean isMailSelected) {
                return 0;
            }

            public int paint(Graphics g, MessageHeader mail, boolean isMailSelected, ScreenParameters screenParameters) {
                return screenParameters.actYPosition;
            }
            
        }
    }
        
    /**
     * Represents screen parameters.
     */
    protected static class ScreenParameters {
        private final int defaultFontHeight;
        private final int screenWidth;
        private final int actYPosition;

        /**
         * 
         * @param defaultFontHeight the height of default font
         * @param screenWidth the width of the screen
         * @param actYPosition actual position when painting in the screen
         */
        public ScreenParameters(int defaultFontHeight, int screenWidth, int actYPosition) {
            this.defaultFontHeight = defaultFontHeight;
            this.screenWidth = screenWidth;
            this.actYPosition = actYPosition;
        }

    }
    
    
    //#ifdef MUJMAIL_TOUCH_SCR
    protected class EventListener extends  MujMailPointerEventListener.MujMailPointerEventListenerAdapter {
    //#else
//#     protected class EventListener {
    //#endif
        public void down() {
            pageJump = 1;
            repaint();
        }

        public void up() {
            pageJump = -1;
            repaint();
        }

        public void left() {
            commandAction(exit, TheBox.this);
        }

        public void right() {
        }

        public void fire() {
            if ( cur >= 0 && cur < storage.getSize() ) {
                commandAction(viewMessage, TheBox.this);
            }
        }

        public void downQuartersStar() {
            direction = true;
            shiftSelectedIndex(true);
        }

        public void upQuartersSlash() {
            direction = false;
            shiftSelectedIndex(false);
        }
    }
}

⌨️ 快捷键说明

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