示例#1
0
  public Object showWindow(final MkWindow macWindow, String title, boolean isModal) {
    listMkWindow.add(macWindow);
    if (isModal) {
      JDialog modalFrame = new JDialog(this, title, true);
      // macWindow.setJanela(modalFrame);
      final MkRun onCloseWindow = macWindow.onCloseWindow;
      modalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
      modalFrame.addWindowListener(
          new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
              if (onCloseWindow != null) {
                onCloseWindow.execute();
              }
              disposeWindow(macWindow);
            }
          });
      modalFrame.setLayout(new BorderLayout());
      modalFrame.add(macWindow, BorderLayout.CENTER);
      modalFrame.pack();
      Dimension desktopSize = desktopPane.getSize();
      int x = (desktopSize.width - modalFrame.getWidth()) / 2;
      int y = (desktopSize.height - modalFrame.getHeight()) / 2;
      modalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y));
      if (macWindow.panelButton != null) {
        modalFrame.getRootPane().setDefaultButton((JButton) macWindow.panelButton.getComponent(0));
      }
      modalFrame.setVisible(true);
      return modalFrame;
    } else {
      JInternalFrame internalFrame = new JInternalFrame(title, true, true, true, true);
      internalFrame.setContentPane(macWindow);
      internalFrame.pack();
      //            internalFrame.setBounds(internalFrame.getBounds()); //pq?
      desktopPane.add(internalFrame);

      internalFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      final MkRun onCloseWindow = macWindow.onCloseWindow;
      if (onCloseWindow != null) {
        internalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);

        internalFrame.addInternalFrameListener(
            new InternalFrameAdapter() {
              public void internalFrameClosing(InternalFrameEvent e) {
                onCloseWindow.execute();
              }
            });
      }

      Dimension desktopSize = desktopPane.getSize();
      int x = (desktopSize.width - internalFrame.getWidth()) / 2;
      int y = (desktopSize.height - internalFrame.getHeight()) / 2;
      internalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y));
      internalFrame.setVisible(true);
      return internalFrame;
    }
  }
 /** Returns a reasonable divider location for the log output. */
 private int getDivider() {
   int height;
   if (desktopPane.getSize().height == 0) {
     Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
     height = size.height;
   } else {
     height = desktopPane.getSize().height;
   }
   return (int) (height * .80);
 }
示例#3
0
 @Override
 public void actionPerformed(ActionEvent actionEvent) {
   Dimension all = parent.getSize();
   Dimension d = dialog.getSize();
   dialog.setLocation((all.width - d.width) / 2, (all.height - d.height) / 2);
   dialog.setVisible(true);
 }
示例#4
0
  /** Creates the GUI in a new thread. */
  @Override
  public void run() {
    setContentPane(jDesktopPane);

    // Show parent frame
    setVisible(true);

    // Create menubar
    setJMenuBar(createMenuBar());

    // Create toolsettings as an internal frame.
    toolSettings = new ActiveToolSettings();
    desktopSize = jDesktopPane.getSize();
    internalFrameSize = toolSettings.getSize();
    toolSettings.setLocation((screenSize.width - internalFrameSize.width) / 2, 0);
    jDesktopPane.add(toolSettings, JLayeredPane.PALETTE_LAYER);
    toolSettings.setVisible(true);

    // Create toolbox as an internal frame.
    toolbox = new Toolbox(toolSettings);
    toolbox.setLocation(0, 0);
    jDesktopPane.add(toolbox, JLayeredPane.PALETTE_LAYER);
    toolbox.setVisible(true);

    // Create panel with primary and secondary color
    activeColorSettings = new ActiveColorSettings(jDesktopPane);
    activeColorSettings.setLocation(82, 0);
    jDesktopPane.add(activeColorSettings, JLayeredPane.PALETTE_LAYER);
    activeColorSettings.setVisible(true);
  }
示例#5
0
  /** Default constructor, creates a new frame. */
  public MainWindow() {
    super("Fargestiften");

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setMinimumSize(new Dimension(640, 480));
    setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);

    jDesktopPane = new JDesktopPane();
    desktopSize = jDesktopPane.getSize();

    firstStartup = true;

    // Create welcome screen
    StartupDialog startupDialog = new StartupDialog(this);

    internalFrameSize = startupDialog.getSize();
    startupDialog.setLocation(
        (screenSize.width - internalFrameSize.width) / 2,
        (screenSize.height - internalFrameSize.height) / 3);

    startupDialog.setVisible(true);

    jDesktopPane.add(startupDialog, JLayeredPane.MODAL_LAYER);
    try {
      startupDialog.setSelected(true);
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }

    serialization = new StorageSerialization();
  }
