Exemplo n.º 1
52
 /**
  * Show the given message in a dialog box or independent window, depending on whether the source
  * component is contained in a Frame or not.
  *
  * @param c The Controller that calls this method, or null if it is not called by a Controller.
  *     (The Controller, if any, will be notified when the error message is cleared.)
  * @param message The message to display.
  */
 public void setErrorMessage(Controller c, String message) {
   if (popup != null) clearErrorMessage();
   if (message == null) return;
   errorSource = c;
   errorMessage = message;
   Component parent = source;
   while (parent != null && !(parent instanceof Frame)) parent = parent.getParent();
   if (parent != null) popup = new Dialog((Frame) parent, "Error Message", true); // modal dialog
   else popup = new Frame("Error Message"); // independent window
   popup.setBackground(Color.white);
   popup.add(new MC(message), BorderLayout.CENTER);
   Panel buttonBar = new Panel();
   buttonBar.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));
   Button OK = new Button("    OK    ");
   OK.addActionListener(this);
   buttonBar.add(OK);
   popup.add(buttonBar, BorderLayout.SOUTH);
   popup.pack();
   if (parent == null) popup.setLocation(100, 80);
   else popup.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 30);
   popup.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent evt) {
           popup.dispose();
         }
       });
   popup.show(); // make the dialog visible.
 }
Exemplo n.º 2
0
    protected void repack() {

      Window w = SwingUtilities.getWindowAncestor(panel);
      if (w != null) {
        w.pack();
      }
    }
Exemplo n.º 3
0
 public void remove(T key) {
   remove(items.remove(key));
   showEmptyMessage();
   setSize(getPreferredSize());
   validate(); // Update container
   containerWindow.pack();
 }
 public void actionPerformed(ActionEvent e) {
   removeAll();
   refresh(((JComboBox) e.getSource()).getSelectedIndex());
   Component w = getParent();
   while (!(w instanceof Window)) w = w.getParent();
   if (w != null) ((Window) w).pack(); // ugly hack...
   return;
 }
Exemplo n.º 5
0
 private void addListener(final Window container) {
   container.addWindowFocusListener(
       new WindowAdapter() {
         public void windowLostFocus(WindowEvent evt) {
           container.setVisible(false);
         }
       });
   container.pack();
 }
Exemplo n.º 6
0
 public void repack() {
   if (panel != null) {
     Window w = SwingUtilities.getWindowAncestor(panel);
     if (w != null) {
       w.pack();
     }
   }
   rebuildViz();
 }
Exemplo n.º 7
0
 public static void setPositionRelativeToParent(
     Window w, Component parent, int hOffset, int vOffset) {
   try {
     Point p = parent.getLocationOnScreen();
     int x = (int) p.getX() + hOffset;
     int y = (int) p.getY() + vOffset;
     w.setLocation(x, y);
     w.pack();
   } catch (Throwable t) {
   }
 }
 public static Window setSize(JComponent content, final Dimension size) {
   final Window popupWindow = SwingUtilities.windowForComponent(content);
   final Point location = popupWindow.getLocation();
   popupWindow.setLocation(location.x, location.y);
   Insets insets = content.getInsets();
   if (insets != null) {
     size.width += insets.left + insets.right;
     size.height += insets.top + insets.bottom;
   }
   content.setPreferredSize(size);
   popupWindow.pack();
   return popupWindow;
 }
