/** TabbedPaneDemo Constructor */
  public TabbedPaneDemo(SwingSet2 swingset) {
    // Set the title for this demo, and an icon used to represent this
    // demo inside the SwingSet2 app.
    super(swingset, "TabbedPaneDemo", "toolbar/JTabbedPane.gif");

    // create tab position controls
    JPanel tabControls = new JPanel();
    tabControls.add(new JLabel(getString("TabbedPaneDemo.label")));
    top = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.top")));
    left = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.left")));
    bottom = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.bottom")));
    right = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.right")));
    getDemoPanel().add(tabControls, BorderLayout.NORTH);

    group = new ButtonGroup();
    group.add(top);
    group.add(bottom);
    group.add(left);
    group.add(right);

    top.setSelected(true);

    top.addActionListener(this);
    bottom.addActionListener(this);
    left.addActionListener(this);
    right.addActionListener(this);

    // create tab
    tabbedpane = new JTabbedPane();
    getDemoPanel().add(tabbedpane, BorderLayout.CENTER);

    String name = getString("TabbedPaneDemo.laine");
    JLabel pix = new JLabel(createImageIcon("tabbedpane/laine.jpg", name));
    tabbedpane.add(name, pix);

    name = getString("TabbedPaneDemo.ewan");
    pix = new JLabel(createImageIcon("tabbedpane/ewan.jpg", name));
    tabbedpane.add(name, pix);

    name = getString("TabbedPaneDemo.hania");
    pix = new JLabel(createImageIcon("tabbedpane/hania.jpg", name));
    tabbedpane.add(name, pix);

    name = getString("TabbedPaneDemo.bounce");
    spin = new HeadSpin();
    tabbedpane.add(name, spin);

    tabbedpane
        .getModel()
        .addChangeListener(
            new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                SingleSelectionModel model = (SingleSelectionModel) e.getSource();
                if (model.getSelectedIndex() == tabbedpane.getTabCount() - 1) {
                  spin.go();
                }
              }
            });
  }
Example #2
0
  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());
          }
        });
  }
