-
-
Notifications
You must be signed in to change notification settings - Fork 256
/
DemoFrame.java
1019 lines (861 loc) · 36.1 KB
/
DemoFrame.java
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
447
448
449
450
451
452
453
454
455
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2019 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.demo;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Year;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.prefs.Preferences;
import javax.swing.*;
import javax.swing.text.DefaultEditorKit;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatDarculaLaf;
import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.demo.HintManager.Hint;
import com.formdev.flatlaf.demo.extras.*;
import com.formdev.flatlaf.demo.intellijthemes.*;
import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
import com.formdev.flatlaf.extras.FlatDesktop;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.formdev.flatlaf.extras.FlatUIDefaultsInspector;
import com.formdev.flatlaf.extras.components.FlatButton;
import com.formdev.flatlaf.extras.components.FlatButton.ButtonType;
import com.formdev.flatlaf.icons.FlatAbstractIcon;
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
import com.formdev.flatlaf.themes.FlatMacLightLaf;
import com.formdev.flatlaf.extras.FlatSVGUtils;
import com.formdev.flatlaf.ui.JBRCustomDecorations;
import com.formdev.flatlaf.util.ColorFunctions;
import com.formdev.flatlaf.util.FontUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.SystemInfo;
import net.miginfocom.layout.ConstraintParser;
import net.miginfocom.layout.LC;
import net.miginfocom.layout.UnitValue;
import net.miginfocom.swing.*;
/**
* @author Karl Tauber
*/
class DemoFrame
extends JFrame
{
private final String[] availableFontFamilyNames;
private int initialFontMenuItemCount = -1;
DemoFrame() {
int tabIndex = DemoPrefs.getState().getInt( FlatLafDemo.KEY_TAB, 0 );
availableFontFamilyNames = FontUtils.getAvailableFontFamilyNames().clone();
Arrays.sort( availableFontFamilyNames );
initComponents();
updateFontMenuItems();
initAccentColors();
controlBar.initialize( this, tabbedPane );
setIconImages( FlatSVGUtils.createWindowIconImages( "/com/formdev/flatlaf/demo/FlatLaf.svg" ) );
if( tabIndex >= 0 && tabIndex < tabbedPane.getTabCount() && tabIndex != tabbedPane.getSelectedIndex() )
tabbedPane.setSelectedIndex( tabIndex );
// macOS (see https://www.formdev.com/flatlaf/macos/)
if( SystemInfo.isMacOS ) {
// hide menu items that are in macOS application menu
exitMenuItem.setVisible( false );
aboutMenuItem.setVisible( false );
// do not use HTML text in menu items because this is not supported in macOS screen menu
htmlMenuItem.setText( "some text" );
if( SystemInfo.isMacFullWindowContentSupported ) {
// expand window content into window title bar and make title bar transparent
getRootPane().putClientProperty( "apple.awt.fullWindowContent", true );
getRootPane().putClientProperty( "apple.awt.transparentTitleBar", true );
// hide window title
if( SystemInfo.isJava_17_orLater )
getRootPane().putClientProperty( "apple.awt.windowTitleVisible", false );
else
setTitle( null );
// add gap to left side of toolbar
toolBar.add( Box.createHorizontalStrut( 70 ), 0 );
}
// enable full screen mode for this window (for Java 8 - 10; not necessary for Java 11+)
if( !SystemInfo.isJava_11_orLater )
getRootPane().putClientProperty( "apple.awt.fullscreenable", true );
}
// integrate into macOS screen menu
FlatDesktop.setAboutHandler( this::aboutActionPerformed );
FlatDesktop.setPreferencesHandler( this::showPreferences );
FlatDesktop.setQuitHandler( response -> {
response.performQuit();
} );
SwingUtilities.invokeLater( () -> {
showHints();
} );
}
@Override
public void dispose() {
super.dispose();
FlatUIDefaultsInspector.hide();
}
private void showHints() {
Hint fontMenuHint = new Hint(
"Use 'Font' menu to increase/decrease font size or try different fonts.",
fontMenu, SwingConstants.BOTTOM, "hint.fontMenu", null );
Hint optionsMenuHint = new Hint(
"Use 'Options' menu to try out various FlatLaf options.",
optionsMenu, SwingConstants.BOTTOM, "hint.optionsMenu", fontMenuHint );
Hint themesHint = new Hint(
"Use 'Themes' list to try out various themes.",
themesPanel, SwingConstants.LEFT, "hint.themesPanel", optionsMenuHint );
HintManager.showHint( themesHint );
}
private void clearHints() {
HintManager.hideAllHints();
Preferences state = DemoPrefs.getState();
state.remove( "hint.fontMenu" );
state.remove( "hint.optionsMenu" );
state.remove( "hint.themesPanel" );
}
private void showUIDefaultsInspector() {
FlatUIDefaultsInspector.show();
}
private void newActionPerformed() {
NewDialog newDialog = new NewDialog( this );
newDialog.setVisible( true );
}
private void openActionPerformed() {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog( this );
}
private void saveAsActionPerformed() {
JFileChooser chooser = new JFileChooser();
chooser.showSaveDialog( this );
}
private void exitActionPerformed() {
dispose();
}
private void aboutActionPerformed() {
JLabel titleLabel = new JLabel( "FlatLaf Demo" );
titleLabel.putClientProperty( FlatClientProperties.STYLE_CLASS, "h1" );
String link = "https://www.formdev.com/flatlaf/";
JLabel linkLabel = new JLabel( "<html><a href=\"#\">" + link + "</a></html>" );
linkLabel.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
linkLabel.addMouseListener( new MouseAdapter() {
@Override
public void mouseClicked( MouseEvent e ) {
try {
Desktop.getDesktop().browse( new URI( link ) );
} catch( IOException | URISyntaxException ex ) {
JOptionPane.showMessageDialog( linkLabel,
"Failed to open '" + link + "' in browser.",
"About", JOptionPane.PLAIN_MESSAGE );
}
}
} );
JOptionPane.showMessageDialog( this,
new Object[] {
titleLabel,
"Demonstrates FlatLaf Swing look and feel",
" ",
"Copyright 2019-" + Year.now() + " FormDev Software GmbH",
linkLabel,
},
"About", JOptionPane.PLAIN_MESSAGE );
}
private void showPreferences() {
JOptionPane.showMessageDialog( this,
"Sorry, but FlatLaf Demo does not have preferences. :(\n"
+ "This dialog is here to demonstrate usage of class 'FlatDesktop' on macOS.",
"Preferences", JOptionPane.PLAIN_MESSAGE );
}
private void selectedTabChanged() {
DemoPrefs.getState().putInt( FlatLafDemo.KEY_TAB, tabbedPane.getSelectedIndex() );
}
private void menuItemActionPerformed( ActionEvent e ) {
SwingUtilities.invokeLater( () -> {
JOptionPane.showMessageDialog( this, e.getActionCommand(), "Menu Item", JOptionPane.PLAIN_MESSAGE );
} );
}
private void windowDecorationsChanged() {
boolean windowDecorations = windowDecorationsCheckBoxMenuItem.isSelected();
// change window decoration of all frames and dialogs
FlatLaf.setUseNativeWindowDecorations( windowDecorations );
menuBarEmbeddedCheckBoxMenuItem.setEnabled( windowDecorations );
unifiedTitleBarMenuItem.setEnabled( windowDecorations );
showTitleBarIconMenuItem.setEnabled( windowDecorations );
}
private void menuBarEmbeddedChanged() {
UIManager.put( "TitlePane.menuBarEmbedded", menuBarEmbeddedCheckBoxMenuItem.isSelected() );
FlatLaf.revalidateAndRepaintAllFramesAndDialogs();
}
private void unifiedTitleBar() {
UIManager.put( "TitlePane.unifiedBackground", unifiedTitleBarMenuItem.isSelected() );
FlatLaf.repaintAllFramesAndDialogs();
}
private void showTitleBarIcon() {
boolean showIcon = showTitleBarIconMenuItem.isSelected();
// for main frame (because already created)
getRootPane().putClientProperty( FlatClientProperties.TITLE_BAR_SHOW_ICON, showIcon );
// for other not yet created frames/dialogs
UIManager.put( "TitlePane.showIcon", showIcon );
}
private void underlineMenuSelection() {
UIManager.put( "MenuItem.selectionType", underlineMenuSelectionMenuItem.isSelected() ? "underline" : null );
}
private void alwaysShowMnemonics() {
UIManager.put( "Component.hideMnemonics", !alwaysShowMnemonicsMenuItem.isSelected() );
repaint();
}
private void animatedLafChangeChanged() {
System.setProperty( "flatlaf.animatedLafChange", String.valueOf( animatedLafChangeMenuItem.isSelected() ) );
}
private void showHintsChanged() {
clearHints();
showHints();
}
private void fontFamilyChanged( ActionEvent e ) {
String fontFamily = e.getActionCommand();
FlatAnimatedLafChange.showSnapshot();
Font font = UIManager.getFont( "defaultFont" );
Font newFont = FontUtils.getCompositeFont( fontFamily, font.getStyle(), font.getSize() );
UIManager.put( "defaultFont", newFont );
FlatLaf.updateUI();
FlatAnimatedLafChange.hideSnapshotWithAnimation();
}
private void fontSizeChanged( ActionEvent e ) {
String fontSizeStr = e.getActionCommand();
Font font = UIManager.getFont( "defaultFont" );
Font newFont = font.deriveFont( (float) Integer.parseInt( fontSizeStr ) );
UIManager.put( "defaultFont", newFont );
FlatLaf.updateUI();
}
private void restoreFont() {
UIManager.put( "defaultFont", null );
updateFontMenuItems();
FlatLaf.updateUI();
}
private void incrFont() {
Font font = UIManager.getFont( "defaultFont" );
Font newFont = font.deriveFont( (float) (font.getSize() + 1) );
UIManager.put( "defaultFont", newFont );
updateFontMenuItems();
FlatLaf.updateUI();
}
private void decrFont() {
Font font = UIManager.getFont( "defaultFont" );
Font newFont = font.deriveFont( (float) Math.max( font.getSize() - 1, 10 ) );
UIManager.put( "defaultFont", newFont );
updateFontMenuItems();
FlatLaf.updateUI();
}
void updateFontMenuItems() {
if( initialFontMenuItemCount < 0 )
initialFontMenuItemCount = fontMenu.getItemCount();
else {
// remove old font items
for( int i = fontMenu.getItemCount() - 1; i >= initialFontMenuItemCount; i-- )
fontMenu.remove( i );
}
// get current font
Font currentFont = UIManager.getFont( "Label.font" );
String currentFamily = currentFont.getFamily();
String currentSize = Integer.toString( currentFont.getSize() );
// add font families
fontMenu.addSeparator();
ArrayList<String> families = new ArrayList<>( Arrays.asList(
"Arial", "Cantarell", "Comic Sans MS", "DejaVu Sans",
"Dialog", "Inter", "Liberation Sans", "Noto Sans", "Open Sans", "Roboto",
"SansSerif", "Segoe UI", "Serif", "Tahoma", "Ubuntu", "Verdana" ) );
if( !families.contains( currentFamily ) )
families.add( currentFamily );
families.sort( String.CASE_INSENSITIVE_ORDER );
ButtonGroup familiesGroup = new ButtonGroup();
for( String family : families ) {
if( Arrays.binarySearch( availableFontFamilyNames, family ) < 0 )
continue; // not available
JCheckBoxMenuItem item = new JCheckBoxMenuItem( family );
item.setSelected( family.equals( currentFamily ) );
item.addActionListener( this::fontFamilyChanged );
fontMenu.add( item );
familiesGroup.add( item );
}
// add font sizes
fontMenu.addSeparator();
ArrayList<String> sizes = new ArrayList<>( Arrays.asList(
"10", "11", "12", "14", "16", "18", "20", "24", "28" ) );
if( !sizes.contains( currentSize ) )
sizes.add( currentSize );
sizes.sort( String.CASE_INSENSITIVE_ORDER );
ButtonGroup sizesGroup = new ButtonGroup();
for( String size : sizes ) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem( size );
item.setSelected( size.equals( currentSize ) );
item.addActionListener( this::fontSizeChanged );
fontMenu.add( item );
sizesGroup.add( item );
}
// enabled/disable items
boolean enabled = UIManager.getLookAndFeel() instanceof FlatLaf;
for( Component item : fontMenu.getMenuComponents() )
item.setEnabled( enabled );
}
// the real colors are defined in
// flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties and
// flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties
private static String[] accentColorKeys = {
"Demo.accent.default", "Demo.accent.blue", "Demo.accent.purple", "Demo.accent.red",
"Demo.accent.orange", "Demo.accent.yellow", "Demo.accent.green",
};
private static String[] accentColorNames = {
"Default", "Blue", "Purple", "Red", "Orange", "Yellow", "Green",
};
private final JToggleButton[] accentColorButtons = new JToggleButton[accentColorKeys.length];
private JLabel accentColorLabel;
private Color accentColor;
private void initAccentColors() {
accentColorLabel = new JLabel( "Accent color: " );
toolBar.add( Box.createHorizontalGlue() );
toolBar.add( accentColorLabel );
ButtonGroup group = new ButtonGroup();
for( int i = 0; i < accentColorButtons.length; i++ ) {
accentColorButtons[i] = new JToggleButton( new AccentColorIcon( accentColorKeys[i] ) );
accentColorButtons[i].setToolTipText( accentColorNames[i] );
accentColorButtons[i].addActionListener( this::accentColorChanged );
toolBar.add( accentColorButtons[i] );
group.add( accentColorButtons[i] );
}
accentColorButtons[0].setSelected( true );
FlatLaf.setSystemColorGetter( name -> {
return name.equals( "accent" ) ? accentColor : null;
} );
UIManager.addPropertyChangeListener( e -> {
if( "lookAndFeel".equals( e.getPropertyName() ) )
updateAccentColorButtons();
} );
updateAccentColorButtons();
}
private void accentColorChanged( ActionEvent e ) {
String accentColorKey = null;
for( int i = 0; i < accentColorButtons.length; i++ ) {
if( accentColorButtons[i].isSelected() ) {
accentColorKey = accentColorKeys[i];
break;
}
}
accentColor = (accentColorKey != null && accentColorKey != accentColorKeys[0])
? UIManager.getColor( accentColorKey )
: null;
Class<? extends LookAndFeel> lafClass = UIManager.getLookAndFeel().getClass();
try {
FlatLaf.setup( lafClass.newInstance() );
FlatLaf.updateUI();
} catch( InstantiationException | IllegalAccessException ex ) {
LoggingFacade.INSTANCE.logSevere( null, ex );
}
}
private void updateAccentColorButtons() {
Class<? extends LookAndFeel> lafClass = UIManager.getLookAndFeel().getClass();
boolean isAccentColorSupported =
lafClass == FlatLightLaf.class ||
lafClass == FlatDarkLaf.class ||
lafClass == FlatIntelliJLaf.class ||
lafClass == FlatDarculaLaf.class ||
lafClass == FlatMacLightLaf.class ||
lafClass == FlatMacDarkLaf.class;
accentColorLabel.setVisible( isAccentColorSupported );
for( int i = 0; i < accentColorButtons.length; i++ )
accentColorButtons[i].setVisible( isAccentColorSupported );
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JMenuBar menuBar1 = new JMenuBar();
JMenu fileMenu = new JMenu();
JMenuItem newMenuItem = new JMenuItem();
JMenuItem openMenuItem = new JMenuItem();
JMenuItem saveAsMenuItem = new JMenuItem();
JMenuItem closeMenuItem = new JMenuItem();
exitMenuItem = new JMenuItem();
JMenu editMenu = new JMenu();
JMenuItem undoMenuItem = new JMenuItem();
JMenuItem redoMenuItem = new JMenuItem();
JMenuItem cutMenuItem = new JMenuItem();
JMenuItem copyMenuItem = new JMenuItem();
JMenuItem pasteMenuItem = new JMenuItem();
JMenuItem deleteMenuItem = new JMenuItem();
JMenu viewMenu = new JMenu();
JCheckBoxMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem();
JMenu menu1 = new JMenu();
JMenu subViewsMenu = new JMenu();
JMenu subSubViewsMenu = new JMenu();
JMenuItem errorLogViewMenuItem = new JMenuItem();
JMenuItem searchViewMenuItem = new JMenuItem();
JMenuItem projectViewMenuItem = new JMenuItem();
JMenuItem structureViewMenuItem = new JMenuItem();
JMenuItem propertiesViewMenuItem = new JMenuItem();
scrollingPopupMenu = new JMenu();
JMenuItem menuItem2 = new JMenuItem();
htmlMenuItem = new JMenuItem();
JRadioButtonMenuItem radioButtonMenuItem1 = new JRadioButtonMenuItem();
JRadioButtonMenuItem radioButtonMenuItem2 = new JRadioButtonMenuItem();
JRadioButtonMenuItem radioButtonMenuItem3 = new JRadioButtonMenuItem();
fontMenu = new JMenu();
JMenuItem restoreFontMenuItem = new JMenuItem();
JMenuItem incrFontMenuItem = new JMenuItem();
JMenuItem decrFontMenuItem = new JMenuItem();
optionsMenu = new JMenu();
windowDecorationsCheckBoxMenuItem = new JCheckBoxMenuItem();
menuBarEmbeddedCheckBoxMenuItem = new JCheckBoxMenuItem();
unifiedTitleBarMenuItem = new JCheckBoxMenuItem();
showTitleBarIconMenuItem = new JCheckBoxMenuItem();
underlineMenuSelectionMenuItem = new JCheckBoxMenuItem();
alwaysShowMnemonicsMenuItem = new JCheckBoxMenuItem();
animatedLafChangeMenuItem = new JCheckBoxMenuItem();
JMenuItem showHintsMenuItem = new JMenuItem();
JMenuItem showUIDefaultsInspectorMenuItem = new JMenuItem();
JMenu helpMenu = new JMenu();
aboutMenuItem = new JMenuItem();
toolBar = new JToolBar();
JButton backButton = new JButton();
JButton forwardButton = new JButton();
JButton cutButton = new JButton();
JButton copyButton = new JButton();
JButton pasteButton = new JButton();
JButton refreshButton = new JButton();
JToggleButton showToggleButton = new JToggleButton();
JPanel contentPanel = new JPanel();
tabbedPane = new JTabbedPane();
BasicComponentsPanel basicComponentsPanel = new BasicComponentsPanel();
MoreComponentsPanel moreComponentsPanel = new MoreComponentsPanel();
DataComponentsPanel dataComponentsPanel = new DataComponentsPanel();
TabsPanel tabsPanel = new TabsPanel();
OptionPanePanel optionPanePanel = new OptionPanePanel();
ExtrasPanel extrasPanel1 = new ExtrasPanel();
controlBar = new ControlBar();
themesPanel = new IJThemesPanel();
//======== this ========
setTitle("FlatLaf Demo");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
//======== menuBar1 ========
{
//======== fileMenu ========
{
fileMenu.setText("File");
fileMenu.setMnemonic('F');
//---- newMenuItem ----
newMenuItem.setText("New");
newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
newMenuItem.setMnemonic('N');
newMenuItem.addActionListener(e -> newActionPerformed());
fileMenu.add(newMenuItem);
//---- openMenuItem ----
openMenuItem.setText("Open...");
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
openMenuItem.setMnemonic('O');
openMenuItem.addActionListener(e -> openActionPerformed());
fileMenu.add(openMenuItem);
//---- saveAsMenuItem ----
saveAsMenuItem.setText("Save As...");
saveAsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
saveAsMenuItem.setMnemonic('S');
saveAsMenuItem.addActionListener(e -> saveAsActionPerformed());
fileMenu.add(saveAsMenuItem);
fileMenu.addSeparator();
//---- closeMenuItem ----
closeMenuItem.setText("Close");
closeMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
closeMenuItem.setMnemonic('C');
closeMenuItem.addActionListener(e -> menuItemActionPerformed(e));
fileMenu.add(closeMenuItem);
fileMenu.addSeparator();
//---- exitMenuItem ----
exitMenuItem.setText("Exit");
exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
exitMenuItem.setMnemonic('X');
exitMenuItem.addActionListener(e -> exitActionPerformed());
fileMenu.add(exitMenuItem);
}
menuBar1.add(fileMenu);
//======== editMenu ========
{
editMenu.setText("Edit");
editMenu.setMnemonic('E');
//---- undoMenuItem ----
undoMenuItem.setText("Undo");
undoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
undoMenuItem.setMnemonic('U');
undoMenuItem.addActionListener(e -> menuItemActionPerformed(e));
editMenu.add(undoMenuItem);
//---- redoMenuItem ----
redoMenuItem.setText("Redo");
redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
redoMenuItem.setMnemonic('R');
redoMenuItem.addActionListener(e -> menuItemActionPerformed(e));
editMenu.add(redoMenuItem);
editMenu.addSeparator();
//---- cutMenuItem ----
cutMenuItem.setText("Cut");
cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
cutMenuItem.setMnemonic('C');
editMenu.add(cutMenuItem);
//---- copyMenuItem ----
copyMenuItem.setText("Copy");
copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
copyMenuItem.setMnemonic('O');
editMenu.add(copyMenuItem);
//---- pasteMenuItem ----
pasteMenuItem.setText("Paste");
pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
pasteMenuItem.setMnemonic('P');
editMenu.add(pasteMenuItem);
editMenu.addSeparator();
//---- deleteMenuItem ----
deleteMenuItem.setText("Delete");
deleteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
deleteMenuItem.setMnemonic('D');
deleteMenuItem.addActionListener(e -> menuItemActionPerformed(e));
editMenu.add(deleteMenuItem);
}
menuBar1.add(editMenu);
//======== viewMenu ========
{
viewMenu.setText("View");
viewMenu.setMnemonic('V');
//---- checkBoxMenuItem1 ----
checkBoxMenuItem1.setText("Show Toolbar");
checkBoxMenuItem1.setSelected(true);
checkBoxMenuItem1.setMnemonic('T');
checkBoxMenuItem1.addActionListener(e -> menuItemActionPerformed(e));
viewMenu.add(checkBoxMenuItem1);
//======== menu1 ========
{
menu1.setText("Show View");
menu1.setMnemonic('V');
//======== subViewsMenu ========
{
subViewsMenu.setText("Sub Views");
subViewsMenu.setMnemonic('S');
//======== subSubViewsMenu ========
{
subSubViewsMenu.setText("Sub sub Views");
subSubViewsMenu.setMnemonic('U');
//---- errorLogViewMenuItem ----
errorLogViewMenuItem.setText("Error Log");
errorLogViewMenuItem.setMnemonic('E');
errorLogViewMenuItem.addActionListener(e -> menuItemActionPerformed(e));
subSubViewsMenu.add(errorLogViewMenuItem);
}
subViewsMenu.add(subSubViewsMenu);
//---- searchViewMenuItem ----
searchViewMenuItem.setText("Search");
searchViewMenuItem.setMnemonic('S');
searchViewMenuItem.addActionListener(e -> menuItemActionPerformed(e));
subViewsMenu.add(searchViewMenuItem);
}
menu1.add(subViewsMenu);
//---- projectViewMenuItem ----
projectViewMenuItem.setText("Project");
projectViewMenuItem.setMnemonic('P');
projectViewMenuItem.addActionListener(e -> menuItemActionPerformed(e));
menu1.add(projectViewMenuItem);
//---- structureViewMenuItem ----
structureViewMenuItem.setText("Structure");
structureViewMenuItem.setMnemonic('T');
structureViewMenuItem.addActionListener(e -> menuItemActionPerformed(e));
menu1.add(structureViewMenuItem);
//---- propertiesViewMenuItem ----
propertiesViewMenuItem.setText("Properties");
propertiesViewMenuItem.setMnemonic('O');
propertiesViewMenuItem.addActionListener(e -> menuItemActionPerformed(e));
menu1.add(propertiesViewMenuItem);
}
viewMenu.add(menu1);
//======== scrollingPopupMenu ========
{
scrollingPopupMenu.setText("Scrolling Popup Menu");
}
viewMenu.add(scrollingPopupMenu);
//---- menuItem2 ----
menuItem2.setText("Disabled Item");
menuItem2.setEnabled(false);
viewMenu.add(menuItem2);
//---- htmlMenuItem ----
htmlMenuItem.setText("<html>some <b color=\"red\">HTML</b> <i color=\"blue\">text</i></html>");
viewMenu.add(htmlMenuItem);
viewMenu.addSeparator();
//---- radioButtonMenuItem1 ----
radioButtonMenuItem1.setText("Details");
radioButtonMenuItem1.setSelected(true);
radioButtonMenuItem1.setMnemonic('D');
radioButtonMenuItem1.addActionListener(e -> menuItemActionPerformed(e));
viewMenu.add(radioButtonMenuItem1);
//---- radioButtonMenuItem2 ----
radioButtonMenuItem2.setText("Small Icons");
radioButtonMenuItem2.setMnemonic('S');
radioButtonMenuItem2.addActionListener(e -> menuItemActionPerformed(e));
viewMenu.add(radioButtonMenuItem2);
//---- radioButtonMenuItem3 ----
radioButtonMenuItem3.setText("Large Icons");
radioButtonMenuItem3.setMnemonic('L');
radioButtonMenuItem3.addActionListener(e -> menuItemActionPerformed(e));
viewMenu.add(radioButtonMenuItem3);
}
menuBar1.add(viewMenu);
//======== fontMenu ========
{
fontMenu.setText("Font");
//---- restoreFontMenuItem ----
restoreFontMenuItem.setText("Restore Font");
restoreFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
restoreFontMenuItem.addActionListener(e -> restoreFont());
fontMenu.add(restoreFontMenuItem);
//---- incrFontMenuItem ----
incrFontMenuItem.setText("Increase Font Size");
incrFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
incrFontMenuItem.addActionListener(e -> incrFont());
fontMenu.add(incrFontMenuItem);
//---- decrFontMenuItem ----
decrFontMenuItem.setText("Decrease Font Size");
decrFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
decrFontMenuItem.addActionListener(e -> decrFont());
fontMenu.add(decrFontMenuItem);
}
menuBar1.add(fontMenu);
//======== optionsMenu ========
{
optionsMenu.setText("Options");
//---- windowDecorationsCheckBoxMenuItem ----
windowDecorationsCheckBoxMenuItem.setText("Window decorations");
windowDecorationsCheckBoxMenuItem.addActionListener(e -> windowDecorationsChanged());
optionsMenu.add(windowDecorationsCheckBoxMenuItem);
//---- menuBarEmbeddedCheckBoxMenuItem ----
menuBarEmbeddedCheckBoxMenuItem.setText("Embedded menu bar");
menuBarEmbeddedCheckBoxMenuItem.addActionListener(e -> menuBarEmbeddedChanged());
optionsMenu.add(menuBarEmbeddedCheckBoxMenuItem);
//---- unifiedTitleBarMenuItem ----
unifiedTitleBarMenuItem.setText("Unified window title bar");
unifiedTitleBarMenuItem.addActionListener(e -> unifiedTitleBar());
optionsMenu.add(unifiedTitleBarMenuItem);
//---- showTitleBarIconMenuItem ----
showTitleBarIconMenuItem.setText("Show window title bar icon");
showTitleBarIconMenuItem.addActionListener(e -> showTitleBarIcon());
optionsMenu.add(showTitleBarIconMenuItem);
//---- underlineMenuSelectionMenuItem ----
underlineMenuSelectionMenuItem.setText("Use underline menu selection");
underlineMenuSelectionMenuItem.addActionListener(e -> underlineMenuSelection());
optionsMenu.add(underlineMenuSelectionMenuItem);
//---- alwaysShowMnemonicsMenuItem ----
alwaysShowMnemonicsMenuItem.setText("Always show mnemonics");
alwaysShowMnemonicsMenuItem.addActionListener(e -> alwaysShowMnemonics());
optionsMenu.add(alwaysShowMnemonicsMenuItem);
//---- animatedLafChangeMenuItem ----
animatedLafChangeMenuItem.setText("Animated Laf Change");
animatedLafChangeMenuItem.setSelected(true);
animatedLafChangeMenuItem.addActionListener(e -> animatedLafChangeChanged());
optionsMenu.add(animatedLafChangeMenuItem);
//---- showHintsMenuItem ----
showHintsMenuItem.setText("Show hints");
showHintsMenuItem.addActionListener(e -> showHintsChanged());
optionsMenu.add(showHintsMenuItem);
//---- showUIDefaultsInspectorMenuItem ----
showUIDefaultsInspectorMenuItem.setText("Show UI Defaults Inspector");
showUIDefaultsInspectorMenuItem.addActionListener(e -> showUIDefaultsInspector());
optionsMenu.add(showUIDefaultsInspectorMenuItem);
}
menuBar1.add(optionsMenu);
//======== helpMenu ========
{
helpMenu.setText("Help");
helpMenu.setMnemonic('H');
//---- aboutMenuItem ----
aboutMenuItem.setText("About");
aboutMenuItem.setMnemonic('A');
aboutMenuItem.addActionListener(e -> aboutActionPerformed());
helpMenu.add(aboutMenuItem);
}
menuBar1.add(helpMenu);
}
setJMenuBar(menuBar1);
//======== toolBar ========
{
toolBar.setMargin(new Insets(3, 3, 3, 3));
//---- backButton ----
backButton.setToolTipText("Back");
toolBar.add(backButton);
//---- forwardButton ----
forwardButton.setToolTipText("Forward");
toolBar.add(forwardButton);
toolBar.addSeparator();
//---- cutButton ----
cutButton.setToolTipText("Cut");
toolBar.add(cutButton);
//---- copyButton ----
copyButton.setToolTipText("Copy");
toolBar.add(copyButton);
//---- pasteButton ----
pasteButton.setToolTipText("Paste");
toolBar.add(pasteButton);
toolBar.addSeparator();
//---- refreshButton ----
refreshButton.setToolTipText("Refresh");
toolBar.add(refreshButton);
toolBar.addSeparator();
//---- showToggleButton ----
showToggleButton.setSelected(true);
showToggleButton.setToolTipText("Show Details");
toolBar.add(showToggleButton);
}
contentPane.add(toolBar, BorderLayout.NORTH);
//======== contentPanel ========
{
contentPanel.setLayout(new MigLayout(
"insets dialog,hidemode 3",
// columns
"[grow,fill]",
// rows
"[grow,fill]"));
//======== tabbedPane ========
{
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
tabbedPane.addChangeListener(e -> selectedTabChanged());
tabbedPane.addTab("Basic Components", basicComponentsPanel);
tabbedPane.addTab("More Components", moreComponentsPanel);
tabbedPane.addTab("Data Components", dataComponentsPanel);
tabbedPane.addTab("Tabs", tabsPanel);
tabbedPane.addTab("Option Pane", optionPanePanel);
tabbedPane.addTab("Extras", extrasPanel1);
}
contentPanel.add(tabbedPane, "cell 0 0");
}
contentPane.add(contentPanel, BorderLayout.CENTER);
contentPane.add(controlBar, BorderLayout.SOUTH);
contentPane.add(themesPanel, BorderLayout.EAST);
//---- buttonGroup1 ----
ButtonGroup buttonGroup1 = new ButtonGroup();
buttonGroup1.add(radioButtonMenuItem1);
buttonGroup1.add(radioButtonMenuItem2);
buttonGroup1.add(radioButtonMenuItem3);
// JFormDesigner - End of component initialization //GEN-END:initComponents
// add "Users" button to menubar
FlatButton usersButton = new FlatButton();
usersButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/users.svg" ) );
usersButton.setButtonType( ButtonType.toolBarButton );
usersButton.setFocusable( false );
usersButton.addActionListener( e -> JOptionPane.showMessageDialog( null, "Hello User! How are you?", "User", JOptionPane.INFORMATION_MESSAGE ) );
menuBar1.add( Box.createGlue() );
menuBar1.add( usersButton );
undoMenuItem.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/undo.svg" ) );
redoMenuItem.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/redo.svg" ) );
cutMenuItem.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/menu-cut.svg" ) );
copyMenuItem.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/copy.svg" ) );
pasteMenuItem.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/menu-paste.svg" ) );
backButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/back.svg" ) );
forwardButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/forward.svg" ) );
cutButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/menu-cut.svg" ) );
copyButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/copy.svg" ) );
pasteButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/menu-paste.svg" ) );
refreshButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/refresh.svg" ) );
showToggleButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/show.svg" ) );
cutMenuItem.addActionListener( new DefaultEditorKit.CutAction() );
copyMenuItem.addActionListener( new DefaultEditorKit.CopyAction() );
pasteMenuItem.addActionListener( new DefaultEditorKit.PasteAction() );
scrollingPopupMenu.add( "Large menus are scrollable" );
scrollingPopupMenu.add( "Use mouse wheel to scroll" );
scrollingPopupMenu.add( "Or use up/down arrows at top/bottom" );
for( int i = 1; i <= 100; i++ )
scrollingPopupMenu.add( "Item " + i );
if( FlatLaf.supportsNativeWindowDecorations() || (SystemInfo.isLinux && JFrame.isDefaultLookAndFeelDecorated()) ) {
if( SystemInfo.isLinux )
unsupported( windowDecorationsCheckBoxMenuItem );
else
windowDecorationsCheckBoxMenuItem.setSelected( FlatLaf.isUseNativeWindowDecorations() );
menuBarEmbeddedCheckBoxMenuItem.setSelected( UIManager.getBoolean( "TitlePane.menuBarEmbedded" ) );
unifiedTitleBarMenuItem.setSelected( UIManager.getBoolean( "TitlePane.unifiedBackground" ) );
showTitleBarIconMenuItem.setSelected( UIManager.getBoolean( "TitlePane.showIcon" ) );
if( JBRCustomDecorations.isSupported() ) {
// If the JetBrains Runtime is used, it forces the use of it's own custom
// window decoration, which can not disabled.
windowDecorationsCheckBoxMenuItem.setEnabled( false );
}
} else {
unsupported( windowDecorationsCheckBoxMenuItem );
unsupported( menuBarEmbeddedCheckBoxMenuItem );
unsupported( unifiedTitleBarMenuItem );
unsupported( showTitleBarIconMenuItem );
}
if( SystemInfo.isMacOS )
unsupported( underlineMenuSelectionMenuItem );
// remove contentPanel bottom insets
MigLayout layout = (MigLayout) contentPanel.getLayout();
LC lc = ConstraintParser.parseLayoutConstraint( (String) layout.getLayoutConstraints() );
UnitValue[] insets = lc.getInsets();
lc.setInsets( new UnitValue[] {
insets[0],
insets[1],
new UnitValue( 0, UnitValue.PIXEL, null ),
insets[3]
} );
layout.setLayoutConstraints( lc );
}
private void unsupported( JCheckBoxMenuItem menuItem ) {
menuItem.setEnabled( false );
menuItem.setSelected( false );
menuItem.setToolTipText( "Not supported on your system." );
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JMenuItem exitMenuItem;
private JMenu scrollingPopupMenu;
private JMenuItem htmlMenuItem;
private JMenu fontMenu;
private JMenu optionsMenu;
private JCheckBoxMenuItem windowDecorationsCheckBoxMenuItem;
private JCheckBoxMenuItem menuBarEmbeddedCheckBoxMenuItem;
private JCheckBoxMenuItem unifiedTitleBarMenuItem;
private JCheckBoxMenuItem showTitleBarIconMenuItem;
private JCheckBoxMenuItem underlineMenuSelectionMenuItem;
private JCheckBoxMenuItem alwaysShowMnemonicsMenuItem;
private JCheckBoxMenuItem animatedLafChangeMenuItem;
private JMenuItem aboutMenuItem;
private JToolBar toolBar;
private JTabbedPane tabbedPane;
private ControlBar controlBar;
IJThemesPanel themesPanel;
// JFormDesigner - End of variables declaration //GEN-END:variables
//---- class AccentColorIcon ----------------------------------------------
private static class AccentColorIcon
extends FlatAbstractIcon
{
private final String colorKey;
AccentColorIcon( String colorKey ) {
super( 16, 16, null );