Пример #1
0
  /**
   * Constructor of class Wizard
   *
   * @param parent the parent frame
   * @param name the title of the dialog
   * @param modal whether the dialog should be modal
   */
  public Wizard(JFrame parent, String name, boolean modal) {
    super(parent, name, modal);

    // Code inspired by http://java.sun.com/developer/technicalArticles/GUI/swing/wizard/

    listeners = new LinkedList<WizardListener>();
    returnCode = -1;
    this.parent = parent;

    panelMap = new HashMap<Object, WizardPanel>();
    panels = new Vector<WizardPanel>();
    firstPanel = null;
    currentPanel = null;

    handler = new EventHandler();

    // Create the main panel

    JPanel buttonPanel = new JPanel();
    Box buttonBox = new Box(BoxLayout.X_AXIS);

    cardPanel = new JPanel();
    cardPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));

    cardLayout = new CardLayout();
    cardPanel.setLayout(cardLayout);
    backButton = new JButton("Back");
    nextButton = new JButton("Next");
    cancelButton = new JButton("Cancel");

    backButton.addActionListener(handler);
    nextButton.addActionListener(handler);
    cancelButton.addActionListener(handler);

    backButton.setEnabled(false);

    buttonPanel.setLayout(new BorderLayout());
    buttonPanel.add(new JSeparator(), BorderLayout.NORTH);

    buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
    buttonBox.add(backButton);
    buttonBox.add(Box.createHorizontalStrut(10));
    buttonBox.add(nextButton);
    buttonBox.add(Box.createHorizontalStrut(30));
    buttonBox.add(cancelButton);
    buttonPanel.add(buttonBox, java.awt.BorderLayout.EAST);
    getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
    getContentPane().add(cardPanel, java.awt.BorderLayout.CENTER);

    pack();
  }
Пример #2
0
  /** Constructs a new GraphEditor for the given EdgeListGraph. */
  public TimeLagGraphEditor(TimeLagGraph graph) {
    setLayout(new BorderLayout());

    this.workbench = new TimeLagGraphWorkbench(graph);
    DagGraphToolbar toolbar = new DagGraphToolbar(getWorkbench());
    JMenuBar menuBar = createGraphMenuBar();
    JScrollPane scroll = new JScrollPane(getWorkbench());
    scroll.setPreferredSize(new Dimension(450, 450));

    add(scroll, BorderLayout.CENTER);
    add(toolbar, BorderLayout.WEST);
    add(menuBar, BorderLayout.NORTH);

    JLabel label = new JLabel("Double click variable to change name.");
    label.setFont(new Font("SansSerif", Font.PLAIN, 12));
    Box b = Box.createHorizontalBox();
    b.add(Box.createHorizontalStrut(2));
    b.add(label);
    b.add(Box.createHorizontalGlue());
    b.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY));

    add(b, BorderLayout.SOUTH);

    this.getWorkbench()
        .addPropertyChangeListener(
            new PropertyChangeListener() {
              public void propertyChange(PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();

                if ("graph".equals(propertyName)) {
                  TimeLagGraph _graph = (TimeLagGraph) evt.getNewValue();

                  if (getWorkbench() != null) {
                    getGraphWrapper().setGraph(_graph);
                  }
                }
              }
            });
  }
Пример #3
0
  //
  // Build installer window
  //
  public static void showInstallerWindow() {
    _installerFrame = new JFrame(Config.getWindowTitle());

    Container cont = _installerFrame.getContentPane();
    cont.setLayout(new BorderLayout());

    // North pane
    Box topPane = new Box(BoxLayout.X_AXIS);
    JLabel title = new JLabel(Config.getWindowHeading());
    Font titleFont = new Font("SansSerif", Font.BOLD, 22);
    title.setFont(titleFont);
    title.setForeground(Color.black);

    // Create Sun logo
    URL urlLogo = Main.class.getResource(Config.getWindowLogo());
    Image img = Toolkit.getDefaultToolkit().getImage(urlLogo);
    MediaTracker md = new MediaTracker(_installerFrame);
    md.addImage(img, 0);
    try {
      md.waitForAll();
    } catch (Exception ioe) {
      Config.trace(ioe.toString());
    }
    if (md.isErrorID(0)) Config.trace("Error loading image");
    Icon sunLogo = new ImageIcon(img);
    JLabel logoLabel = new JLabel(sunLogo);
    logoLabel.setOpaque(true);
    topPane.add(topPane.createHorizontalStrut(5));
    topPane.add(title);
    topPane.add(topPane.createHorizontalGlue());
    topPane.add(logoLabel);
    topPane.add(topPane.createHorizontalStrut(5));

    // West Pane
    Box westPane = new Box(BoxLayout.X_AXIS);
    westPane.add(westPane.createHorizontalStrut(10));

    // South Pane
    Box bottomPane = new Box(BoxLayout.X_AXIS);
    bottomPane.add(bottomPane.createHorizontalGlue());
    JButton abortButton = new JButton(Config.getWindowAbortButton());
    abortButton.setMnemonic(Config.getWindowAbortMnemonic());
    bottomPane.add(abortButton);
    bottomPane.add(bottomPane.createHorizontalGlue());
    bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));

    // Center Pane
    Box centerPane = new Box(BoxLayout.Y_AXIS);
    JLabel hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);
    _stepLabels = new JLabel[5];
    for (int i = 0; i < _stepLabels.length; i++) {
      _stepLabels[i] = new JLabel(Config.getWindowStep(i));
      _stepLabels[i].setEnabled(false);
      centerPane.add(_stepLabels[i]);

      // install label's length will expand,so set a longer size.
      if (i == STEP_INSTALL) {
        Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize();
        _stepLabels[i].setPreferredSize(dim);
      }
    }
    hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);

    // Setup box layout
    cont.add(topPane, "North");
    cont.add(westPane, "West");
    cont.add(bottomPane, "South");
    cont.add(centerPane, "Center");

    _installerFrame.pack();
    Dimension dim = _installerFrame.getSize();

    // hard code to ensure title is completely visible on Sol/lin.
    if (dim.width < 400) {
      dim.width = 400;
      _installerFrame.setSize(dim);
    }

    Rectangle size = _installerFrame.getBounds();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    size.width = Math.min(screenSize.width, size.width);
    size.height = Math.min(screenSize.height, size.height);
    // Put window at 1/4, 1/4 of screen resoluion
    _installerFrame.setBounds(
        (screenSize.width - size.width) / 4,
        (screenSize.height - size.height) / 4,
        size.width,
        size.height);

    // Setup event listners
    _installerFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent we) {
            installFailed("Window closed", null);
          }
        });

    abortButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            installFailed("Abort pressed", null);
          }
        });

    // Show window
    _installerFrame.show();
  }