Example #1
0
  /** Frees resources, clears references */
  public void dispose() {
    if (tempFloatingTimer != null) {
      tempFloatingTimer.stop();
    }

    if (initialized) {
      if (winListener != null) removeListener(winListener);
      if (cmpListener != null) c.removeComponentListener(cmpListener);

      wh.removeWindow(this, null);
      //			AbstractApplication.getApplication().addComponent( getClass().getName(), null );

      if (borrowMenuBar) {
        borrowMenuBar(null);
        wh.removeBorrowListener(this);
      }
      if (wh.getMenuBarBorrower() == this) wh.setMenuBarBorrower(null);
      if (ownMenuBar) {
        setJMenuBar(null);
        wh.getMenuBarRoot().destroy(this);
      }
    }

    if (w != null) {
      w.dispose();
    } else if (jif != null) {
      jif.dispose();
    }

    if (ggTitle != null) ggTitle.dispose();

    classPrefs = null;
    cmpListener = null;
    winListener = null;
  }
Example #2
0
  protected void init() {
    gh = new BasicGraphicsHandler();
    dh = createDocumentHandler();
    mf = createMenuFactory();
    wh = createWindowHandler();

    mf.init();
    wh.init();
  }
Example #3
0
 public void setJMenuBar(JMenuBar m) {
   try {
     if (jf != null) {
       bar = m;
       jf.setJMenuBar(m);
     } else if (jif != null) {
       bar = m;
       if (active && ownMenuBar) wh.getMasterFrame().setJMenuBar(bar);
       //			jif.setJMenuBar( m );
     } else {
       throw new IllegalStateException();
     }
   }
   // seems to be a bug ... !
   catch (NullPointerException e1) {
     e1.printStackTrace();
   }
 }
Example #4
0
 protected void borrowMenuBar(AbstractWindow aw) {
   if (borrowMenuBar && (barBorrower != aw)) {
     if ((bar != null) && (barBorrower != null)) {
       barBorrower.setJMenuBar(bar);
       bar = null;
     }
     barBorrower = aw;
     bar = barBorrower == null ? null : barBorrower.getJMenuBar();
     // System.err.println( "setting bar " + bar + " for window " + this + "; active = "+active );
     if (active) {
       if (barBorrower != null) barBorrower.setJMenuBar(null);
       if (jf != null) {
         jf.setJMenuBar(bar);
       } else if (jif != null) {
         wh.getMasterFrame().setJMenuBar(bar);
       } else {
         throw new IllegalStateException();
       }
     }
   }
 }
Example #5
0
 public void setLocationRelativeTo(Component comp) {
   if (w != null) {
     w.setLocationRelativeTo(comp);
   } else {
     //			throw new IllegalStateException();
     final Point p;
     if (comp == null) {
       if (jif == null) {
         p = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
       } else {
         comp = wh.getMasterFrame().getWindow();
         p = new Point(comp.getWidth() >> 1, comp.getHeight() >> 1);
       }
     } else {
       p = comp.getLocation();
       p.translate(comp.getWidth() >> 1, comp.getHeight() >> 1);
     }
     final Point p2 = SwingUtilities.convertPoint(comp, p, c);
     p2.translate(-(c.getWidth() >> 1), -(c.getHeight() >> 1));
     c.setLocation(p2);
   }
 }
Example #6
0
  /*
   *  Restores this frame's bounds and visibility
   *  from its class preferences.
   *
   *  @see	#restoreAllFromPrefs()
   */
  private void restoreFromPrefs() {
    String sizeVal = classPrefs.get(KEY_SIZE, null);
    String locVal = classPrefs.get(KEY_LOCATION, null);
    String visiVal = classPrefs.get(KEY_VISIBLE, null);
    Rectangle r = c.getBounds();
    //		Insets		i		= getInsets();

    // System.err.println( "this "+getClass().getName()+ " visi = "+visiVal );

    Dimension dim = stringToDimension(sizeVal);
    if ((dim == null) || alwaysPackSize()) {
      pack();
      dim = c.getSize();
    }

    r.setSize(dim);
    Point p = stringToPoint(locVal);
    if (p != null) {
      r.setLocation(p);
      c.setBounds(r);
    } else {
      c.setSize(dim);
      final Point2D prefLoc = getPreferredLocation();
      wh.place(this, (float) prefLoc.getX(), (float) prefLoc.getY());
      //			if( shouldBeCentered() ) setLocationRelativeTo( null );
    }
    c.invalidate();
    //		if( alwaysPackSize() ) {
    //			pack();
    //		} else {
    c.validate();
    //		}
    //		lim.queue( this );
    if ((visiVal != null) && restoreVisibility()) {
      setVisible(new Boolean(visiVal).booleanValue());
    }
  }
