3 * Copyright 2000-2009 JetBrains s.r.o.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 import java
.awt
.event
.ActionEvent
;
20 import java
.text
.MessageFormat
;
21 import java
.util
.ResourceBundle
;
23 public class FormPreviewFrame
{
24 private JComponent myComponent
;
25 private static final ResourceBundle ourBundle
= ResourceBundle
.getBundle("RuntimeBundle");
27 // Note: this class should not be obfuscated
29 public static void main(String
[] args
) {
30 FormPreviewFrame f
= new FormPreviewFrame();
32 JFrame frame
= new JFrame(ourBundle
.getString("form.preview.title"));
33 frame
.setContentPane(f
.myComponent
);
34 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
37 final JMenuBar menuBar
= new JMenuBar();
38 frame
.setJMenuBar(menuBar
);
40 final JMenu menuFile
= new JMenu(ourBundle
.getString("form.menu.preview"));
41 menuFile
.setMnemonic(ourBundle
.getString("form.menu.preview.mnemonic").charAt(0));
42 menuFile
.add(new JMenuItem(new MyPackAction(frame
)));
43 menuFile
.add(new JMenuItem(new MyExitAction()));
44 menuBar
.add(menuFile
);
46 final JMenu viewMenu
= new JMenu(ourBundle
.getString("form.menu.laf"));
47 viewMenu
.setMnemonic(ourBundle
.getString("form.menu.laf.mnemonic").charAt(0));
48 menuBar
.add(viewMenu
);
50 final UIManager
.LookAndFeelInfo
[] lafs
= UIManager
.getInstalledLookAndFeels();
51 for(int i
= 0; i
< lafs
.length
; i
++){
52 viewMenu
.add(new MySetLafAction(frame
, lafs
[i
]));
56 Dimension screenSize
= Toolkit
.getDefaultToolkit().getScreenSize();
57 frame
.setLocation((screenSize
.width
- frame
.getWidth())/2, (screenSize
.height
- frame
.getHeight())/2);
58 frame
.setVisible(true);
61 private static final class MyExitAction
extends AbstractAction
{
62 public MyExitAction() {
63 super(ourBundle
.getString("form.menu.file.exit"));
66 public void actionPerformed(final ActionEvent e
) {
71 private static final class MyPackAction
extends AbstractAction
{
72 private final JFrame myFrame
;
74 public MyPackAction(final JFrame frame
) {
75 super(ourBundle
.getString("form.menu.view.pack"));
79 public void actionPerformed(final ActionEvent e
) {
84 private static final class MySetLafAction
extends AbstractAction
{
85 private final JFrame myFrame
;
86 private final UIManager
.LookAndFeelInfo myInfo
;
88 public MySetLafAction(final JFrame frame
, final UIManager
.LookAndFeelInfo info
) {
89 super(info
.getName());
94 public void actionPerformed(ActionEvent e
) {
96 UIManager
.setLookAndFeel(myInfo
.getClassName());
97 SwingUtilities
.updateComponentTreeUI(myFrame
);
98 Dimension prefSize
= myFrame
.getPreferredSize();
99 if(prefSize
.width
> myFrame
.getWidth() || prefSize
.height
> myFrame
.getHeight()){
103 catch(Exception exc
){
104 JOptionPane
.showMessageDialog(
106 MessageFormat
.format(ourBundle
.getString("error.cannot.change.look.feel"), new Object
[] {exc
.getMessage()}),
107 ourBundle
.getString("error.title"),
108 JOptionPane
.ERROR_MESSAGE