001: package org.jvnet.substance.netbeans;
002:
003: import javax.swing.JComponent;
004: import javax.swing.JDialog;
005: import javax.swing.JFrame;
006: import javax.swing.JRootPane;
007: import javax.swing.LookAndFeel;
008: import javax.swing.RepaintManager;
009: import javax.swing.SwingUtilities;
010: import javax.swing.UIManager;
011: import javax.swing.UnsupportedLookAndFeelException;
012: import org.jvnet.lafwidget.animation.FadeConfigurationManager;
013: import org.jvnet.substance.SubstanceLookAndFeel;
014: import org.jvnet.substance.netbeans.ui.ButtonShapeSelector;
015: import org.jvnet.substance.netbeans.ui.ColorSelector;
016: import org.jvnet.substance.netbeans.ui.SkinSelector;
017: import org.jvnet.substance.netbeans.ui.ThemeSelector;
018: import org.jvnet.substance.netbeans.ui.WatermarkSelector;
019: import org.jvnet.substance.utils.MemoryAnalyzer;
020: import org.jvnet.substance.utils.params.ParamReader;
021: import org.netbeans.swing.plaf.LFCustoms;
022: import org.netbeans.swing.plaf.Startup;
023: import org.openide.ErrorManager;
024: import org.openide.modules.ModuleInstall;
025: import org.openide.windows.WindowManager;
026:
027: /**
028: * Runs on NetBeans startup to set the look and feel.
029: *
030: * @author Timothy Boudreau
031: * @author Kirill Grouchnikov
032: */
033: public class SubstanceModule extends ModuleInstall {
034:
035: public void restored() {
036: try {
037: SubstanceLookAndFeel slf = new SubstanceLookAndFeel();
038: UIManager.setLookAndFeel(slf);
039: new NetbeansPlugin().initialize();
040:
041: // check if need to restore parameters or prefer VM / file /
042: // other Substance command parameters
043: SkinSelector.restore();
044: ParamReader paramReader = slf.getParamReader();
045: if (paramReader.getButtonShaperProperty() == null) {
046: ButtonShapeSelector.restore();
047: }
048: if (paramReader.getThemeProperty() == null) {
049: ThemeSelector.restore();
050: }
051: WatermarkSelector.restore(paramReader
052: .getWatermarkProperty(), paramReader
053: .getWatermarkImageProperty());
054: if (paramReader.getGradientPainterProperty() == null) {
055: ColorSelector.restore();
056: }
057: ButtonShapeSelector.updateUIs();
058:
059: FadeConfigurationManager
060: .getInstance()
061: .allowFades(
062: SubstanceLookAndFeel.TREE_DECORATIONS_ANIMATION_KIND);
063: FadeConfigurationManager
064: .getInstance()
065: .allowFades(
066: SubstanceLookAndFeel.TREE_SMART_SCROLL_ANIMATION_KIND);
067: updateLookAndFeel();
068:
069: // RepaintManager.setCurrentManager(new RepaintManager() {
070: //
071: // @Override
072: // public void addDirtyRegion(JComponent c, int x, int y, int w,
073: // int h) {
074: // super.addDirtyRegion(c, x, y, w, h);
075: // try {
076: // throw new Exception();
077: // } catch (Exception exc) {
078: // StringBuffer sb = new StringBuffer();
079: // StackTraceElement[] stack = exc.getStackTrace();
080: // int count = 0;
081: // for (StackTraceElement stackEntry : stack) {
082: // if (count++ > 20) {
083: // break;
084: // }
085: // sb.append(stackEntry.getClassName() + ".");
086: // sb.append(stackEntry.getMethodName() + " [");
087: // sb.append(stackEntry.getLineNumber() + "]");
088: // sb.append("\n");
089: // }
090: // MemoryAnalyzer.enqueueUsage("Repaint request came from\n" +
091: // sb.toString());
092: // }
093: // MemoryAnalyzer.enqueueUsage("Repainting " +
094: // c.getClass().getName() + " at " + x + ":" + y + ":" +
095: // w + ":" + h);
096: // }
097: // });
098: } catch (UnsupportedLookAndFeelException ulafe) {
099: ErrorManager.getDefault().notify(ulafe);
100: throw new RuntimeException(ulafe);
101: }
102: }
103:
104: private static void updateLookAndFeel() {
105: if (!SwingUtilities.isEventDispatchThread()) {
106: try {
107: SwingUtilities.invokeAndWait(new Runnable() {
108:
109: public void run() {
110: updateLookAndFeel();
111: }
112: });
113: } catch (Exception ex) {
114: /**
115: * includes InvocationTargetException and InterruptedException
116: */
117: ErrorManager.getDefault().notify(ex);
118: }
119: return;
120: }
121:
122: try {
123: LookAndFeel laf = UIManager.getLookAndFeel();
124: if (laf.getSupportsWindowDecorations()) {
125: ErrorManager.getDefault().log(ErrorManager.WARNING,
126: "Look and Feel supports window decorations!");
127: JFrame.setDefaultLookAndFeelDecorated(true);
128: JDialog.setDefaultLookAndFeelDecorated(true);
129: // set main IDE window to be decorated, too
130: JFrame frame = (JFrame) WindowManager.getDefault()
131: .getMainWindow();
132: boolean needToDispose = frame.isDisplayable();
133: boolean isVisible = frame.isVisible();
134: if (needToDispose) {
135: frame.dispose();
136: }
137: frame.setUndecorated(true);
138: frame.getRootPane().setWindowDecorationStyle(
139: JRootPane.FRAME);
140: frame.getRootPane().updateUI();
141: if (needToDispose) {
142: frame.pack();
143: frame.setVisible(isVisible);
144: }
145: } else {
146: JFrame.setDefaultLookAndFeelDecorated(false);
147: JDialog.setDefaultLookAndFeelDecorated(false);
148: }
149: } catch (Exception ex) {
150: ErrorManager.getDefault().notify(ex);
151: }
152: }
153: }
|