FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

implementing new splash screen, sorting out other static init problems · irisSchaffer/processing@7b56136 · GitHub

Repository navigation

Commit 7b56136

Browse files
committed
implementing new splash screen, sorting out other static init problems
1 parent 7b767c6 commit 7b56136

15 files changed

Lines changed: 164 additions & 82 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package processing.app;
2+
3+
import java.io.File;
4+
5+
import processing.app.ui.SplashWindow;
6+
import processing.app.ui.Toolkit;
7+
8+
9+
public class BaseSplash {
10+
static public void main(String[] args) {
11+
try {
12+
final boolean hidpi = Toolkit.highResDisplay();
13+
final String filename = "lib/about-" + (hidpi ? 2 : 1) + "x.png";
14+
File splashFile = Platform.getContentFile(filename);
15+
SplashWindow.splash(splashFile.toURI().toURL(), hidpi);
16+
SplashWindow.invokeMain("processing.app.Base", args);
17+
SplashWindow.disposeSplash();
18+
} catch (Exception e) {
19+
e.printStackTrace();
20+
// !@#!@$$! umm
21+
//SplashWindow.invokeMain("processing.app.Base", args);
22+
}
23+
}
24+
}

‎app/src/processing/app/Language.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ static public String pluralize(String key, int count) {
212212
}
213213

214214

215+
/**
216+
* @param which either yes, no, cancel, ok, or browse
217+
*/
218+
static public String getPrompt(String which) {
219+
return Language.text("prompt." + which);
220+
}
221+
222+
215223
/** Get all available languages */
216224
static public Map<String, String> getLanguages() {
217225
return init().languages;

‎app/src/processing/app/Sketch.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ public void keyTyped(KeyEvent event) {
401401
JOptionPane.OK_CANCEL_OPTION,
402402
JOptionPane.PLAIN_MESSAGE,
403403
null, new Object[] {
404-
Toolkit.PROMPT_OK,
405-
Toolkit.PROMPT_CANCEL },
404+
Language.getPrompt("ok"),
405+
Language.getPrompt("cancel") },
406406
field);
407407

