為JEdit設定牆紙(add wallpaper for jedit)

來源:互聯網
上載者:User
1). 前提(condition)+ jedit4.2final+ jdk 1.42). 步驟(steps)1. add this at org.gjt.sp.jedit.textarea.TextAreaPainterin method paintComponent(...)after:        extensionMgr.paintScreenLineRange(textArea, gfx, firstInvalid,                lastInvalid, y, height);add:        { // paint wallpaper after all that should be paint        Rectangle rect = this.getVisibleRect();        Wallpaper.paintWallpaper(gfx, rect.x, rect.y, rect.width,                rect.width, this);        }        2. add in org.gjt.sp.jedit.textarea.JEditTextArea        //    {{{ changeWallpaperDialog() method   // for change the wallpaper    /**         * Displays the 'changeWallpaperDialog' dialog box.     * @author neoedmund     */    public void changeWallpaperDialog()    {            if (Wallpaper.changeWallpaper(this)){            repaint();                }    } //}}}3. add new class org.gjt.sp.jedit.textarea.Wallpaper/* * Created on 2005-3-26 */package org.gjt.sp.jedit.textarea;import java.awt.AlphaComposite;import java.awt.Composite;import java.awt.Graphics2D;import java.awt.image.BufferedImage;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import javax.imageio.ImageIO;import javax.swing.JComponent;import javax.swing.JFileChooser;/** * @author neoe */public class Wallpaper {        static BufferedImage pic;    private static final String DEFALUT_IMG = "org/gjt/sp/jedit/icons/wallpaper.jpg";    static{        System.out.println("hello Wallpaper");        loadPic(ClassLoader                .getSystemResourceAsStream(DEFALUT_IMG));            }        static AlphaComposite alpha = AlphaComposite.getInstance(            AlphaComposite.SRC_OVER, 0.2f);    /**     * @param gfx     * @param width     * @param height     */    public static void paintWallpaper(Graphics2D g, int cx, int cy, int width, int height, JComponent view) {        if (pic==null){            return;        }        int y = 0;        int w = pic.getWidth();        int h = pic.getHeight();        Composite old = g.getComposite();        g.setComposite(alpha);        while (true) {            int x = 0;            while (true) {                g.drawImage(pic, cx+x, cy+y, view);                x += w;                if (w <= 0 || x >= width) {                    break;                }            }            y += h;            if (h <= 0 || y >= height) {                break;            }        }        g.setComposite(old);    }    /**     * @param in     */    private static void loadPic(InputStream in) {        try {            pic = ImageIO.read(in);        } catch (IOException e) {                        e.printStackTrace();        }            }    static File f;    /**     *      */    public static boolean changeWallpaper(JComponent parent) {        JFileChooser jfc = new JFileChooser(f);        int returnVal = jfc.showOpenDialog(parent);        if (returnVal == JFileChooser.APPROVE_OPTION) {            f = jfc.getSelectedFile();            try {                loadPic(new FileInputStream(f));                return true;            } catch (IOException e1) {                e1.printStackTrace();            }        }        return false;    }}4. copy default wallpaper whatever you like into org/gjt/sp/jedit/icons/wallpaper.jpg5. add this into org\gjt p\jedit\actions.xml<ACTION NAME="change-wallpaper">    <CODE>        textArea.changeWallpaperDialog();    </CODE></ACTION>6. change org\gjt p\jedit\jedit_gui.props, add "change-wallpaper" in tool bar#{{{ Tool barview.toolbar=new-file open-file close-buffer save - print page-setup - \    undo redo cut copy paste - find find-next - new-view unsplit \    split-horizontal split-vertical - buffer-options global-options - \    plugin-manager - help - change-wallpaper.........change-wallpaper.icon=Help.png........change-wallpaper.label=Change $Wallpaper7. last step, rebuild source, restart jedit, have fun. notes: I don`t know if it is something slowdown, but I like it :)

相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。