Example #7
0
  /**
   * Subclasses should call this after having constructed their GUI. Then this method will attach a
   * copy of the main menu from <code>root.menuFactory</code> and restore bounds from preferences.
   *
   * @param root application root
   * @see MenuFactory#gimmeSomethingReal( AppWindow )
   */
  public void init() {
    if (initialized) throw new IllegalStateException("Window was already initialized.");

    // System.out.println( "init " + getClass().getName() );

    if (borrowMenuBar) {
      borrowMenuBar(wh.getMenuBarBorrower());
      wh.addBorrowListener(this);
    } else if (ownMenuBar) {
      setJMenuBar(wh.getMenuBarRoot().createBar(this));
    }
    //		AbstractApplication.getApplication().addComponent( getClass().getName(), this );

    winListener =
        new AbstractWindow.Adapter() {
          public void windowOpened(AbstractWindow.Event e) {
            // System.err.println( "shown" );
            if (classPrefs != null) classPrefs.putBoolean(KEY_VISIBLE, true);
            if (!initialized)
              System.err.println("WARNING: window not initialized (" + e.getWindow() + ")");
          }

          //			public void windowClosing( WindowEvent e )
          //			{
          //				classPrefs.putBoolean( PrefsUtil.KEY_VISIBLE, false );
          //			}

          public void windowClosed(AbstractWindow.Event e) {
            // System.err.println( "hidden" );
            if (classPrefs != null) classPrefs.putBoolean(KEY_VISIBLE, false);
          }

          public void windowActivated(AbstractWindow.Event e) {
            try {
              active = true;
              if (wh.usesInternalFrames() && ownMenuBar) {
                wh.getMasterFrame().setJMenuBar(bar);
              } else if (borrowMenuBar && (barBorrower != null)) {
                barBorrower.setJMenuBar(null);
                if (jf != null) {
                  jf.setJMenuBar(bar);
                } else if (jif != null) {
                  wh.getMasterFrame().setJMenuBar(bar);
                } else {
                  throw new IllegalStateException();
                }
              }
              if (tempFloating) {
                if (jif == null) {
                  // System.out.println( "activ " + enc_getClass().getName() );
                  ////							wh.removeWindow( AbstractWindow.this, null );
                  tempFloatingTimer.restart();
                  //							GUIUtil.setAlwaysOnTop( getWindow(), true );
                  ////							floating = true;
                  ////							wh.addWindow( AbstractWindow.this, null );
                } else {
                  jif.setLayer(JLayeredPane.MODAL_LAYER);
                }
                //					} else if( wh.usesFloating() ) {
                //						// tricky...
                //						// we need to do this because if the opposite's
                //						// window is tempFloating, it will reset
                //						// alwaysOnTop to false too late for the OS,
                //						// so this one is not jumping to the front
                //						// automatically upon activation...
                //						toFront();
              }
            }
            // seems to be a bug ... !
            catch (NullPointerException e1) {
              e1.printStackTrace();
            }
          }

          public void windowDeactivated(AbstractWindow.Event e) {
            // System.out.println( "deac2 " + enc_getClass().getName() );
            try {
              active = false;
              if (wh.usesInternalFrames() && ownMenuBar) {
                if (wh.getMasterFrame().getJMenuBar() == bar) wh.getMasterFrame().setJMenuBar(null);
              } else if (borrowMenuBar && (barBorrower != null)) {
                if (jf != null) {
                  jf.setJMenuBar(null);
                }
                barBorrower.setJMenuBar(bar);
              }
              if (tempFloating) {
                if (jif == null) {
                  // System.out.println( "deact " + enc_getClass().getName() );
                  //							wh.removeWindow( AbstractWindow.this, null );
                  GUIUtil.setAlwaysOnTop(getWindow(), false);
                  tempFloatingTimer.stop();
                  //							floating = false;
                  //							wh.addWindow( AbstractWindow.this, null );

                  // find the new active window (is valid only after
                  // the next event cycle) and re-put it in the front\
                  // coz setAlwaysOnTop came "too late"
                  EventQueue.invokeLater(
                      new Runnable() {
                        public void run() {
                          final AbstractWindow fw =
                              FloatingPaletteHandler.getInstance().getFocussedWindow();
                          if (fw != null) fw.toFront();
                        }
                      });
                } else {
                  jif.setLayer(JLayeredPane.DEFAULT_LAYER);
                }
              }
            }
            // seems to be a bug ... !
            catch (NullPointerException e1) {
              e1.printStackTrace();
            }
          }
        };
    addListener(winListener);

    if (autoUpdatePrefs()) {
      getClassPrefs(); // this creates the prefs
      restoreFromPrefs();
      cmpListener =
          new ComponentAdapter() {
            public void componentResized(ComponentEvent e) {
              classPrefs.put(KEY_SIZE, dimensionToString(e.getComponent().getSize()));
            }

            public void componentMoved(ComponentEvent e) {
              classPrefs.put(KEY_LOCATION, pointToString(e.getComponent().getLocation()));
            }

            public void componentShown(ComponentEvent e) {
              classPrefs.putBoolean(KEY_VISIBLE, true);
            }

            public void componentHidden(ComponentEvent e) {
              classPrefs.putBoolean(KEY_VISIBLE, false);
              // System.err.println( "hidden" );
            }
          };
      c.addComponentListener(cmpListener);
    } else {
      if (alwaysPackSize()) {
        pack();
      }
    }

    wh.addWindow(this, null);
    initialized = true;
  }
