Example #1
0
 public void init() {
   // 向内部窗口中添加组件
   iframe.add(new JScrollPane(new JTextArea(8, 40)));
   desktop.setPreferredSize(new Dimension(400, 300));
   // 把虚拟桌面添加到JFrame窗口中
   jf.add(desktop);
   // 设置内部窗口的大小、位置
   iframe.reshape(0, 0, 300, 200);
   // 显示并选中内部窗口
   iframe.show();
   desktop.add(iframe);
   JPanel jp = new JPanel();
   deskBn.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent event) {
           // 弹出内部对话框,以虚拟桌面作为父组件
           JOptionPane.showInternalMessageDialog(desktop, "属于虚拟桌面的对话框");
         }
       });
   internalBn.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent event) {
           // 弹出内部对话框,以内部窗口作为父组件
           JOptionPane.showInternalMessageDialog(iframe, "属于内部窗口的对话框");
         }
       });
   jp.add(deskBn);
   jp.add(internalBn);
   jf.add(jp, BorderLayout.SOUTH);
   jf.pack();
   jf.setVisible(true);
 }
 /**
  * This will activate <b>f</b> moving it to the front. It will set the current active frame's (if
  * any) <code>IS_SELECTED_PROPERTY</code> to <code>false</code>. There can be only one active
  * frame across all Layers.
  *
  * @param f the <code>JInternalFrame</code> to be activated
  */
 public void activateFrame(JInternalFrame f) {
   Container p = f.getParent();
   Component[] c;
   JDesktopPane d = f.getDesktopPane();
   JInternalFrame currentlyActiveFrame = (d == null) ? null : d.getSelectedFrame();
   // fix for bug: 4162443
   if (p == null) {
     // If the frame is not in parent, its icon maybe, check it
     p = f.getDesktopIcon().getParent();
     if (p == null) return;
   }
   // we only need to keep track of the currentActive InternalFrame, if any
   if (currentlyActiveFrame == null) {
     if (d != null) {
       d.setSelectedFrame(f);
     }
   } else if (currentlyActiveFrame != f) {
     // if not the same frame as the current active
     // we deactivate the current
     if (currentlyActiveFrame.isSelected()) {
       try {
         currentlyActiveFrame.setSelected(false);
       } catch (PropertyVetoException e2) {
       }
     }
     if (d != null) {
       d.setSelectedFrame(f);
     }
   }
   f.moveToFront();
 }
 private void setupDragMode(JComponent f) {
   JDesktopPane p = getDesktopPane(f);
   Container parent = f.getParent();
   dragMode = DEFAULT_DRAG_MODE;
   if (p != null) {
     String mode = (String) p.getClientProperty("JDesktopPane.dragMode");
     Window window = SwingUtilities.getWindowAncestor(f);
     if (window != null && !AWTUtilities.isWindowOpaque(window)) {
       dragMode = DEFAULT_DRAG_MODE;
     } else if (mode != null && mode.equals("outline")) {
       dragMode = OUTLINE_DRAG_MODE;
     } else if (mode != null
         && mode.equals("faster")
         && f instanceof JInternalFrame
         && ((JInternalFrame) f).isOpaque()
         && (parent == null || parent.isOpaque())) {
       dragMode = FASTER_DRAG_MODE;
     } else {
       if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE) {
         dragMode = OUTLINE_DRAG_MODE;
       } else if (p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
           && f instanceof JInternalFrame
           && ((JInternalFrame) f).isOpaque()) {
         dragMode = FASTER_DRAG_MODE;
       } else {
         dragMode = DEFAULT_DRAG_MODE;
       }
     }
   }
 }
  /**
   * 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());
  }
 /**
  * Removes the frame, and, if necessary, the <code>desktopIcon</code>, from its parent.
  *
  * @param f the <code>JInternalFrame</code> to be removed
  */
 public void closeFrame(JInternalFrame f) {
   JDesktopPane d = f.getDesktopPane();
   if (d == null) {
     return;
   }
   boolean findNext = f.isSelected();
   Container c = f.getParent();
   JInternalFrame nextFrame = null;
   if (findNext) {
     nextFrame = d.getNextFrame(f);
     try {
       f.setSelected(false);
     } catch (PropertyVetoException e2) {
     }
   }
   if (c != null) {
     c.remove(f); // Removes the focus.
     c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
   }
   removeIconFor(f);
   if (f.getNormalBounds() != null) f.setNormalBounds(null);
   if (wasIcon(f)) setWasIcon(f, null);
   if (nextFrame != null) {
     try {
       nextFrame.setSelected(true);
     } catch (PropertyVetoException e2) {
     }
   } else if (findNext && d.getComponentCount() == 0) {
     // It was selected and was the last component on the desktop.
     d.requestFocus();
   }
 }
 protected void installDesktopManager() {
   desktopManager = desktop.getDesktopManager();
   if (desktopManager == null) {
     desktopManager = new BasicDesktopManager();
     desktop.setDesktopManager(desktopManager);
   }
 }
 private void setState(JDesktopPane dp, String state) {
   if (state == CLOSE) {
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     f.doDefaultCloseAction();
   } else if (state == MAXIMIZE) {
     // maximize the selected frame
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     if (!f.isMaximum()) {
       if (f.isIcon()) {
         try {
           f.setIcon(false);
           f.setMaximum(true);
         } catch (PropertyVetoException pve) {
         }
       } else {
         try {
           f.setMaximum(true);
         } catch (PropertyVetoException pve) {
         }
       }
     }
   } else if (state == MINIMIZE) {
     // minimize the selected frame
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     if (!f.isIcon()) {
       try {
         f.setIcon(true);
       } catch (PropertyVetoException pve) {
       }
     }
   } else if (state == RESTORE) {
     // restore the selected minimized or maximized frame
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     try {
       if (f.isIcon()) {
         f.setIcon(false);
       } else if (f.isMaximum()) {
         f.setMaximum(false);
       }
       f.setSelected(true);
     } catch (PropertyVetoException pve) {
     }
   }
 }
 /** 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);
 }
 public void testFindsTopLevelWindowIfActiveWindowIsInternalFrame() {
   JFrame frame = new JFrame("testTopLevelWindow");
   JDesktopPane pane = new JDesktopPane();
   JInternalFrame internalFrame = new JInternalFrame("Test");
   pane.add(internalFrame);
   frame.setContentPane(pane);
   windowContext.setActiveWindow(internalFrame);
   assertSame(frame, windowContext.activeTopLevelWindow());
   frame.dispose();
 }
  /** Constructs a new desktop. */
  public TetradDesktop() {
    setBackground(new Color(204, 204, 204));
    sessionNodeKeys = new ArrayList();
    // Create the desktop pane.
    this.desktopPane = new JDesktopPane();

    // Do layout.
    setLayout(new BorderLayout());
    desktopPane.setDesktopManager(new DefaultDesktopManager());
    desktopPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
    desktopPane.addPropertyChangeListener(this);

    this.setupDesktop();
    TetradLogger.getInstance().addTetradLoggerListener(new LoggerListener());
  }
 private void jMenuItemViewLSAResultsActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemViewLSAResultsActionPerformed
   if (this.currentResults != null) {
     LSAResultsFrame f = new LSAResultsFrame(this.currentResults, this.theProject);
     theDesktop.add(f);
   }
 } // GEN-LAST:event_jMenuItemViewLSAResultsActionPerformed
  /**
   * 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);
  }
Example #13
0
  public MainUI() {
    super("Neato Burrito");

    dLog.trace("In MainUI: " + MainUI.class.getCanonicalName());

    this.setBounds(0, 0, 500, 500);
    Container container = getContentPane();
    container.add(theDesktop);
    setJMenuBar(menubar);
    JMenu fileMenu = new JMenu("File");
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setMnemonic('X');
    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    fileMenu.add(exitItem);
    menubar.add(fileMenu);

    StatusUI statUI = new StatusUI();
    statUI.setVisible(true);
    theDesktop.add(statUI);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    setVisible(true);
  }
Example #14
0
 public void verificaTelaAberta(String nomeTela) {
   if (ctlTela == null) {
     switch (nomeTela) {
       case "Pedido":
         ctlTela = new ctlPedido(nomeTela, this);
         break;
       case "Receber Pedidos Pendentes":
         ctlTela = new ctlReceberPedidosPendentes(nomeTela, this);
         break;
       case "Realizar Entrega":
         ctlTela = new ctlRealizarEntrega(nomeTela, this);
         break;
       case "Efetuar Pagamento":
         ctlTela = new ctlEfetuarPagamento(nomeTela, this);
         break;
       case "Cadastrar Cliente":
         ctlTela = new ctlCadCliente(nomeTela, this);
         break;
       case "Cadastrar Produto":
         ctlTela = new ctlCadProduto(nomeTela, this);
         break;
     }
     try {
       ctlTela.setMaximum(true);
       jdPane.moveToFront(ctlTela);
     } catch (PropertyVetoException ex) {
       Logger.getLogger(frmMenu.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
 }
Example #15
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);
 }
  void windowMenu_menuSelected(MenuEvent e) {
    // <<TODO:MAINTAINABILITY>> This algorithm is not robust. It assumes
    // the Window
    // menu has exactly one "regular" menu item (newWindowMenuItem). [Jon
    // Aquino]
    if (windowMenu.getItemCount() > 0
        && windowMenu.getItem(0) != null
        && windowMenu
            .getItem(0)
            .getText()
            .equals(AbstractPlugIn.createName(CloneWindowPlugIn.class))) {
      JMenuItem newWindowMenuItem = windowMenu.getItem(0);
      windowMenu.removeAll();
      windowMenu.add(newWindowMenuItem);
      windowMenu.addSeparator();
    } else {
      // ezLink doesn't have a Clone Window menu [Jon Aquino]
      windowMenu.removeAll();
    }

    // final TaskComponent[] frames = (TaskComponent[]) desktopPane.getAllFrames();
    final JInternalFrame[] frames = desktopPane.getAllFrames();
    for (int i = 0; i < frames.length; i++) {
      JMenuItem menuItem = new JMenuItem();
      // Increase truncation threshold from 20 to 40, for eziLink [Jon
      // Aquino]
      menuItem.setText(GUIUtil.truncateString(frames[i].getTitle(), 40));
      associate(menuItem, frames[i]);
      windowMenu.add(menuItem);
    }
    if (windowMenu.getItemCount() == 0) {
      // For ezLink [Jon Aquino]
      windowMenu.add(new JMenuItem("(No Windows)"));
    }
  }
Example #17
0
 /** This method will create a new frame to place a new Sudoku puzzle. */
 protected void createNewGameFrame() {
   newGameFrame = new SudokuInternal();
   newGameFrame.setVisible(true);
   newGameFrame.setSize(500, 280);
   newGameFrame.doneButton.addActionListener(new DoneActionListener());
   desktop.add(newGameFrame);
 }
 private void jMenuItemViewVisualResultsActionPerformed(
     java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemViewVisualResultsActionPerformed
     { // GEN-HEADEREND:event_jMenuItemViewVisualResultsActionPerformed
   if (this.currentResults != null) {
     VisualAnalysisFrame f = new VisualAnalysisFrame(this.currentResults, this.theProject);
     theDesktop.add(f);
   }
 } // GEN-LAST:event_jMenuItemViewVisualResultsActionPerformed
 public TaskComponent[] getInternalTaskComponents() {
   JInternalFrame[] internalFrames = desktopPane.getAllFrames();
   TaskComponent[] taskComponents = new TaskComponent[internalFrames.length];
   for (int n = 0; n < internalFrames.length; n++) {
     taskComponents[n] = (TaskComponent) internalFrames[n];
   }
   return taskComponents;
 }
Example #20
0
  public MapEditor(LocalSettings localSettings) throws HeadlessException {
    setTitle(TITLE);
    setSize(WIDTH, HEIGHT);

    this.localSettings = localSettings;

    mainpane = new JDesktopPane();
    mainpane.setSize(WIDTH, HEIGHT);
    mainpane.setBackground(Color.GRAY);
    setContentPane(mainpane);

    LwjglApplicationConfiguration configuration = new LwjglApplicationConfiguration();
    configuration.width = WIDTH;
    configuration.height = HEIGHT;

    levelHolder = new LevelHolder();
    final LwjglCanvas lwjglCanvas = new LwjglCanvas(levelHolder, configuration);
    canvas = lwjglCanvas;
    levelHolderFrame = new JInternalFrame("EnJine2D Map", false, false, false, true);
    levelHolderFrame.setSize(WIDTH, HEIGHT);
    levelHolderFrame.setVisible(true);

    palette = new Palette("Palette", true, false, true, true);
    palette.setVisible(true);
    palette.setLevelHolder(levelHolder);
    levelHolder.setPalette(palette);

    getContentPane().add(palette);
    getContentPane().add(levelHolderFrame);

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            levelHolderFrame.getContentPane().add(lwjglCanvas.getCanvas());
            setVisible(true);
          }
        });

    loadSettings();

    levelHolderFrame.addComponentListener(this);
    palette.addComponentListener(this);

    addWindowListener(this);
  }
 public void openInBox() {
   JInternalFrame doc = new MetalworksInBox();
   desktop.add(doc, DOCLAYER);
   try {
     doc.setVisible(true);
     doc.setSelected(true);
   } catch (java.beans.PropertyVetoException e2) {
   }
 }
 public void openHelpWindow() {
   JInternalFrame help = new MetalworksHelp();
   desktop.add(help, HELPLAYER);
   try {
     help.setVisible(true);
     help.setSelected(true);
   } catch (java.beans.PropertyVetoException e2) {
   }
 }
 private void jMenuItemViewDocumentsActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemViewDocumentsActionPerformed
   if (this.docFrameTableModel == null) {
     this.docFrameTableModel = new DocumentFrameTableModel(theProject.getDocumentCollection());
   }
   DocumentFrame d =
       new DocumentFrame(this.docFrameTableModel, theDesktop, theProject.getDocumentCollection());
   d.setVisible(true);
   theDesktop.add(d);
 } // GEN-LAST:event_jMenuItemViewDocumentsActionPerformed
  public boolean hasInternalFrame(JInternalFrame internalFrame) {
    JInternalFrame[] frames = desktopPane.getAllFrames();
    for (int i = 0; i < frames.length; i++) {
      if (frames[i] == internalFrame) {
        return true;
      }
    }

    return false;
  }
  private void initUserComponents() {
    // required to attach windows to in the MDI world
    theDesktop = new JDesktopPane();
    setContentPane(theDesktop);

    // create and add the debug frame
    debugFrame = new DebugFrame();
    debugFrame.setVisible(false);
    theDesktop.add(debugFrame);
  }
  private void jMenuItemCutActionPerformed(
      java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemCutActionPerformed
      { // GEN-HEADEREND:event_jMenuItemCutActionPerformed
    Toolkit t = java.awt.Toolkit.getDefaultToolkit();
    Clipboard c = t.getSystemClipboard();

    JInternalFrame currentFrame = theDesktop.getSelectedFrame();
    /*StringSelection contents = new StringSelection(srcData);
    clipboard.setContents(contents, this);*/

  } // GEN-LAST:event_jMenuItemCutActionPerformed
 public boolean isEnabled(Object sender) {
   if (sender instanceof JDesktopPane) {
     JDesktopPane dp = (JDesktopPane) sender;
     String action = getName();
     if (action == Actions.NEXT_FRAME || action == Actions.PREVIOUS_FRAME) {
       return true;
     }
     JInternalFrame iFrame = dp.getSelectedFrame();
     if (iFrame == null) {
       return false;
     } else if (action == Actions.CLOSE) {
       return iFrame.isClosable();
     } else if (action == Actions.MINIMIZE) {
       return iFrame.isIconifiable();
     } else if (action == Actions.MAXIMIZE) {
       return iFrame.isMaximizable();
     }
     return true;
   }
   return false;
 }
Example #28
0
 /** This method will create a frame to show the user all the scores in order. */
 protected void createHighscoreFrame() {
   highScoreFrame = new Highscore();
   highScoreFrame.setVisible(true);
   highScoreFrame.setBounds(
       250, // left
       10, // top
       10, // bottom
       10); // right
   highScoreFrame.newGame.addActionListener(new NewGameButtonListener());
   highScoreFrame.pack();
   desktop.add(highScoreFrame);
 }
  /**
   * Removes the frame from its parent and adds its <code>desktopIcon</code> to the parent.
   *
   * @param f the <code>JInternalFrame</code> to be iconified
   */
  public void iconifyFrame(JInternalFrame f) {
    JInternalFrame.JDesktopIcon desktopIcon;
    Container c = f.getParent();
    JDesktopPane d = f.getDesktopPane();
    boolean findNext = f.isSelected();
    desktopIcon = f.getDesktopIcon();
    if (!wasIcon(f)) {
      Rectangle r = getBoundsForIconOf(f);
      desktopIcon.setBounds(r.x, r.y, r.width, r.height);
      setWasIcon(f, Boolean.TRUE);
    }

    if (c == null || d == null) {
      return;
    }

    if (c instanceof JLayeredPane) {
      JLayeredPane lp = (JLayeredPane) c;
      int layer = lp.getLayer(f);
      lp.putLayer(desktopIcon, layer);
    }

    // If we are maximized we already have the normal bounds recorded
    // don't try to re-record them, otherwise we incorrectly set the
    // normal bounds to maximized state.
    if (!f.isMaximum()) {
      f.setNormalBounds(f.getBounds());
    }
    d.setComponentOrderCheckingEnabled(false);
    c.remove(f);
    c.add(desktopIcon);
    d.setComponentOrderCheckingEnabled(true);
    c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
    if (findNext) {
      if (d.selectFrame(true) == null) {
        // The icon is the last frame.
        f.restoreSubcomponentFocus();
      }
    }
  }
Example #30
0
 private void handleSpecialCase(String cname, int condition) {
   Component comp = null;
   JComponent mapComp = null;
   try {
     if (cname.equals("javax.swing.JApplet")
         || cname.equals("javax.swing.JDialog")
         || cname.equals("javax.swing.JFrame")
         || cname.equals("javax.swing.JWindow")) {
       comp = (Component) Class.forName(cname).newInstance();
       mapComp = (JComponent) ((JApplet) comp).getLayeredPane();
       results.setText("Map entries for " + cname + " (delegated to JRootPane):\n\n");
     } else if (cname.equals("javax.swing.JInternalFrame")) {
       JDesktopPane jdp = new JDesktopPane();
       JInternalFrame jif = new JInternalFrame("Demo");
       jif.setVisible(true);
       jdp.add(jif);
       mapComp = jif;
     }
     if (inputB.isSelected()) {
       loadInputMap(mapComp.getInputMap(condition), "");
       results.append("\n");
     }
     if (actionB.isSelected()) {
       loadActionMap(mapComp.getActionMap(), "");
       results.append("\n");
     }
     if (bindingB.isSelected()) {
       loadBindingMap(mapComp, condition);
     }
   } catch (ClassCastException cce) {
     results.setText(cname + " is not a subclass of JComponent.");
   } catch (ClassNotFoundException cnfe) {
     results.setText(cname + " was not found.");
   } catch (InstantiationException ie) {
     results.setText(cname + " could not be instantiated.");
   } catch (Exception e) {
     results.setText("Exception found:\n" + e);
     e.printStackTrace();
   }
 }