public final void readExternal(final Element element) {
    final Element frameElement = element.getChild(FRAME_ELEMENT);
    if (frameElement != null) {
      myFrameBounds = loadFrameBounds(frameElement);
      try {
        myFrameExtendedState =
            Integer.parseInt(frameElement.getAttributeValue(EXTENDED_STATE_ATTR));
        if ((myFrameExtendedState & Frame.ICONIFIED) > 0) {
          myFrameExtendedState = Frame.NORMAL;
        }
      } catch (NumberFormatException ignored) {
        myFrameExtendedState = Frame.NORMAL;
      }
    }

    final Element desktopElement = element.getChild(DesktopLayout.TAG);
    if (desktopElement != null) {
      myLayout.readExternal(desktopElement);
    }
  }
  public final void writeExternal(final Element element) {
    // Save frame bounds
    final Element frameElement = new Element(FRAME_ELEMENT);
    element.addContent(frameElement);
    final Project[] projects = ProjectManager.getInstance().getOpenProjects();
    final Project project;
    if (projects.length > 0) {
      project = projects[projects.length - 1];
    } else {
      project = null;
    }

    final IdeFrameImpl frame = getFrame(project);
    if (frame != null) {
      int extendedState = frame.getExtendedState();
      if (SystemInfo.isMacOSLion && frame.getPeer() instanceof FramePeer) {
        // frame.state is not updated by jdk so get it directly from peer
        extendedState = ((FramePeer) frame.getPeer()).getState();
      }
      boolean usePreviousBounds =
          extendedState == Frame.MAXIMIZED_BOTH
              || isFullScreenSupportedInCurrentOS()
                  && WindowManagerEx.getInstanceEx().isFullScreen(frame);
      Rectangle rectangle = usePreviousBounds ? myFrameBounds : frame.getBounds();
      if (rectangle == null) { // frame is out of the screen?
        rectangle = ScreenUtil.getScreenRectangle(0, 0);
      }
      frameElement.setAttribute(X_ATTR, Integer.toString(rectangle.x));
      frameElement.setAttribute(Y_ATTR, Integer.toString(rectangle.y));
      frameElement.setAttribute(WIDTH_ATTR, Integer.toString(rectangle.width));
      frameElement.setAttribute(HEIGHT_ATTR, Integer.toString(rectangle.height));
      frameElement.setAttribute(EXTENDED_STATE_ATTR, Integer.toString(extendedState));

      // Save default layout
      final Element layoutElement = new Element(DesktopLayout.TAG);
      element.addContent(layoutElement);
      myLayout.writeExternal(layoutElement);
    }
  }
 public final void setLayout(final DesktopLayout layout) {
   myLayout.copyFrom(layout);
 }