示例#6
0
  /**
   * This method handels the creation of a new DrawingArea
   *
   * @param projectName Name of project created
   */
  private void createDrawing(String projectName) {
    if (firstStartup) {
      dailyTips();
      firstStartup = false;
    }

    drawingArea = new DrawingArea(toolbox, toolSettings, activeColorSettings);
    drawingArea.setProjectName(projectName.toLowerCase());

    Dimension desktopSize = jDesktopPane.getSize();
    Dimension jInternalFrameSize = drawingArea.getSize();
    drawingArea.setLocation(
        (desktopSize.width - jInternalFrameSize.width) / 2,
        (desktopSize.height - jInternalFrameSize.height) / 2);

    drawingArea.setTitle("Prosjekt: " + projectName);

    drawingArea.setVisible(true);

    jDesktopPane.add(drawingArea);
    try {
      drawingArea.setSelected(true);
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }
  }
  /**
   * Randomly picks the location of a new window, such that it fits completely on the screen.
   *
   * @param desktopPane the desktop pane that the frame is being added to.
   * @param frame the JInternalFrame which is being added.
   * @param desiredSize the desired dimensions of the frame.
   */
  private static void setGoodBounds(
      JInternalFrame frame, JDesktopPane desktopPane, Dimension desiredSize) {
    RandomUtil randomUtil = RandomUtil.getInstance();
    Dimension desktopSize = desktopPane.getSize();

    Dimension d = new Dimension(desiredSize);
    int tx = desktopSize.width - d.width;
    int ty = desktopSize.height - d.height;

    if (tx < 0) {
      tx = 0;
      d.width = desktopSize.width;
    } else {
      tx = (int) (randomUtil.nextDouble() * tx);
    }

    if (ty < 0) {
      ty = 0;
      d.height = desktopSize.height;
    } else {
      ty = (int) (randomUtil.nextDouble() * ty);
    }

    frame.setBounds(tx, ty, d.width, d.height);
  }
  /**
   * Adds a component to the middle layer of the desktop--that is, the layer for session node
   * editors. Note: The comp is a SessionEditor
   */
  public void addSessionEditor(SessionEditorIndirectRef editorRef) {
    SessionEditor editor = (SessionEditor) editorRef;

    JInternalFrame frame = new TetradInternalFrame(null);

    frame.getContentPane().add(editor);
    framesMap.put(editor, frame);
    editor.addPropertyChangeListener(this);

    // Set the "small" size of the frame so that it has sensible
    // bounds when the users unmazimizes it.
    Dimension fullSize = desktopPane.getSize();
    int smallSize = Math.min(fullSize.width - MARGIN, fullSize.height - MARGIN);
    Dimension size = new Dimension(smallSize, smallSize);
    setGoodBounds(frame, desktopPane, size);
    desktopPane.add(frame);

    // Set the frame to be maximized. This step must come after the frame
    // is added to the desktop. -Raul. 6/21/01
    try {
      frame.setMaximum(true);
    } catch (Exception e) {
      throw new RuntimeException("Problem setting frame to max: " + frame);
    }

    desktopPane.setLayer(frame, 0);
    frame.moveToFront();
    frame.setTitle(editor.getName());
    frame.setVisible(true);

    setMainTitle(editor.getName());
  }
