├── .gitignore
├── .idea
├── .name
├── ant.xml
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── misc.xml
├── modules.xml
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml
├── Intellij-IDEA-Plugin-Background-Image.iml
├── README.mkd
├── build.xml
├── sample-screen.png
└── src
├── META-INF
└── plugin.xml
├── images
├── lil_nemo.png
└── nemo.jpg
└── org
└── intellij
└── plugins
└── backgroundimage
├── BackgroundBorder.java
├── BackgroundImageConfiguration.java
├── BackgroundImageConfigurationPanel.java
├── BackgroundImagePlugin.java
├── BackgroundImageVisibleAreaListener.java
└── EditorBackgroundListener.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | build
3 | classes
4 | out
5 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Intellij-IDEA-Plugin-Background-Image
--------------------------------------------------------------------------------
/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | http://www.w3.org/1999/xhtml
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | false
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 | localhost
447 | 5050
448 |
449 |
450 |
451 |
452 |
453 |
454 | 1300468193014
455 | 1300468193014
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 | Android
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 | IDEA-SDK
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 | 1.6.0_24
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 | Intellij-IDEA-Plugin-Background-Image
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
--------------------------------------------------------------------------------
/Intellij-IDEA-Plugin-Background-Image.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/README.mkd:
--------------------------------------------------------------------------------
1 | BackgroundImage - plus for Jetbrains family of IDEs
2 | ===================================================
3 | This is a plugin for Intellij IDEA, it lets you change the background for your editor window to any of a random set of images that the user supplies. The trick to using several images is to edit the location text box to point at a directory instead of a specific image. It will then pick a random image from that directory.
4 |
5 | Here is the entry for this plugin in the Intellij IDEA plugin repository.
6 |
7 | * http://plugins.intellij.net/plugin/?idea_ce&id=72
8 |
9 | NOTE
10 | ----
11 | Works on Mac OSX - but only seems to handle gif files (png and jpg dont show the code on top of the image :( )
12 |
13 | Screenshot
14 | ----------
15 | 
16 |
17 | TODO
18 | ----
19 | * handle png and jpg images on OSX (works on Windows)
20 | * upon changing the image path/url, handle properly the restart (or remove requirement to restart)
21 |
22 | BACKGROUND
23 | ----------
24 | Info on making a plugin work with the whole family of IDEA editors:
25 |
26 | * http://confluence.jetbrains.net/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
27 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/sample-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kimptoc/Intellij-IDEA-Plugin-Background-Image/82ae0541ef81eb09593196e986e753f96d2f8668/sample-screen.png
--------------------------------------------------------------------------------
/src/META-INF/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 | BackgroundImage
3 | Editor
4 | Plugin that loads a background image into editors
5 | 0.10.2
6 | Eric Sheffer/Charles DeCroes/Chris Kimpton
7 |
8 | com.intellij.modules.lang
9 |
11 | Support for IDEA 10.5 and above.
12 |
13 | ]]>
14 |
15 |
16 |
17 | org.intellij.plugins.backgroundimage.BackgroundImagePlugin
18 | org.intellij.plugins.backgroundimage.BackgroundImagePlugin
19 |
20 |
21 | org.intellij.plugins.backgroundimage.BackgroundImageConfiguration
22 | org.intellij.plugins.backgroundimage.BackgroundImageConfiguration
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/images/lil_nemo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kimptoc/Intellij-IDEA-Plugin-Background-Image/82ae0541ef81eb09593196e986e753f96d2f8668/src/images/lil_nemo.png
--------------------------------------------------------------------------------
/src/images/nemo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kimptoc/Intellij-IDEA-Plugin-Background-Image/82ae0541ef81eb09593196e986e753f96d2f8668/src/images/nemo.jpg
--------------------------------------------------------------------------------
/src/org/intellij/plugins/backgroundimage/BackgroundBorder.java:
--------------------------------------------------------------------------------
1 | package org.intellij.plugins.backgroundimage;
2 |
3 | import javax.swing.border.Border;
4 | import java.awt.*;
5 | import java.awt.image.BufferedImage;
6 |
7 | /**
8 | * BackgroundBorder - border that holds the image to load into the background
9 | */
10 | public class BackgroundBorder implements Border {
11 |
12 | /** Default image */
13 | private Image image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
14 | private boolean scale = NO_SCALE;
15 | public static final boolean SCALE = true;
16 | public static final boolean NO_SCALE = false;
17 |
18 | /**
19 | * Constructs a border that scales the image to fit the bound
20 | *
21 | * @param image
22 | */
23 | public BackgroundBorder(Image image) {
24 | this(image, SCALE);
25 | }
26 |
27 | /**
28 | *
29 | * @param image
30 | * @param scale
31 | */
32 | public BackgroundBorder(Image image, boolean scale) {
33 | this.scale = scale;
34 | this.image = image;
35 | }
36 |
37 | public void paintBorder(Component component, Graphics graphics, int x, int y, int width, int height) {
38 | Graphics2D g2 = (Graphics2D) graphics;
39 | g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
40 |
41 | //g2.drawImage(image, 1, 1, width, height, 1, 1, image.getWidth(), image.getHeight(), component);
42 |
43 | // only need to draw from x, y filling width, height
44 |
45 | for (int ix=x; ix<(x+width); ix+=image.getWidth(null))
46 | {
47 | for (int iy=y; iy<(y+height); iy+=image.getHeight(null))
48 | {
49 | g2.drawImage(image, ix, iy, component);
50 | }
51 | }
52 |
53 | /*
54 | g2.drawImage(image, 0,0,component);
55 | g2.drawImage(image, 0, image.getHeight(), component);
56 | g2.drawImage(image, 0, 2*image.getHeight(), component);
57 | g2.drawImage(image, 0, 3*image.getHeight(), component);
58 | g2.drawImage(image, 0, 4*image.getHeight(), component);
59 | */
60 |
61 | /*
62 | if (scale) {
63 | AffineTransform scale = new AffineTransform();
64 | //scale.scale(((double) width) / ((double) image.getWidth()), ((double) height) / ((double) image.getHeight()));
65 | double proportion = ((double) width) / ((double) image.getWidth());
66 | scale.scale(proportion, proportion);
67 | g2.drawImage(image, scale, component);
68 | } else {
69 | g2.drawImage(image, g2.getTransform(), component);
70 | }
71 | */
72 | }
73 |
74 | public Insets getBorderInsets(Component c) {
75 | return new Insets(0, 0, 0, 0);
76 | }
77 |
78 | public boolean isBorderOpaque() {
79 | return true;
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/src/org/intellij/plugins/backgroundimage/BackgroundImageConfiguration.java:
--------------------------------------------------------------------------------
1 | package org.intellij.plugins.backgroundimage;
2 |
3 | import com.intellij.openapi.util.JDOMExternalizable;
4 | import com.intellij.openapi.util.WriteExternalException;
5 | import com.intellij.openapi.util.InvalidDataException;
6 | import com.intellij.openapi.util.DefaultJDOMExternalizer;
7 | import com.intellij.openapi.components.ApplicationComponent;
8 | import org.jdom.Element;
9 |
10 | /**
11 | * BackgroundImageConfiguration
12 | */
13 | public class BackgroundImageConfiguration implements ApplicationComponent, JDOMExternalizable {
14 |
15 | public String getComponentName() {
16 | return "BackgroundImageConfiguration";
17 | }
18 |
19 | public void initComponent() {
20 | }
21 |
22 | public void disposeComponent() {
23 | }
24 |
25 | public void writeExternal(Element element) throws WriteExternalException {
26 | DefaultJDOMExternalizer.writeExternal(this, element);
27 | }
28 |
29 | public void readExternal(Element element) throws InvalidDataException {
30 | DefaultJDOMExternalizer.readExternal(this, element);
31 | }
32 |
33 | public boolean equals(final Object bj) {
34 | if (this == bj) {
35 | return true;
36 | }
37 | if (!(bj instanceof BackgroundImageConfiguration)) {
38 | return false;
39 | }
40 |
41 | final BackgroundImageConfiguration backgroundImageConfiguration = (BackgroundImageConfiguration) bj;
42 |
43 | if (!filename.equalsIgnoreCase(backgroundImageConfiguration.filename)) {
44 | return false;
45 | }
46 |
47 | if (localFile != backgroundImageConfiguration.localFile) {
48 | return false;
49 | }
50 |
51 | if (enabled != backgroundImageConfiguration.enabled) {
52 | return false;
53 | }
54 |
55 | return true;
56 | }
57 |
58 | public String filename = "";
59 | public boolean localFile;
60 | public boolean enabled;
61 | }
62 |
--------------------------------------------------------------------------------
/src/org/intellij/plugins/backgroundimage/BackgroundImageConfigurationPanel.java:
--------------------------------------------------------------------------------
1 | package org.intellij.plugins.backgroundimage;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 | import java.awt.event.ActionListener;
6 | import java.awt.event.ActionEvent;
7 | import java.awt.event.ItemListener;
8 | import java.awt.event.ItemEvent;
9 | import java.io.File;
10 | import java.text.MessageFormat;
11 |
12 | /**
13 | * BackgroundImageConfigurationPanel
14 | */
15 | public class BackgroundImageConfigurationPanel extends JComponent {
16 |
17 | public BackgroundImageConfigurationPanel() {
18 | this.setLayout(new GridBagLayout());
19 | GridBagConstraints gb = new GridBagConstraints();
20 | Insets defaultInsets = new Insets(5, 5, 5, 0);
21 | gb.insets = defaultInsets;
22 | gb.weightx = 0.0D;
23 | gb.weighty = 0.0D;
24 | gb.gridx = 0;
25 | gb.gridy = 0;
26 | gb.fill = 2;
27 |
28 | cbxEnabled = new Checkbox("Enabled", false);
29 | this.add(cbxEnabled, gb);
30 | cbxEnabled.addItemListener(new ItemListener() {
31 | public void itemStateChanged(ItemEvent event) {
32 | setEnabled(ItemEvent.SELECTED == event.getStateChange());
33 | }
34 | });
35 |
36 | gb.gridx = 0;
37 | gb.gridy++;
38 | imageLabel = new JLabel("Image: ");
39 | this.add(imageLabel, gb);
40 |
41 | gb.gridx++;
42 | gb.gridwidth = 5;
43 | fileSystemFilename = new JTextField();
44 | Dimension fieldPreferredSize = new Dimension(200, fileSystemFilename.getPreferredSize().height);
45 | fileSystemFilename.setPreferredSize(fieldPreferredSize);
46 | this.add(fileSystemFilename, gb);
47 |
48 | gb.insets = defaultInsets;
49 | gb.gridx += 5;
50 | gb.gridwidth = 1;
51 | gb.insets = new Insets(0, 0, 0, 0);
52 | btnProject = new JButton("...");
53 | Dimension d = new Dimension(fileSystemFilename.getPreferredSize().height, fileSystemFilename.getPreferredSize().height);
54 | btnProject.setPreferredSize(d);
55 | btnProject.setMinimumSize(d);
56 | btnProject.setMaximumSize(d);
57 | this.add(btnProject, gb);
58 |
59 | gb.insets = defaultInsets;
60 | btnProject.addActionListener(new ActionListener() {
61 |
62 | public void actionPerformed(ActionEvent e) {
63 | selectImage();
64 | }
65 |
66 | });
67 |
68 | gb.gridx = 1;
69 | gb.gridy++;
70 | cbxgrpFileType = new CheckboxGroup();
71 | cbxFileSystem = new Checkbox(FILE_SYSTEM_LABEL, false, cbxgrpFileType);
72 | cbxUrl = new Checkbox(URL_LABEL, true, cbxgrpFileType);
73 | this.add(cbxFileSystem, gb);
74 | gb.gridx++;
75 | this.add(cbxUrl, gb);
76 |
77 | gb.gridx = 10;
78 | gb.gridy++;
79 | gb.weightx = 1.0D;
80 | gb.weighty = 1.0D;
81 | gb.fill = 1;
82 | this.add(new JPanel(), gb);
83 |
84 | }
85 |
86 | public String getFilename() {
87 | return fileSystemFilename.getText();
88 | }
89 |
90 | public void setFilename(String s) {
91 | fileSystemFilename.setText(s);
92 | }
93 |
94 | public boolean isLocalFile() {
95 | return FILE_SYSTEM_LABEL.equalsIgnoreCase(cbxgrpFileType.getSelectedCheckbox().getLabel());
96 | }
97 |
98 | public void setLocalFile(boolean b){
99 | if (b) {
100 | cbxgrpFileType.setSelectedCheckbox(cbxFileSystem);
101 | } else {
102 | cbxgrpFileType.setSelectedCheckbox(cbxUrl);
103 | }
104 | }
105 |
106 | public boolean isEnabled() {
107 | return cbxEnabled.getState();
108 | }
109 |
110 | public void setEnabled(boolean b) {
111 | cbxEnabled.setState(b);
112 | fileSystemFilename.setEnabled(b);
113 | cbxFileSystem.setEnabled(b);
114 | cbxUrl.setEnabled(b);
115 | btnProject.setEnabled(b);
116 | imageLabel.setEnabled(b);
117 | }
118 |
119 | private void selectImage() {
120 | JFileChooser fileChooser = null;
121 | if (fileSystemFilename.getText() == null || fileSystemFilename.getText().equals("")) {
122 | fileChooser = new JFileChooser();
123 | } else {
124 | fileChooser = new JFileChooser(fileSystemFilename.getText());
125 | }
126 |
127 | fileChooser.setDialogTitle("Select Image:");
128 | File fileToOpen = null;
129 | do {
130 | int res = fileChooser.showOpenDialog(this);
131 | if (res != 0) {
132 | return;
133 | }
134 | fileToOpen = fileChooser.getSelectedFile();
135 | if (!fileToOpen.exists()) {
136 | JOptionPane.showMessageDialog(this, MessageFormat.format("File {0} does not exist.", new Object[]{
137 | fileToOpen.toString()
138 | }), "File Error", 0);
139 | } else {
140 | fileSystemFilename.setText(fileToOpen.getPath());
141 | return;
142 | }
143 | } while (true);
144 | }
145 |
146 | private JTextField fileSystemFilename;
147 | private CheckboxGroup cbxgrpFileType;
148 | private Checkbox cbxFileSystem;
149 | private Checkbox cbxUrl;
150 | private Checkbox cbxEnabled;
151 | private JButton btnProject;
152 | private JLabel imageLabel;
153 |
154 | private static String FILE_SYSTEM_LABEL = "FileSystem";
155 | private static String URL_LABEL = "URL";
156 | }
157 |
--------------------------------------------------------------------------------
/src/org/intellij/plugins/backgroundimage/BackgroundImagePlugin.java:
--------------------------------------------------------------------------------
1 | package org.intellij.plugins.backgroundimage;
2 |
3 |
4 | import com.intellij.openapi.application.Application;
5 | import com.intellij.openapi.application.ApplicationManager;
6 | import com.intellij.openapi.components.ApplicationComponent;
7 | import com.intellij.openapi.editor.EditorFactory;
8 | import com.intellij.openapi.options.Configurable;
9 | import com.intellij.openapi.ui.Messages;
10 |
11 | import javax.swing.*;
12 | import java.awt.*;
13 |
14 | /**
15 | *
BackgroundImagePlugin
16 | */
17 | public class BackgroundImagePlugin implements ApplicationComponent, Configurable {
18 |
19 | private BackgroundImageConfiguration theConfiguration;
20 | private BackgroundImageConfigurationPanel userInterface;
21 |
22 | public BackgroundImagePlugin() {
23 | super();
24 | icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/nemo.jpg")));
25 | }
26 |
27 | public String getDisplayName() {
28 | return "Background Image";
29 | }
30 |
31 | public String getHelpTopic() {
32 | return "plugins.BackgroundImagePlugin";
33 | }
34 |
35 | public void disposeUIResources() {
36 | userInterface = null;
37 | }
38 |
39 | public Icon getIcon() {
40 | return icon;
41 | }
42 |
43 | public JComponent createComponent() {
44 | if (userInterface == null) {
45 | userInterface = new BackgroundImageConfigurationPanel();
46 | reset();
47 | }
48 |
49 | return userInterface;
50 | }
51 |
52 | public void initComponent() {
53 | Application application = ApplicationManager.getApplication();
54 | theConfiguration = (BackgroundImageConfiguration) application.getComponent(BackgroundImageConfiguration.class);
55 |
56 | if (theConfiguration.filename.equalsIgnoreCase("")) {
57 | theConfiguration.filename = "http://i.imdb.com/Photos/Ss/0266543/Nemo102.jpg";
58 | theConfiguration.localFile = false;
59 | }
60 |
61 | backgroundListener = new EditorBackgroundListener(theConfiguration.filename, theConfiguration.localFile);
62 |
63 | if (theConfiguration.enabled) {
64 | EditorFactory.getInstance().addEditorFactoryListener(backgroundListener);
65 | }
66 | //visibleAreaChangedListener = new BackgroundImageVisibleAreaListener();
67 | //EditorFactory.getInstance().getEventMulticaster().addVisibleAreaListener(visibleAreaChangedListener);
68 |
69 | }
70 |
71 | public boolean isModified() {
72 | boolean flag = false;
73 | if (userInterface != null && theConfiguration != null) {
74 | flag = !userInterface.getFilename().equals(theConfiguration.filename) ||
75 | userInterface.isLocalFile() != theConfiguration.localFile ||
76 | userInterface.isEnabled() != theConfiguration.enabled;
77 | }
78 | return flag;
79 | }
80 |
81 | public void apply() {
82 | if (userInterface != null && theConfiguration != null) {
83 | theConfiguration.filename = userInterface.getFilename();
84 | theConfiguration.localFile = userInterface.isLocalFile();
85 | theConfiguration.enabled = userInterface.isEnabled();
86 | }
87 |
88 | if (0 == Messages.showYesNoDialog(DIALOG_MSG, "Warning!", null)) {
89 | ApplicationManager.getApplication().exit();
90 | }
91 | }
92 |
93 | public void reset() {
94 | if (userInterface != null && theConfiguration != null) {
95 | userInterface.setFilename(theConfiguration.filename);
96 | userInterface.setLocalFile(theConfiguration.localFile);
97 | userInterface.setEnabled(theConfiguration.enabled);
98 | }
99 | }
100 |
101 | /**
102 | * This method is called on plugin disposal.
103 | */
104 | public void disposeComponent() {
105 | if (theConfiguration.enabled) {
106 | EditorFactory.getInstance().removeEditorFactoryListener(backgroundListener);
107 | //EditorFactory.getInstance().getEventMulticaster().removeVisibleAreaListener(visibleAreaChangedListener);
108 | }
109 | }
110 |
111 | public String getComponentName() {
112 | return "BackgroundImagePlugin";
113 | }
114 |
115 | private Icon icon;
116 | private EditorBackgroundListener backgroundListener;
117 | //private VisibleAreaListener visibleAreaChangedListener;
118 |
119 | private static String DIALOG_MSG =
120 | "IDEA must be restarted for changes to take" +
121 | "\neffect. Would you like to shutdown IDEA?\n";
122 | }
123 |
--------------------------------------------------------------------------------
/src/org/intellij/plugins/backgroundimage/BackgroundImageVisibleAreaListener.java:
--------------------------------------------------------------------------------
1 | package org.intellij.plugins.backgroundimage;
2 |
3 | import com.intellij.openapi.editor.event.VisibleAreaListener;
4 | import com.intellij.openapi.editor.event.VisibleAreaEvent;
5 | import com.intellij.openapi.editor.Editor;
6 |
7 | import javax.swing.border.Border;
8 | import java.awt.*;
9 |
10 | /**
11 | * BackgroundImageVisibleAreaListener
12 | */
13 | public class BackgroundImageVisibleAreaListener implements VisibleAreaListener {
14 | public void visibleAreaChanged(VisibleAreaEvent event) {
15 | Rectangle rect = event.getNewRectangle();
16 | Editor editor = event.getEditor();
17 | Border border = editor.getContentComponent().getBorder();
18 | border.paintBorder(editor.getContentComponent(),
19 | editor.getContentComponent().getGraphics(),
20 | rect.x,
21 | rect.y,
22 | rect.width,
23 | rect.height);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/org/intellij/plugins/backgroundimage/EditorBackgroundListener.java:
--------------------------------------------------------------------------------
1 | package org.intellij.plugins.backgroundimage;
2 |
3 | import com.intellij.openapi.editor.event.EditorFactoryListener;
4 | import com.intellij.openapi.editor.event.EditorFactoryEvent;
5 | import com.intellij.openapi.editor.Editor;
6 | import com.intellij.openapi.ui.Messages;
7 |
8 | import javax.swing.border.Border;
9 | import javax.imageio.ImageIO;
10 | import java.net.URL;
11 | import java.io.File;
12 | import java.io.IOException;
13 | import java.io.FileFilter;
14 | import java.util.*;
15 | import java.awt.Toolkit;
16 |
17 | /**
18 | * EditorBackgroundListener - listens for new editors opening and adds a background image
19 | */
20 | public class EditorBackgroundListener implements EditorFactoryListener {
21 |
22 | public EditorBackgroundListener(String s, boolean b) {
23 | this.url = s;
24 | this.isLocalFile = b;
25 |
26 | try {
27 | if (isLocalFile) {
28 | background = getFileBackgroundBorder();
29 | } else {
30 | background = new BackgroundBorder(ImageIO.read(new URL(url)));
31 | }
32 | } catch (Exception e) {
33 | Messages.showErrorDialog(e.toString(), "Error loading background image");
34 | }
35 | }
36 |
37 | public void editorReleased(EditorFactoryEvent event) {
38 | event.getEditor().getContentComponent().setBorder(null);
39 | }
40 |
41 | public void editorCreated(EditorFactoryEvent event) {
42 |
43 | Editor editor = event.getEditor();
44 |
45 | try {
46 | editor.getContentComponent().setBorder(getBackground());
47 | } catch (Exception e) {
48 | Messages.showErrorDialog(e.toString(), "Error setting background image.");
49 | }
50 | }
51 |
52 | private Border getBackground() {
53 | if (null == background) {
54 | try {
55 | if (isLocalFile) {
56 | background = getFileBackgroundBorder();
57 | } else {
58 | background = new BackgroundBorder(ImageIO.read(new URL(url)));
59 | }
60 | } catch (Exception e) {
61 | Messages.showErrorDialog(e.toString(), "Error loading background image");
62 | }
63 | }
64 | return background;
65 | }
66 |
67 | private BackgroundBorder getFileBackgroundBorder() throws IOException {
68 | File file = new File(url);
69 | if (file.isFile())
70 | {
71 | return new BackgroundBorder(ImageIO.read(file));
72 | }
73 |
74 | // its a directory, so pick a random file...
75 | List allFiles = getAllFilesIncludingSubdirectories(file);
76 | File selectedFile = (File) allFiles.get((int) (Math.random()*allFiles.size()));
77 | // return new BackgroundBorder(ImageIO.read(selectedFile));
78 | return new BackgroundBorder(Toolkit.getDefaultToolkit().getImage(selectedFile.getAbsolutePath()));
79 | }
80 |
81 | private List getAllFilesIncludingSubdirectories(File file) {
82 | List results = new ArrayList();
83 | results.addAll(getAllFilesInDirectory(file));
84 |
85 | File[] subdirs = file.listFiles(new FileFilter(){
86 | public boolean accept(File pathname) {
87 | if (pathname.isDirectory())
88 | {
89 | return true;
90 | }
91 | return false;
92 | }
93 | });
94 |
95 | for (int i = 0; i < subdirs.length; i++) {
96 | File subdir = subdirs[i];
97 | results.addAll(getAllFilesIncludingSubdirectories(subdir));
98 | }
99 |
100 | return results;
101 | }
102 |
103 | private Collection getAllFilesInDirectory(File file) {
104 | File[] files = file.listFiles(new FileFilter(){
105 | public boolean accept(File pathname) {
106 | String name = pathname.getName();
107 | if (name.toLowerCase().endsWith(".jpg") ||
108 | name.toLowerCase().endsWith(".jpeg") ||
109 | name.toLowerCase().endsWith(".gif") ||
110 | name.toLowerCase().endsWith(".png") )
111 | {
112 | return true;
113 | }
114 | return false;
115 | }
116 | });
117 |
118 | return Arrays.asList(files);
119 | }
120 |
121 | private Border background;
122 | private String url;
123 | private boolean isLocalFile;
124 | /*private Border background = null;
125 | private String url = "http://i.imdb.com/Photos/Ss/0266543/Nemo102.jpg";
126 | private boolean isLocalFile = true;*/
127 | }
128 |
--------------------------------------------------------------------------------