Exemplo n.º 9
0
  public JButton add(final T key, String buttonText) {
    JButton editButton = new JButton(buttonText);
    editButton.setBackground(Color.WHITE);
    // editButton.setOpaque(true);
    editButton.setUI(new BasicButtonUI());
    editButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
    editButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent event) {
            startEditor(key, (JButton) event.getSource());
          }
        });

    ImageIcon icon =
        new ImageIcon(
            GraphEditor.class.getResource("/edu/incense/designer/images/remove-icon.png"));
    JButton removeButton = new JButton(icon);
    removeButton.setBackground(Color.WHITE);
    removeButton.setUI(new BasicButtonUI());
    removeButton.setSize(ICON_WIDTH, BUTTON_HEIGHT);
    removeButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent event) {
            remove(key);
          }
        });

    JPanel itemPanel = new JPanel();
    SpringLayout layout = new SpringLayout();
    itemPanel.setLayout(layout);
    itemPanel.setBackground(Color.WHITE);
    itemPanel.setBorder(new LineBorder(Color.DARK_GRAY));
    itemPanel.add(editButton);
    itemPanel.add(removeButton);
    layout.putConstraint(SpringLayout.WEST, editButton, 0, SpringLayout.WEST, itemPanel);
    layout.putConstraint(SpringLayout.EAST, editButton, 0, SpringLayout.WEST, removeButton);
    layout.putConstraint(SpringLayout.EAST, removeButton, 0, SpringLayout.EAST, itemPanel);

    if (items.isEmpty()) removeEmptyMessage();
    items.put(key, itemPanel);
    add(itemPanel);
    setSize(getPreferredSize());
    validate(); // Update container
    containerWindow.pack();
    return editButton;
  }
  /**
   * Utility method for initializing a Window for displaying a JXErrorPane. This is particularly
   * useful because the differences between JFrame and JDialog are so minor. removed.
   */
  private void initWindow(final Window w, final JXErrorPane pane) {
    w.setLayout(new BorderLayout());
    w.add(pane, BorderLayout.CENTER);
    final Action closeAction = new CloseAction(w);
    closeButton.addActionListener(closeAction);
    final ResizeWindow resizeListener = new ResizeWindow(w);
    // make sure this action listener is last (or, oddly, the first in the list)
    ActionListener[] list = detailButton.getActionListeners();
    for (ActionListener a : list) {
      detailButton.removeActionListener(a);
    }
    detailButton.addActionListener(resizeListener);
    for (ActionListener a : list) {
      detailButton.addActionListener(a);
    }

    if (w instanceof JFrame) {
      final JFrame f = (JFrame) w;
      f.getRootPane().setDefaultButton(closeButton);
      f.setResizable(true);
      f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
      f.getRootPane().registerKeyboardAction(closeAction, ks, JComponent.WHEN_IN_FOCUSED_WINDOW);
    } else if (w instanceof JDialog) {
      final JDialog d = (JDialog) w;
      d.getRootPane().setDefaultButton(closeButton);
      d.setResizable(true);
      d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
      d.getRootPane().registerKeyboardAction(closeAction, ks, JComponent.WHEN_IN_FOCUSED_WINDOW);
    }

    w.addWindowListener(
        new WindowAdapter() {
          public void windowClosed(WindowEvent e) {
            // remove the action listener
            closeButton.removeActionListener(closeAction);
            detailButton.removeActionListener(resizeListener);
            exitIfFatal();
          }
        });
    w.pack();
  }
Exemplo n.º 11
0
 public void pack() {
   this.invalidate();
   Component c = this.getParent();
   while (true) {
     if (c == null) {
       break;
     } else if (c instanceof Window) {
       ((Window) c).pack();
       break;
     } else if (c instanceof Frame) {
       ((Frame) c).pack();
       break;
     } else if (c instanceof Dialog) {
       ((Dialog) c).pack();
       break;
     } else {
       c = c.getParent();
     }
   }
 }
