/* * @(#)JideDemos.java 2/14/2005 * * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved. */ import com.jidesoft.action.DefaultDockableBarDockableHolder; import com.jidesoft.docking.DefaultDockingManager; import com.jidesoft.docking.DockContext; import com.jidesoft.docking.DockableFrame; import com.jidesoft.document.*; import com.jidesoft.icons.JideIconsFactory; import com.jidesoft.pane.CollapsiblePane; import com.jidesoft.pane.CollapsiblePanes; import com.jidesoft.plaf.JideTabbedPaneUI; import com.jidesoft.plaf.LookAndFeelFactory; import com.jidesoft.plaf.office2003.BasicOffice2003Theme; import com.jidesoft.plaf.office2003.Office2003Painter; import com.jidesoft.status.MemoryStatusBarItem; import com.jidesoft.status.ProgressStatusBarItem; import com.jidesoft.status.ResizeStatusBarItem; import com.jidesoft.status.StatusBar; import com.jidesoft.swing.JideBoxLayout; import com.jidesoft.swing.JideSwingUtilities; import com.jidesoft.swing.JideTabbedPane; import com.jidesoft.swing.MultilineLabel; import com.jidesoft.utils.Lm; import com.jidesoft.utils.SystemInfo; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JideDemos extends DefaultDockableBarDockableHolder { private static JideDemos _frame; private static IDocumentPane _documentPane; private static StatusBar _statusBar; private static final String PROFILE_NAME = "jidesoft-demoes"; private static boolean _autohideAll = false; private static String _fullScreenLayout; public static final String DEMOS_DOCKABLEFRAME_KEY = "Demos"; public static final String OPTIONS_DOCKABLEFRAME_KEY = "Options"; public static WindowAdapter _windowListener; public JideDemos(String title) throws HeadlessException { super(title); } public JideDemos() throws HeadlessException { this(""); } public static void main(String[] args) { // JFrame.setDefaultLookAndFeelDecorated(true); if (!SystemInfo.isJdk14Above()) { Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog(null, "JDK 1.4 or above is required for this demo.", "JIDE Software, Inc.", JOptionPane.WARNING_MESSAGE); System.exit(0); } if (!SystemInfo.isJdk142Above()) { Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog(null, "JDK 1.4.2 or above is recommended for this demo for the best experience of seamless integration with Windows XP.", "JIDE Software, Inc.", JOptionPane.WARNING_MESSAGE); } if (SystemInfo.isMacOSX()) { // set special properties for Mac OS X System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("apple.awt.brushMetalLook", "true"); } // add an example custom theme BasicOffice2003Theme theme = new BasicOffice2003Theme("Custom"); theme.setBaseColor(new Color(50, 190, 150), true, "default"); ((Office2003Painter) Office2003Painter.getInstance()).addTheme(theme); LookAndFeelFactory.installDefaultLookAndFeelAndExtension(); _frame = new JideDemos("Demo of JIDE Products"); _frame.setIconImage(JideIconsFactory.getImageIcon(JideIconsFactory.JIDE32).getImage()); Lm.setParent(_frame); // add a widnow listener so that timer can be stopped when exit _windowListener = new WindowAdapter() { public void windowClosing(WindowEvent e) { super.windowClosing(e); clearUp(); System.exit(0); } }; _frame.addWindowListener(_windowListener); // set the profile key _frame.getLayoutPersistence().setProfileKey(PROFILE_NAME); // comment this if you don't want to use javax pref // _frame.getLayoutPersistence().setUsePref(false); // draw full outline when outside main JFrame _frame.getDockingManager().setOutlineMode(0); _frame.getDockingManager().setAllowedDockSides(DockContext.DOCK_SIDE_VERTICAL); // uncomment following to adjust the sliding speed of autohide frame // _frame.getDockingManager().setInitDelay(100); // _frame.getDockingManager().setSteps(1); // _frame.getDockingManager().setStepDelay(0); // create tabbed-document interface and add it to workspace area _documentPane = createDocumentTabs(); _frame.getDockingManager().getWorkspace().setLayout(new BorderLayout()); _frame.getDockingManager().getWorkspace().add((Component) _documentPane, BorderLayout.CENTER); _frame.getDockableBarManager().setProfileKey(PROFILE_NAME); // add toolbar _frame.getDockableBarManager().addDockableBar(DemosCommandBarFactory.createMenuCommandBar(_frame)); _frame.getDockableBarManager().addDockableBar(DemosCommandBarFactory.createLookAndFeelCommandBar(_frame)); // add status bar _statusBar = createStatusBar(); _frame.getContentPane().add(_statusBar, BorderLayout.AFTER_LAST_LINE); _frame.getDockingManager().setUndoLimit(10); _frame.getDockingManager().setAutohideShowingContentHidden(false); _frame.getDockingManager().beginLoadLayoutData(); // _frame.getDockingManager().setFloatable(false); _frame.getDockingManager().setInitSplitPriority(DefaultDockingManager.SPLIT_SOUTH_NORTH_EAST_WEST); // add all dockable frames _frame.getDockingManager().addFrame(new DemosDockableFrame(DEMOS_DOCKABLEFRAME_KEY)); DockableFrame optionsFrame = new DockableFrame(OPTIONS_DOCKABLEFRAME_KEY, DemoIconsFactory.getImageIcon(DemoIconsFactory.Frame.OPTIONS)); optionsFrame.getContext().setInitMode(DockContext.STATE_HIDDEN); _frame.getDockingManager().addFrame(optionsFrame); _frame.getDockingManager().setDefaultFocusComponent((JComponent) _documentPane); // let dockablebar manager handles frame bounds and state. _frame.getDockingManager().setUseFrameBounds(false); _frame.getDockingManager().setUseFrameState(false); _frame.getLayoutPersistence().loadLayoutData(); _frame.getDockingManager().hideFrame(OPTIONS_DOCKABLEFRAME_KEY); _frame.getDockingManager().setShowGripper(true); _frame.toFront(); } private static void clearUp() { _frame.removeWindowListener(_windowListener); _windowListener = null; if (_frame.getLayoutPersistence() != null) { _frame.getLayoutPersistence().saveLayoutData(); } _documentPane = null; if (_statusBar != null && _statusBar.getParent() != null) _statusBar.getParent().remove(_statusBar); _statusBar = null; _frame.dispose(); Lm.setParent(null); _frame = null; } private static StatusBar createStatusBar() { // setup status bar StatusBar statusBar = new StatusBar(); final ProgressStatusBarItem progress = new ProgressStatusBarItem(); progress.setCancelCallback(new ProgressStatusBarItem.CancelCallback() { public void cancelPerformed() { progress.setStatus("Cancelled"); progress.showStatus(); } }); statusBar.add(progress, JideBoxLayout.VARY); final MemoryStatusBarItem gc = new MemoryStatusBarItem(); gc.setPreferredWidth(100); statusBar.add(gc, JideBoxLayout.FLEXIBLE); final ResizeStatusBarItem resize = new ResizeStatusBarItem(); statusBar.add(resize, JideBoxLayout.FLEXIBLE); return statusBar; } private static DocumentPane createDocumentTabs() { final DocumentPane pane = new DocumentPane() { // add function to maximize (autohideAll) the document pane when mouse double clicks on the tabs of DocumentPane. protected IDocumentGroup createDocumentGroup() { IDocumentGroup group = super.createDocumentGroup(); if (group instanceof JideTabbedPane) { ((JideTabbedPaneUI) ((JideTabbedPane) group).getUI()).getTabPanel().addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { if (!_autohideAll) { _fullScreenLayout = _frame.getDockingManager().getLayoutData(); _frame.getDockingManager().autohideAll(); _autohideAll = true; } else { // call next two methods so that the farme bounds and state will not change. _frame.getDockingManager().setUseFrameBounds(false); _frame.getDockingManager().setUseFrameState(false); if (_fullScreenLayout != null) { _frame.getDockingManager().setLayoutData(_fullScreenLayout); } _autohideAll = false; } } } }); } return group; } }; pane.registerKeyboardAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { pane.closeDocument(pane.getActiveDocumentName()); } }, KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.CTRL_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); pane.registerKeyboardAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { pane.nextDocument(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); pane.registerKeyboardAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { pane.prevDocument(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); pane.setTabPlacement(JTabbedPane.TOP); return pane; } private static CollapsiblePane createCollapsiblePane(String title) { return new CollapsiblePane(title); } public void openDemo(final Demo demo) { if (!_documentPane.isDocumentOpened(demo.getName())) { DocumentComponent documentComponent = new DemoDocumentComponent(demo); documentComponent.addDocumentComponentListener(new DocumentComponentAdapter() { public void documentComponentOpened(DocumentComponentEvent e) { } public void documentComponentClosing(DocumentComponentEvent e) { DockableFrame frame = getDockingManager().getFrame(OPTIONS_DOCKABLEFRAME_KEY); frame.getContentPane().removeAll(); getDockingManager().hideFrame(OPTIONS_DOCKABLEFRAME_KEY); } public void documentComponentClosed(DocumentComponentEvent e) { } public void documentComponentActivated(final DocumentComponentEvent e) { CollapsiblePanes panes = new CollapsiblePanes(); Component optionsPanel = demo.getOptionsPanel(); if (optionsPanel != null) { CollapsiblePane pane = createCollapsiblePane("Options"); pane.setEmphasized(true); if (optionsPanel instanceof JComponent) { JComponent optionPanel = (JComponent) optionsPanel; optionPanel.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10)); JideSwingUtilities.setOpaqueRecursively(optionPanel, false); pane.setContentPane(optionPanel); } panes.add(pane); } String description = demo.getDescription(); if (description != null && description.trim().length() > 0) { CollapsiblePane pane = createCollapsiblePane("Description"); MultilineLabel label = new MultilineLabel(description); label.setColumns(30); label.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10)); pane.setContentPane(label); panes.add(pane); } String[] source = demo.getDemoSource(); if (source != null && source.length > 0) { CollapsiblePane pane = createCollapsiblePane("Source Code"); JPanel panel = new JPanel(new BorderLayout(4, 4)); StringBuffer sourceFiles = new StringBuffer(); sourceFiles.append("Under examples/" + demo.getDemoFolder()); for (int i = 0; i < source.length; i++) { String s = source[i]; sourceFiles.append("\n - "); sourceFiles.append(s); } MultilineLabel label = new MultilineLabel(sourceFiles.toString()); label.setColumns(30); panel.add(label); panel.add(JideSwingUtilities.createLeftPanel(new JButton(new AbstractAction("Browse Source Code") { public void actionPerformed(ActionEvent ae) { ((DemoDocumentComponent) e.getDocumentComponent()).browseSourceCode(); } })), BorderLayout.AFTER_LAST_LINE); pane.setContentPane(panel); panel.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10)); JideSwingUtilities.setOpaqueRecursively(panel, false); panes.add(pane); } DockableFrame frame = getDockingManager().getFrame(OPTIONS_DOCKABLEFRAME_KEY); frame.getContentPane().removeAll(); if (panes.getComponentCount() >= 1) { panes.addExpansion(); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(new JScrollPane(panes), BorderLayout.CENTER); frame.setPreferredSize(new Dimension(300, 300)); frame.setTitle("Options - " + demo.getName()); if (frame.isHidden()) { getDockingManager().showFrame(OPTIONS_DOCKABLEFRAME_KEY); } } else { frame.setTitle("Options"); getDockingManager().hideFrame(OPTIONS_DOCKABLEFRAME_KEY); } } public void documentComponentDeactivated(DocumentComponentEvent e) { DockableFrame frame = getDockingManager().getFrame(OPTIONS_DOCKABLEFRAME_KEY); frame.setTitle("Options"); frame.getContentPane().removeAll(); } }); _documentPane.openDocument(documentComponent); } _documentPane.setActiveDocument(demo.getName()); } public static StatusBar getStatusBar() { return _statusBar; } }