Revet color chemes API chages. Will be commited via "Remote run commit"
[fedora-idea.git] / runtimesource / FormPreviewFrame.java
blobb3b81312f04a7d137c739da89a355800da4c1aed
2 import javax.swing.*;
3 import java.awt.*;
4 import java.awt.event.ActionEvent;
5 import java.text.MessageFormat;
6 import java.util.ResourceBundle;
8 public class FormPreviewFrame {
9 private JComponent myComponent;
10 private static ResourceBundle ourBundle = ResourceBundle.getBundle("RuntimeBundle");
12 // Note: this class should not be obfuscated
14 public static void main(String[] args) {
15 FormPreviewFrame f = new FormPreviewFrame();
17 JFrame frame = new JFrame(ourBundle.getString("form.preview.title"));
18 frame.setContentPane(f.myComponent);
19 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21 // Add menu bar
22 final JMenuBar menuBar = new JMenuBar();
23 frame.setJMenuBar(menuBar);
25 final JMenu menuFile = new JMenu(ourBundle.getString("form.menu.preview"));
26 menuFile.setMnemonic(ourBundle.getString("form.menu.preview.mnemonic").charAt(0));
27 menuFile.add(new JMenuItem(new MyPackAction(frame)));
28 menuFile.add(new JMenuItem(new MyExitAction()));
29 menuBar.add(menuFile);
31 final JMenu viewMenu = new JMenu(ourBundle.getString("form.menu.laf"));
32 viewMenu.setMnemonic(ourBundle.getString("form.menu.laf.mnemonic").charAt(0));
33 menuBar.add(viewMenu);
35 final UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
36 for(int i = 0; i < lafs.length; i++){
37 viewMenu.add(new MySetLafAction(frame, lafs[i]));
40 frame.pack();
41 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
42 frame.setLocation((screenSize.width - frame.getWidth())/2, (screenSize.height - frame.getHeight())/2);
43 frame.setVisible(true);
46 private static final class MyExitAction extends AbstractAction{
47 public MyExitAction() {
48 super(ourBundle.getString("form.menu.file.exit"));
51 public void actionPerformed(final ActionEvent e) {
52 System.exit(0);
56 private static final class MyPackAction extends AbstractAction{
57 private final JFrame myFrame;
59 public MyPackAction(final JFrame frame) {
60 super(ourBundle.getString("form.menu.view.pack"));
61 myFrame = frame;
64 public void actionPerformed(final ActionEvent e) {
65 myFrame.pack();
69 private static final class MySetLafAction extends AbstractAction{
70 private final JFrame myFrame;
71 private final UIManager.LookAndFeelInfo myInfo;
73 public MySetLafAction(final JFrame frame, final UIManager.LookAndFeelInfo info) {
74 super(info.getName());
75 myFrame = frame;
76 myInfo = info;
79 public void actionPerformed(ActionEvent e) {
80 try{
81 UIManager.setLookAndFeel(myInfo.getClassName());
82 SwingUtilities.updateComponentTreeUI(myFrame);
83 Dimension prefSize = myFrame.getPreferredSize();
84 if(prefSize.width > myFrame.getWidth() || prefSize.height > myFrame.getHeight()){
85 myFrame.pack();
88 catch(Exception exc){
89 JOptionPane.showMessageDialog(
90 myFrame,
91 MessageFormat.format(ourBundle.getString("error.cannot.change.look.feel"), new Object[] {exc.getMessage()}),
92 ourBundle.getString("error.title"),
93 JOptionPane.ERROR_MESSAGE