| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | 25 | import java.awt.*; | |
| 26 | 26 | import java.awt.event.*; | |
| 27 | + import java.awt.image.BufferedImage; | ||
| 27 | 28 | import java.util.ArrayList; | |
| 28 | 29 | ||
| 29 | 30 | import javax.swing.*; | |
@@ -96,17 +97,6 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) { | |||
| 96 | 97 | // this.menu = menu; | |
| 97 | 98 | ||
| 98 | 99 | buttons = new ArrayList<Button>(); | |
| 99 | - // buttonCount = 0; | ||
| 100 | - // which = new int[BUTTON_COUNT]; | ||
| 101 | - | ||
| 102 | - // which[buttonCount++] = RUN; | ||
| 103 | - // which[buttonCount++] = STOP; | ||
| 104 | - // which[buttonCount++] = NEW; | ||
| 105 | - // which[buttonCount++] = OPEN; | ||
| 106 | - // which[buttonCount++] = SAVE; | ||
| 107 | - // which[buttonCount++] = EXPORT; | ||
| 108 | - | ||
| 109 | - // currentRollover = -1; | ||
| 110 | 100 | rollover = null; | |
| 111 | 101 | ||
| 112 | 102 | mode = editor.getMode(); | |
@@ -131,23 +121,37 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) { | |||
| 131 | 121 | * otherwise createImage() might fail. | |
| 132 | 122 | */ | |
| 133 | 123 | public Image[][] loadImages() { | |
| 134 | - // Image allButtons = Base.getThemeImage("buttons.gif", this); | ||
| 135 | - // Image allButtons = Base.loadImage(file); | ||
| 136 | - Image allButtons = mode.loadImage("theme/buttons.gif"); | ||
| 137 | - int count = allButtons.getWidth(this) / BUTTON_WIDTH; | ||
| 138 | - // System.out.println("width is " + allButtons.getWidth(this)); | ||
| 124 | + int res = Toolkit.isRetina() ? 2 : 1; | ||
| 125 | + | ||
| 126 | + Image allButtons = null; | ||
| 127 | + // Some modes may not have a 2x version. If a mode doesn't have a 1x | ||
| 128 | + // version, this will cause an error... they should always have 1x. | ||
| 129 | + if (res == 2) { | ||
| 130 | + allButtons = mode.loadImage("theme/buttons-2x.png"); | ||
| 131 | + if (allButtons == null) { | ||
| 132 | + res = 1; // take him down a notch | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + if (res == 1) { | ||
| 136 | + allButtons = mode.loadImage("theme/buttons.png"); | ||
| 137 | + if (allButtons == null) { | ||
| 138 | + // use the old (pre-2.0b9) file name | ||
| 139 | + allButtons = mode.loadImage("theme/buttons.gif"); | ||
| 140 | + } | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + int count = allButtons.getWidth(this) / BUTTON_WIDTH*res; | ||
| 139 | 144 | Image[][] buttonImages = new Image[count][3]; | |
| 140 | 145 | ||
| 141 | 146 | for (int i = 0; i < count; i++) { | |
| 142 | 147 | for (int state = 0; state < 3; state++) { | |
| 143 | - // Toolkit tk = Toolkit.getDefaultToolkit(); | ||
| 144 | - // Image image = tk.createImage(BUTTON_WIDTH, BUTTON_HEIGHT); | ||
| 145 | - // System.out.println("image is " + image + " " + BUTTON_WIDTH + " " + BUTTON_HEIGHT); | ||
| 146 | - Image image = createImage(BUTTON_WIDTH, BUTTON_HEIGHT); | ||
| 148 | + // Image image = createImage(BUTTON_WIDTH*res, BUTTON_HEIGHT*res); | ||
| 149 | + Image image = new BufferedImage(BUTTON_WIDTH*res, BUTTON_HEIGHT*res, BufferedImage.TYPE_INT_ARGB); | ||
| 147 | 150 | Graphics g = image.getGraphics(); | |
| 148 | 151 | g.drawImage(allButtons, | |
| 149 | - -(i*BUTTON_IMAGE_SIZE) - 3, | ||
| 150 | - (-2 + state)*BUTTON_IMAGE_SIZE, null); | ||
| 152 | + -(i*BUTTON_IMAGE_SIZE*res) - 3, | ||
| 153 | + (state-2)*BUTTON_IMAGE_SIZE*res, null); | ||
| 154 | + g.dispose(); | ||
| 151 | 155 | buttonImages[i][state] = image; | |
| 152 | 156 | } | |
| 153 | 157 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -803,6 +803,9 @@ void expandTree(JTree tree, Object object, String[] items, DefaultMutableTreeNod | |||
| 803 | 803 | */ | |
| 804 | 804 | public Image loadImage(String filename) { | |
| 805 | 805 | File file = new File(folder, filename); | |
| 806 | + if (!file.exists()) { | ||
| 807 | + return null; | ||
| 808 | + } | ||
| 806 | 809 | return new ImageIcon(file.getAbsolutePath()).getImage(); | |
| 807 | 810 | } | |
| 808 | 811 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -216,6 +216,7 @@ static public Clipboard getSystemClipboard() { | |||
| 216 | 216 | ||
| 217 | 217 | static Boolean retinaProp; | |
| 218 | 218 | ||
| 219 | + /** Yes, retina is a marketing term. But no, nobody else has implemented hi-dpi. */ | ||
| 219 | 220 | static public boolean isRetina() { | |
| 220 | 221 | if (Base.isMacOS()) { | |
| 221 | 222 | // This should probably be reset each time there's a display change. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments