| 1 | |
package net.miginfocom.demo; |
| 2 | |
|
| 3 | |
import net.miginfocom.layout.PlatformDefaults; |
| 4 | |
import net.miginfocom.layout.UnitValue; |
| 5 | |
import net.miginfocom.swing.MigLayout; |
| 6 | |
import org.jvnet.substance.SubstanceLookAndFeel; |
| 7 | |
import org.jvnet.substance.fonts.SubstanceFontUtilities; |
| 8 | |
import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel; |
| 9 | |
|
| 10 | |
import javax.swing.*; |
| 11 | |
import javax.swing.border.LineBorder; |
| 12 | |
import javax.swing.plaf.FontUIResource; |
| 13 | |
import java.awt.*; |
| 14 | |
import java.awt.event.ActionEvent; |
| 15 | |
import java.awt.event.ActionListener; |
| 16 | |
import java.awt.event.ItemEvent; |
| 17 | |
import java.awt.event.ItemListener; |
| 18 | |
import java.awt.geom.AffineTransform; |
| 19 | |
import java.awt.image.BufferedImage; |
| 20 | |
import java.util.*; |
| 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 | |
public class HiDPISimulator |
| 59 | |
{ |
| 60 | |
static final String SYSTEM_LAF_NAME = "System"; |
| 61 | |
static final String SUBSTANCE_LAF_NAME = "Substance"; |
| 62 | |
static final String OCEAN_LAF_NAME = "Ocean"; |
| 63 | |
static final String NUMBUS_LAF_NAME = "Nimbus (Soon..)"; |
| 64 | |
|
| 65 | |
static JFrame APP_GUI_FRAME; |
| 66 | |
static HiDPIDemoPanel HiDPIDEMO_PANEL; |
| 67 | |
static JPanel SIM_PANEL; |
| 68 | |
static JPanel MIRROR_PANEL; |
| 69 | |
static JScrollPane MAIN_SCROLL; |
| 70 | |
static JTextArea TEXT_AREA; |
| 71 | |
|
| 72 | |
static boolean SCALE_LAF = false; |
| 73 | |
static boolean SCALE_FONTS = true; |
| 74 | |
static boolean SCALE_LAYOUT = true; |
| 75 | |
|
| 76 | |
static boolean PAINT_GHOSTED = false; |
| 77 | |
|
| 78 | |
static BufferedImage GUI_BUF = null; |
| 79 | |
static BufferedImage ORIG_GUI_BUF = null; |
| 80 | |
|
| 81 | |
static int CUR_DPI = PlatformDefaults.getDefaultDPI(); |
| 82 | |
static HashMap<String, Font> ORIG_DEFAULTS; |
| 83 | |
|
| 84 | |
private static JPanel createScaleMirror() |
| 85 | |
{ |
| 86 | |
return new JPanel(new MigLayout()) { |
| 87 | |
protected void paintComponent(Graphics g) |
| 88 | |
{ |
| 89 | |
super.paintComponent(g); |
| 90 | |
|
| 91 | |
if (GUI_BUF != null) { |
| 92 | |
Graphics2D g2 = (Graphics2D) g.create(); |
| 93 | |
|
| 94 | |
double dpi = getToolkit().getScreenResolution(); |
| 95 | |
|
| 96 | |
AffineTransform oldTrans = g2.getTransform(); |
| 97 | |
g2.scale(dpi / CUR_DPI, dpi / CUR_DPI); |
| 98 | |
|
| 99 | |
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
| 100 | |
|
| 101 | |
g2.drawImage(GUI_BUF, 0, 0, null); |
| 102 | |
|
| 103 | |
g2.setTransform(oldTrans); |
| 104 | |
|
| 105 | |
if (ORIG_GUI_BUF != null && PAINT_GHOSTED) { |
| 106 | |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f)); |
| 107 | |
g2.drawImage(ORIG_GUI_BUF, 0, 0, null); |
| 108 | |
} |
| 109 | |
|
| 110 | |
g2.dispose(); |
| 111 | |
} |
| 112 | |
} |
| 113 | |
|
| 114 | |
public Dimension getPreferredSize() |
| 115 | |
{ |
| 116 | |
return ORIG_GUI_BUF != null ? new Dimension(ORIG_GUI_BUF.getWidth(), ORIG_GUI_BUF.getHeight()) : new Dimension(100, 100); |
| 117 | |
} |
| 118 | |
|
| 119 | |
public Dimension getMinimumSize() |
| 120 | |
{ |
| 121 | |
return getPreferredSize(); |
| 122 | |
} |
| 123 | |
}; |
| 124 | |
} |
| 125 | |
|
| 126 | |
private static JPanel createSimulator() |
| 127 | |
{ |
| 128 | |
final JRadioButton scaleCompsFonts = new JRadioButton("UIManager Font Substitution", true); |
| 129 | |
final JRadioButton scaleCompsLaf = new JRadioButton("Native Look&Feel Scaling", false); |
| 130 | |
final JRadioButton scaleCompsNone = new JRadioButton("No Scaling", false); |
| 131 | |
final JRadioButton scaleLayoutMig = new JRadioButton("Native MigLayout Gap Scaling", true); |
| 132 | |
final JRadioButton scaleLayoutNone = new JRadioButton("No Gap Scaling", false); |
| 133 | |
final JComboBox lafCombo = new JComboBox(new String[] {SYSTEM_LAF_NAME, SUBSTANCE_LAF_NAME, OCEAN_LAF_NAME, NUMBUS_LAF_NAME}); |
| 134 | |
|
| 135 | |
final ButtonGroup bg1 = new ButtonGroup(); |
| 136 | |
final ButtonGroup bg2 = new ButtonGroup(); |
| 137 | |
final JCheckBox ghostCheck = new JCheckBox("Overlay \"Optimal\" HiDPI Result"); |
| 138 | |
|
| 139 | |
scaleCompsLaf.setEnabled(false); |
| 140 | |
|
| 141 | |
bg1.add(scaleCompsFonts); |
| 142 | |
bg1.add(scaleCompsLaf); |
| 143 | |
bg1.add(scaleCompsNone); |
| 144 | |
|
| 145 | |
bg2.add(scaleLayoutMig); |
| 146 | |
bg2.add(scaleLayoutNone); |
| 147 | |
|
| 148 | |
Vector<String> dpiStrings = new Vector<String>(); |
| 149 | |
|
| 150 | |
for (float f = 0.5f; f < 2.01f; f += 0.1f) |
| 151 | |
dpiStrings.add(Math.round(PlatformDefaults.getDefaultDPI() * f) + " DPI (" + Math.round(f * 100f + 0.499f) + "%)"); |
| 152 | |
|
| 153 | |
final JComboBox dpiCombo = new JComboBox(dpiStrings); |
| 154 | |
dpiCombo.setSelectedIndex(5); |
| 155 | |
|
| 156 | |
JPanel panel = new JPanel(new MigLayout("alignx center, insets 10px, flowy", "[]", "[]3px[]0px[]")); |
| 157 | |
|
| 158 | |
JLabel lafLabel = new JLabel("Look & Feel:"); |
| 159 | |
JLabel sliderLabel = new JLabel("Simulated DPI:"); |
| 160 | |
JLabel scaleLabel = new JLabel("Component/Text Scaling:"); |
| 161 | |
JLabel layoutLabel = new JLabel("LayoutManager Scaling:"); |
| 162 | |
JLabel visualsLabel = new JLabel("Visual Aids:"); |
| 163 | |
|
| 164 | |
panel.add(lafLabel, ""); |
| 165 | |
panel.add(lafCombo, "wrap"); |
| 166 | |
|
| 167 | |
panel.add(sliderLabel, ""); |
| 168 | |
panel.add(dpiCombo, "wrap"); |
| 169 | |
|
| 170 | |
panel.add(scaleLabel, ""); |
| 171 | |
panel.add(scaleCompsFonts, ""); |
| 172 | |
panel.add(scaleCompsLaf, ""); |
| 173 | |
panel.add(scaleCompsNone, "wrap"); |
| 174 | |
|
| 175 | |
panel.add(layoutLabel, ""); |
| 176 | |
panel.add(scaleLayoutMig, ""); |
| 177 | |
panel.add(scaleLayoutNone, "wrap"); |
| 178 | |
|
| 179 | |
panel.add(visualsLabel, ""); |
| 180 | |
panel.add(ghostCheck, ""); |
| 181 | |
|
| 182 | |
lockFont(dpiCombo, scaleCompsFonts, scaleCompsLaf, scaleLayoutMig, scaleCompsNone, lafCombo, ghostCheck, panel, lafLabel, sliderLabel, scaleLayoutNone, scaleLabel, layoutLabel, visualsLabel); |
| 183 | |
|
| 184 | |
lafCombo.addActionListener(new ActionListener() { |
| 185 | |
public void actionPerformed(ActionEvent e) |
| 186 | |
{ |
| 187 | |
GUI_BUF = null; |
| 188 | |
try { |
| 189 | |
Object s = lafCombo.getSelectedItem(); |
| 190 | |
|
| 191 | |
dpiCombo.setSelectedIndex(5); |
| 192 | |
|
| 193 | |
if (s.equals(SYSTEM_LAF_NAME)) { |
| 194 | |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 195 | |
} else if (s.equals(SUBSTANCE_LAF_NAME)) { |
| 196 | |
UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel()); |
| 197 | |
} else if (s.equals(OCEAN_LAF_NAME)) { |
| 198 | |
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); |
| 199 | |
} else { |
| 200 | |
JOptionPane.showMessageDialog(APP_GUI_FRAME, "Nimbus will be included as soon as it is ready!"); |
| 201 | |
} |
| 202 | |
|
| 203 | |
if (ORIG_DEFAULTS != null) { |
| 204 | |
for (String key : ORIG_DEFAULTS.keySet()) |
| 205 | |
UIManager.put(key, null); |
| 206 | |
} |
| 207 | |
ORIG_DEFAULTS = null; |
| 208 | |
|
| 209 | |
if (UIManager.getLookAndFeel().getName().toLowerCase().contains("windows")) { |
| 210 | |
UIManager.put("TextArea.font", UIManager.getFont("TextField.font")); |
| 211 | |
} else { |
| 212 | |
UIManager.put("TextArea.font", null); |
| 213 | |
} |
| 214 | |
|
| 215 | |
SwingUtilities.updateComponentTreeUI(APP_GUI_FRAME); |
| 216 | |
MAIN_SCROLL.setBorder(null); |
| 217 | |
|
| 218 | |
if (s.equals(SYSTEM_LAF_NAME)) { |
| 219 | |
if (scaleCompsLaf.isSelected()) |
| 220 | |
scaleCompsFonts.setSelected(true); |
| 221 | |
|
| 222 | |
scaleCompsLaf.setEnabled(false); |
| 223 | |
|
| 224 | |
} else if (s.equals(SUBSTANCE_LAF_NAME)) { |
| 225 | |
scaleCompsLaf.setEnabled(true); |
| 226 | |
|
| 227 | |
} else if (s.equals(OCEAN_LAF_NAME)) { |
| 228 | |
if (scaleCompsLaf.isSelected()) |
| 229 | |
scaleCompsFonts.setSelected(true); |
| 230 | |
scaleCompsLaf.setEnabled(false); |
| 231 | |
} |
| 232 | |
|
| 233 | |
setDPI(CUR_DPI); |
| 234 | |
|
| 235 | |
} catch (Exception ex) { |
| 236 | |
ex.printStackTrace(); |
| 237 | |
} |
| 238 | |
} |
| 239 | |
}); |
| 240 | |
|
| 241 | |
ghostCheck.addActionListener(new ActionListener() { |
| 242 | |
public void actionPerformed(ActionEvent actionEvent) |
| 243 | |
{ |
| 244 | |
GUI_BUF = null; |
| 245 | |
PAINT_GHOSTED = ghostCheck.isSelected(); |
| 246 | |
APP_GUI_FRAME.repaint(); |
| 247 | |
} |
| 248 | |
}); |
| 249 | |
|
| 250 | |
scaleLayoutMig.addItemListener(new ItemListener() { |
| 251 | |
public void itemStateChanged(ItemEvent e) |
| 252 | |
{ |
| 253 | |
GUI_BUF = null; |
| 254 | |
SCALE_LAYOUT = scaleLayoutMig.isSelected(); |
| 255 | |
setDPI(CUR_DPI); |
| 256 | |
} |
| 257 | |
}); |
| 258 | |
|
| 259 | |
ItemListener il = new ItemListener() { |
| 260 | |
public void itemStateChanged(ItemEvent e) |
| 261 | |
{ |
| 262 | |
if (e.getStateChange() == ItemEvent.SELECTED) { |
| 263 | |
GUI_BUF = null; |
| 264 | |
SCALE_LAF = scaleCompsLaf.isSelected(); |
| 265 | |
SCALE_FONTS = scaleCompsFonts.isSelected(); |
| 266 | |
setDPI(CUR_DPI); |
| 267 | |
} |
| 268 | |
} |
| 269 | |
}; |
| 270 | |
|
| 271 | |
scaleCompsLaf.addItemListener(il); |
| 272 | |
scaleCompsFonts.addItemListener(il); |
| 273 | |
scaleCompsNone.addItemListener(il); |
| 274 | |
|
| 275 | |
dpiCombo.addItemListener(new ItemListener() { |
| 276 | |
public void itemStateChanged(ItemEvent e) |
| 277 | |
{ |
| 278 | |
if (e.getStateChange() == ItemEvent.SELECTED) { |
| 279 | |
GUI_BUF = null; |
| 280 | |
CUR_DPI = Integer.parseInt(dpiCombo.getSelectedItem().toString().substring(0, 3).trim()); |
| 281 | |
setDPI(CUR_DPI); |
| 282 | |
} |
| 283 | |
} |
| 284 | |
}); |
| 285 | |
|
| 286 | |
return panel; |
| 287 | |
} |
| 288 | |
|
| 289 | |
private static void lockFont(Component ... comps) |
| 290 | |
{ |
| 291 | |
for (Component c : comps) { |
| 292 | |
Font f = c.getFont(); |
| 293 | |
c.setFont(f.deriveFont((float) f.getSize())); |
| 294 | |
} |
| 295 | |
} |
| 296 | |
|
| 297 | |
private static void revalidateGUI() |
| 298 | |
{ |
| 299 | |
APP_GUI_FRAME.getContentPane().invalidate(); |
| 300 | |
APP_GUI_FRAME.repaint(); |
| 301 | |
} |
| 302 | |
|
| 303 | |
private synchronized static void setDPI(int dpi) |
| 304 | |
{ |
| 305 | |
float scaleFactor = dpi / (float) Toolkit.getDefaultToolkit().getScreenResolution(); |
| 306 | |
TEXT_AREA.setSize(0, 0); |
| 307 | |
PlatformDefaults.setHorizontalScaleFactor(.1f); |
| 308 | |
PlatformDefaults.setHorizontalScaleFactor(SCALE_LAYOUT ? scaleFactor : null); |
| 309 | |
PlatformDefaults.setVerticalScaleFactor(SCALE_LAYOUT ? scaleFactor : null); |
| 310 | |
|
| 311 | |
float fontScale = SCALE_FONTS ? dpi / (float) Toolkit.getDefaultToolkit().getScreenResolution() : 1f; |
| 312 | |
|
| 313 | |
if (ORIG_DEFAULTS == null) { |
| 314 | |
ORIG_DEFAULTS = new HashMap<String, Font>(); |
| 315 | |
|
| 316 | |
Set entries = new HashSet(UIManager.getLookAndFeelDefaults().keySet()); |
| 317 | |
for (Iterator it = entries.iterator(); it.hasNext();) { |
| 318 | |
String key = it.next().toString(); |
| 319 | |
Object value = UIManager.get(key); |
| 320 | |
|
| 321 | |
if (value instanceof Font) |
| 322 | |
ORIG_DEFAULTS.put(key, (Font) value); |
| 323 | |
} |
| 324 | |
} |
| 325 | |
|
| 326 | |
Set entries = ORIG_DEFAULTS.entrySet(); |
| 327 | |
for (Iterator<Map.Entry<String, Font>> it = entries.iterator(); it.hasNext();) { |
| 328 | |
Map.Entry<String, Font> e = it.next(); |
| 329 | |
Font origFont = e.getValue(); |
| 330 | |
|
| 331 | |
if (SCALE_LAF == false) { |
| 332 | |
UIManager.put(e.getKey(), new FontUIResource(origFont.deriveFont(origFont.getSize() * fontScale))); |
| 333 | |
} else { |
| 334 | |
UIManager.put(e.getKey(), null); |
| 335 | |
} |
| 336 | |
} |
| 337 | |
|
| 338 | |
if (SCALE_LAF) { |
| 339 | |
scaleSubstanceLAF(scaleFactor); |
| 340 | |
} else if (UIManager.getLookAndFeel().getName().toLowerCase().contains("substance")) { |
| 341 | |
scaleSubstanceLAF(1); |
| 342 | |
} |
| 343 | |
|
| 344 | |
SwingUtilities.updateComponentTreeUI(HiDPIDEMO_PANEL); |
| 345 | |
revalidateGUI(); |
| 346 | |
} |
| 347 | |
|
| 348 | |
private static void scaleSubstanceLAF(float factor) |
| 349 | |
{ |
| 350 | |
SubstanceLookAndFeel.setFontPolicy(SubstanceFontUtilities.getScaledFontPolicy(factor)); |
| 351 | |
|
| 352 | |
try { |
| 353 | |
UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel()); |
| 354 | |
} catch (Exception exc) { |
| 355 | |
} |
| 356 | |
|
| 357 | |
SwingUtilities.updateComponentTreeUI(APP_GUI_FRAME); |
| 358 | |
MAIN_SCROLL.setBorder(null); |
| 359 | |
} |
| 360 | |
|
| 361 | |
public static void main(String[] args) |
| 362 | |
{ |
| 363 | |
try { |
| 364 | |
System.setProperty("apple.laf.useScreenMenuBar", "true"); |
| 365 | |
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "HiDPI Simulator"); |
| 366 | |
} catch(Exception ex) {} |
| 367 | |
|
| 368 | |
PlatformDefaults.setDefaultHorizontalUnit(UnitValue.LPX); |
| 369 | |
PlatformDefaults.setDefaultVerticalUnit(UnitValue.LPY); |
| 370 | |
|
| 371 | |
SwingUtilities.invokeLater(new Runnable() { |
| 372 | |
public void run() { |
| 373 | |
try { |
| 374 | |
|
| 375 | |
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); |
| 376 | |
} catch (Exception ex) { |
| 377 | |
ex.printStackTrace(); |
| 378 | |
} |
| 379 | |
|
| 380 | |
if (UIManager.getLookAndFeel().getName().toLowerCase().contains("windows")) |
| 381 | |
UIManager.put("TextArea.font", UIManager.getFont("TextField.font")); |
| 382 | |
|
| 383 | |
APP_GUI_FRAME = new JFrame("Resolution Independence Simulator"); |
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
JPanel uberPanel = new JPanel(new MigLayout("fill, insets 0px, nocache")); |
| 388 | |
|
| 389 | |
JPanel mainPanel = new JPanel(new MigLayout("fill, insets 0px, nocache")) { |
| 390 | |
public void paintComponent(Graphics g) |
| 391 | |
{ |
| 392 | |
Graphics2D g2 = (Graphics2D) g.create(); |
| 393 | |
|
| 394 | |
g2.setPaint(new GradientPaint(0, 0, new Color(20, 20, 30), 0, getHeight(), new Color(90, 90, 110), false)); |
| 395 | |
g2.fillRect(0, 0, getWidth(), getHeight()); |
| 396 | |
|
| 397 | |
g2.setFont(g2.getFont().deriveFont(Font.BOLD, 13)); |
| 398 | |
g2.setPaint(Color.WHITE); |
| 399 | |
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
| 400 | |
|
| 401 | |
g2.drawString("Left panel shows the scaled version. Right side shows how this would look on a HiDPI screen. It should look the same as the original panel!", 10, 19); |
| 402 | |
|
| 403 | |
g2.dispose(); |
| 404 | |
} |
| 405 | |
}; |
| 406 | |
|
| 407 | |
HiDPIDEMO_PANEL = new HiDPIDemoPanel(); |
| 408 | |
SIM_PANEL = createSimulator(); |
| 409 | |
MIRROR_PANEL = createScaleMirror(); |
| 410 | |
|
| 411 | |
MAIN_SCROLL = new JScrollPane(mainPanel); |
| 412 | |
MAIN_SCROLL.setBorder(null); |
| 413 | |
|
| 414 | |
mainPanel.add(HiDPIDEMO_PANEL, "align center center, split, span, width pref!"); |
| 415 | |
mainPanel.add(MIRROR_PANEL, "id mirror, gap 20px!, width pref!"); |
| 416 | |
|
| 417 | |
uberPanel.add(SIM_PANEL, "dock south"); |
| 418 | |
uberPanel.add(MAIN_SCROLL, "dock center"); |
| 419 | |
|
| 420 | |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
| 421 | |
APP_GUI_FRAME.setContentPane(uberPanel); |
| 422 | |
APP_GUI_FRAME.setSize(Math.min(1240, screenSize.width), Math.min(950, screenSize.height - 30)); |
| 423 | |
APP_GUI_FRAME.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
| 424 | |
APP_GUI_FRAME.setLocationRelativeTo(null); |
| 425 | |
APP_GUI_FRAME.setVisible(true); |
| 426 | |
} |
| 427 | |
}); |
| 428 | |
} |
| 429 | |
} |
| 430 | |
|
| 431 | |
class HiDPIDemoPanel extends JPanel { |
| 432 | |
public HiDPIDemoPanel() |
| 433 | |
{ |
| 434 | |
super(new MigLayout()); |
| 435 | |
|
| 436 | |
JLabel jLabel1 = new JLabel("A Small Label:"); |
| 437 | |
JTextField jTextField1 = new JTextField(10); |
| 438 | |
JButton jButton1 = new JButton("Cancel"); |
| 439 | |
JButton jButton2 = new JButton("OK"); |
| 440 | |
JButton jButton4 = new JButton("Help"); |
| 441 | |
JList jList1 = new JList(); |
| 442 | |
JLabel jLabel2 = new JLabel("Label:"); |
| 443 | |
JTextField jTextField2 = new JTextField(10); |
| 444 | |
JLabel jLabel3 = new JLabel("This is another section"); |
| 445 | |
JSeparator jSeparator1 = new JSeparator(); |
| 446 | |
JTextArea jTextArea1 = new JTextArea("Some general text that takes place, doesn't offend anyone and fills some pixels.", 3, 30); |
| 447 | |
JLabel jLabel4 = new JLabel("Some Text Area"); |
| 448 | |
JLabel jLabel6 = new JLabel("Some List:"); |
| 449 | |
JComboBox jComboBox1 = new JComboBox(); |
| 450 | |
JCheckBox jCheckBox1 = new JCheckBox("Orange"); |
| 451 | |
|
| 452 | |
JScrollBar scroll1 = new JScrollBar(JScrollBar.VERTICAL); |
| 453 | |
JScrollBar scroll2 = new JScrollBar(JScrollBar.HORIZONTAL, 30, 40, 0, 100); |
| 454 | |
JRadioButton radio = new JRadioButton("Apple"); |
| 455 | |
JProgressBar prog = new JProgressBar(); |
| 456 | |
prog.setValue(50); |
| 457 | |
JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 1)); |
| 458 | |
JTree tree = new JTree(); |
| 459 | |
tree.setOpaque(false); |
| 460 | |
tree.setEnabled(false); |
| 461 | |
|
| 462 | |
jList1.setModel(new AbstractListModel() { |
| 463 | |
String[] strings = { "Donald Duck", "Mickey Mouse", "Pluto", "Cartman" }; |
| 464 | |
public int getSize() { return strings.length; } |
| 465 | |
public Object getElementAt(int i) { return strings[i]; } |
| 466 | |
}); |
| 467 | |
|
| 468 | |
jList1.setVisibleRowCount(4); |
| 469 | |
jList1.setBorder(new LineBorder(Color.GRAY)); |
| 470 | |
jTextArea1.setLineWrap(true); |
| 471 | |
jTextArea1.setWrapStyleWord(true); |
| 472 | |
jTextArea1.setBorder(new LineBorder(Color.GRAY)); |
| 473 | |
jComboBox1.setModel(new DefaultComboBoxModel(new String[] {"Text in ComboBox"})); |
| 474 | |
jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
| 475 | |
|
| 476 | |
add(jLabel1, "split, span"); |
| 477 | |
add(jTextField1, ""); |
| 478 | |
add(jLabel2, "gap unrelated"); |
| 479 | |
add(jTextField2, "wrap"); |
| 480 | |
add(jLabel3, "split, span"); |
| 481 | |
add(jSeparator1, "growx, span, gap 2, wrap unrelated"); |
| 482 | |
add(jLabel4, "wrap 2"); |
| 483 | |
add(jTextArea1, "span, wmin 150, wrap unrelated"); |
| 484 | |
add(jLabel6, "wrap 2"); |
| 485 | |
add(jList1, "split, span"); |
| 486 | |
add(scroll1, "growy"); |
| 487 | |
add(prog, "width 80!"); |
| 488 | |
add(tree, "wrap unrelated"); |
| 489 | |
|
| 490 | |
add(scroll2, "split, span, growx"); |
| 491 | |
add(spinner, "wrap unrelated"); |
| 492 | |
add(jComboBox1, "span, split"); |
| 493 | |
add(radio, ""); |
| 494 | |
add(jCheckBox1, "wrap unrelated"); |
| 495 | |
add(jButton4, "split, span, tag help2"); |
| 496 | |
add(jButton2, "tag ok"); |
| 497 | |
add(jButton1, "tag cancel"); |
| 498 | |
|
| 499 | |
HiDPISimulator.TEXT_AREA = jTextArea1; |
| 500 | |
} |
| 501 | |
|
| 502 | |
public void paint(Graphics g) |
| 503 | |
{ |
| 504 | |
if (HiDPISimulator.GUI_BUF == null) { |
| 505 | |
BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); |
| 506 | |
|
| 507 | |
Graphics2D g2 = bi.createGraphics(); |
| 508 | |
|
| 509 | |
super.paint(g2); |
| 510 | |
|
| 511 | |
g2.dispose(); |
| 512 | |
|
| 513 | |
g.drawImage(bi, 0, 0, null); |
| 514 | |
|
| 515 | |
HiDPISimulator.GUI_BUF = bi; |
| 516 | |
|
| 517 | |
if (HiDPISimulator.CUR_DPI == PlatformDefaults.getDefaultDPI()) |
| 518 | |
HiDPISimulator.ORIG_GUI_BUF = bi; |
| 519 | |
|
| 520 | |
SwingUtilities.invokeLater(new Runnable() { |
| 521 | |
public void run() { |
| 522 | |
HiDPISimulator.MIRROR_PANEL.revalidate(); |
| 523 | |
HiDPISimulator.MIRROR_PANEL.repaint(); |
| 524 | |
} |
| 525 | |
}); |
| 526 | |
} else { |
| 527 | |
super.paint(g); |
| 528 | |
} |
| 529 | |
} |
| 530 | |
} |