gt:         if (viewport_position != null)
context: /*
   *  Copyright (C) 2014  Alfons Wirtz  
   *   website www.freerouting.net
   *
   *   This program is free software: you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation, either version 3 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License at <http://www.gnu.org/licenses/> 
   *   for more details.
   */
  
  package gui;
  
  import interactive.ScreenMessages;
  
  import java.io.File;
  
  import datastructures.FileFilter;
  import datastructures.IdNoGenerator;
  
  import board.TestLevel;
  import board.BoardObservers;
  
  import designformats.specctra.DsnFile;
  
  /**
   *
   * Graphical frame of for interactive editing of a routing board.
   *
   * @author  Alfons Wirtz
   */
  
  public class BoardFrame extends javax.swing.JFrame
  {
      public enum Option
      {
          FROM_START_MENU, SINGLE_FRAME, SESSION_FILE, WEBSTART, EXTENDED_TOOL_BAR
      }
      
      /**
       * Creates a new board frame with the input design file imbedded into a host cad software.
       */
      public static BoardFrame get_embedded_instance(String p_design_file_path_name,
              BoardObservers p_observers, IdNoGenerator p_id_no_generator, java.util.Locale p_locale)
      {
          final gui.DesignFile design_file = gui.DesignFile.get_instance(p_design_file_path_name, false);
          if (design_file == null)
          {
              WindowMessage.show("designfile not found");
              return null;
          }
          gui.BoardFrame board_frame = new gui.BoardFrame(design_file, gui.BoardFrame.Option.SINGLE_FRAME,
                  TestLevel.RELEASE_VERSION, p_observers, p_id_no_generator, p_locale, false);
          
          
          if (board_frame == null)
          {
              WindowMessage.show("board_frame is null");
              return null;
          }
          java.io.InputStream input_stream = design_file.get_input_stream();
          boolean read_ok =  board_frame.read(input_stream, true, null);
          if (!read_ok)
          {
              String error_message = "Unable to read design file with pathname " + p_design_file_path_name;
              board_frame.setVisible(true); // to be able to display the status message
              board_frame.screen_messages.set_status_message(error_message);
          }
          return board_frame;
      }
      
      /**
       * Creates new form BoardFrame.
       * If p_option = FROM_START_MENU this frame is created from a start menu frame.
       * If p_option = SINGLE_FRAME, this frame is created directly a single frame.
       * If p_option = Option.IN_SAND_BOX, no security sensitive actions like for example choosing
       *  If p_option = Option.WEBSTART, the application has  been started with Java Webstart.
       * files are allowed, so that the frame can be used in an applet.
       * Currently Option.EXTENDED_TOOL_BAR is used only if a new board is
       * created by the application from scratch.
       * If p_test_level > RELEASE_VERSION, functionality not yet ready for release is included.
       * Also the warning output depends on p_test_level.
       */
      public BoardFrame(DesignFile p_design, Option p_option, TestLevel p_test_level,
              java.util.Locale p_locale, boolean p_confirm_cancel)
      {
          this(p_design, p_option, p_test_level,
                  new board.BoardObserverAdaptor(), new board.ItemIdNoGenerator(),
                  p_locale, p_confirm_cancel);
      }
      
      /**
       * Creates new form BoardFrame.
       * The parameters p_item_observers and p_item_id_no_generator are used for syncronizing purposes,
       * if the frame is embedded into a host system,
       */
      BoardFrame(DesignFile p_design, Option p_option, TestLevel p_test_level, BoardObservers p_observers,
              datastructures.IdNoGenerator p_item_id_no_generator, java.util.Locale p_locale, boolean p_confirm_cancel)
      {
          this.design_file = p_design;
          this.is_web_start = (p_option == Option.WEBSTART);
          this.test_level = p_test_level;
          
          this.confirm_cancel = p_confirm_cancel;
          this.board_observers = p_observers;
          this.item_id_no_generator = p_item_id_no_generator;
          this.locale = p_locale;
          this.resources = java.util.ResourceBundle.getBundle("gui.resources.BoardFrame", p_locale);
          BoardMenuBar curr_menubar;
          boolean session_file_option = (p_option == Option.SESSION_FILE);
          boolean curr_help_system_used =  true;
          try
          {
              curr_menubar = BoardMenuBar.get_instance(this, curr_help_system_used, session_file_option);
          }
          catch (java.lang.NoClassDefFoundError e)
          {
              // the system-file jh.jar may be missing
              curr_help_system_used = false;
              curr_menubar = BoardMenuBar.get_instance(this, false, session_file_option);
              System.out.println("Online-Help deactivated because system file jh.jar is missing");
          }
          this.menubar = curr_menubar;
          this.help_system_used = curr_help_system_used;
          setJMenuBar(this.menubar);
          
          this.toolbar_panel = new BoardToolbar(this);
          this.add(this.toolbar_panel, java.awt.BorderLayout.NORTH);
          
          this.message_panel = new BoardPanelStatus(this.locale);
          this.add(this.message_panel, java.awt.BorderLayout.SOUTH);
          
          this.select_toolbar = new BoardToolbarSelectedItem(this, p_option == Option.EXTENDED_TOOL_BAR);
          
          this.screen_messages =
                  new ScreenMessages(this.message_panel.status_message, this.message_panel.add_message,
                  this.message_panel.current_layer, this.message_panel.mouse_position, this.locale);
          
          this.scroll_pane = new javax.swing.JScrollPane();
          this.scroll_pane.setPreferredSize(new java.awt.Dimension(1150, 800));
          this.scroll_pane.setVerifyInputWhenFocusTarget(false);
          this.add(scroll_pane, java.awt.BorderLayout.CENTER);
          
          this.board_panel = new BoardPanel(screen_messages, this, this.is_web_start, p_locale);
          this.scroll_pane.setViewportView(board_panel);
          
          this.setTitle(resources.getString("title"));
          this.addWindowListener(new WindowStateListener());
          
          this.pack();
      }
      
      /**
       * Reads interactive actions from a logfile.
       */
      void read_logfile(java.io.InputStream p_input_stream)
      {
          board_panel.board_handling.read_logfile(p_input_stream);
      }
      
      
      /**
       * Reads an existing board design from file.
       * If p_is_import, the design is read from a scpecctra dsn file.
       * Returns false, if the file is invalid.
       */
      boolean read(java.io.InputStream p_input_stream, boolean p_is_import, javax.swing.JTextField p_message_field)
      {
          java.awt.Point viewport_position = null;
          if (p_is_import)
          {
              DsnFile.ReadResult read_result = board_panel.board_handling.import_design(p_input_stream, this.board_observers,
                      this.item_id_no_generator, this.test_level);
              if (read_result !=  DsnFile.ReadResult.OK)
              {
                  if (p_message_field != null)
                  {
                      if (read_result == DsnFile.ReadResult.OUTLINE_MISSING)
                      {
                          p_message_field.setText(resources.getString("error_7"));
                      }
                      else
                      {
                           p_message_field.setText(resources.getString("error_6"));
                      }
                  }
                  return false;
              }
              viewport_position = new java.awt.Point(0,0);
              initialize_windows();
          }
          else
          {
              java.io.ObjectInputStream object_stream = null;
              try
              {
                  object_stream = new java.io.ObjectInputStream(p_input_stream);
              }
              catch (java.io.IOException e)
              {
                  return false;
              }
              boolean read_ok = board_panel.board_handling.read_design(object_stream, this.test_level);
              if (!read_ok)
              {
                  return false;
              }
              java.awt.Point frame_location;
              java.awt.Rectangle frame_bounds;
              try
              {
                  viewport_position = (java.awt.Point) object_stream.readObject();
                  frame_location = (java.awt.Point) object_stream.readObject();
                  frame_bounds = (java.awt.Rectangle) object_stream.readObject();
              }
              catch (Exception e)
              {
                  return false;
              }
              this.setLocation(frame_location);
              this.setBounds(frame_bounds);
              
              allocate_permanent_subwindows();
              
              for (int i = 0; i < this.permanent_subwindows.length; ++i)
              {
                  this.permanent_subwindows[i].read(object_stream);
              }
          }
          try
          {
              p_input_stream.close();
          }
          catch (java.io.IOException e)
          {
              return false;
          }
          
          java.awt.Dimension panel_size = board_panel.board_handling.graphics_context.get_panel_size();
          board_panel.setSize(panel_size);
          board_panel.setPreferredSize(panel_size);
  