Exemplo n.º 12
0
 /*
 	This could live in the desktop script.
 	However we'd like to get it on the screen as quickly as possible.
 */
 public static void startSplashScreen() {
   int width = 275, height = 148;
   Window win = new Window(new Frame());
   win.pack();
   BshCanvas can = new BshCanvas();
   can.setSize(width, height); // why is this necessary?
   Toolkit tk = Toolkit.getDefaultToolkit();
   Dimension dim = tk.getScreenSize();
   win.setBounds(dim.width / 2 - width / 2, dim.height / 2 - height / 2, width, height);
   win.add("Center", can);
   Image img = tk.getImage(Interpreter.class.getResource("/bsh/util/lib/splash.gif"));
   MediaTracker mt = new MediaTracker(can);
   mt.addImage(img, 0);
   try {
     mt.waitForAll();
   } catch (Exception e) {
   }
   Graphics gr = can.getBufferedGraphics();
   gr.drawImage(img, 0, 0, can);
   win.setVisible(true);
   win.toFront();
   splashScreen = win;
 }
 @Messages({
   "CTL_ModulesTab=Modules",
   "CTL_SourcesTab=Sources",
   "CTL_JavadocTab=Javadoc",
   "CTL_HarnessTab=Harness"
 })
 private void initTabs() {
   if (platformsList.getModel().getSize() > 0) {
     platformsList.setSelectedIndex(0);
     sourcesTab = new NbPlatformCustomizerSources();
     modulesTab = new NbPlatformCustomizerModules();
     javadocTab = new NbPlatformCustomizerJavadoc();
     harnessTab = new NbPlatformCustomizerHarness();
     detailPane.addTab(CTL_ModulesTab(), modulesTab);
     detailPane.addTab(CTL_SourcesTab(), sourcesTab);
     detailPane.addTab(CTL_JavadocTab(), javadocTab);
     detailPane.addTab(CTL_HarnessTab(), harnessTab);
     Container window = this.getTopLevelAncestor();
     if (window != null && window instanceof Window) {
       ((Window) window).pack();
     }
   }
 }
Exemplo n.º 14
0
 public void pack() {
   if (w != null) {
     // circumvention for bug 1924630 : this throws a NullPointerException
     // with the combination Metal-lnf / java 1.5 / screen menu bar / laf window deco
     // / floating palettes. We have to make sure the window is focusable
     // during pack():
     final boolean wasFocusable = w.getFocusableWindowState();
     if (!wasFocusable) {
       w.setFocusableWindowState(true);
     }
     w.pack();
     if (!wasFocusable) {
       w.setFocusableWindowState(false);
     }
   } else if (jif != null) {
     // bug in swing??
     // when using undecorated windows plus metal-lnf plus lnf-window-deco
     //			try { jif.pack(); } catch( NullPointerException e ) {}
     jif.pack();
   } else {
     throw new IllegalStateException();
   }
 }
Exemplo n.º 15
0
  /**
   * Create a toolbar containing the given tools (if any).
   *
   * @param template Conta
   */
  protected void changeToolBar(JComponent[] template, IControlCenterPlugin selplugin) {
    // Setup the tool bar.
    if (toolbar == null) {
      toolbar = new JToolBar("Main Toolbar");
      getContentPane().add(BorderLayout.NORTH, toolbar);
      // Add standard entries (after gap).
      toolbar.add(Box.createGlue());
      toolcnt++;
      toolbar.addSeparator();
      toolcnt++;

      // ButtonGroup bg = new ButtonGroup();
      IControlCenterPlugin[] plugins = controlcenter.getPlugins();
      for (int i = 0; i < plugins.length; i++) {
        final IControlCenterPlugin plugin = plugins[i];
        // final JToggleButton button = new JToggleButton(new PluginAction(plugins[i]));
        final JButton button = new JButton(new PluginAction(plugins[i]));
        Icon ic = plugin.getToolIcon(selplugin.getName().equals(plugins[i].getName()));
        if (ic != null) button.setIcon(ic);
        else button.setText(plugins[i].getName());
        button.setText("A");
        button.putClientProperty("plugin", plugins[i]);
        button.setBorder(null);
        button.setText(null);
        button.setMinimumSize(BUTTON_DIM);
        button.setHorizontalAlignment(SwingConstants.CENTER);
        button.setVerticalAlignment(SwingConstants.CENTER);
        button.setToolTipText(plugins[i].getName());
        button
            .getModel()
            .addItemListener(
                new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                    // System.out.println(plugin.getName()+" :"+button.isSelected());
                    button.setIcon(plugin.getToolIcon(button.isSelected()));
                  }
                });
        //	            if(plugins[i].getHelpID()!=null)
        //	            	SHelp.setupHelp(button, plugins[i].getHelpID());

        // bg.add(button);
        toolbar.add(button);
        toolcnt++;
      }
      toolbar.addSeparator();
      toolcnt++;
      toolbar.add(new JadexLogoButton(toolbar));
      toolcnt++;
    } else {
      while (toolbar.getComponentCount() > toolcnt) {
        //				Component	comp	= toolbar.getComponent(0);
        toolbar.remove(0);
        // if(lasttoolbar!=null)
        //	lasttoolbar.add(comp);
      }
    }

    for (int i = 0; template != null && i < template.length; i++) toolbar.add(template[i], i);
    // lasttoolbar	= template;

    // Select plugins
    for (int i = 0; i < toolbar.getComponentCount(); i++) {
      JComponent comp = (JComponent) toolbar.getComponent(i);
      if (comp.getClientProperty("plugin") != null) {
        IControlCenterPlugin pl = (IControlCenterPlugin) comp.getClientProperty("plugin");
        ((JButton) comp).setIcon(pl.getToolIcon(pl.equals(selplugin)));
        // ((JToggleButton)comp).setSelected(pluginname.equals(comp.getClientProperty("pluginname")));
      }
    }

    toolbar.validate();
    toolbar.repaint();

    // If toolbar has been dropped out -> pack the window (hack???).
    Container root = toolbar;
    while (root.getParent() != null && !(root instanceof Window)) root = root.getParent();
    if (root != null && !(root instanceof JFrame)) {
      ((Window) root).pack();
    }
  }
