コード例 #1
0
ファイル: Check.java プロジェクト: charlesa101/insubstantial
  public static JToolBar getToolbar(String label, int size, boolean hasStrings) {
    JToolBar toolBar = new JToolBar();

    JButton buttonCut = new JButton(hasStrings ? "cut" : null, getIcon(size + "/edit-cut"));
    buttonCut.putClientProperty(SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE);
    toolBar.add(buttonCut);
    JButton buttonCopy = new JButton(hasStrings ? "copy" : null, getIcon(size + "/edit-copy"));
    buttonCopy.putClientProperty(SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE);
    buttonCopy.setEnabled(false);
    toolBar.add(buttonCopy);
    JButton buttonPaste = new JButton(getIcon(size + "/edit-paste"));
    toolBar.add(buttonPaste);
    JButton buttonSelectAll = new JButton(getIcon(size + "/edit-select-all"));
    toolBar.add(buttonSelectAll);
    JButton buttonDelete = new JButton(getIcon(size + "/edit-delete"));
    toolBar.add(buttonDelete);
    toolBar.addSeparator();

    // add an inner toolbar to check the painting of toolbar
    // gradient and drop shadows under different skins.
    JToolBar innerToolbar = new JToolBar(JToolBar.HORIZONTAL);
    innerToolbar.setFloatable(false);
    JToggleButton buttonFormatCenter = new JToggleButton(getIcon(size + "/format-justify-center"));
    buttonFormatCenter.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 5.0f);
    innerToolbar.add(buttonFormatCenter);
    JToggleButton buttonFormatLeft = new JToggleButton(getIcon(size + "/format-justify-left"));
    innerToolbar.add(buttonFormatLeft);
    JToggleButton buttonFormatRight = new JToggleButton(getIcon(size + "/format-justify-right"));
    innerToolbar.add(buttonFormatRight);
    JToggleButton buttonFormatFill = new JToggleButton(getIcon(size + "/format-justify-fill"));
    buttonFormatFill.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 0.0f);
    innerToolbar.add(buttonFormatFill);

    toolBar.add(innerToolbar);
    toolBar.addSeparator();

    if (size > 20) {
      JToolBar innerToolbar2 = new JToolBar(JToolBar.HORIZONTAL);
      innerToolbar2.setFloatable(false);

      JPanel innerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
      innerToolbar2.add(innerPanel, BorderLayout.CENTER);

      final JToggleButton buttonStyleBold = new JToggleButton(getIcon(size + "/format-text-bold"));
      Set<Side> rightSide = EnumSet.of(Side.RIGHT);
      buttonStyleBold.putClientProperty(SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, rightSide);
      buttonStyleBold.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 3.0f);

      final JToggleButton buttonStyleItalic =
          new JToggleButton(getIcon(size + "/format-text-italic"));
      buttonStyleItalic.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 0.0f);
      buttonStyleItalic.putClientProperty(
          SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, rightSide);

      final JToggleButton buttonStyleUnderline =
          new JToggleButton(getIcon(size + "/format-text-underline"));
      buttonStyleUnderline.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 0.0f);
      buttonStyleUnderline.putClientProperty(
          SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, rightSide);

      final JToggleButton buttonStyleStrikethrough =
          new JToggleButton(getIcon(size + "/format-text-strikethrough"));
      buttonStyleStrikethrough.putClientProperty(
          SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, EnumSet.of(Side.LEFT));
      buttonStyleStrikethrough.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 3.0f);
      buttonStyleBold.setSelected(true);

      innerPanel.add(buttonStyleBold);
      innerPanel.add(buttonStyleItalic);
      innerPanel.add(buttonStyleUnderline);
      innerPanel.add(buttonStyleStrikethrough);

      toolBar.add(innerToolbar2);
    }

    toolBar.add(Box.createGlue());
    JButton buttonExit = new JButton(getIcon(size + "/process-stop"));
    buttonExit.setToolTipText("Closes the test application");
    buttonExit.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    toolBar.add(buttonExit);

    return toolBar;
  }
コード例 #2
0
  /**
   * Returns the main control panel.
   *
   * @param mainFrame The main test frame.
   * @param mainTabbedPane The main tabbed pane.
   * @param mainTabPreviewPainter The preview painter of the main tabbed pane.
   * @param toolbar The toolbar of the main test frame.
   * @return The main control panel.
   */
  public static JPanel getMainControlPanel(
      final JFrame mainFrame,
      final JTabbedPane mainTabbedPane,
      final MyMainTabPreviewPainter mainTabPreviewPainter,
      final JToolBar toolbar) {
    FormLayout lm = new FormLayout("right:pref, 4dlu, fill:pref:grow", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm);
    // builder.setDefaultDialogBorder();

    builder.appendSeparator("Title pane settings");
    final JCheckBox markAsModified = new JCheckBox("Marked modified");
    markAsModified.setOpaque(false);
    markAsModified.setSelected(false);
    markAsModified.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            mainFrame
                .getRootPane()
                .putClientProperty(
                    SubstanceLookAndFeel.WINDOW_MODIFIED,
                    (markAsModified.isSelected() ? Boolean.TRUE : false));
          }
        });
    builder.append("Modified", markAsModified);

    final JCheckBox heapPanel = new JCheckBox("Has heap panel");
    heapPanel.setOpaque(false);
    heapPanel.setSelected(false);
    heapPanel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SubstanceLookAndFeel.setWidgetVisible(
                mainFrame.getRootPane(),
                heapPanel.isSelected(),
                SubstanceWidgetType.TITLE_PANE_HEAP_STATUS);
          }
        });
    builder.append("Heap panel", heapPanel);

    JButton changeTitleButton = new JButton("Change");
    changeTitleButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String random = "abcdefghijklmnopqrstuvwxyz ";
            int length = 60 + (int) (150 * Math.random());
            String title = "";
            while (length > 0) {
              title += random.charAt((int) (random.length() * Math.random()));
              length--;
            }
            mainFrame.setTitle(title);
          }
        });
    builder.append("Title string", changeTitleButton);

    builder.appendSeparator("Miscellaneous");

    final JCheckBox defaultRoundedCorners = new JCheckBox("by default");
    defaultRoundedCorners.setOpaque(false);
    boolean roundable =
        Boolean.valueOf(
            System.getProperty(SubstanceLookAndFeel.WINDOW_ROUNDED_CORNERS_PROPERTY, "True"));
    defaultRoundedCorners.setSelected(roundable);
    defaultRoundedCorners.setEnabled(roundable);
    defaultRoundedCorners.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            UIManager.put(
                SubstanceLookAndFeel.WINDOW_ROUNDED_CORNERS, defaultRoundedCorners.isSelected());
          }
        });
    builder.append("Rounded Windows", defaultRoundedCorners);

    final JCheckBox useThemedDefaultIconsCheckBox = new JCheckBox("use themed icons");
    useThemedDefaultIconsCheckBox.setOpaque(false);
    useThemedDefaultIconsCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    UIManager.put(
                        SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS,
                        useThemedDefaultIconsCheckBox.isSelected() ? Boolean.TRUE : null);
                    mainFrame.repaint();
                  }
                });
          }
        });
    builder.append("Themed icons", useThemedDefaultIconsCheckBox);

    final JCheckBox useConstantThemesOnDialogs = new JCheckBox("use constant themes");
    useConstantThemesOnDialogs.setOpaque(false);
    useConstantThemesOnDialogs.setSelected(SubstanceLookAndFeel.isToUseConstantThemesOnDialogs());
    useConstantThemesOnDialogs.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    SubstanceLookAndFeel.setToUseConstantThemesOnDialogs(
                        useConstantThemesOnDialogs.isSelected());
                    SubstanceLookAndFeel.setSkin(
                        SubstanceLookAndFeel.getCurrentSkin(mainFrame.getRootPane()));
                  }
                });
          }
        });
    builder.append("Option pane icons", useConstantThemesOnDialogs);

    final JComboBox placementCombo = new JComboBox(new Object[] {"top", "bottom", "left", "right"});
    placementCombo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String selected = (String) placementCombo.getSelectedItem();
            if ("top".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.TOP);
            if ("bottom".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
            if ("left".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.LEFT);
            if ("right".equals(selected)) mainTabbedPane.setTabPlacement(JTabbedPane.RIGHT);
          }
        });
    builder.append("Placement", placementCombo);

    try {
      final JComboBox overviewKindCombo =
          new FlexiComboBox<TabOverviewKind>(
              TabOverviewKind.GRID, TabOverviewKind.MENU_CAROUSEL, TabOverviewKind.ROUND_CAROUSEL) {
            @Override
            public String getCaption(TabOverviewKind item) {
              return item.getName();
            }
          };
      overviewKindCombo.setSelectedItem(
          LafWidgetUtilities2.getTabPreviewPainter(mainTabbedPane).getOverviewKind(mainTabbedPane));
      overviewKindCombo.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              mainTabPreviewPainter.setTabOverviewKind(
                  (TabOverviewKind) overviewKindCombo.getSelectedItem());
            }
          });

      builder.append("Overview kind", overviewKindCombo);
    } catch (NoClassDefFoundError ignored) {
    }

    final JComboBox menuGutterFillCombo =
        new FlexiComboBox<MenuGutterFillKind>(
            MenuGutterFillKind.NONE,
            MenuGutterFillKind.SOFT,
            MenuGutterFillKind.HARD,
            MenuGutterFillKind.SOFT_FILL,
            MenuGutterFillKind.HARD_FILL) {
          @Override
          public String getCaption(MenuGutterFillKind item) {
            return item.name();
          }
        };
    menuGutterFillCombo.setSelectedItem(MenuGutterFillKind.HARD);
    menuGutterFillCombo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            UIManager.put(
                SubstanceLookAndFeel.MENU_GUTTER_FILL_KIND, menuGutterFillCombo.getSelectedItem());
          }
        });
    builder.append("Menu fill", menuGutterFillCombo);

    final JComboBox focusKindCombo =
        new FlexiComboBox<FocusKind>(FocusKind.values()) {
          @Override
          public String getCaption(FocusKind item) {
            return item.name();
          }
        };
    focusKindCombo.setSelectedItem(FocusKind.ALL_INNER);
    focusKindCombo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            UIManager.put(SubstanceLookAndFeel.FOCUS_KIND, focusKindCombo.getSelectedItem());
          }
        });
    builder.append("Focus kind", focusKindCombo);

    JButton buttonGlassPane = new JButton("Show");
    buttonGlassPane.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final JPanel glassPane =
                new JPanel() {
                  @Override
                  public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    Graphics2D graphics = (Graphics2D) g;
                    int height = getHeight();
                    int width = getWidth();
                    Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) 0.4);
                    graphics.setComposite(c);
                    for (int i = 0; i < height; i++) {
                      Color color =
                          (i % 2 == 0) ? new Color(200, 200, 255) : new Color(230, 230, 255);
                      graphics.setColor(color);
                      graphics.drawLine(0, i, width, i);
                    }
                    Composite c2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) 1.0);
                    graphics.setComposite(c2);
                  }
                };
            glassPane.setOpaque(false);
            glassPane.addMouseListener(new MouseAdapter() {});
            glassPane.addKeyListener(new KeyAdapter() {});
            mainFrame.setGlassPane(glassPane);
            new Thread() {
              @Override
              public void run() {
                glassPane.setVisible(true);
                try {
                  Thread.sleep(5000);
                } catch (InterruptedException ie) {
                  ie.printStackTrace();
                }
                glassPane.setVisible(false);
              }
            }.start();
          }
        });
    builder.append("Glass pane", buttonGlassPane);

    builder.appendSeparator("Custom animations");
    final JCheckBox allowFocusLoopAnimations = new JCheckBox("Allow animation");
    allowFocusLoopAnimations.setOpaque(false);
    allowFocusLoopAnimations.setSelected(
        AnimationConfigurationManager.getInstance()
            .isAnimationAllowed(AnimationFacet.FOCUS_LOOP_ANIMATION, null));
    allowFocusLoopAnimations.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (allowFocusLoopAnimations.isSelected()) {
              AnimationConfigurationManager.getInstance()
                  .allowAnimations(AnimationFacet.FOCUS_LOOP_ANIMATION);
            } else {
              AnimationConfigurationManager.getInstance()
                  .disallowAnimations(AnimationFacet.FOCUS_LOOP_ANIMATION);
            }
          }
        });
    builder.append("Focus loop", allowFocusLoopAnimations);

    final JCheckBox allowGlowIconAnimations = new JCheckBox("Allow animation");
    allowGlowIconAnimations.setOpaque(false);
    allowGlowIconAnimations.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (allowGlowIconAnimations.isSelected()) {
              AnimationConfigurationManager.getInstance().allowAnimations(AnimationFacet.ICON_GLOW);
            } else {
              AnimationConfigurationManager.getInstance()
                  .disallowAnimations(AnimationFacet.ICON_GLOW);
            }
          }
        });
    builder.append("Icon glow", allowGlowIconAnimations);

    final JCheckBox allowGhostIconAnimations = new JCheckBox("Allow animation");
    allowGhostIconAnimations.setOpaque(false);
    allowGhostIconAnimations.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (allowGhostIconAnimations.isSelected()) {
              AnimationConfigurationManager.getInstance()
                  .allowAnimations(AnimationFacet.GHOSTING_ICON_ROLLOVER);
            } else {
              AnimationConfigurationManager.getInstance()
                  .disallowAnimations(AnimationFacet.GHOSTING_ICON_ROLLOVER);
            }
          }
        });
    builder.append("Icon rollover", allowGhostIconAnimations);

    final JCheckBox allowGhostPressAnimations = new JCheckBox("Allow animation");
    allowGhostPressAnimations.setOpaque(false);
    allowGhostPressAnimations.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (allowGhostPressAnimations.isSelected()) {
              AnimationConfigurationManager.getInstance()
                  .allowAnimations(AnimationFacet.GHOSTING_BUTTON_PRESS);
            } else {
              AnimationConfigurationManager.getInstance()
                  .disallowAnimations(AnimationFacet.GHOSTING_BUTTON_PRESS);
            }
          }
        });
    builder.append("Button press", allowGhostPressAnimations);

    builder.appendSeparator("Toolbar");
    final JCheckBox isToolbarFlat = new JCheckBox("Is flat");
    isToolbarFlat.setOpaque(false);
    isToolbarFlat.setSelected(true);
    isToolbarFlat.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            toolbar.putClientProperty(
                SubstanceLookAndFeel.FLAT_PROPERTY, isToolbarFlat.isSelected());
            toolbar.repaint();
          }
        });
    builder.append("Flat", isToolbarFlat);

    builder.appendSeparator("Menu bar");
    final JCheckBox menuSearch = new JCheckBox("Has menu search");
    menuSearch.setOpaque(false);
    menuSearch.setSelected(false);
    menuSearch.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SubstanceLookAndFeel.setWidgetVisible(
                mainFrame.getRootPane(), menuSearch.isSelected(), SubstanceWidgetType.MENU_SEARCH);
          }
        });
    builder.append("Menu search", menuSearch);

    final JCheckBox menuLocale = new JCheckBox("Has custom locale");
    menuLocale.setOpaque(false);
    menuLocale.setSelected(false);
    menuLocale.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (menuLocale.isSelected()) {
              mainFrame.getJMenuBar().setLocale(Locale.FRENCH);
              mainFrame
                  .getJMenuBar()
                  .putClientProperty(LafWidget.IGNORE_GLOBAL_LOCALE, Boolean.TRUE);
            } else {
              mainFrame.getJMenuBar().putClientProperty(LafWidget.IGNORE_GLOBAL_LOCALE, null);
            }
          }
        });
    builder.append("Menu locale", menuLocale);

    JPanel result = builder.getPanel();
    result.setName("Main control panel");
    return result;
  }
