setDefaultCloseOperation ( WebFrame.DISPOSE_ON_CLOSE );
ComponentMoveAdapter.install ( getRootPane (), ExampleFrame.this );
// Sample menu bar
final WebMenuBar menuBar = new WebMenuBar ();
menuBar.setUndecorated ( true );
menuBar.setBorder ( BorderFactory.createEmptyBorder ( 2, 2, 2, 2 ) );
menuBar.add ( new WebMenu ( "Menu 1" )
{
{
add ( new WebMenuItem ( "Menu item 1" ) );
add ( new WebMenuItem ( "Menu item 2" ) );
addSeparator ();
add ( new WebMenuItem ( "Menu item 3" ) );
}
} );
menuBar.add ( new WebMenu ( "Menu 2" )
{
{
add ( new WebMenuItem ( "Menu item 1" ) );
add ( new WebMenuItem ( "Menu item 2" ) );
add ( new WebMenuItem ( "Menu item 3" ) );
}
} );
menuBar.add ( new WebMenu ( "Menu 3" )
{
{
add ( new WebMenuItem ( "Menu item 1" ) );
add ( new WebMenuItem ( "Menu item 2" ) );
}
} );
menuBar.add ( new WebMenu ( "Menu 4" )
{
{
add ( new WebMenuItem ( "Menu item 1" ) );
addSeparator ();
add ( new WebMenuItem ( "Menu item 2" ) );
}
} );
setJMenuBar ( menuBar );
// Options panel
add ( new BorderPanel ( new WebPanel ( new VerticalFlowLayout ( 10, 10 ) )
{
{
setMargin ( 15 );
final TitledBorderPainter titledBorderPainter = new TitledBorderPainter ( "Window settings" );
titledBorderPainter.setTitleOffset ( 10 );
titledBorderPainter.setRound ( Math.max ( 0, ExampleFrame.this.getRound () - 2 ) );
setPainter ( titledBorderPainter );
final WebCheckBox showTitle = new WebCheckBox ( "Show title" )
{
{
setSelected ( ExampleFrame.this.isShowTitleComponent () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setShowTitleComponent ( isSelected () );
ExampleFrame.this.pack ();
}
} );
}
};
add ( new GroupPanel ( 10, showTitle, new WebTextField ( ExampleFrame.this.getTitle (), 1 )
{
{
putClientProperty ( GroupPanel.FILL_CELL, true );
setEnabled ( showTitle.isSelected () );
showTitle.addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
setEnabled ( showTitle.isSelected () );
}
} );
addCaretListener ( new CaretListener ()
{
@Override
public void caretUpdate ( CaretEvent e )
{
if ( !ExampleFrame.this.getTitle ().equals ( getText () ) )
{
ExampleFrame.this.setTitle ( getText () );
ExampleFrame.this.pack ();
}
}
} );
}
} ) );
add ( new WebSeparator ( false, true ) );
final WebCheckBox showWindowButtons = new WebCheckBox ( "Show window buttons" )
{
{
setSelected ( ExampleFrame.this.isShowWindowButtons () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setShowWindowButtons ( isSelected () );
ExampleFrame.this.pack ();
}
} );
}
};
add ( new GroupPanel ( 10, showWindowButtons, new WebButtonGroup ( new WebToggleButton ( WebRootPaneUI.minimizeIcon )
{
{
setSelected ( ExampleFrame.this.isShowMinimizeButton () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setShowMinimizeButton ( isSelected () );
}
} );
}
}, new WebToggleButton ( WebRootPaneUI.maximizeIcon )
{
{
setSelected ( ExampleFrame.this.isShowMaximizeButton () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setShowMaximizeButton ( isSelected () );
}
} );
}
}, new WebToggleButton ( WebRootPaneUI.closeIcon )
{
{
setSelected ( ExampleFrame.this.isShowCloseButton () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setShowCloseButton ( isSelected () );
}
} );
}
}
)
{
{
setButtonsMargin ( 2, 4, 2, 4 );
setButtonsDrawFocus ( false );
setEnabled ( showWindowButtons.isSelected () );
showWindowButtons.addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
setEnabled ( showWindowButtons.isSelected () );
}
} );
}
} ) );
add ( new WebCheckBox ( "Attach window buttons to sides" )
{
{
setSelected ( ExampleFrame.this.isAttachButtons () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setAttachButtons ( isSelected () );
ExampleFrame.this.pack ();
}
} );
}
} );
add ( new WebCheckBox ( "Group window buttons" )
{
{
setSelected ( ExampleFrame.this.isGroupButtons () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setGroupButtons ( isSelected () );
ExampleFrame.this.pack ();
}
} );
}
} );
add ( new WebSeparator ( false, true ) );
final WebCheckBox showMenuBar = new WebCheckBox ( "Show menu bar" )
{
{
setSelected ( ExampleFrame.this.isShowMenuBar () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setShowMenuBar ( isSelected () );
ExampleFrame.this.pack ();
}
} );
}
};
add ( new GroupPanel ( 10, showMenuBar, new WebComboBox ( new String[]{ "undecorated", "attached", "standalone" } )
{
{
addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
int i = getSelectedIndex ();
if ( i == 0 )
{
menuBar.setUndecorated ( true );
}
else
{
menuBar.setUndecorated ( false );
menuBar.setMenuBarStyle ( i == 1 ? MenuBarStyle.attached : MenuBarStyle.standalone );
}
ExampleFrame.this.pack ();
}
} );
setEnabled ( showMenuBar.isSelected () );
showMenuBar.addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
setEnabled ( showMenuBar.isSelected () );
}
} );
}
} ) );
add ( new WebSeparator ( false, true ) );
add ( new WebCheckBox ( "Show resize corner" )
{
{
setSelected ( ExampleFrame.this.isShowResizeCorner () );
addItemListener ( new ItemListener ()
{
@Override
public void itemStateChanged ( ItemEvent e )
{
ExampleFrame.this.setShowResizeCorner ( isSelected () );
ExampleFrame.this.pack ();
}
} );
}
} );
add ( new WebSeparator ( false, true ) );
add ( new WebPanel ()
{
{
setOpaque ( false );
setLayout ( new BorderLayout ( 10, 0 ) );
add ( new WebLabel ( "Corners round" ), BorderLayout.LINE_START );
add ( new WebSlider ( 0, 10, ExampleFrame.this.getRound () )
{
{
putClientProperty ( GroupPanel.FILL_CELL, true );
addChangeListener ( new ChangeListener ()
{
@Override
public void stateChanged ( ChangeEvent e )
{
menuBar.setRound ( Math.max ( 0, ExampleFrame.this.getRound () - 2 ) );
titledBorderPainter.setRound ( Math.max ( 0, ExampleFrame.this.getRound () - 2 ) );
ExampleFrame.this.setRound ( getValue () );
}
} );
}