408408
if (userReply == JOptionPane.OK_OPTION) {

‎app/src/processing/app/ui/About.java‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,31 @@
2323
package processing.app.ui;
2424

2525
import java.awt.Color;
26-
import java.awt.Dimension;
2726
import java.awt.Font;
2827
import java.awt.Frame;
2928
import java.awt.Graphics;
30-
import java.awt.Graphics2D;
31-
import java.awt.Image;
32-
import java.awt.RenderingHints;
3329
import java.awt.Window;
3430
import java.awt.event.MouseAdapter;
3531
import java.awt.event.MouseEvent;
3632

33+
import javax.swing.ImageIcon;
34+
3735
import processing.app.Base;
3836

3937

4038
public class About extends Window {
41-
Image image;
39+
ImageIcon icon;
4240
int width, height;
4341

4442

4543
public About(Frame frame) {
4644
super(frame);
4745

46+
icon = Toolkit.getLibIconX("about");
47+
width = icon.getIconWidth();
48+
height = icon.getIconHeight();
49+
50+
/*
4851
if (Toolkit.highResDisplay()) {
4952
image = Toolkit.getLibImage("about-2x.jpg"); //$NON-NLS-1$
5053
width = image.getWidth(null) / 2;
@@ -54,28 +57,31 @@ public About(Frame frame) {
5457
width = image.getWidth(null);
5558
height = image.getHeight(null);
5659
}
60+
*/
5761

5862
addMouseListener(new MouseAdapter() {
5963
public void mousePressed(MouseEvent e) {
6064
dispose();
6165
}
6266
});
6367

64-
Dimension screen = Toolkit.getScreenSize();
65-
setBounds((screen.width-width)/2, (screen.height-height)/2, width, height);
68+
// Dimension screen = Toolkit.getScreenSize();
69+
// setBounds((screen.width-width)/2, (screen.height-height)/2, width, height);
70+
setLocationRelativeTo(null);
6671
setVisible(true);
6772
}
6873

6974

7075
public void paint(Graphics g) {
71-
g.drawImage(image, 0, 0, width, height, null);
76+
g.drawImage(icon.getImage(), 0, 0, width, height, null);
7277

73-
Graphics2D g2 = (Graphics2D) g;
74-
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
75-
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
78+
// Graphics2D g2 = (Graphics2D) g;
79+
// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
80+
// RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
7681

77-
g.setFont(new Font("SansSerif", Font.PLAIN, 10)); //$NON-NLS-1$
82+
g.setFont(Toolkit.getSansFont(Font.PLAIN, 10));
83+
//g.setFont(new Font("SansSerif", Font.PLAIN, 10)); //$NON-NLS-1$
7884
g.setColor(Color.white);
79-
g.drawString(Base.getVersionName(), 90, 29);
85+
g.drawString(Base.getVersionName(), 26, 29);
8086
}
8187
}

‎app/src/processing/app/ui/EditorStatus.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javax.swing.plaf.basic.BasicSplitPaneDivider;
3232
import javax.swing.plaf.basic.BasicSplitPaneUI;
3333

34+
import processing.app.Language;
3435
import processing.app.Mode;
3536
import processing.app.Platform;
3637
import processing.core.PApplet;
@@ -265,7 +266,7 @@ public void paint(Graphics screen) {
265266
if (indeterminate) {
266267
//int x = cancelButton.getX();
267268
//int w = cancelButton.getWidth();
268-
int w = Toolkit.BUTTON_WIDTH;
269+
int w = Toolkit.getButtonWidth();
269270
int x = getWidth() - RIGHT_MARGIN - w;
270271
int y = getHeight() / 3;
271272
int h = getHeight() / 3;

‎app/src/processing/app/ui/PreferencesFrame.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public PreferencesFrame(Base base) {
109109

110110
sketchbookLocationField = new JTextField(40);
111111

112-
browseButton = new JButton(Toolkit.PROMPT_BROWSE);
112+
browseButton = new JButton(Language.getPrompt("browse"));
113113
browseButton.addActionListener(new ActionListener() {
114114
public void actionPerformed(ActionEvent e) {
115115
File dflt = new File(sketchbookLocationField.getText());
@@ -362,21 +362,22 @@ public void mouseExited(MouseEvent e) {
362362

363363
// [ OK ] [ Cancel ]
364364

365-
okButton = new JButton(Toolkit.PROMPT_OK);
365+
okButton = new JButton(Language.getPrompt("ok"));
366366
okButton.addActionListener(new ActionListener() {
367367
public void actionPerformed(ActionEvent e) {
368368
applyFrame();
369369
disposeFrame();
370370
}
371371
});
372372

373-
JButton cancelButton = new JButton(Toolkit.PROMPT_CANCEL);
373+
JButton cancelButton = new JButton(Language.getPrompt("cancel"));
374374
cancelButton.addActionListener(new ActionListener() {
375375
public void actionPerformed(ActionEvent e) {
376376
disposeFrame();
377377
}
378378
});
379379

380+
final int buttonWidth = Toolkit.getButtonWidth();
380381
layout.setHorizontalGroup(layout.createSequentialGroup() // sequential group for border + mainContent + border
381382
.addGap(BORDER)
382383
.addGroup(layout.createParallelGroup() // parallel group for rest of the components
@@ -431,8 +432,8 @@ public void actionPerformed(ActionEvent e) {
431432
.addComponent(preferencePathLabel)
432433
.addComponent(preferenceHintLabel)
433434
.addGroup(GroupLayout.Alignment.TRAILING,layout.createSequentialGroup() // Trailing so that the buttons are to the right
434-
.addComponent(okButton, Toolkit.BUTTON_WIDTH, GroupLayout.DEFAULT_SIZE, Toolkit.BUTTON_WIDTH) // Ok and Cancel buttton are now of size BUTTON_WIDTH
435-
.addComponent(cancelButton, Toolkit.BUTTON_WIDTH, GroupLayout.DEFAULT_SIZE, Toolkit.BUTTON_WIDTH)
435+
.addComponent(okButton, buttonWidth, GroupLayout.DEFAULT_SIZE, buttonWidth) // Ok and Cancel buttton are now of size BUTTON_WIDTH
436+
.addComponent(cancelButton, buttonWidth, GroupLayout.DEFAULT_SIZE, buttonWidth)
436437
))
437438
.addGap(BORDER)
438439
);

‎app/src/processing/app/ui/SplashWindow.java‎

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package processing.app.ui;
2+
13
/*
24
* @(#)SplashWindow.java 2.2.1 2006-05-27
35
*
@@ -9,10 +11,16 @@
911
* without having to attribute to Werner Randelshofer.
1012
*/
1113

12-
import java.awt.*;
13-
import java.awt.event.*;
14-
import java.net.*;
15-
import java.io.*;
14+
import java.awt.EventQueue;
15+
import java.awt.Frame;
16+
import java.awt.Graphics;
17+
import java.awt.Image;
18+
import java.awt.MediaTracker;
19+
import java.awt.Toolkit;
20+
import java.awt.Window;
21+
import java.awt.event.MouseAdapter;
22+
import java.awt.event.MouseEvent;
23+
import java.net.URL;
1624

1725
/**
1826
* A Splash window.
@@ -42,12 +50,12 @@ public class SplashWindow extends Window {
4250
* (Singleton design pattern).
4351
*/
4452
private static SplashWindow instance;
45-
53+
4654
/**
4755
* The splash image which is displayed on the splash window.
4856
*/
4957
private Image image;
50-
58+
5159
/**
5260
* This attribute indicates whether the method
5361
* paint(Graphics) has been called at least once since the
@@ -62,23 +70,23 @@ public class SplashWindow extends Window {
6270
* @see #splash
6371
*/
6472
private boolean paintCalled = false;
65-
73+
6674
/**
6775
* Creates a new instance.
6876
* @param parent the parent of the window.
6977
* @param image the splash image.
7078
*/
71-
private SplashWindow(Frame parent, Image image) {
79+
private SplashWindow(Frame parent, Image image, boolean hidpi) {
7280
super(parent);
7381
this.image = image;
74-
82+
7583
// Load the image
7684
MediaTracker mt = new MediaTracker(this);
7785
mt.addImage(image,0);
7886
try {
7987
mt.waitForID(0);
8088
} catch(InterruptedException ie){}
81-
89+
8290
// Abort on failure
8391
if (mt.isErrorID(0)) {
8492
setSize(0,0);
@@ -89,17 +97,21 @@ private SplashWindow(Frame parent, Image image) {
8997
}
9098
return;
9199
}
92-
100+
93101
// Center the window on the screen
94102
int imgWidth = image.getWidth(this);
95103
int imgHeight = image.getHeight(this);
104+
105+
if (hidpi) {
106+
imgWidth /= 2;
107+
imgHeight /= 2;
108+
}
96109
setSize(imgWidth, imgHeight);
97-
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
98-
setLocation(
99-
(screenDim.width - imgWidth) / 2,
100-
(screenDim.height - imgHeight) / 2
101-
);
102-
110+
// Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
111+
// setLocation((screenDim.width - imgWidth) / 2,
112+
// (screenDim.height - imgHeight) / 2);
113+
setLocationRelativeTo(null);
114+
103115
// Users shall be able to close the splash window by
104116
// clicking on its display area. This mouse listener
105117
// listens for mouse clicks and disposes the splash window.
@@ -119,7 +131,7 @@ public void mouseClicked(MouseEvent evt) {
119131
};
120132
addMouseListener(disposeOnClick);
121133
}
122-
134+
123135
/**
124136
* Updates the display area of the window.
125137
*/
@@ -134,8 +146,8 @@ public void update(Graphics g) {
134146
* Paints the image on the window.
135147
*/
136148
public void paint(Graphics g) {
137-
g.drawImage(image, 0, 0, this);
138-
149+
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
150+
139151
// Notify method splash that the window
140152
// has been painted.
141153
// Note: To improve performance we do not enter
@@ -145,21 +157,21 @@ public void paint(Graphics g) {
145157
synchronized (this) { notifyAll(); }
146158
}
147159
}
148-
160+
149161
/**
150162
* Open's a splash window using the specified image.
151163
* @param image The splash image.
152164
*/
153-
public static void splash(Image image) {
165+
public static void splash(Image image, boolean hidpi) {
154166
if (instance == null && image != null) {
155167
Frame f = new Frame();
156-
168+
157169
// Create the splash image
158-
instance = new SplashWindow(f, image);
159-
170+
instance = new SplashWindow(f, image, hidpi);
171+
160172
// Show the window.
161-
instance.show();
162-
173+
instance.setVisible(true);
174+
163175
// Note: To make sure the user gets a chance to see the
164176
// splash window we wait until its paint method has been
165177
// called at least once by the AWT event dispatcher thread.
@@ -175,16 +187,17 @@ public static void splash(Image image) {
175187
}
176188
}
177189
}
190+
178191
/**
179192
* Open's a splash window using the specified image.
180193
* @param imageURL The url of the splash image.
181194
*/
182-
public static void splash(URL imageURL) {
195+
public static void splash(URL imageURL, boolean hidpi) {
183196
if (imageURL != null) {
184-
splash(Toolkit.getDefaultToolkit().createImage(imageURL));
197+
splash(Toolkit.getDefaultToolkit().createImage(imageURL), hidpi);
185198
}
186199
}
187-
200+
188201
/**
189202
* Closes the splash window.
190203
*/
@@ -194,7 +207,7 @@ public static void disposeSplash() {
194207
instance = null;
195208
}
196209
}
197-
210+
198211
/**
199212
* Invokes the main method of the provided class name.
200213
* @param args the command line arguments

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL