Feature #541 ยป antialias_fonType.patch
com/servoyguy/plugins/busy/BusyScriptObject.java (working copy) | ||
---|---|---|
17 | 17 |
package com.servoyguy.plugins.busy; |
18 | 18 |
|
19 | 19 |
import java.awt.Color; |
20 |
import java.awt.Font; |
|
20 | 21 |
|
21 | 22 |
import net.stuff.servoy.BusyAbstractProvider; |
22 | 23 |
import net.stuff.servoy.plugins.busy.wicket.BusyWicketProvider; |
... | ... | |
59 | 60 |
private Object[] processArgs; |
60 | 61 |
private Color paneColor; |
61 | 62 |
private Color textColor; |
63 |
private Font fontType; |
|
62 | 64 |
|
63 | 65 |
public BusyScriptObject(IClientPluginAccess application) { |
64 | 66 |
this.application = application; |
... | ... | |
102 | 104 |
processFunction = null; |
103 | 105 |
//callBackFunction = null; |
104 | 106 |
float opacity = (showGlassPane) ? 0.5f : 0f; |
105 |
getProvider().busy(msg, dialogName, opacity, showCancelButton, null); |
|
107 |
getProvider().busy(msg, dialogName, opacity, showCancelButton, null, null);
|
|
106 | 108 |
} |
107 | 109 |
} |
108 | 110 |
|
... | ... | |
143 | 145 |
if (params.has("textColor", params)) { |
144 | 146 |
textColor = PersistHelper.createColor((String)params.get("textColor", params)); |
145 | 147 |
} |
148 |
if (params.has("fontType", params)) { |
|
149 |
fontType = PersistHelper.createFont((String)params.get("fontType", params)); |
|
150 |
} |
|
146 | 151 |
if (params.has("showCancelButton", params)) { |
147 | 152 |
showCancelButton = Utils.getAsBoolean(params.get("showCancelButton", params)); |
148 | 153 |
} |
... | ... | |
179 | 184 |
} |
180 | 185 |
} |
181 | 186 |
} |
182 |
getProvider().busy(msg, dg, opacity, showCancelButton, cancelBtnText); |
|
187 |
getProvider().busy(msg, dg, opacity, showCancelButton, cancelBtnText, fontType);
|
|
183 | 188 |
} |
184 | 189 |
|
185 | 190 |
public void js_unblock() { |
... | ... | |
367 | 372 |
*/ |
368 | 373 |
public Color getTextColor() { |
369 | 374 |
return this.textColor; |
375 |
} |
|
376 |
|
|
377 |
/** |
|
378 |
* @return the fontType |
|
379 |
*/ |
|
380 |
public Font getFontType() { |
|
381 |
return this.fontType; |
|
370 | 382 |
} |
371 | 383 |
|
372 | 384 |
} |
com/servoyguy/plugins/busy/swing/BusySwingProvider.java (working copy) | ||
---|---|---|
18 | 18 | |
19 | 19 |
import java.awt.Component; |
20 | 20 |
import java.awt.Cursor; |
21 |
import java.awt.Font; |
|
21 | 22 |
import java.awt.Window; |
22 | 23 |
import java.awt.event.ActionEvent; |
23 | 24 |
import java.awt.event.ActionListener; |
... | ... | |
52 | 53 |
} |
53 | 54 |
|
54 | 55 |
public void busy(String msg, String dialogName, float opacity, |
55 |
boolean showCancelButton, String cancelBtnText) |
|
56 |
boolean showCancelButton, String cancelBtnText, Font fontType)
|
|
56 | 57 |
{ |
57 | 58 |
this.dialogName = dialogName; |
58 | 59 |
if (!busy.get()) { |
... | ... | |
82 | 83 |
if (cancelBtnText != null) { |
83 | 84 |
glassPane.setCancelBtnText(cancelBtnText); |
84 | 85 |
}; |
86 |
if (fontType != null) { |
|
87 |
glassPane.setFontType(fontType); |
|
88 |
}; |
|
85 | 89 |
if (!isMain() && !is5OrMore()) { |
86 | 90 |
mainPane = glassPane.getCopy(); |
87 | 91 |
setMainGlassPane(mainPane); |
com/servoyguy/plugins/busy/swing/GlassPane.java (working copy) | ||
---|---|---|
21 | 21 |
import java.awt.Dimension; |
22 | 22 |
import java.awt.Font; |
23 | 23 |
import java.awt.Graphics; |
24 |
import java.awt.Graphics2D; |
|
25 |
import java.awt.RenderingHints; |
|
24 | 26 |
import java.awt.event.ActionEvent; |
25 | 27 |
import java.awt.event.ActionListener; |
28 |
import java.awt.event.KeyAdapter; |
|
29 |
import java.awt.event.KeyEvent; |
|
26 | 30 |
import java.awt.event.MouseAdapter; |
27 | 31 | |
28 | 32 |
import javax.swing.JButton; |
29 | 33 |
import javax.swing.JPanel; |
30 | 34 | |
31 | 35 |
/** |
32 |
* @author Scott Buttler |
|
33 |
* http://www.servoyguy.com/ |
|
36 |
* @author Scott Buttler http://www.servoyguy.com/ |
|
34 | 37 |
* |
35 |
* modified by Servoy Stuff |
|
36 |
* http://www.servoy-stuff.net/ |
|
38 |
* modified by Servoy Stuff http://www.servoy-stuff.net/ |
|
37 | 39 |
*/ |
38 | 40 |
public class GlassPane extends JPanel { |
39 | 41 | |
40 | 42 |
private static final long serialVersionUID = 1L; |
41 |
|
|
43 | ||
42 | 44 |
private static final String DEFAULT_TEXT = null; |
43 | 45 |
private String text = DEFAULT_TEXT; |
44 | 46 |
private String[] lines; |
... | ... | |
48 | 50 |
private String cancelBtnText = "Cancel"; |
49 | 51 |
private Color paneColor = Color.black; |
50 | 52 |
private Color textColor = Color.white; |
51 |
|
|
53 |
private Font fontType; |
|
54 | ||
52 | 55 |
public GlassPane() { |
53 | 56 |
setOpaque(false); |
54 |
addMouseListener(new MouseAdapter(){}); |
|
57 |
addMouseListener(new MouseAdapter() { |
|
58 |
}); |
|
55 | 59 |
setLayout(null); |
56 | 60 |
add(getCancel()); |
57 | 61 |
} |
58 |
|
|
59 |
public JButton getCancel() |
|
60 |
{ |
|
62 | ||
63 |
public JButton getCancel() { |
|
61 | 64 |
if (cancelButton == null) { |
62 | 65 |
cancelButton = new JButton(cancelBtnText); |
63 | 66 |
cancelButton.setOpaque(false); |
64 | 67 |
cancelButton.setCursor(Cursor.getDefaultCursor()); |
65 |
cancelButton.addActionListener(new ActionListener(){ |
|
68 |
cancelButton.addActionListener(new ActionListener() {
|
|
66 | 69 |
public void actionPerformed(ActionEvent e) { |
67 | 70 |
canceled = true; |
68 | 71 |
cancelButton.setEnabled(false); |
69 |
}}); |
|
72 |
} |
|
73 |
}); |
|
70 | 74 |
cancelButton.setVisible(false); |
71 | 75 |
} |
72 | 76 |
return cancelButton; |
73 | 77 |
} |
74 |
|
|
78 | ||
75 | 79 |
protected void paintComponent(Graphics g) { |
76 |
Color color = getPaneColor(); |
|
77 |
float[] f = color.getComponents(null); |
|
78 |
g.setColor(new Color(f[0], f[1], f[2], opacity)); |
|
79 |
|
|
80 |
g.fillRect(0,0,super.getWidth(),super.getHeight()); |
|
81 |
Dimension size = cancelButton.getPreferredSize(); |
|
82 |
|
|
83 |
if (lines != null) { |
|
84 |
g.setColor(getTextColor()); |
|
85 |
g.setFont(g.getFont().deriveFont(Font.BOLD, 24)); |
|
86 |
float totalLineHeights = 0f; |
|
87 |
for (int i = 0; i < lines.length; i++) { |
|
88 |
totalLineHeights += g.getFontMetrics().getLineMetrics(lines[i], g).getHeight() + 5; |
|
89 |
} |
|
90 |
float lineHeight = 0; |
|
91 |
for (int i = 0; i < lines.length; i++) { |
|
92 |
String line = lines[i]; |
|
93 |
int width = g.getFontMetrics().stringWidth(line); |
|
94 |
lineHeight += g.getFontMetrics().getLineMetrics(line, g).getAscent(); |
|
95 |
g.drawString(line,(super.getWidth()/2) - (width/2), super.getHeight()/2 - (int)((totalLineHeights/2) - lineHeight) ); |
|
96 |
lineHeight += g.getFontMetrics().getLineMetrics(line, g).getDescent() + g.getFontMetrics().getLineMetrics(line, g).getLeading(); |
|
97 |
lineHeight += 5; |
|
98 |
} |
|
99 |
cancelButton.setBounds((super.getWidth()/2) - (size.width/2), (super.getHeight()/2) + (int)lineHeight-10,size.width, size.height); |
|
100 | 80 | |
101 |
} else { |
|
102 |
cancelButton.setBounds((super.getWidth()/2) - (size.width/2), (super.getHeight()/2),size.width, size.height); |
|
103 |
} |
|
81 |
// Cast the Graphics object into Graphics2D in oder to get anti aliasing support |
|
82 |
Graphics2D g2D = (Graphics2D) g; |
|
83 |
g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
|
84 | ||
85 |
Color color = getPaneColor(); |
|
86 |
float[] f = color.getComponents(null); |
|
87 |
g2D.setColor(new Color(f[0], f[1], f[2], opacity)); |
|
88 | ||
89 |
g2D.fillRect(0, 0, super.getWidth(), super.getHeight()); |
|
90 |
Dimension size = cancelButton.getPreferredSize(); |
|
91 | ||
92 |
if (lines != null) { |
|
93 |
g2D.setColor(getTextColor()); |
|
94 | ||
95 |
// Font management |
|
96 |
if (fontType == null) { |
|
97 |
fontType = g2D.getFont().deriveFont(Font.BOLD, 24); |
|
98 |
} |
|
99 |
g2D.setFont(fontType); |
|
100 | ||
101 |
float totalLineHeights = 0f; |
|
102 |
for (int i = 0; i < lines.length; i++) { |
|
103 |
totalLineHeights += g2D.getFontMetrics().getLineMetrics(lines[i], g2D).getHeight() + 5; |
|
104 |
} |
|
105 |
float lineHeight = 0; |
|
106 |
for (int i = 0; i < lines.length; i++) { |
|
107 |
String line = lines[i]; |
|
108 |
int width = g2D.getFontMetrics().stringWidth(line); |
|
109 |
lineHeight += g2D.getFontMetrics().getLineMetrics(line, g2D).getAscent(); |
|
110 |
g2D.drawString(line, (super.getWidth() / 2) - (width / 2), super.getHeight() / 2 |
|
111 |
- (int) ((totalLineHeights / 2) - lineHeight)); |
|
112 |
lineHeight += g2D.getFontMetrics().getLineMetrics(line, g2D).getDescent() |
|
113 |
+ g2D.getFontMetrics().getLineMetrics(line, g2D).getLeading(); |
|
114 |
lineHeight += 5; |
|
115 |
} |
|
116 |
cancelButton.setBounds((super.getWidth() / 2) - (size.width / 2), (super.getHeight() / 2) |
|
117 |
+ (int) lineHeight - 10, size.width, size.height); |
|
118 | ||
119 |
} else { |
|
120 |
cancelButton.setBounds((super.getWidth() / 2) - (size.width / 2), (super.getHeight() / 2), size.width, |
|
121 |
size.height); |
|
122 |
} |
|
104 | 123 |
} |
105 |
|
|
124 | ||
106 | 125 |
public void setVisible(boolean aFlag) { |
107 |
if(!aFlag) |
|
126 |
if (!aFlag)
|
|
108 | 127 |
setText(DEFAULT_TEXT); |
109 | 128 |
else |
110 | 129 |
setCanceled(false); |
... | ... | |
121 | 140 |
lines = text.split("\\n"); |
122 | 141 |
} |
123 | 142 |
} |
143 | ||
124 | 144 |
public boolean isCanceled() { |
125 | 145 |
return canceled; |
126 | 146 |
} |
127 | 147 | |
128 | 148 |
public void setCanceled(boolean canceled) { |
129 |
if(!canceled) |
|
149 |
if (!canceled)
|
|
130 | 150 |
cancelButton.setEnabled(true); |
131 | 151 |
this.canceled = canceled; |
132 | 152 |
} |
... | ... | |
147 | 167 |
} |
148 | 168 | |
149 | 169 |
/** |
150 |
* @param opacity the opacity to set |
|
170 |
* @param opacity |
|
171 |
* the opacity to set |
|
151 | 172 |
*/ |
152 | 173 |
public void setOpacity(float opacity) { |
153 | 174 |
this.opacity = opacity; |
... | ... | |
161 | 182 |
} |
162 | 183 | |
163 | 184 |
/** |
164 |
* @param cancelBtnText the cancelBtnText to set |
|
185 |
* @param cancelBtnText |
|
186 |
* the cancelBtnText to set |
|
165 | 187 |
*/ |
166 | 188 |
public void setCancelBtnText(String cancelBtnText) { |
167 | 189 |
this.cancelBtnText = cancelBtnText; |
... | ... | |
179 | 201 |
} |
180 | 202 | |
181 | 203 |
/** |
182 |
* @param paneColor the paneColor to set |
|
204 |
* @param paneColor |
|
205 |
* the paneColor to set |
|
183 | 206 |
*/ |
184 | 207 |
public void setPaneColor(Color paneColor) { |
185 | 208 |
this.paneColor = paneColor; |
... | ... | |
209 | 232 |
} |
210 | 233 | |
211 | 234 |
/** |
212 |
* @param textColor the textColor to set |
|
235 |
* @param textColor |
|
236 |
* the textColor to set |
|
213 | 237 |
*/ |
214 | 238 |
public void setTextColor(Color textColor) { |
215 | 239 |
this.textColor = textColor; |
216 | 240 |
} |
217 |
|
|
218 |
|
|
219 |
|
|
241 | ||
242 |
/** |
|
243 |
* @return the fontType |
|
244 |
*/ |
|
245 |
public Color getFontType() { |
|
246 |
return textColor; |
|
247 |
} |
|
248 | ||
249 |
/** |
|
250 |
* @param fontType |
|
251 |
* |
|
252 |
*/ |
|
253 |
public void setFontType(Font font) { |
|
254 |
this.fontType = font; |
|
255 |
} |
|
220 | 256 |
} |
net/stuff/servoy/BusyAbstractProvider.java (working copy) | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package net.stuff.servoy; |
20 | 20 |
|
21 |
import java.awt.Font; |
|
21 | 22 |
import java.util.concurrent.atomic.AtomicBoolean; |
22 | 23 |
|
23 | 24 |
import com.servoy.j2db.plugins.IClientPluginAccess; |
... | ... | |
43 | 44 |
} |
44 | 45 |
|
45 | 46 |
public abstract void busy(final String msg, final String dialogName, final float opacity, |
46 |
final boolean showCancelButton, final String cancelBtnText); |
|
47 |
final boolean showCancelButton, final String cancelBtnText, final Font fontType);
|
|
47 | 48 |
|
48 | 49 |
public abstract void ready(); |
49 | 50 |
|
net/stuff/servoy/plugins/busy/wicket/busy.js (working copy) | ||
---|---|---|
8 | 8 |
$j.unblockUI(); |
9 | 9 |
return false; |
10 | 10 |
}); |
11 |
$j.busy = function(msg, transparency, btn, callback, paneColor, textColor, msgBtn) { |
|
11 |
$j.busy = function(msg, transparency, btn, callback, paneColor, textColor, msgBtn, fontType) {
|
|
12 | 12 |
if (!msg) msg = ''; |
13 | 13 |
$j('#questionDiv > h1').html(msg); |
14 | 14 |
if (textColor) $j('#questionDiv > h1').css('color', textColor); |
15 |
if (fontType) $j('#questionDiv > h1').css('font-family', fontType); |
|
15 | 16 |
if (transparency < 0.5) $j('#questionDiv > h1').css('color', 'black'); |
16 | 17 |
if (btn) $j('#noBtn').css('display', 'inline'); |
17 | 18 |
if (callback) $j.blockUI.defaults.onUnblock = callback; |
net/stuff/servoy/plugins/busy/wicket/BusyWicketProvider.java (working copy) | ||
---|---|---|
19 | 19 |
package net.stuff.servoy.plugins.busy.wicket; |
20 | 20 |
|
21 | 21 |
import java.awt.Color; |
22 |
import java.awt.Font; |
|
22 | 23 |
|
23 | 24 |
import net.stuff.servoy.BusyAbstractProvider; |
24 | 25 |
import net.stuff.servoy.BusyServerPlugin; |
... | ... | |
34 | 35 |
import com.servoyguy.plugins.busy.BusyScriptObject; |
35 | 36 |
|
36 | 37 |
/** |
37 |
* @author Servoy Stuff |
|
38 |
* http://www.servoy-stuff.net/ |
|
38 |
* @author Servoy Stuff http://www.servoy-stuff.net/ |
|
39 | 39 |
*/ |
40 | 40 |
public class BusyWicketProvider extends BusyAbstractProvider { |
41 | 41 |
|
42 | 42 |
private BusyScriptBehaviorCancel behaviorCancel; |
43 | 43 |
private BusyScriptBehaviorStart behaviorStart; |
44 |
|
|
44 |
|
|
45 | 45 |
public BusyWicketProvider(final IClientPluginAccess app, final BusyScriptObject parent) { |
46 | 46 |
super(app, parent); |
47 | 47 |
} |
48 |
|
|
49 |
public void busy(final String msg, final String dialogName, final float opacity, |
|
50 |
final boolean showCancelButton, final String cancelBtnText) {
|
|
51 |
|
|
48 |
|
|
49 |
public void busy(final String msg, final String dialogName, final float opacity, final boolean showCancelButton,
|
|
50 |
final String cancelBtnText, final Font fontType) {
|
|
51 |
|
|
52 | 52 |
if (useAjax() && !busy.get()) { |
53 |
|
|
53 |
|
|
54 | 54 |
IPageContributor pc = initialize(); |
55 |
|
|
55 |
|
|
56 | 56 |
StringBuffer js = new StringBuffer("$j.busy("); |
57 | 57 |
if (msg == null) { |
58 | 58 |
js.append("null"); |
... | ... | |
62 | 62 |
js.append("'"); |
63 | 63 |
} |
64 | 64 |
js.append(", "); |
65 |
|
|
65 |
|
|
66 | 66 |
js.append(opacity); |
67 | 67 |
js.append(", "); |
68 |
|
|
68 |
|
|
69 | 69 |
js.append(showCancelButton); |
70 | 70 |
js.append(", "); |
71 |
|
|
72 |
|
|
71 |
|
|
73 | 72 |
String script = null; |
74 | 73 |
try { |
75 | 74 |
script = behaviorCancel.getScriptCallBack(); |
... | ... | |
83 | 82 |
js.append(script); |
84 | 83 |
js.append("}"); |
85 | 84 |
} |
86 |
|
|
85 |
|
|
87 | 86 |
final Color paneColor = parent.getPaneColor(); |
88 | 87 |
if (paneColor == null) { |
89 | 88 |
js.append(", null"); |
... | ... | |
93 | 92 |
js.append(color); |
94 | 93 |
js.append("'"); |
95 | 94 |
} |
96 |
|
|
95 |
|
|
97 | 96 |
final Color textColor = parent.getTextColor(); |
98 | 97 |
if (textColor == null) { |
99 | 98 |
js.append(", null"); |
... | ... | |
103 | 102 |
js.append(color); |
104 | 103 |
js.append("'"); |
105 | 104 |
} |
106 |
|
|
105 |
|
|
106 |
if (fontType == null) { |
|
107 |
js.append(", null"); |
|
108 |
} else { |
|
109 |
final String font = PersistHelper.createFontCssString(parent.getFontType()); |
|
110 |
js.append(", '"); |
|
111 |
js.append(font); |
|
112 |
js.append("'"); |
|
113 |
} |
|
114 |
|
|
107 | 115 |
if (cancelBtnText != null) { |
108 | 116 |
js.append(", '"); |
109 | 117 |
js.append(cancelBtnText); |
110 | 118 |
js.append("'"); |
111 | 119 |
} |
112 |
|
|
120 |
|
|
113 | 121 |
js.append(");\n"); |
114 | 122 |
js.append(behaviorStart.getScriptForCallback()); |
115 | 123 |
pc.addDynamicJavaScript(js.toString()); |
116 | 124 |
|
117 | 125 |
setCanceled(false); |
118 | 126 |
} |
119 |
|
|
120 |
//callProcess(); |
|
127 |
|
|
128 |
// callProcess();
|
|
121 | 129 |
} |
122 | 130 |
|
123 | 131 |
public void ready() { |
... | ... | |
131 | 139 |
Debug.error(ex); |
132 | 140 |
} |
133 | 141 |
if (useAjax()) { |
134 |
final IPageContributor pc = ((IWebClientPluginAccess)application).getPageContributor(); |
|
142 |
final IPageContributor pc = ((IWebClientPluginAccess) application).getPageContributor();
|
|
135 | 143 |
final String js = "$j.unblockUI({ onUnblock: null });"; |
136 | 144 |
pc.addDynamicJavaScript(js); |
137 | 145 |
} |
138 | 146 |
setCanceled(true); |
139 | 147 |
} |
140 |
|
|
148 |
|
|
141 | 149 |
public void prepare() { |
142 | 150 |
initialize(); |
143 | 151 |
} |
144 |
|
|
145 |
/* (non-Javadoc) |
|
152 |
|
|
153 |
/* |
|
154 |
* (non-Javadoc) |
|
155 |
* |
|
146 | 156 |
* @see com.servoyguy.plugins.busy.BusyAbstractScriptObject#dispose() |
147 | 157 |
*/ |
148 | 158 |
public void dispose() { |
... | ... | |
150 | 160 |
behaviorStart = null; |
151 | 161 |
behaviorCancel = null; |
152 | 162 |
} |
153 |
|
|
163 |
|
|
154 | 164 |
public String getClientID() { |
155 | 165 |
return application.getClientID(); |
156 | 166 |
} |
157 |
|
|
167 |
|
|
158 | 168 |
private IPageContributor initialize() { |
159 |
final IPageContributor ipc = ((IWebClientPluginAccess)application).getPageContributor(); |
|
169 |
final IPageContributor ipc = ((IWebClientPluginAccess) application).getPageContributor();
|
|
160 | 170 |
if (useAjax() && !busy.get()) { |
161 |
|
|
171 |
|
|
162 | 172 |
if (ipc.getBehavior(JQueryHeaderContributor.BEHAVIOR_TAG) == null) { |
163 | 173 |
ipc.addBehavior(JQueryHeaderContributor.BEHAVIOR_TAG, new JQueryHeaderContributor()); |
164 | 174 |
} |
... | ... | |
168 | 178 |
if (ipc.getBehavior(BusyHeaderContributor.BEHAVIOR_TAG) == null) { |
169 | 179 |
ipc.addBehavior(BusyHeaderContributor.BEHAVIOR_TAG, new BusyHeaderContributor()); |
170 | 180 |
} |
171 |
|
|
181 |
|
|
172 | 182 |
if (ipc.getBehavior(BusyScriptBehaviorStart.BEHAVIOR_TAG) == null) { |
173 | 183 |
behaviorStart = new BusyScriptBehaviorStart(this); |
174 | 184 |
ipc.addBehavior(BusyScriptBehaviorStart.BEHAVIOR_TAG, behaviorStart); |
... | ... | |
181 | 191 |
return ipc; |
182 | 192 |
} |
183 | 193 |
|
184 |
/* (non-Javadoc) |
|
194 |
/* |
|
195 |
* (non-Javadoc) |
|
196 |
* |
|
185 | 197 |
* @see net.stuff.servoy.BusyAbstractProvider#isCanceled() |
186 | 198 |
*/ |
187 | 199 |
@Override |