1515 */
1616package ch .sla .jdbcperflogger .console .ui ;
1717
18+ import java .awt .Component ;
1819import java .awt .Cursor ;
1920import java .awt .GridBagConstraints ;
2021import java .awt .GridBagLayout ;
2526import java .awt .event .KeyEvent ;
2627import java .awt .event .MouseAdapter ;
2728import java .awt .event .MouseEvent ;
29+ import java .beans .Beans ;
2830import java .util .TreeSet ;
2931import java .util .prefs .BackingStoreException ;
3032import java .util .prefs .Preferences ;
3133
3234import javax .annotation .Nullable ;
35+ import javax .swing .DefaultComboBoxModel ;
36+ import javax .swing .DefaultListCellRenderer ;
3337import javax .swing .ImageIcon ;
3438import javax .swing .JButton ;
39+ import javax .swing .JComboBox ;
3540import javax .swing .JLabel ;
3641import javax .swing .JList ;
42+ import javax .swing .JOptionPane ;
3743import javax .swing .JPanel ;
3844import javax .swing .JScrollPane ;
3945import javax .swing .JTextField ;
4046import javax .swing .JTextPane ;
4147import javax .swing .ListSelectionModel ;
4248import javax .swing .UIManager ;
49+ import javax .swing .UIManager .LookAndFeelInfo ;
4350import javax .swing .border .TitledBorder ;
4451import javax .swing .event .HyperlinkEvent ;
4552import javax .swing .event .HyperlinkListener ;
@@ -59,19 +66,82 @@ public class WelcomePanel extends JPanel {
5966 public WelcomePanel (final IClientConnectionDelegate clientConnectionCreator ) {
6067 final GridBagLayout gridBagLayout = new GridBagLayout ();
6168 gridBagLayout .columnWidths = new int [] { 438 , 0 };
62- gridBagLayout .rowHeights = new int [] { 46 , 88 , 0 , 0 };
69+ gridBagLayout .rowHeights = new int [] { 0 , 46 , 88 , 0 , 0 };
6370 gridBagLayout .columnWeights = new double [] { 1.0 , Double .MIN_VALUE };
64- gridBagLayout .rowWeights = new double [] { 0.0 , 1.0 , 1.0 , Double .MIN_VALUE };
71+ gridBagLayout .rowWeights = new double [] { 0.0 , 0.0 , 1.0 , 1.0 , Double .MIN_VALUE };
6572 setLayout (gridBagLayout );
6673
74+ final JPanel lookAndFeelPanel = new JPanel ();
75+ lookAndFeelPanel .setBorder (new TitledBorder (null , "Look and Feel" , TitledBorder .LEADING , TitledBorder .TOP ,
76+ null , null ));
77+ final GridBagConstraints gbc_lookAndFeelPanel = new GridBagConstraints ();
78+ gbc_lookAndFeelPanel .insets = new Insets (0 , 0 , 5 , 0 );
79+ gbc_lookAndFeelPanel .fill = GridBagConstraints .BOTH ;
80+ gbc_lookAndFeelPanel .gridx = 0 ;
81+ gbc_lookAndFeelPanel .gridy = 0 ;
82+ add (lookAndFeelPanel , gbc_lookAndFeelPanel );
83+ final GridBagLayout gbl_lookAndFeelPanel = new GridBagLayout ();
84+ gbl_lookAndFeelPanel .columnWidths = new int [] { 263 , 0 , 0 };
85+ gbl_lookAndFeelPanel .rowHeights = new int [] { 0 , 0 };
86+ gbl_lookAndFeelPanel .columnWeights = new double [] { 0.0 , 1.0 , Double .MIN_VALUE };
87+ gbl_lookAndFeelPanel .rowWeights = new double [] { 0.0 , Double .MIN_VALUE };
88+ lookAndFeelPanel .setLayout (gbl_lookAndFeelPanel );
89+
90+ final JComboBox <LookAndFeelInfo > lookAndFeelsCombobox = new JComboBox <LookAndFeelInfo >();
91+ final GridBagConstraints gbc_lookAndFeelComboBox = new GridBagConstraints ();
92+ gbc_lookAndFeelComboBox .fill = GridBagConstraints .HORIZONTAL ;
93+ gbc_lookAndFeelComboBox .gridx = 0 ;
94+ gbc_lookAndFeelComboBox .gridy = 0 ;
95+ lookAndFeelPanel .add (lookAndFeelsCombobox , gbc_lookAndFeelComboBox );
96+ if (!Beans .isDesignTime ()) {
97+ final LookAndFeelInfo [] lookAndFeels = UIManager .getInstalledLookAndFeels ();
98+ final DefaultComboBoxModel <LookAndFeelInfo > lookAndFeelsCboxModel = new DefaultComboBoxModel <LookAndFeelInfo >(
99+ lookAndFeels );
100+ lookAndFeelsCboxModel .insertElementAt (null , 0 );
101+ lookAndFeelsCombobox .setModel (lookAndFeelsCboxModel );
102+ final String initialPreferredLookAndFeel = PerfLoggerGuiMain .getPreferredLookAndFeel ();
103+ if (initialPreferredLookAndFeel == null ) {
104+ lookAndFeelsCombobox .setSelectedIndex (0 );
105+ } else {
106+ for (int i = 0 ; i < lookAndFeels .length ; i ++) {
107+ if (lookAndFeels [i ].getClassName ().equals (initialPreferredLookAndFeel )) {
108+ lookAndFeelsCombobox .setSelectedIndex (1 + i );
109+ break ;
110+ }
111+ }
112+ }
113+ }
114+ lookAndFeelsCombobox .setRenderer (new DefaultListCellRenderer () {
115+ @ Override
116+ public Component getListCellRendererComponent (@ Nullable final JList <?> list , @ Nullable final Object value ,
117+ final int index , final boolean isSelected , final boolean cellHasFocus ) {
118+ if (value == null ) {
119+ return super .getListCellRendererComponent (list , "(default)" , index , isSelected , cellHasFocus );
120+ }
121+ final LookAndFeelInfo lfInfo = (LookAndFeelInfo ) value ;
122+ return super .getListCellRendererComponent (list , lfInfo .getName (), index , isSelected , cellHasFocus );
123+ }
124+ });
125+ lookAndFeelsCombobox .addActionListener (new ActionListener () {
126+ @ Override
127+ public void actionPerformed (@ Nullable final ActionEvent e ) {
128+ @ Nullable
129+ final LookAndFeelInfo selectedLf = (LookAndFeelInfo ) lookAndFeelsCombobox .getSelectedItem ();
130+ PerfLoggerGuiMain .savePreferredLookAndFeel (selectedLf != null ? selectedLf .getClassName () : null );
131+
132+ JOptionPane .showMessageDialog (WelcomePanel .this ,
133+ "You need to relaunch the application to apply the new look and feel." );
134+ }
135+ });
136+
67137 final JPanel serverModePanel = new JPanel ();
68138 serverModePanel .setBorder (new TitledBorder ("Server mode" ));
69139 final GridBagConstraints gbc_serverModePanel = new GridBagConstraints ();
70140 gbc_serverModePanel .anchor = GridBagConstraints .NORTH ;
71141 gbc_serverModePanel .fill = GridBagConstraints .HORIZONTAL ;
72142 gbc_serverModePanel .insets = new Insets (0 , 0 , 5 , 0 );
73143 gbc_serverModePanel .gridx = 0 ;
74- gbc_serverModePanel .gridy = 0 ;
144+ gbc_serverModePanel .gridy = 1 ;
75145 add (serverModePanel , gbc_serverModePanel );
76146 final GridBagLayout gbl_serverModePanel = new GridBagLayout ();
77147 gbl_serverModePanel .columnWidths = new int [] { 204 , 32 , 0 };
@@ -101,7 +171,7 @@ public WelcomePanel(final IClientConnectionDelegate clientConnectionCreator) {
101171 gbc_clientModePanel .insets = new Insets (0 , 0 , 5 , 0 );
102172 gbc_clientModePanel .fill = GridBagConstraints .BOTH ;
103173 gbc_clientModePanel .gridx = 0 ;
104- gbc_clientModePanel .gridy = 1 ;
174+ gbc_clientModePanel .gridy = 2 ;
105175 add (clientModePanel , gbc_clientModePanel );
106176 final GridBagLayout gbl_clientModePanel = new GridBagLayout ();
107177 gbl_clientModePanel .columnWidths = new int [] { 30 , 74 , 292 , 0 };
@@ -229,7 +299,7 @@ public void mouseClicked(@Nullable final MouseEvent e) {
229299 final GridBagConstraints gbc_aboutPanel = new GridBagConstraints ();
230300 gbc_aboutPanel .fill = GridBagConstraints .BOTH ;
231301 gbc_aboutPanel .gridx = 0 ;
232- gbc_aboutPanel .gridy = 2 ;
302+ gbc_aboutPanel .gridy = 3 ;
233303 add (aboutPanel , gbc_aboutPanel );
234304 final GridBagLayout gbl_aboutPanel = new GridBagLayout ();
235305 gbl_aboutPanel .columnWidths = new int [] { 0 , 0 , 0 };
0 commit comments