Example #8
0
  public AppWindow(int flags) {
    super();
    final Application app = AbstractApplication.getApplication();
    final int type = flags & TYPES_MASK;
    wh = (BasicWindowHandler) app.getWindowHandler();

    switch (type) {
      case REGULAR:
      case SUPPORT:
        if (wh.usesInternalFrames()) {
          c = jc = jif = new JInternalFrame(null, true, true, true, true);
          w = f = jf = null;
          d = jd = null;
          wh.getDesktop().add(jif);
          ownMenuBar = type == REGULAR;

        } else {
          c = w = f = jf = new JFrame();
          jc = jif = null;
          d = jd = null;
          ownMenuBar = wh.usesScreenMenuBar() || (type == REGULAR);
        }
        //			floating			= false;
        tempFloating = (type == SUPPORT) && wh.usesFloating();
        floating = tempFloating;
        borrowMenuBar = false;
        ggTitle = null;
        break;

      case PALETTE:
        floating = wh.usesFloating();
        tempFloating = false;
        ownMenuBar = false;

        if (wh.usesInternalFrames()) {
          c = jc = jif = new JInternalFrame(null, true, true, true, true);
          w = f = jf = null;
          d = jd = null;
          borrowMenuBar = true;
          ggTitle = null;

          if (floating) jif.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
          wh.getDesktop()
              .add(jif, floating ? JLayeredPane.PALETTE_LAYER : JLayeredPane.DEFAULT_LAYER);

        } else {

          c = w = f = jf = new JFrame();
          jc = jif = null;
          d = jd = null;
          //				borrowMenuBar	= wh.usesScreenMenuBar();

          if (floating) {
            ggTitle = new AquaWindowBar(this, true);
            ggTitle.setAlwaysOnTop(true);
            borrowMenuBar = false;
            jf.setUndecorated(true);

            final Container cp = jf.getContentPane();

            //					cp.add( ggTitle, orient == HORIZONTAL ? BorderLayout.NORTH : BorderLayout.WEST );
            cp.add(ggTitle, BorderLayout.NORTH);

            //					if( resizable ) {
            //						final JPanel p = new JPanel( new BorderLayout() );
            //						p.add( new AquaResizeGadget(), BorderLayout.EAST );
            //						cp.add( p, BorderLayout.SOUTH );
            //					}
            //				} else {
            //					if( prefs.getBoolean( PrefsUtil.KEY_INTRUDINGSIZE, false )) {
            //						getContentPane().add( Box.createVerticalStrut( 16 ), BorderLayout.SOUTH );
            //					}
          } else {
            borrowMenuBar = wh.usesScreenMenuBar();
            ggTitle = null;
          }
        }
        break;

      default:
        throw new IllegalArgumentException("Unsupported window type : " + (flags & TYPES_MASK));
    }

    initTempFloating();
  }