示例#9
0
  /**
   * This method handles the loading of an existing project into a new DrawingArea. Gives feedback
   * to the user if project is not found or incompatible with the current version
   *
   * @param projectName Name of project to load
   */
  private void loadDrawing(String projectName) {
    if (firstStartup) {
      dailyTips();
      firstStartup = false;
    }

    drawingArea = new DrawingArea(toolbox, toolSettings, activeColorSettings);
    drawingArea.setProjectName(projectName.toLowerCase());

    try {
      serialization.load(drawingArea, projectName.toLowerCase());

      Dimension desktopSize = jDesktopPane.getSize();
      Dimension jInternalFrameSize = drawingArea.getSize();
      drawingArea.setLocation(
          (desktopSize.width - jInternalFrameSize.width) / 2,
          (desktopSize.height - jInternalFrameSize.height) / 2);

      drawingArea.setTitle("Prosjekt: " + projectName);

      drawingArea.setVisible(true);

      jDesktopPane.add(drawingArea);

    } catch (StorageException ex) {
      // ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
      JOptionPane.showMessageDialog(
          null, "Fant ikke prosjektet på serveren.", "Feil", JOptionPane.ERROR_MESSAGE);

    } catch (IOException ex) {
      // ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
      JOptionPane.showMessageDialog(
          null,
          "Dette prosjektet ble laget på en eldre versjon av programmet.\n"
              + "Dessverre er det ikke kompatibelt med nåværende versjon.",
          "Gammel versjon",
          JOptionPane.ERROR_MESSAGE);

    } catch (URISyntaxException | ClassNotFoundException ex) {
      ex.printStackTrace();
    }

    try {
      drawingArea.setSelected(true);
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }
  }
 /**
  * Open the internal frame for the given {@link BuildOutput} (or bring it to the front, if it is
  * already open)
  *
  * @param buildOutput The {@link BuildOutput}
  */
 private void openBuildOutputFrame(BuildOutput buildOutput) {
   JInternalFrame buildOutputFrame = openedBuildOutputFrames.get(buildOutput);
   if (buildOutputFrame != null) {
     buildOutputFrame.toFront();
     return;
   }
   buildOutputFrame = new JInternalFrame(buildOutput.getProjectName(), true, true, true, true);
   openedBuildOutputFrames.put(buildOutput, buildOutputFrame);
   buildOutputFrame.addInternalFrameListener(
       new InternalFrameAdapter() {
         @Override
         public void internalFrameClosed(InternalFrameEvent e) {
           openedBuildOutputFrames.remove(buildOutput);
         }
       });
   buildOutputFrame.getContentPane().add(new BuildOutputPanel(buildOutput));
   desktopPane.add(buildOutputFrame);
   buildOutputFrame.setLocation(0, 0);
   buildOutputFrame.setSize(desktopPane.getSize());
   buildOutputFrame.setVisible(true);
 }
  /** Adds the given componet to the given layer. */
  public void addEditorWindow(EditorWindowIndirectRef windowRef) {
    final JInternalFrame window = (JInternalFrame) windowRef;

    Dimension desktopSize = desktopPane.getSize();
    Dimension preferredSize = window.getPreferredSize();

    int x = desktopSize.width / 2 - preferredSize.width / 2;
    int y = desktopSize.height / 2 - preferredSize.height / 2;

    window.setBounds(x, y, preferredSize.width, preferredSize.height);

    // This line sometimes hangs, so I'm putting it in a watch process
    // so it can be stopped by the user. Not ideal.
    //        Window owner = (Window) getTopLevelAncestor();
    //
    //        new WatchedProcess(owner) {
    //            public void watch() {
    getDesktopPane().add(window);
    window.setLayer(100);
    window.moveToFront();

    try {
      window.setVisible(true);
    } catch (Exception e) {
      if (e instanceof ClassCastException || e instanceof NullPointerException) {
        // skip. These is being caused apparently the workbench
        // having labeled nodes and edges. Can't find a
        // workaround--probably a Java bug. jdramsey
      } else {
        e.printStackTrace();
      }
    }

    // prevents the component from being hidden.
    //                window.addComponentListener(new PositionListener());
    //            }
    //        };
  }
示例#12
0
 /**
  * Creates a window for reporting progress. The window will not appears immediately. It will
  * appears only when the {@link #started} method will be invoked.
  *
  * @param parent The parent component, or {@code null} if none.
  */
 public ProgressWindow(final Component parent) {
   /*
    * Creates the window containing the components.
    */
   Dimension parentSize;
   final Vocabulary resources =
       Vocabulary.getResources(parent != null ? parent.getLocale() : null);
   final String title = resources.getString(VocabularyKeys.PROGRESSION);
   final JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(parent);
   if (desktop != null) {
     final JInternalFrame frame;
     frame = new JInternalFrame(title);
     window = frame;
     content = new JPanel(); // Pour avoir un fond opaque
     parentSize = desktop.getSize();
     frame.setContentPane(content);
     frame.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
     desktop.add(frame, JLayeredPane.PALETTE_LAYER);
   } else {
     final JDialog dialog;
     dialog = new JDialog((Frame) null, title);
     window = dialog;
     content = (JComponent) dialog.getContentPane();
     parentSize = Toolkit.getDefaultToolkit().getScreenSize();
     dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
     dialog.setResizable(false);
   }
   window.setBounds(
       (parentSize.width - WIDTH) / 2, (parentSize.height - HEIGHT) / 2, WIDTH, HEIGHT);
   /*
    * Creates the label that is going to display the undergoing operation.
    * This label is initially empty.
    */
   description = new JLabel();
   description.setHorizontalAlignment(JLabel.CENTER);
   /*
    * Creates the progress bar.
    */
   progressBar = new JProgressBar();
   progressBar.setIndeterminate(true);
   progressBar.setBorder(
       BorderFactory.createCompoundBorder(
           BorderFactory.createEmptyBorder(6, 9, 6, 9), progressBar.getBorder()));
   /*
    * Creates the cancel button.
    */
   cancel = new JButton(resources.getString(VocabularyKeys.CANCEL));
   cancel.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           setCanceled(true);
         }
       });
   final Box cancelBox = Box.createHorizontalBox();
   cancelBox.add(Box.createGlue());
   cancelBox.add(cancel);
   cancelBox.add(Box.createGlue());
   cancelBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0));
   /*
    * Layout the elements inside the window. An empty border is created in
    * order to put some space between the window content and the window border.
    */
   final JPanel panel = new JPanel(new GridLayout(2, 1));
   panel.setBorder(
       BorderFactory.createCompoundBorder(
           BorderFactory.createEmptyBorder(VMARGIN, HMARGIN, VMARGIN, HMARGIN),
           BorderFactory.createEtchedBorder()));
   panel.add(description);
   panel.add(progressBar);
   content.setLayout(new BorderLayout());
   content.add(panel, BorderLayout.NORTH);
   content.add(cancelBox, BorderLayout.SOUTH);
 }