Example #3
0
  protected static JXStatusBar getStatusBar(
      final JXPanel jxPanel, final JTabbedPane mainTabbedPane) {
    JXStatusBar statusBar = new JXStatusBar();

    try {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      Enumeration<URL> urls = cl.getResources("META-INF/MANIFEST.MF");
      String substanceVer = null;
      String substanceBuildStamp = null;
      while (urls.hasMoreElements()) {
        InputStream is = urls.nextElement().openStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        while (true) {
          String line = br.readLine();
          if (line == null) break;
          int firstColonIndex = line.indexOf(":");
          if (firstColonIndex < 0) continue;
          String name = line.substring(0, firstColonIndex).trim();
          String val = line.substring(firstColonIndex + 1).trim();
          if (name.compareTo("Substance-Version") == 0) substanceVer = val;
          if (name.compareTo("Substance-BuildStamp") == 0) substanceBuildStamp = val;
        }
        try {
          br.close();
        } catch (IOException ioe) {
        }
      }
      if (substanceVer != null) {
        JLabel statusLabel = new JLabel(substanceVer + " [built on " + substanceBuildStamp + "]");
        JXStatusBar.Constraint cStatusLabel = new JXStatusBar.Constraint();
        cStatusLabel.setFixedWidth(300);
        statusBar.add(statusLabel, cStatusLabel);
      }
    } catch (IOException ioe) {
    }

    JXStatusBar.Constraint c2 =
        new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL);
    final JLabel tabLabel = new JLabel("");
    statusBar.add(tabLabel, c2);
    mainTabbedPane
        .getModel()
        .addChangeListener(
            new ChangeListener() {
              @Override
              public void stateChanged(ChangeEvent e) {
                int selectedIndex = mainTabbedPane.getSelectedIndex();
                if (selectedIndex < 0) tabLabel.setText("No selected tab");
                else
                  tabLabel.setText("Tab " + mainTabbedPane.getTitleAt(selectedIndex) + " selected");
              }
            });

    JPanel fontSizePanel = FontSizePanel.getPanel();
    JXStatusBar.Constraint fontSizePanelConstraints = new JXStatusBar.Constraint();
    fontSizePanelConstraints.setFixedWidth(270);
    statusBar.add(fontSizePanel, fontSizePanelConstraints);

    JPanel alphaPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));

    final JLabel alphaLabel = new JLabel("100%");
    final JSlider alphaSlider = new JSlider(0, 100, 100);
    alphaSlider.setFocusable(false);
    alphaSlider.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            int currValue = alphaSlider.getValue();
            alphaLabel.setText(currValue + "%");
            jxPanel.setAlpha(currValue / 100.0f);
          }
        });
    alphaSlider.setToolTipText("Changes the global opacity. Is not Substance-specific");
    alphaSlider.setPreferredSize(new Dimension(120, alphaSlider.getPreferredSize().height));

    alphaPanel.add(alphaLabel);
    alphaPanel.add(alphaSlider);

    JXStatusBar.Constraint alphaPanelConstraints = new JXStatusBar.Constraint();
    alphaPanelConstraints.setFixedWidth(160);
    statusBar.add(alphaPanel, alphaPanelConstraints);
    return statusBar;
  }
  public MultiWorkspaceExample(JFrame frame) {
    super(new BorderLayout());

    // Create the content components.
    TextPanel textPanel1 = new TextPanel("I am window 1.");
    TextPanel textPanel2 = new TextPanel("I am window 2.");
    TextPanel textPanel3 = new TextPanel("I am window 3.");
    TextPanel textPanel4 = new TextPanel("I am window 4.");
    TextPanel textPanel5 = new TextPanel("I am window 5.");
    TextPanel textPanel6 = new TextPanel("I am window 6.");
    TextPanel textPanel7 = new TextPanel("I am window 7.");
    TextPanel textPanel8 = new TextPanel("I am window 8.");
    TextPanel textPanel9 = new TextPanel("I am window 9.");
    TextPanel textPanel10 = new TextPanel("I am window 10.");
    TextPanel textPanel11 = new TextPanel("I am window 11.");
    TextPanel textPanel12 = new TextPanel("I am window 12.");
    TextPanel textPanel13 = new TextPanel("I am window 13.");
    TextPanel textPanel14 = new TextPanel("I am window 14.");

    // Create the dockables around the content components.
    Dockable[] dockables = new Dockable[14];
    dockables[0] = new DefaultDockable("Window1", textPanel1, "Window 1", null, DockingMode.ALL);
    dockables[1] = new DefaultDockable("Window2", textPanel2, "Window 2", null, DockingMode.ALL);
    dockables[2] = new DefaultDockable("Window3", textPanel3, "Window 3", null, DockingMode.ALL);
    dockables[3] = new DefaultDockable("Window4", textPanel4, "Window 4", null, DockingMode.ALL);
    dockables[4] = new DefaultDockable("Window5", textPanel5, "Window 5", null, DockingMode.ALL);
    dockables[5] = new DefaultDockable("Window6", textPanel6, "Window 6", null, DockingMode.ALL);
    dockables[6] = new DefaultDockable("Window7", textPanel7, "Window 7", null, DockingMode.ALL);
    dockables[7] = new DefaultDockable("Window8", textPanel8, "Window 8", null, DockingMode.ALL);
    dockables[8] = new DefaultDockable("Window9", textPanel9, "Window 9", null, DockingMode.ALL);
    dockables[9] = new DefaultDockable("Window10", textPanel10, "Window 10", null, DockingMode.ALL);
    dockables[10] =
        new DefaultDockable("Window11", textPanel11, "Window 11", null, DockingMode.ALL);
    dockables[11] =
        new DefaultDockable("Window12", textPanel12, "Window 12", null, DockingMode.ALL);
    dockables[12] =
        new DefaultDockable("Window13", textPanel13, "Window 13", null, DockingMode.ALL);
    dockables[13] =
        new DefaultDockable("Window14", textPanel14, "Window 14", null, DockingMode.ALL);

    // Add minimize, maximize, externalize, and close actions to the dockables.
    dockables[0] = addActions(dockables[0]);
    dockables[1] = addActions(dockables[1]);
    dockables[2] = addActions(dockables[2]);
    dockables[3] = addActions(dockables[3]);
    dockables[4] = addActions(dockables[4]);
    dockables[5] = addActions(dockables[5]);
    dockables[6] = addActions(dockables[6]);
    dockables[7] = addActions(dockables[7]);
    dockables[8] = addActions(dockables[8]);
    dockables[9] = addActions(dockables[9]);
    dockables[10] = addActions(dockables[10]);
    dockables[11] = addActions(dockables[11]);
    dockables[12] = addActions(dockables[12]);
    dockables[13] = addActions(dockables[13]);

    // Create the buttons with a dockable around.
    Dockable[] buttonDockables = createButtonDockables();

    // Create a minimizer.
    LineMinimizer minimizer1 = new LineMinimizer();
    LineMinimizer minimizer2 = new LineMinimizer();

    // Create a maximizer.
    SingleMaximizer maximizer1 = new SingleMaximizer(minimizer1);
    SingleMaximizer maximizer2 = new SingleMaximizer(minimizer2);

    // Create an externalizer.
    FloatExternalizer externalizer1 = new FloatExternalizer(frame);
    FloatExternalizer externalizer2 = new FloatExternalizer(frame);
    externalizer2.setHidden(true);

    // The UI.
    JTabbedPane tabbedPane = new JTabbedPane();
    this.add(tabbedPane, BorderLayout.CENTER);

    // Try to decode the dock model from file.
    DockModelPropertiesDecoder dockModelDecoder = new DockModelPropertiesDecoder();
    if (dockModelDecoder.canDecodeSource(SOURCE)) {
      try {
        // Create the map with the dockables, that the decoder needs.
        Map dockablesMap = new HashMap();
        for (int index = 0; index < dockables.length; index++) {
          dockablesMap.put(dockables[index].getID(), dockables[index]);
        }
        for (int index = 0; index < buttonDockables.length; index++) {
          dockablesMap.put(buttonDockables[index].getID(), buttonDockables[index]);
        }

        // Create the map with the owner windows, that the decoder needs.
        Map ownersMap = new HashMap();
        ownersMap.put(frameId, frame);

        // Create the map with the visualizers, that the decoder needs.
        Map visualizersMap = new HashMap();
        visualizersMap.put("maximizer1", maximizer1);
        visualizersMap.put("maximizer2", maximizer2);
        visualizersMap.put("minimizer1", minimizer1);
        visualizersMap.put("minimizer2", minimizer2);
        visualizersMap.put("externalizer1", externalizer1);
        visualizersMap.put("externalizer2", externalizer2);

        // Decode the file.
        dockModel =
            (DockModel) dockModelDecoder.decode(SOURCE, dockablesMap, ownersMap, visualizersMap);
      } catch (FileNotFoundException fileNotFoundException) {
        System.out.println("Could not find the file [" + SOURCE + "] with the saved dock model.");
        System.out.println("Continuing with the default dock model.");
      } catch (IOException ioException) {
        System.out.println("Could not decode a dock model: [" + ioException + "].");
        ioException.printStackTrace();
        System.out.println("Continuing with the default dock model.");
      }
    }

    // These are the root docks of the dock model.
    SplitDock splitDock1 = null;
    SplitDock splitDock2 = null;
    BorderDock toolBarBorderDock1 = null;
    BorderDock toolBarBorderDock2 = null;
    HidableFloatDock float1 = null;
    HidableFloatDock float2 = null;

    // Could we decode a dock model?
    if (dockModel == null) {
      // Create the dock model and dock model group.
      dockModel = new DefaultDockModel(SOURCE);
      dockModel.addOwner("frame", frame);

      // Give the dock model to the docking manager.
      DockingManager.setDockModel(dockModel);

      // Add visualizers.
      dockModel.addVisualizer("minimizer1", minimizer1, frame);
      dockModel.addVisualizer("minimizer2", minimizer2, frame);
      dockModel.addVisualizer("maximizer1", maximizer1, frame);
      dockModel.addVisualizer("maximizer2", maximizer2, frame);
      dockModel.addVisualizer("externalizer1", externalizer1, frame);
      dockModel.addVisualizer("externalizer2", externalizer2, frame);

      // Create the float docks.
      float1 = new HidableFloatDock(frame);
      float2 = new HidableFloatDock(frame);
      float2.setHidden(true);

      // Create the child tab docks.
      TabDock leftTabDock1 = new TabDock();
      TabDock rightTabDock1 = new TabDock();
      TabDock leftTabDock2 = new TabDock();
      TabDock rightTabDock2 = new TabDock();

      // Add the dockables to these tab docks.
      leftTabDock1.addDockable(dockables[0], new Position(0));
      leftTabDock1.addDockable(dockables[1], new Point(), new Point());
      rightTabDock1.addDockable(dockables[2], new Point(), new Point());
      rightTabDock1.addDockable(dockables[3], new Point(), new Point());
      leftTabDock2.addDockable(dockables[7], new Point(), new Point());
      leftTabDock2.addDockable(dockables[8], new Point(), new Point());
      rightTabDock2.addDockable(dockables[9], new Point(), new Point());
      rightTabDock2.addDockable(dockables[10], new Point(), new Point());

      // Create the split docks.
      splitDock1 = new SplitDock();
      splitDock2 = new SplitDock();

      // Add the child docks to the split dock at the left and right.
      splitDock1.addChildDock(leftTabDock1, new Position(Position.LEFT));
      splitDock1.addChildDock(rightTabDock1, new Position(Position.RIGHT));
      splitDock1.setDividerLocation(FRAME_WIDTH / 2);
      splitDock2.addChildDock(leftTabDock2, new Position(Position.LEFT));
      splitDock2.addChildDock(rightTabDock2, new Position(Position.RIGHT));
      splitDock2.setDividerLocation(FRAME_WIDTH / 2);

      // Create the border dock for the buttons.
      toolBarBorderDock1 = new BorderDock(new CompositeToolBarDockFactory());
      toolBarBorderDock2 = new BorderDock(new CompositeToolBarDockFactory());
      toolBarBorderDock1.setMode(BorderDock.MODE_TOOL_BAR);
      toolBarBorderDock2.setMode(BorderDock.MODE_TOOL_BAR);
      CompositeLineDock compositeToolBarDock1 =
          new CompositeLineDock(
              CompositeLineDock.ORIENTATION_HORIZONTAL,
              false,
              new ToolBarDockFactory(),
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      CompositeLineDock compositeToolBarDock2 =
          new CompositeLineDock(
              CompositeLineDock.ORIENTATION_VERTICAL,
              false,
              new ToolBarDockFactory(),
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      CompositeLineDock compositeToolBarDock3 =
          new CompositeLineDock(
              CompositeLineDock.ORIENTATION_HORIZONTAL,
              false,
              new ToolBarDockFactory(),
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      CompositeLineDock compositeToolBarDock4 =
          new CompositeLineDock(
              CompositeLineDock.ORIENTATION_VERTICAL,
              false,
              new ToolBarDockFactory(),
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      toolBarBorderDock1.setDock(compositeToolBarDock1, Position.TOP);
      toolBarBorderDock1.setDock(compositeToolBarDock2, Position.LEFT);
      toolBarBorderDock2.setDock(compositeToolBarDock3, Position.TOP);
      toolBarBorderDock2.setDock(compositeToolBarDock4, Position.LEFT);

      // The line docks for the buttons.
      LineDock toolBarDock1 =
          new LineDock(
              LineDock.ORIENTATION_HORIZONTAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock2 =
          new LineDock(
              LineDock.ORIENTATION_HORIZONTAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock3 =
          new LineDock(
              LineDock.ORIENTATION_HORIZONTAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock4 =
          new LineDock(
              LineDock.ORIENTATION_HORIZONTAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock5 =
          new LineDock(
              LineDock.ORIENTATION_VERTICAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock6 =
          new LineDock(
              LineDock.ORIENTATION_VERTICAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock7 =
          new LineDock(
              LineDock.ORIENTATION_VERTICAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);

      LineDock toolBarDock8 =
          new LineDock(
              LineDock.ORIENTATION_HORIZONTAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock9 =
          new LineDock(
              LineDock.ORIENTATION_HORIZONTAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock10 =
          new LineDock(
              LineDock.ORIENTATION_HORIZONTAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock11 =
          new LineDock(
              LineDock.ORIENTATION_VERTICAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);
      LineDock toolBarDock12 =
          new LineDock(
              LineDock.ORIENTATION_VERTICAL,
              false,
              DockingMode.HORIZONTAL_TOOLBAR,
              DockingMode.VERTICAL_TOOLBAR);

      GridDock toolGridDock1 = new GridDock(DockingMode.TOOL_GRID);
      GridDock toolGridDock2 = new GridDock(DockingMode.TOOL_GRID);

      // Add the dockables to the line docks and the grid dock.
      toolBarDock1.addDockable(buttonDockables[0], new Position(0));
      toolBarDock1.addDockable(buttonDockables[1], new Position(1));
      toolBarDock1.addDockable(buttonDockables[2], new Position(2));
      toolBarDock1.addDockable(buttonDockables[3], new Position(3));

      toolBarDock2.addDockable(buttonDockables[4], new Position(4));
      toolBarDock2.addDockable(buttonDockables[5], new Position(5));
      toolBarDock2.addDockable(buttonDockables[6], new Position(6));

      toolBarDock3.addDockable(buttonDockables[7], new Position(0));
      toolBarDock3.addDockable(buttonDockables[8], new Position(1));
      toolBarDock3.addDockable(buttonDockables[9], new Position(2));

      toolBarDock4.addDockable(buttonDockables[10], new Position(0));
      toolBarDock4.addDockable(buttonDockables[11], new Position(1));
      toolBarDock4.addDockable(buttonDockables[12], new Position(2));

      toolBarDock5.addDockable(buttonDockables[13], new Position(0));
      toolBarDock5.addDockable(buttonDockables[14], new Position(1));
      toolBarDock5.addDockable(buttonDockables[15], new Position(2));
      toolBarDock6.addDockable(buttonDockables[16], new Position(3));
      toolBarDock6.addDockable(buttonDockables[17], new Position(4));

      toolBarDock7.addDockable(buttonDockables[18], new Position(0));
      toolBarDock7.addDockable(buttonDockables[19], new Position(1));

      toolGridDock1.addDockable(buttonDockables[20], new Position(0));
      toolGridDock1.addDockable(buttonDockables[21], new Position(1));
      toolGridDock1.addDockable(buttonDockables[22], new Position(2));
      toolGridDock1.addDockable(buttonDockables[23], new Position(3));
      toolGridDock1.addDockable(buttonDockables[24], new Position(4));
      toolGridDock2.addDockable(buttonDockables[25], new Position(5));
      toolGridDock2.addDockable(buttonDockables[26], new Position(6));
      toolGridDock2.addDockable(buttonDockables[27], new Position(7));
      toolGridDock2.addDockable(buttonDockables[28], new Position(8));

      toolBarDock8.addDockable(buttonDockables[29], new Position(0));
      toolBarDock8.addDockable(buttonDockables[30], new Position(1));
      toolBarDock8.addDockable(buttonDockables[31], new Position(2));

      toolBarDock9.addDockable(buttonDockables[32], new Position(3));
      toolBarDock9.addDockable(buttonDockables[33], new Position(4));
      toolBarDock10.addDockable(buttonDockables[34], new Position(5));
      toolBarDock10.addDockable(buttonDockables[35], new Position(6));
      toolBarDock10.addDockable(buttonDockables[36], new Position(6));

      toolBarDock11.addDockable(buttonDockables[37], new Position(0));
      toolBarDock11.addDockable(buttonDockables[38], new Position(1));
      toolBarDock12.addDockable(buttonDockables[39], new Position(2));
      toolBarDock12.addDockable(buttonDockables[40], new Position(3));
      toolBarDock12.addDockable(buttonDockables[41], new Position(4));

      // Add the line docks and grid to their composite parents.
      compositeToolBarDock1.addChildDock(toolBarDock1, new Position(0));
      compositeToolBarDock1.addChildDock(toolBarDock2, new Position(1));
      compositeToolBarDock1.addChildDock(toolBarDock3, new Position(2));
      compositeToolBarDock1.addChildDock(toolBarDock4, new Position(3));
      compositeToolBarDock2.addChildDock(toolBarDock5, new Position(0));
      compositeToolBarDock2.addChildDock(toolBarDock6, new Position(1));
      compositeToolBarDock2.addChildDock(toolBarDock7, new Position(2));

      compositeToolBarDock3.addChildDock(toolBarDock8, new Position(0));
      compositeToolBarDock3.addChildDock(toolBarDock9, new Position(1));
      compositeToolBarDock3.addChildDock(toolBarDock10, new Position(2));
      compositeToolBarDock4.addChildDock(toolBarDock11, new Position(0));
      compositeToolBarDock4.addChildDock(toolBarDock12, new Position(1));

      float1.addChildDock(toolGridDock1, new Position(400, 300));
      float2.addChildDock(toolGridDock2, new Position(450, 350));

      // Minimize dockables.
      minimizer1.visualizeDockable(dockables[4]);
      minimizer1.visualizeDockable(dockables[5]);
      minimizer2.visualizeDockable(dockables[11]);
      minimizer2.visualizeDockable(dockables[12]);

      // Externalize dockable.
      // externalizer.visualizeDockable(dockable13);
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Point location = new Point((screenSize.width - 200) / 2, (screenSize.height - 200) / 2);
      externalizer1.externalizeDockable(dockables[6], location);
      externalizer2.externalizeDockable(dockables[13], location);

      // Add the root docks to the dock model.
      dockModel.addRootDock("dock1", splitDock1, frame);
      dockModel.addRootDock("dock2", splitDock2, frame);
      dockModel.addRootDock("toolBarBorderDock1", toolBarBorderDock1, frame);
      dockModel.addRootDock("toolBarBorderDock2", toolBarBorderDock2, frame);
      dockModel.addRootDock("float1", float1, frame);
      dockModel.addRootDock("float2", float2, frame);

      // Add docking paths.
      addDockingPath(dockables[0]);
      addDockingPath(dockables[1]);
      addDockingPath(dockables[2]);
      addDockingPath(dockables[3]);
      addDockingPath(dockables[4]);
      addDockingPath(dockables[5]);
      addDockingPath(dockables[7]);
      addDockingPath(dockables[8]);
      addDockingPath(dockables[9]);
      addDockingPath(dockables[10]);
      addDockingPath(dockables[11]);
      addDockingPath(dockables[12]);

      DockingPath dockingPathToCopy1 =
          DockingManager.getDockingPathModel().getDockingPath(dockables[0].getID());
      DockingPath dockingPathToCopy2 =
          DockingManager.getDockingPathModel().getDockingPath(dockables[9].getID());
      DockingPath dockingPath1 =
          DefaultDockingPath.copyDockingPath(dockables[6], dockingPathToCopy1);
      DockingPath dockingPath2 =
          DefaultDockingPath.copyDockingPath(dockables[13], dockingPathToCopy2);
      DockingManager.getDockingPathModel().add(dockingPath1);
      DockingManager.getDockingPathModel().add(dockingPath2);

    } else {

      // Get the root dock from the dock model.
      splitDock1 = (SplitDock) dockModel.getRootDock("dock1");
      splitDock2 = (SplitDock) dockModel.getRootDock("dock2");
      toolBarBorderDock1 = (BorderDock) dockModel.getRootDock("toolBarBorderDock1");
      toolBarBorderDock2 = (BorderDock) dockModel.getRootDock("toolBarBorderDock2");
      float1 = (HidableFloatDock) dockModel.getRootDock("float1");
      float2 = (HidableFloatDock) dockModel.getRootDock("float2");
    }

    // Listen when the frame is closed. The workspace should be saved.
    frame.addWindowListener(new WorkspaceSaver());

    // General code.
    tabbedPane.addTab("Workspace 1", toolBarBorderDock1);
    tabbedPane.addTab("Workspace 2", toolBarBorderDock2);

    toolBarBorderDock1.setCenterComponent(maximizer1);
    toolBarBorderDock2.setCenterComponent(maximizer2);

    minimizer1.setContent(splitDock1);
    minimizer2.setContent(splitDock2);

    // Listen to the selections of the tabs.
    SingleSelectionModel selectionModel = tabbedPane.getModel();
    selectionModel.addChangeListener(
        new TabChangelistener(tabbedPane, float1, float2, externalizer1, externalizer2));
  }