コード例 #3
0
ファイル: Check.java プロジェクト: charlesa101/insubstantial
  public Check() {
    super(
        "Substance test with very very very very very very very very very very very very very very long title");

    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
      setIconImage(
          SubstanceLogo.getLogoImage(
              SubstanceLookAndFeel.getCurrentSkin(this.getRootPane())
                  .getColorScheme(
                      DecorationAreaType.PRIMARY_TITLE_PANE,
                      ColorSchemeAssociationKind.FILL,
                      ComponentState.ENABLED)));
    }
    SubstanceLookAndFeel.registerSkinChangeListener(
        new SkinChangeListener() {
          @Override
          public void skinChanged() {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    setIconImage(
                        SubstanceLogo.getLogoImage(
                            SubstanceLookAndFeel.getCurrentSkin(Check.this.getRootPane())
                                .getColorScheme(
                                    DecorationAreaType.PRIMARY_TITLE_PANE,
                                    ColorSchemeAssociationKind.FILL,
                                    ComponentState.ENABLED)));
                  }
                });
          }
        });

    setLayout(new BorderLayout());

    jtp = new JTabbedPane();
    try {
      mainTabPreviewPainter = new MyMainTabPreviewPainter();
      jtp.putClientProperty(LafWidget.TABBED_PANE_PREVIEW_PAINTER, mainTabPreviewPainter);
    } catch (Throwable e) {
    }
    jtp.getModel().addChangeListener(new TabSwitchListener());

    final JXPanel jxPanel = new JXPanel(new BorderLayout());
    toolbar = getToolbar("", 22, true);
    jxPanel.add(toolbar, BorderLayout.NORTH);

    JXStatusBar statusBar = getStatusBar(jxPanel, jtp);
    this.add(statusBar, BorderLayout.SOUTH);

    taskPaneContainer =
        new JXTaskPaneContainer() {
          @Override
          public boolean getScrollableTracksViewportWidth() {
            return false;
          }
        };
    taskPaneContainer.setScrollableTracksViewportHeight(false);
    taskPaneContainer.setScrollableTracksViewportWidth(false);

    mainTaskPane = new JXTaskPane();
    mainTaskPane.setLayout(new BorderLayout());
    JPanel mainControlPanel =
        ControlPanelFactory.getMainControlPanel(this, jtp, mainTabPreviewPainter, toolbar);
    // mainControlPanel.setOpaque(false);
    mainTaskPane.add(mainControlPanel, BorderLayout.CENTER);
    mainTaskPane.setTitle("General settings");
    mainTaskPane.setIcon(getIcon("JFrameColor16"));
    mainTaskPane.setCollapsed(true);
    taskPaneContainer.add(mainTaskPane);

    JPanel dialogControlPanel = ControlPanelFactory.getDialogControlPanel(this);
    JXTaskPane dialogTaskPane = new JXTaskPane();
    dialogTaskPane.setLayout(new BorderLayout());
    dialogTaskPane.add(dialogControlPanel, BorderLayout.CENTER);
    dialogTaskPane.setTitle("Frames & Dialogs");
    dialogTaskPane.setIcon(getIcon("JDialogColor16"));
    dialogTaskPane.setCollapsed(true);
    // dialogTaskPane.setOpaque(false);
    taskPaneContainer.add(dialogTaskPane);

    currentSpecificTaskPane = null;

    final JScrollPane scrollPane =
        new JScrollPane(
            taskPaneContainer,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    SubstanceLookAndFeel.setDecorationType(scrollPane, DecorationAreaType.GENERAL);
    // scrollPane.setOpaque(false);
    // scrollPane.getViewport().setOpaque(false);

    JPanel mainPanel = new JPanel();
    mainPanel.add(scrollPane);
    mainPanel.add(jtp);
    mainPanel.setLayout(
        new LayoutManager() {
          @Override
          public void addLayoutComponent(String name, Component comp) {}

          @Override
          public Dimension minimumLayoutSize(Container parent) {
            Dimension min1 = scrollPane.getMinimumSize();
            Dimension min2 = jtp.getMinimumSize();
            return new Dimension(min1.width + min2.width, min1.height + min2.height);
          }

          @Override
          public void layoutContainer(Container parent) {
            // give 30% width to task pane container and
            // 70% width to the tabbed pane with controls.
            int width = parent.getWidth();
            int height = parent.getHeight();
            scrollPane.setBounds(0, 0, (int) (0.3 * width), height);
            jtp.setBounds((int) (0.3 * width), 0, width - (int) (0.3 * width), height);
          }

          @Override
          public Dimension preferredLayoutSize(Container parent) {
            Dimension pref1 = scrollPane.getPreferredSize();
            Dimension pref2 = jtp.getPreferredSize();
            return new Dimension(pref1.width + pref2.width, pref1.height + pref2.height);
          }

          @Override
          public void removeLayoutComponent(Component comp) {}
        });
    jxPanel.add(mainPanel, BorderLayout.CENTER);

    this.add(jxPanel, BorderLayout.CENTER);

    setPreferredSize(new Dimension(400, 400));
    this.setSize(getPreferredSize());
    setMinimumSize(getPreferredSize());

    ButtonsPanel buttonsPanel = new ButtonsPanel();
    jtp.addTab("Buttons", getIcon("JButtonColor16"), buttonsPanel);
    getRootPane().setDefaultButton(buttonsPanel.defaultButton);

    jtp.addTab("Combo box", getIcon("JComboBoxColor16"), new CombosPanel());

    jtp.addTab("Scroll pane", getIcon("JScrollPaneColor16"), new ScrollPanel());

    TabCloseCallback closeCallback =
        new TabCloseCallback() {
          @Override
          public TabCloseKind onAreaClick(
              JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) {
            if (mouseEvent.getButton() != MouseEvent.BUTTON3) return TabCloseKind.NONE;
            if (mouseEvent.isShiftDown()) {
              return TabCloseKind.ALL;
            }
            return TabCloseKind.THIS;
          }

          @Override
          public TabCloseKind onCloseButtonClick(
              JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) {
            if (mouseEvent.isAltDown()) {
              return TabCloseKind.ALL_BUT_THIS;
            }
            if (mouseEvent.isShiftDown()) {
              return TabCloseKind.ALL;
            }
            return TabCloseKind.THIS;
          }

          @Override
          public String getAreaTooltip(JTabbedPane tabbedPane, int tabIndex) {
            return null;
          }

          @Override
          public String getCloseButtonTooltip(JTabbedPane tabbedPane, int tabIndex) {
            StringBuffer result = new StringBuffer();
            result.append("<html><body>");
            result.append("Mouse click closes <b>" + tabbedPane.getTitleAt(tabIndex) + "</b> tab");
            result.append(
                "<br><b>Alt</b>-Mouse click closes all tabs but <b>"
                    + tabbedPane.getTitleAt(tabIndex)
                    + "</b> tab");
            result.append("<br><b>Shift</b>-Mouse click closes all tabs");
            result.append("</body></html>");
            return result.toString();
          }
        };

    try {
      TabPanel tp = new TabPanel();
      tp.jtp.putClientProperty(SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK, closeCallback);
      jtp.addTab("Tabs", getIcon("JTabbedPaneColor16"), tp);
    } catch (NoClassDefFoundError ncdfe) {
    }

    jtp.addTab("Split", new SplitPanel());

    jtp.addTab("Desktop", getIcon("JDesktopPaneColor16"), new DesktopPanel());

    jtp.addTab("Text fields", getIcon("JTextPaneColor16"), new TextFieldsPanel());

    jtp.addTab("Table", getIcon("JTableColor16"), new TablePanel());

    try {
      jtp.addTab("List", getIcon("JListColor16"), new ListPanel());
    } catch (NoClassDefFoundError ncdfe) {
    }

    jtp.addTab("Slider", getIcon("JSliderColor16"), new SliderPanel());

    jtp.addTab("Progress bar", getIcon("JProgressBarColor16"), new ProgressBarPanel());

    jtp.addTab("Spinner", getIcon("JSpinnerColor16"), new SpinnerPanel());

    jtp.addTab("Tree", getIcon("JTreeColor16"), new TreePanel());

    jtp.addTab("File tree", getIcon("JTreeColor16"), new FileTreePanel());

    jtp.addTab("Cards", new CardPanel());

    JPanel verticalButtonPanel = new JPanel();
    verticalButtonPanel.setLayout(new GridLayout(1, 3));
    verticalButtonPanel.add(new JButton("Vert button 1"));
    verticalButtonPanel.add(new JButton("Vert button 2"));
    JPanel smallVerticalButtonPanel = new JPanel();
    smallVerticalButtonPanel.setLayout(new GridLayout(4, 4));
    for (int row = 0; row < 4; row++) {
      for (int col = 0; col < 4; col++) {
        JButton vertButton = new JButton("vert");
        vertButton.setToolTipText("Vertical button " + row + ":" + col);
        smallVerticalButtonPanel.add(vertButton);
      }
    }
    verticalButtonPanel.add(smallVerticalButtonPanel);
    jtp.addTab("V-Buttons", verticalButtonPanel);

    jtp.addTab("Colored", new ColoredControlsPanel());

    jtp.addTab("Colorized", new ColorizedControlsPanel());

    jtp.addTab("Cells", new CellsPanel());

    jtp.addTab("Sizes", new SizesPanel());

    jtp.addTab("H-Align", new HAlignmentPanel());

    jtp.addTab("V-Align", new VAlignmentPanel());

    // sample menu bar
    JMenuBar jmb = new JMenuBar();
    if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
      jmb.add(SampleMenuFactory.getSkinMenu());
      jmb.add(SampleMenuFactory.getTransformMenu());
    }
    JMenu coloredMenu = new JMenu("Colors");
    coloredMenu.setMnemonic('0');
    JMenuItem coloredMI = new JMenuItem("Italic red");
    coloredMI.setFont(coloredMI.getFont().deriveFont(Font.ITALIC));
    coloredMI.setForeground(Color.red);
    coloredMenu.add(coloredMI);
    JRadioButtonMenuItem coloredRBMI = new JRadioButtonMenuItem("Bold green");
    coloredRBMI.setFont(coloredRBMI.getFont().deriveFont(Font.BOLD));
    coloredRBMI.setForeground(Color.green);
    coloredMenu.add(coloredRBMI);
    JCheckBoxMenuItem coloredCBMI = new JCheckBoxMenuItem("Big blue");
    coloredCBMI.setFont(coloredCBMI.getFont().deriveFont(32f));
    coloredCBMI.setForeground(Color.blue);
    coloredMenu.add(coloredCBMI);
    JMenu coloredM = new JMenu("Always big magenta");
    coloredM.setForeground(Color.magenta);
    coloredM.setFont(coloredM.getFont().deriveFont(24f));
    coloredMenu.add(coloredM);
    jmb.add(coloredMenu);

    JMenu testMenu = SampleMenuFactory.getTestMenu();
    jmb.add(testMenu);

    JMenu jm4 = new JMenu("Disabled");
    jm4.add(new JMenuItem("dummy4"));
    jm4.setMnemonic('4');
    jmb.add(jm4);
    jm4.setEnabled(false);

    // LAF changing
    jmb.add(SampleMenuFactory.getLookAndFeelMenu(this));
    setJMenuBar(jmb);

    TabCloseCallback closeCallbackMain =
        new TabCloseCallback() {
          @Override
          public TabCloseKind onAreaClick(
              JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) {
            if (mouseEvent.getButton() != MouseEvent.BUTTON2) return TabCloseKind.NONE;
            if (mouseEvent.isShiftDown()) {
              return TabCloseKind.ALL;
            }
            return TabCloseKind.THIS;
          }

          @Override
          public TabCloseKind onCloseButtonClick(
              JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) {
            if (mouseEvent.isAltDown()) {
              return TabCloseKind.ALL_BUT_THIS;
            }
            if (mouseEvent.isShiftDown()) {
              return TabCloseKind.ALL;
            }
            return TabCloseKind.THIS;
          }

          @Override
          public String getAreaTooltip(JTabbedPane tabbedPane, int tabIndex) {
            return null;
          }

          @Override
          public String getCloseButtonTooltip(JTabbedPane tabbedPane, int tabIndex) {
            StringBuffer result = new StringBuffer();
            result.append("<html><body>");
            result.append("Mouse click closes <b>" + tabbedPane.getTitleAt(tabIndex) + "</b> tab");
            result.append(
                "<br><b>Alt</b>-Mouse click closes all tabs but <b>"
                    + tabbedPane.getTitleAt(tabIndex)
                    + "</b> tab");
            result.append("<br><b>Shift</b>-Mouse click closes all tabs");
            result.append("</body></html>");
            return result.toString();
          }
        };

    jtp.putClientProperty(SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK, closeCallbackMain);
    SubstanceLookAndFeel.registerTabCloseChangeListener(
        new TabCloseListener() {
          @Override
          public void tabClosed(JTabbedPane tabbedPane, Component tabComponent) {
            out("Closed tab");
          }

          @Override
          public void tabClosing(JTabbedPane tabbedPane, Component tabComponent) {
            out("Closing tab");
          }
        });

    SubstanceLookAndFeel.registerTabCloseChangeListener(
        jtp,
        new VetoableTabCloseListener() {
          @Override
          public void tabClosed(JTabbedPane tabbedPane, Component tabComponent) {
            out("Closed tab - specific");
          }

          @Override
          public void tabClosing(JTabbedPane tabbedPane, Component tabComponent) {
            out("Closing tab - specific");
          }

          @Override
          public boolean vetoTabClosing(JTabbedPane tabbedPane, Component tabComponent) {
            int userCloseAnswer =
                JOptionPane.showConfirmDialog(
                    Check.this,
                    "Are you sure you want to close '"
                        + tabbedPane.getTitleAt(tabbedPane.indexOfComponent(tabComponent))
                        + "' tab?",
                    "Confirm dialog",
                    JOptionPane.YES_NO_OPTION);
            return (userCloseAnswer == JOptionPane.NO_OPTION);
          }
        });

    SubstanceLookAndFeel.registerTabCloseChangeListener(
        jtp,
        new VetoableMultipleTabCloseListener() {
          @Override
          public void tabsClosed(JTabbedPane tabbedPane, Set<Component> tabComponents) {
            out("Closed " + tabComponents.size() + " tabs - specific");
          }

          @Override
          public void tabsClosing(JTabbedPane tabbedPane, Set<Component> tabComponents) {
            out("Closing " + tabComponents.size() + " tabs - specific");
          }

          @Override
          public boolean vetoTabsClosing(JTabbedPane tabbedPane, Set<Component> tabComponents) {
            int userCloseAnswer =
                JOptionPane.showConfirmDialog(
                    Check.this,
                    "Are you sure you want to close " + tabComponents.size() + " tabs?",
                    "Confirm dialog",
                    JOptionPane.YES_NO_OPTION);
            return (userCloseAnswer == JOptionPane.NO_OPTION);
          }
        });

    addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent e) {
            System.out.println("Size " + getSize());
          }
        });
  }
コード例 #4
0
  /**
   * Returns the control panel for testing dialogs.
   *
   * @param mainFrame The main test frame.
   * @return Control panel for testing dialogs.
   */
  public static JPanel getDialogControlPanel(final JFrame mainFrame) {
    FormLayout lm = new FormLayout("right:pref, 4dlu, fill:pref:grow", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm);

    builder.appendSeparator("Core choosers");
    JButton bfo = new JButton("Open dialog", Check.getIcon("JFileChooserColor16"));
    bfo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFileChooser jfc = new JFileChooser();
                    jfc.showOpenDialog(mainFrame);
                  }
                });
          }
        });
    builder.append("File chooser", bfo);

    JButton bfs = new JButton("Save dialog", Check.getIcon("JFileChooserColor16"));
    bfs.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFileChooser jfc = new JFileChooser();
                    jfc.showSaveDialog(mainFrame);
                  }
                });
          }
        });
    builder.append("", bfs);

    JButton bc = new JButton("Open", Check.getIcon("JColorChooserColor16"));
    bc.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    Color color =
                        JColorChooser.showDialog(
                            mainFrame, "Color chooser", new Color(23, 45, 200));
                    if (color != null) {
                      Check.out("Chosen " + color.toString());
                    }
                  }
                });
          }
        });
    builder.append("Color chooser", bc);

    JButton bcWindow = new JButton("open in window");
    bcWindow.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    final Window window = new Window(mainFrame);
                    window.setLayout(new BorderLayout());
                    window.add(new JColorChooser());
                    window.pack();
                    window.setLocationRelativeTo(null);
                    window.setVisible(true);
                    Timer timerDispose =
                        new Timer(
                            5000,
                            new ActionListener() {
                              @Override
                              public void actionPerformed(ActionEvent e) {
                                window.dispose();
                              }
                            });
                    timerDispose.setRepeats(false);
                    timerDispose.start();
                  }
                });
          }
        });
    builder.append("", bcWindow);

    builder.appendSeparator("Option panes");

    JButton bop = new JButton("Show");
    bop.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane pane = new JOptionPane("Sample option pane");
                    JDialog dialog = pane.createDialog(mainFrame, "Sample title");
                    dialog.setVisible(true);
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Plain", bop);

    JButton bopi = new JButton("Show", Check.getIcon("22/dialog-information"));
    bopi.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample info message",
                        "Sample title",
                        JOptionPane.INFORMATION_MESSAGE);
                  }
                });
          }
        });
    builder.append("Info", bopi);

    JButton bope = new JButton("Show", Check.getIcon("22/dialog-error"));
    bope.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample error message",
                        "Sample title",
                        JOptionPane.ERROR_MESSAGE);
                  }
                });
          }
        });
    builder.append("Error", bope);

    JButton bopw = new JButton("Show", Check.getIcon("22/dialog-warning"));
    bopw.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample warning message",
                        "Sample title",
                        JOptionPane.WARNING_MESSAGE);
                  }
                });
          }
        });
    builder.append("Warning", bopw);

    JButton bopq = new JButton("Show", Check.getIcon("22/help-browser"));
    bopq.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample question message",
                        "Sample title",
                        JOptionPane.QUESTION_MESSAGE);
                  }
                });
          }
        });
    builder.append("Question", bopq);

    JButton bopc = new JButton("Show");
    bopc.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showOptionDialog(
                        mainFrame,
                        new JPanel(),
                        "Option",
                        JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.PLAIN_MESSAGE,
                        null,
                        null,
                        null);
                  }
                });
          }
        });
    builder.append("Custom", bopc);

    JButton buttonOptionPaneSimpleInput = new JButton("Show");
    buttonOptionPaneSimpleInput.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, "Sample dialog", true);
                    dialog.setSize(400, 300);
                    dialog.setLocationRelativeTo(mainFrame);
                    dialog.setLayout(new BorderLayout());
                    JDesktopPane panel = new JDesktopPane();
                    dialog.add(panel, BorderLayout.CENTER);
                    JOptionPane.showInputDialog(
                        panel, "Sample Question Message?", "Default Answer");
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Simple input", buttonOptionPaneSimpleInput);

    JButton buttonOptionPaneComplexInput = new JButton("Show");
    buttonOptionPaneComplexInput.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, "Sample dialog", true);
                    dialog.setSize(400, 300);
                    dialog.setLocationRelativeTo(mainFrame);
                    dialog.setLayout(new BorderLayout());
                    JDesktopPane panel = new JDesktopPane();
                    dialog.add(panel, BorderLayout.CENTER);
                    // dialog.setVisible(true);
                    String optionChoices[] = new String[] {"entry1", "entry2", "entry3", "entry4"};
                    JOptionPane.showInputDialog(
                        panel,
                        "Sample Question Message?",
                        "Title Goes Here",
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        optionChoices,
                        "entry1");
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Complex input", buttonOptionPaneComplexInput);

    JButton buttonOptionPaneInternalInput = new JButton("Show");
    buttonOptionPaneInternalInput.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, "Sample dialog", true);
                    dialog.setSize(400, 300);
                    dialog.setLocationRelativeTo(mainFrame);
                    dialog.setLayout(new BorderLayout());
                    JDesktopPane panel = new JDesktopPane();
                    dialog.add(panel, BorderLayout.CENTER);
                    // dialog.setVisible(true);
                    JOptionPane.showInternalInputDialog(
                        panel,
                        "Sample info message",
                        "Sample title",
                        JOptionPane.INFORMATION_MESSAGE);
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Internal input", buttonOptionPaneInternalInput);

    builder.appendSeparator("Default buttons");

    JButton openDisposable = new JButton("Open");
    openDisposable.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    if (disposableDialog != null) {
                      disposableDialog.setVisible(true);
                      return;
                    }
                    disposableDialog = new JDialog();
                    disposableDialog.setTitle("Disposable");

                    JTree tree = new JTree();
                    JScrollPane jsp =
                        new JScrollPane(
                            tree,
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                    jsp.putClientProperty(
                        LafWidget.COMPONENT_PREVIEW_PAINTER, new DefaultPreviewPainter());

                    disposableDialog.setLayout(new BorderLayout());
                    disposableDialog.add(jsp, BorderLayout.CENTER);

                    disposableDialog.setSize(200, 100);
                    disposableDialog.setLocationRelativeTo(null);
                    disposableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                    disposableDialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Disposable dialog", openDisposable);

    JButton launchFrameDialogWithIcon = new JButton("Open");
    launchFrameDialogWithIcon.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    SimpleDialog sd = new SimpleDialog();
                    if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
                      sd.setIconImage(
                          SubstanceLogo.getLogoImage(
                              SubstanceLookAndFeel.getCurrentSkin(sd.getRootPane())
                                  .getColorScheme(
                                      DecorationAreaType.PRIMARY_TITLE_PANE,
                                      ColorSchemeAssociationKind.FILL,
                                      ComponentState.ENABLED)));
                    }
                    sd.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
                    sd.setModal(false);
                    sd.pack();
                    sd.setLocationRelativeTo(null);
                    sd.setVisible(true);
                    sd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                  }
                });
          }
        });
    builder.append("Dialog with icon", launchFrameDialogWithIcon);

    JButton bd = new JButton("Open");
    bd.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    SimpleDialog sd = new SimpleDialog();
                    sd.setModal(false);
                    sd.pack();
                    sd.setLocationRelativeTo(null);
                    sd.setVisible(true);
                    simpleDialog = sd;
                  }
                });
          }
        });
    builder.append("Open a dialog", bd);

    JButton bcd = new JButton("Close");
    bcd.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    if (simpleDialog != null) {
                      simpleDialog.removeAll();
                      simpleDialog.dispose();
                      ReferenceQueue<JButton> weakQueue = new ReferenceQueue<JButton>();
                      WeakReference<JButton> weakRef =
                          new WeakReference<JButton>(simpleDialog.b1, weakQueue);
                      weakRef.enqueue();
                      simpleDialog.b1 = null;
                      simpleDialog = null;
                      System.gc();
                      // Wait until the weak reference is on the queue and
                      // remove
                      // it
                      Check.out("Waiting to remove");
                      try {
                        Reference<?> ref = weakQueue.remove();
                        ref.clear();
                      } catch (InterruptedException ie) {
                        ie.printStackTrace();
                        return;
                      }
                      Check.out("Removed");
                    }
                  }
                });
          }
        });
    builder.append("Close the dialog", bcd);

    JButton buttonDialogCloseOnEsc = new JButton("Show");
    buttonDialogCloseOnEsc.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    final JDialog dialog = new JDialog((Frame) null, "Click ESC to dispose");
                    dialog.setSize(200, 200);
                    dialog.setLayout(new BorderLayout());

                    JPanel myContentPane = new JPanel();
                    myContentPane.setLayout(new BorderLayout());
                    dialog.setContentPane(myContentPane);

                    JTabbedPane tabs = new JTabbedPane();
                    JPanel tab1 = new JPanel(new FlowLayout());
                    tab1.add(new JLabel("test"));
                    JTextField tab1TextField = new JTextField("some text");
                    tab1TextField.putClientProperty(
                        LafWidget.TEXT_FLIP_SELECT_ON_ESCAPE, Boolean.TRUE);
                    tab1.add(tab1TextField);
                    tabs.addTab("Foo", tab1);
                    JPanel tab2 = new JPanel(new FlowLayout());
                    tab2.add(new JButton("Test"));
                    tabs.addTab("Bar", tab2);
                    dialog.add(tabs, BorderLayout.CENTER);

                    dialog.add(new JLabel("Press Esc to close dialog"), BorderLayout.NORTH);

                    // connect "Esc" key with disposing the dialog
                    String actionName = "VK_ESCAPE";
                    Action action =
                        new AbstractAction(actionName) {
                          @Override
                          public void actionPerformed(ActionEvent e) {
                            dialog.dispose();
                          }
                        };
                    myContentPane.getActionMap().put(actionName, action);
                    myContentPane
                        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
                        .put(
                            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0),
                            actionName);

                    dialog.setLocationRelativeTo(null);
                    dialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Dialog with ESC close", buttonDialogCloseOnEsc);

    JButton buttonDialogUndecorated = new JButton("Show");
    buttonDialogUndecorated.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    final JDialog dialog = new JDialog((Frame) null, "");
                    dialog.setSize(200, 200);
                    dialog.setUndecorated(true);
                    dialog.setLayout(new BorderLayout());

                    JPanel myContentPane = new JPanel();
                    myContentPane.setLayout(new BorderLayout());
                    dialog.setContentPane(myContentPane);

                    dialog.add(new JLabel("Press Esc to close dialog"), BorderLayout.NORTH);

                    // connect "Esc" key with "System.exit(0)"
                    String actionName = "VK_ESCAPE";
                    Action action =
                        new AbstractAction(actionName) {
                          @Override
                          public void actionPerformed(ActionEvent e) {
                            dialog.dispose();
                          }
                        };
                    myContentPane.getActionMap().put(actionName, action);
                    myContentPane
                        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
                        .put(
                            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0),
                            actionName);

                    dialog.setLocationRelativeTo(null);
                    dialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Undecorated dialog", buttonDialogUndecorated);

    builder.appendSeparator("Miscellaneous");

    JButton customSkinFrame = new JButton("Show");
    customSkinFrame.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFrame testFrame = new SampleFrame();
                    testFrame
                        .getRootPane()
                        .putClientProperty(
                            SubstanceLookAndFeel.SKIN_PROPERTY, new NebulaBrickWallSkin());
                    SwingUtilities.updateComponentTreeUI(testFrame.getRootPane());
                    testFrame.setSize(315, 245);
                    testFrame.setLocationRelativeTo(mainFrame);
                    testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    testFrame.setVisible(true);
                  }
                });
          }
        });
    builder.append("Nebula brick wall frame", customSkinFrame);

    JButton btf = new JButton("Show");
    btf.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFrame testFrame = new JFrame("test1");
                    testFrame.setSize(262, 100);
                    testFrame.setLocationRelativeTo(mainFrame);
                    testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    testFrame.setVisible(true);
                  }
                });
          }
        });
    builder.append("Regular frame", btf);

    JButton btfU = new JButton("Show");
    btfU.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFrame.setDefaultLookAndFeelDecorated(false);
                    JDialog.setDefaultLookAndFeelDecorated(false);

                    JFrame testFrame = new JFrame("test undecorated");
                    // testFrame.setUndecorated(true);

                    testFrame.setSize(262, 100);
                    testFrame.setLocation(400, 400);
                    testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    testFrame.setVisible(true);

                    JFrame.setDefaultLookAndFeelDecorated(true);
                    JDialog.setDefaultLookAndFeelDecorated(true);
                  }
                });
          }
        });
    builder.append("Undecorated frame", btfU);

    JButton bcp = new JButton("Open");
    bcp.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {

                    JFrame colorFrame = new JFrame();
                    final ColorPanel cp1 = new ColorPanel("default");
                    final ColorPanel cp2 = new ColorPanel("green");
                    cp2.setBackground(Color.green);
                    final ColorPanel cp3 = new ColorPanel("red");
                    cp3.setBackground(Color.red);
                    final ColorPanel cp4 = new ColorPanel("black");
                    cp4.setBackground(Color.black);
                    // cp2.setBackground(Color.GREEN);
                    colorFrame.setLayout(
                        new LayoutManager() {
                          @Override
                          public void addLayoutComponent(String name, Component comp) {}

                          @Override
                          public void layoutContainer(Container parent) {
                            int h = parent.getHeight() / 2;
                            int w = parent.getWidth() / 2;
                            cp1.setBounds(0, 0, w, h);
                            cp2.setBounds(0, h, w, parent.getHeight() - h);
                            cp3.setBounds(w, 0, w, h + 1);
                            cp4.setBounds(w, h + 1, w, parent.getHeight() - h);
                          }

                          @Override
                          public Dimension minimumLayoutSize(Container parent) {
                            return preferredLayoutSize(parent);
                          }

                          @Override
                          public Dimension preferredLayoutSize(Container parent) {
                            return new Dimension(100, 100);
                          }

                          @Override
                          public void removeLayoutComponent(Component comp) {}
                        });
                    colorFrame.add(cp1);
                    colorFrame.add(cp2);
                    colorFrame.add(cp3);
                    colorFrame.add(cp4);

                    colorFrame.setSize(400, 399);
                    colorFrame.setLocation(300, 300);
                    colorFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    colorFrame.setVisible(true);
                  }
                });
          }
        });
    builder.append("Color panels", bcp);

    JButton paneDialog = new JButton("Open");
    paneDialog.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, true);
                    dialog.setTitle("Test text pane in scroll pane");
                    JTextPane textPane = new JTextPane();
                    String contents = "";
                    for (int i = 0; i < 100; i++)
                      contents +=
                          "This is sample line " + i + " and a lot of other irrelevant text\n";
                    textPane.replaceSelection(contents);

                    JScrollPane scroll = new JScrollPane(textPane);
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    panel.add(scroll, BorderLayout.CENTER);

                    dialog.setLayout(new BorderLayout());
                    dialog.add(panel, BorderLayout.CENTER);
                    dialog.setSize(400, 400);
                    dialog.setLocation(400, 200);
                    dialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Text pane dialog", paneDialog);

    return builder.getPanel();
  }