Exemplo n.º 16
0
  /**
   * This method is used at the end of a drag session to place the frame in either its original
   * parent as a docked JToolBar or in its floating frame.
   *
   * @param position The position of the mouse cursor relative to the JToolBar.
   * @param origin The screen position of the JToolBar before the drag session started.
   */
  protected void floatAt(Point position, Point origin) {
    Point p = new Point(position);
    int aoc = areaOfClick(origParent, SwingUtilities.convertPoint(toolBar, p, origParent));

    Container oldParent = toolBar.getParent();

    oldParent.remove(toolBar);
    oldParent.doLayout();
    oldParent.repaint();

    Container newParent;

    if (aoc == -1) newParent = ((RootPaneContainer) floatFrame).getContentPane();
    else {
      floatFrame.hide();
      newParent = origParent;
    }

    String constraint;
    switch (aoc) {
      case SwingConstants.EAST:
        constraint = BorderLayout.EAST;
        break;
      case SwingConstants.NORTH:
        constraint = BorderLayout.NORTH;
        break;
      case SwingConstants.SOUTH:
        constraint = BorderLayout.SOUTH;
        break;
      case SwingConstants.WEST:
        constraint = BorderLayout.WEST;
        break;
      default:
        constraint = BorderLayout.CENTER;
        break;
    }

    int newOrientation = SwingConstants.HORIZONTAL;
    if ((aoc != -1) && ((aoc == SwingConstants.EAST) || (aoc == SwingConstants.WEST)))
      newOrientation = SwingConstants.VERTICAL;

    if (aoc != -1) {
      constraintBeforeFloating = constraint;
      lastGoodOrientation = newOrientation;
    }

    newParent.add(toolBar, constraint);

    setFloating(aoc == -1, null);
    toolBar.setOrientation(newOrientation);

    Insets insets = floatFrame.getInsets();
    Dimension dims = toolBar.getPreferredSize();
    p = dragWindow.getOffset();
    setFloatingLocation(
        (position.x + origin.x) - p.x - ((insets.left + insets.right) / 2),
        (position.y + origin.y) - p.y - ((insets.top + insets.bottom) / 2));

    if (aoc == -1) {
      floatFrame.pack();
      floatFrame.setSize(
          dims.width + insets.left + insets.right, dims.height + insets.top + insets.bottom);
      floatFrame.show();
    }

    newParent.invalidate();
    newParent.validate();
    newParent.repaint();
  }
Exemplo n.º 17
0
 private static void repaintAfterChange() {
   for (Window windowsEffected1 : windowsEffected) {
     SwingUtilities.updateComponentTreeUI(windowsEffected1);
     windowsEffected1.pack();
   }
 }
  public void pack() {
    final Window window = SwingUtilities.getWindowAncestor(myContent);

    window.pack();
  }