/** Initializes the call button. */
  private void initCallButton() {
    List<ProtocolProviderService> telephonyProviders = CallManager.getTelephonyProviders();

    if (telephonyProviders != null && telephonyProviders.size() > 0) {
      if (callButton.getParent() != null) return;

      callButton.setAlignmentX(JButton.CENTER_ALIGNMENT);

      callButton.setMnemonic(
          GuiActivator.getResources().getI18nMnemonic("service.gui.CALL_CONTACT"));

      buttonPanel.add(callButton);

      callButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String searchText = parentWindow.getCurrentSearchText();

              if (searchText == null) return;

              CallManager.createCall(searchText, callButton);
            }
          });
    } else {
      buttonPanel.remove(callButton);
    }
  }
Exemple #2
0
  // constructor of TextFrame
  public TextFrame() {
    // this.message = message;
    message = "Click to Edit Text";
    messageFont = new Font("Arial", Font.PLAIN, 30);
    foreground = Color.black;
    background = Color.white;

    // custom dialog (it's a private class inside TextFrame)
    cd = new CustomDialog(this);

    messageField = new JTextField();
    messageField.setPreferredSize(new Dimension(300, 200));
    messageField.setEditable(false);
    messageField.setHorizontalAlignment(SwingConstants.CENTER);
    messageField.setAlignmentX(Component.CENTER_ALIGNMENT);
    updateMessage();

    customize = new JButton("Customize");
    customize.setMaximumSize(customize.getPreferredSize());
    customize.setAlignmentX(Component.CENTER_ALIGNMENT);

    apply = new JButton("Apply");
    apply.setMaximumSize(customize.getPreferredSize());
    apply.setAlignmentX(Component.CENTER_ALIGNMENT);

    /*add the listeners*/
    customize.addActionListener(this);
    apply.addActionListener(this);
    messageField.addMouseListener(new PopUpClass());

    // customize
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(customize);
    p.add(Box.createRigidArea(new Dimension(0, 25)));
    p.add(messageField);
    p.add(Box.createRigidArea(new Dimension(0, 25)));
    p.add(apply);
    p.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));

    // make panel this JFrame's content pane

    this.setContentPane(p);
  }
  @Override
  protected void inicializarPantalla(JFrame pantalla) {

    // ~~----------------------------------------------------- Panel principal
    JPanel panel = new JPanel();
    panel.setOpaque(true);
    panel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Pruebas"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    // ~~----------------------------------------------------- Botón de avance
    JButton avanzar = new JButton("Avanzar Tiempo");
    avanzar.addActionListener(new AvanzarTiempo(this.jugador));
    avanzar.setAlignmentX(Component.CENTER_ALIGNMENT);

    JButton avanzarRapido = new JButton("Avanzar Tiempo Rápido");
    // ToDo hacer que el avanze sea configurable con un slider
    avanzarRapido.addActionListener(new AvanzarTiempo(this.jugador, FACTOR_DE_MULTIPLICACION));
    avanzarRapido.setAlignmentX(Component.CENTER_ALIGNMENT);

    JButton terremoto = new JButton("Terremoto");
    terremoto.addActionListener(new GenerarTerremoto(jugador.getMapa(), mensajero));
    terremoto.setAlignmentX(Component.CENTER_ALIGNMENT);

    JButton godzilla = new JButton("Godzilla Lineal");
    godzilla.addActionListener(
        new GenerarGodzilla(new GodzillaLineal(jugador.getMapa(), new AzarReal()), mensajero));
    godzilla.setAlignmentX(Component.CENTER_ALIGNMENT);

    JButton godzillaZigZag = new JButton("Godzilla ZigZag");
    godzillaZigZag.addActionListener(
        new GenerarGodzilla(new GodzillaZigZag(jugador.getMapa(), new AzarReal()), mensajero));
    godzillaZigZag.setAlignmentX(Component.CENTER_ALIGNMENT);

    JButton godzillaDiagonal = new JButton("Godzilla Diagonal");
    godzillaDiagonal.addActionListener(
        new GenerarGodzilla(new GodzillaDiagonal(jugador.getMapa(), new AzarReal()), mensajero));
    godzillaDiagonal.setAlignmentX(Component.CENTER_ALIGNMENT);

    JButton bomberos = new JButton("Bomberos");
    bomberos.addActionListener(new LlamarBomberos(jugador, mensajero));
    bomberos.setAlignmentX(Component.CENTER_ALIGNMENT);

    panel.add(avanzar);
    panel.add(avanzarRapido);
    panel.add(terremoto);
    panel.add(godzilla);
    panel.add(godzillaDiagonal);
    panel.add(godzillaZigZag);
    panel.add(bomberos);
    pantalla.getContentPane().add(panel);

    pantalla.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  }
  protected JToolBar createToolBar() {

    JToolBar jtoolbar = new JToolBar();

    jtoolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);

    // ---------------------------------------
    JButton jbuttonClear = new JButton("Clear SQL Statement");

    jbuttonClear.setToolTipText("Clear SQL Statement");
    jbuttonClear.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionevent) {
            clear();
          }
        });

    // ---------------------------------------
    JButton jbuttonExecute = new JButton("Execute SQL Statement");

    jbuttonExecute.setToolTipText("Execute SQL Statement");
    jbuttonExecute.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionevent) {
            execute();
          }
        });
    jtoolbar.addSeparator();
    jtoolbar.add(jbuttonClear);
    jtoolbar.addSeparator();
    jtoolbar.add(jbuttonExecute);
    jtoolbar.addSeparator();
    jbuttonClear.setAlignmentY(0.5F);
    jbuttonClear.setAlignmentX(0.5F);
    jbuttonExecute.setAlignmentY(0.5F);
    jbuttonExecute.setAlignmentX(0.5F);

    return jtoolbar;
  }
 /**
  * Gets the instance of the SlowButton
  *
  * @return The instance of the SlowButton
  */
 public static JButton getSlowButton() {
   if (slowButton == null) {
     slowButton = new JButton();
     slowButton.setText(Constants.STOP);
     slowButton.setHorizontalAlignment(SwingConstants.CENTER);
     slowButton.setFont(Constants.DEFAULT_BUTTON_FONT);
     slowButton.setAlignmentX(Component.CENTER_ALIGNMENT);
     slowButton.setActionCommand(Constants.SLOW);
     slowButton.addActionListener(ButtonListener.getInstance());
   }
   return slowButton;
 }
 /**
  * Gets the instance of the CenterButton
  *
  * @return The instance of the CenterButton
  */
 public static JButton getCenterButton() {
   if (centerButton == null) {
     centerButton = new JButton();
     centerButton.setText(Constants.CENTER);
     centerButton.setHorizontalAlignment(SwingConstants.CENTER);
     centerButton.setFont(new Font("Dialog", Font.BOLD, 14));
     centerButton.setAlignmentX(Component.CENTER_ALIGNMENT);
     centerButton.setActionCommand(Constants.CENTER);
     centerButton.addActionListener(ButtonListener.getInstance());
   }
   return centerButton;
 }
 /**
  * Gets the instance of the ConnectButton
  *
  * @return The instance of the ConnectButton
  */
 public static JButton getConnectButton() {
   if (connectButton == null) {
     connectButton = new JButton();
     connectButton.setText(Constants.CONNECT);
     connectButton.setHorizontalAlignment(SwingConstants.CENTER);
     connectButton.setFont(Constants.DEFAULT_BUTTON_FONT);
     connectButton.setAlignmentX(Component.CENTER_ALIGNMENT);
     connectButton.setActionCommand(Constants.CONNECT);
     connectButton.addActionListener(ButtonListener.getInstance());
   }
   return connectButton;
 }
 /**
  * Gets the instance of the ResetButton
  *
  * @return The instance of the ResetButton
  */
 public static JButton getResetButton() {
   if (resetButton == null) {
     resetButton = new JButton();
     resetButton.setText(Constants.RESET);
     resetButton.setHorizontalAlignment(SwingConstants.CENTER);
     resetButton.setFont(Constants.DEFAULT_BUTTON_FONT);
     resetButton.setAlignmentX(Component.CENTER_ALIGNMENT);
     resetButton.setActionCommand(Constants.RESET);
     resetButton.addActionListener(ButtonListener.getInstance());
     resetButton.setEnabled(false);
   }
   return resetButton;
 }
  private void initAddContactButton() {
    addButton.setAlignmentX(JButton.CENTER_ALIGNMENT);

    addButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.ADD_CONTACT"));

    buttonPanel.add(addButton);

    addButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            AddContactDialog dialog = new AddContactDialog(parentWindow);

            dialog.setContactAddress(parentWindow.getCurrentSearchText());
            dialog.setVisible(true);
          }
        });
  }
  /** Creates an instance of <tt>SkinManagerPanel</tt>. */
  public SkinManagerPanel() {
    super(new BorderLayout());

    JPanel selectorPanel = new TransparentPanel();
    selectorPanel.setLayout(new BoxLayout(selectorPanel, BoxLayout.Y_AXIS));

    skinSelector.setAlignmentX(Component.CENTER_ALIGNMENT);
    skinSelector.addItemListener(new EnableDisableListener());
    selectorPanel.add(skinSelector);

    rmButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    rmButton.addActionListener(new RemoveListener());
    selectorPanel.add(rmButton);

    enableDisableButton();

    add(selectorPanel, BorderLayout.NORTH);
  }
Exemple #11
0
  slideshow(String title) {
    super(title);

    next = new JButton("Next");
    next.addActionListener(new slideshowListener());
    next.setAlignmentX(Component.CENTER_ALIGNMENT);

    Info = new DefaultListModel();
    list = new JList(Info);
    list.setSelectionMode(1);

    JPanel slide = new JPanel();
    slide.add(next);

    JScrollPane show = new JScrollPane(list);
    show.setBorder(BorderFactory.createTitledBorder("Picture:"));

    JPanel header = new Borders("Project", "Slide Show");

    add(header, BorderLayout.NORTH);
    add(show, BorderLayout.CENTER);
    add(slide, BorderLayout.SOUTH);
  }
Exemple #12
0
    public final void initUI() throws FileNotFoundException, IOException {

      String FileName = "config.txt";
      String DirSeparator = System.getProperty("file.separator");
      File currentDir = new File(".");
      String FilePath = currentDir.getCanonicalPath() + DirSeparator + FileName;

      myProperties = new Properties();
      myProperties.load(new FileInputStream(FilePath));

      setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

      add(Box.createRigidArea(new Dimension(0, 10)));

      JLabel label = new JLabel();
      label.setAlignmentX(0.5f);
      add(label);

      add(Box.createRigidArea(new Dimension(0, 10)));

      String result = myProperties.getProperty("1");
      if (result == null) result = "0";

      JLabel name = new JLabel("Level 1:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("2");
      if (result == null) result = "0";
      name = new JLabel("Level 2:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("3");
      if (result == null) result = "0";
      name = new JLabel("Level 3:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("4");
      if (result == null) result = "0";
      name = new JLabel("Level 4:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("5");
      if (result == null) result = "0";
      name = new JLabel("Level 5:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      myProperties = null;

      add(Box.createRigidArea(new Dimension(0, 50)));

      JButton close = new JButton("Close");
      close.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent event) {
              dispose();
            }
          });

      close.setAlignmentX(0.5f);
      add(close);

      setModalityType(ModalityType.APPLICATION_MODAL);

      setTitle("Table of records");
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      setLocationRelativeTo(null);
      setSize(300, 200);
    }
Exemple #13
0
  Primary() {
    // Initial declarations, adding of listeners, and database linking.
    // Database link
    DBHookUp db = new DBHookUp();

    // Frame stuff
    frame = new JFrame("4 Byte Warrior");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBackground(Color.RED);
    frame.setResizable(false);
    // Panels
    main = new JPanel();
    scores = new JPanel();
    credits = new JPanel();
    story = new JPanel();
    tutorial = new JPanel();
    main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
    main.setBackground(Color.RED);
    main.setOpaque(true);
    scores.setLayout(new BorderLayout());
    scores.setBackground(Color.RED);
    scores.setOpaque(true);
    credits.setLayout(new BorderLayout());
    credits.setBackground(Color.RED);
    credits.setOpaque(true);
    // story.setLayout(new BoxLayout(story, BoxLayout.PAGE_AXIS));
    story.setLayout(new BorderLayout());
    story.setBackground(Color.RED);
    story.setOpaque(true);
    // tutorial.setLayout(new BoxLayout(tutorial, BoxLayout.PAGE_AXIS));
    tutorial.setLayout(new BorderLayout());
    tutorial.setBackground(Color.RED);
    tutorial.setOpaque(true);

    // Buttons
    start = new JButton("Go");
    start.addActionListener(this);
    start.setPreferredSize(new Dimension(125, 35));
    start.setAlignmentX(start.CENTER_ALIGNMENT);
    start.setBackground(Color.BLACK);
    start.setForeground(Color.WHITE);
    start.setHorizontalAlignment(SwingConstants.CENTER);
    cred = new JButton("Credits");
    cred.setPreferredSize(new Dimension(125, 35));
    cred.addActionListener(this);
    cred.setAlignmentX(cred.CENTER_ALIGNMENT);
    cred.setBackground(Color.BLACK);
    cred.setForeground(Color.WHITE);
    cred.setHorizontalAlignment(SwingConstants.CENTER);
    high = new JButton("High Scores");
    high.addActionListener(this);
    high.setPreferredSize(new Dimension(125, 35));
    high.setAlignmentX(high.CENTER_ALIGNMENT);
    high.setBackground(Color.BLACK);
    high.setForeground(Color.WHITE);
    high.setHorizontalAlignment(SwingConstants.CENTER);
    stor = new JButton("Next");
    stor.addActionListener(this);
    stor.setPreferredSize(new Dimension(100, 35));
    stor.setAlignmentX(stor.CENTER_ALIGNMENT);
    stor.setBackground(Color.BLACK);
    stor.setForeground(Color.WHITE);
    stor.setHorizontalAlignment(SwingConstants.CENTER);
    tutor = new JButton("Play");
    tutor.addActionListener(this);
    tutor.setPreferredSize(new Dimension(100, 35));
    tutor.setAlignmentX(tutor.CENTER_ALIGNMENT);
    tutor.setBackground(Color.BLACK);
    tutor.setForeground(Color.WHITE);
    returns1 = new JButton("Return");
    returns1.addActionListener(this);
    returns1.setPreferredSize(new Dimension(100, 35));
    returns1.setAlignmentX(returns1.CENTER_ALIGNMENT);
    returns1.setBackground(Color.BLACK);
    returns1.setForeground(Color.WHITE);
    returns1.setHorizontalAlignment(SwingConstants.CENTER);
    returns2 = new JButton("Return");
    returns2.addActionListener(this);
    returns2.setPreferredSize(new Dimension(100, 35));
    returns2.setAlignmentX(returns2.CENTER_ALIGNMENT);
    returns2.setBackground(Color.BLACK);
    returns2.setForeground(Color.WHITE);
    returns2.setHorizontalAlignment(SwingConstants.CENTER);
    returns3 = new JButton("Return");
    returns3.addActionListener(this);
    returns3.setPreferredSize(new Dimension(100, 35));
    returns3.setAlignmentX(returns3.CENTER_ALIGNMENT);
    returns3.setBackground(Color.BLACK);
    returns3.setForeground(Color.WHITE);
    returns3.setHorizontalAlignment(SwingConstants.CENTER);
    returns4 = new JButton("Return");
    returns4.addActionListener(this);
    returns4.setPreferredSize(new Dimension(100, 35));
    returns4.setAlignmentX(returns4.CENTER_ALIGNMENT);
    returns4.setBackground(Color.BLACK);
    returns4.setForeground(Color.WHITE);
    returns4.setHorizontalAlignment(SwingConstants.CENTER);

    // Text display
    theme = new JLabel();
    String text =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            300,
            "Binary was a land of peace, ruled by the good king Groshi. "
                + "One day, the Dark Knight and his armies descended upon "
                + "the kingdom, throwing it into chaos. The Dark Knight "
                + "killed Groshi and kidnapped his daughter Elsie. "
                + "Only one memember of the kingdom could hope to "
                + "save the kingdom...<br/><br/>"
                + "<font size = \"7\"> THE 4 BYTE WARRIOR </font>");
    theme.setText(text);
    theme.setHorizontalAlignment(JLabel.CENTER);
    theme.setVerticalAlignment(JLabel.CENTER);
    theme.setForeground(Color.WHITE);
    instruct = new JLabel();
    String instruction =
        String.format(
            "<html><div style=\"width:%dpx;\"><center>%s</center></div><html>",
            200,
            "Z Key: Attack<br/>X Key: Cycle through inventory<br/>D-Pad: Movement<br/>A: Pause<br/><br/><br/>Defeat the enemeies to advance. Fight the bosses, get through the 8 worlds of Binary, and save Princess Elsie.");
    instruct.setText(instruction);
    instruct.setHorizontalAlignment(JLabel.CENTER);
    instruct.setVerticalAlignment(JLabel.CENTER);
    instruct.setForeground(Color.WHITE);
    String names =
        String.format(
            "<html><div style=\"width:%dpx;\"><center>%s</center></div><html>",
            150, "Alexander Friebe<br/>Charles Heckel<br/>Nicholas Lindsley<br/>Ben McWerthy<br/>");
    people = new JLabel(names);
    people.setHorizontalAlignment(JLabel.CENTER);
    people.setVerticalAlignment(JLabel.CENTER);
    people.setForeground(Color.WHITE);
    String major =
        String.format(
            "<html><div style=\"width:%dpx;\"><center>%s</center></div><html>",
            150,
            "Computer Science<br/>Computer Engineering<br/>Computer Engineering<br/>Computer Science<br/>");
    majors = new JLabel(major);
    majors.setHorizontalAlignment(JLabel.CENTER);
    majors.setVerticalAlignment(JLabel.CENTER);
    majors.setForeground(Color.WHITE);
    String credi =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            150, "Credits");
    top = new JLabel(credi);
    top.setHorizontalAlignment(JLabel.CENTER);
    top.setVerticalAlignment(JLabel.CENTER);
    top.setForeground(Color.WHITE);
    scoresTop = new JLabel();
    String scTop =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            200, "High Scores for Enemies Killed");
    scoresTop.setText(scTop);
    scoresTop.setForeground(Color.WHITE);
    scoresTop.setHorizontalAlignment(JLabel.CENTER);
    scoresTop.setVerticalAlignment(JLabel.CENTER);
    JLabel dbScores = new JLabel();
    ArrayList<Integer> sc = db.getScores();
    System.out.println(sc.size());
    // System.out.println(sc.get(0));
    String actual =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            100, sc.get(0) + "<br/>" + sc.get(1) + "<br/>" + sc.get(2) + "<br/>");
    dbScores.setText(actual);
    dbScores.setHorizontalAlignment(JLabel.CENTER);
    dbScores.setVerticalAlignment(JLabel.CENTER);
    dbScores.setForeground(Color.WHITE);

    // Additions to main
    mainButtons = new JPanel(new GridLayout(3, 1));
    mainButtons.add(start);
    mainButtons.add(high);
    mainButtons.add(cred);
    main.add(mainButtons);

    // Additions to credits
    credits.add(top, BorderLayout.PAGE_START);
    // credits.add(people, BorderLayout.LINE_START);
    // credits.add(majors, BorderLayout.LINE_END);
    JPanel middle = new JPanel(new GridLayout(1, 2));
    middle.add(people);
    middle.add(majors);
    middle.setBackground(Color.RED);
    JPanel bottom = new JPanel(new GridLayout(1, 1));
    bottom.add(returns2);
    bottom.setBackground(Color.RED);
    credits.add(middle, BorderLayout.CENTER);
    credits.add(bottom, BorderLayout.PAGE_END);

    // Additions to high scores
    scores.add(scoresTop, BorderLayout.PAGE_START);
    scores.add(dbScores, BorderLayout.CENTER);
    JPanel bot = new JPanel(new GridLayout(1, 1));
    bot.add(returns1);
    bot.setBackground(Color.RED);
    scores.add(bot, BorderLayout.PAGE_END);

    // Additions to story
    story.add(theme, BorderLayout.CENTER);
    buttons = new JPanel(new GridLayout(2, 1));
    buttons.setBackground(Color.RED);
    // buttons.setOpaque(true);
    buttons.add(stor);
    buttons.add(returns3);
    story.add(buttons, BorderLayout.PAGE_END);

    // Additions to tutorial
    JPanel tutButtons = new JPanel(new GridLayout(2, 1));
    tutorial.add(instruct, BorderLayout.CENTER);
    tutButtons.add(tutor);
    tutButtons.add(returns4);
    tutButtons.setBackground(Color.RED);
    tutorial.add(tutButtons, BorderLayout.PAGE_END);

    main.setBorder(new EmptyBorder(100, 150, 100, 150));
    bot.setBorder(new EmptyBorder(0, 150, 0, 150));
    // middle.setBorder(new EmptyBorder(0,150,0,150));
    bottom.setBorder(new EmptyBorder(0, 150, 0, 150));
    buttons.setBorder(new EmptyBorder(0, 150, 0, 150));
    tutButtons.setBorder(new EmptyBorder(0, 150, 0, 150));
    frame.add(main);

    frame
        .pack(); // critical to call before you make the window visible in order to make everything
                 // look right 100% of the time
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
Exemple #14
0
  public final void createBathymetryUI(boolean bandCreated) {

    final int rightInset = 5;

    final MaskEnabledAllBandsCheckbox maskEnabledAllBandsCheckbox =
        new MaskEnabledAllBandsCheckbox(bathymetryData);
    final MaskTransparencySpinner maskTransparencySpinner =
        new MaskTransparencySpinner(bathymetryData);
    final MaskColorComboBox maskColorComboBox = new MaskColorComboBox(bathymetryData);
    final MaskMaxDepthTextfield maskMaxDepthTextfield = new MaskMaxDepthTextfield(bathymetryData);
    final MaskMinDepthTextfield maskMinDepthTextfield = new MaskMinDepthTextfield(bathymetryData);

    final boolean[] fileSelectorEnabled = {true};

    if (bandCreated) {
      fileSelectorEnabled[0] = false;
    } else {
      fileSelectorEnabled[0] = true;
    }

    final ResolutionComboBox resolutionComboBox = new ResolutionComboBox(bathymetryData);

    JPanel resolutionSamplingPanel = new JPanel(new GridBagLayout());
    resolutionSamplingPanel.setBorder(BorderFactory.createTitledBorder(""));

    if (fileSelectorEnabled[0]) {
      resolutionSamplingPanel.add(
          resolutionComboBox.getjLabel(),
          new ExGridBagConstraints(
              0,
              0,
              0,
              0,
              GridBagConstraints.EAST,
              GridBagConstraints.NONE,
              new Insets(0, 0, 0, rightInset)));

      JComboBox jComboBox = resolutionComboBox.getjComboBox();
      jComboBox.setEnabled(fileSelectorEnabled[0]);

      bathymetryData.addPropertyChangeListener(
          BathymetryData.PROMPT_REQUEST_TO_INSTALL_FILE_EVENT,
          new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
              SourceFileInfo sourceFileInfo =
                  (SourceFileInfo) resolutionComboBox.getjComboBox().getSelectedItem();

              InstallResolutionFileDialog dialog =
                  new InstallResolutionFileDialog(
                      bathymetryData,
                      sourceFileInfo,
                      InstallResolutionFileDialog.Step.INSTALLATION);
              dialog.setVisible(true);
              dialog.setEnabled(true);
            }
          });

      resolutionSamplingPanel.add(
          jComboBox,
          new ExGridBagConstraints(1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
    } else {
      resolutionSamplingPanel.add(
          new JLabel("Note: Cannot recreate a different band, only a different mask"),
          new ExGridBagConstraints(1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
    }

    JPanel maskJPanel = new JPanel(new GridBagLayout());
    maskJPanel.setBorder(BorderFactory.createTitledBorder(""));

    JTextField maskNameTextfield = new JTextField(bathymetryData.getMaskName());
    maskNameTextfield.setEditable(false);
    maskNameTextfield.setToolTipText("Name of the mask (this field is not editable)");

    maskJPanel.add(
        new JLabel("Mask Name"),
        new ExGridBagConstraints(
            0,
            0,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskNameTextfield,
        new ExGridBagConstraints(1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskColorComboBox.getjLabel(),
        new ExGridBagConstraints(
            0,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskColorComboBox.getColorExComboBox(),
        new ExGridBagConstraints(1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskTransparencySpinner.getjLabel(),
        new ExGridBagConstraints(
            0,
            2,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskTransparencySpinner.getjSpinner(),
        new ExGridBagConstraints(1, 2, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskMaxDepthTextfield.getjLabel(),
        new ExGridBagConstraints(
            0,
            3,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskMaxDepthTextfield.getjTextField(),
        new ExGridBagConstraints(1, 3, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskMinDepthTextfield.getjLabel(),
        new ExGridBagConstraints(
            0,
            4,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskMinDepthTextfield.getjTextField(),
        new ExGridBagConstraints(1, 4, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    maskJPanel.add(
        maskEnabledAllBandsCheckbox.getjLabel(),
        new ExGridBagConstraints(
            0,
            5,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, rightInset)));

    maskJPanel.add(
        maskEnabledAllBandsCheckbox.getjCheckBox(),
        new ExGridBagConstraints(1, 5, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));

    JPanel mainPanel = new JPanel(new GridBagLayout());

    mainPanel.add(
        resolutionSamplingPanel,
        new ExGridBagConstraints(
            0, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 3));

    mainPanel.add(
        maskJPanel,
        new ExGridBagConstraints(
            0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 3));

    String label;
    if (bandCreated) {
      label = "Recreate Bathymetry Mask";
    } else {
      label = "Create Bathymetry Band and Mask";
    }
    JButton createMasks = new JButton(label);
    createMasks.setPreferredSize(createMasks.getPreferredSize());
    createMasks.setMinimumSize(createMasks.getPreferredSize());
    createMasks.setMaximumSize(createMasks.getPreferredSize());

    createMasks.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            bathymetryData.setCreateMasks(true);
            dispose();
          }
        });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.setPreferredSize(cancelButton.getPreferredSize());
    cancelButton.setMinimumSize(cancelButton.getPreferredSize());
    cancelButton.setMaximumSize(cancelButton.getPreferredSize());

    cancelButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            dispose();
          }
        });

    JLabel filler = new JLabel("                            ");

    JPanel buttonsJPanel = new JPanel(new GridBagLayout());
    buttonsJPanel.add(
        cancelButton,
        new ExGridBagConstraints(0, 0, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE));
    buttonsJPanel.add(
        filler,
        new ExGridBagConstraints(
            1, 0, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL));
    buttonsJPanel.add(
        createMasks,
        new ExGridBagConstraints(2, 0, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE));
    buttonsJPanel.add(
        helpButton,
        new ExGridBagConstraints(3, 0, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE));

    createMasks.setAlignmentX(0.5f);

    mainPanel.add(
        buttonsJPanel,
        new ExGridBagConstraints(0, 4, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, 5));

    add(mainPanel);

    setModalityType(ModalityType.APPLICATION_MODAL);

    setTitle("Bathymetry");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLocationRelativeTo(null);
    pack();

    setPreferredSize(getPreferredSize());
    setMinimumSize(getPreferredSize());
    setMaximumSize(getPreferredSize());
    setSize(getPreferredSize());
  }
 /**
  * Constructor to setup GUI components and event handling; Pre: null; Post: the safety questions
  * will be set and stored into database.
  */
 public GUISafetyQues() {
   frame = new JFrame("Safety Questions");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   contentPane = new JPanel();
   contentPane.setLayout(
       new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); // To use BoxLayout to line items up
   contentPane.setBorder(
       BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Create empty borders around items
   ques1 = new JLabel(CustInfo.safetyQues[0]);
   ques1.setFont(f); // To keep the font of texts on items the same
   ques1.setAlignmentX(
       JLabel.CENTER_ALIGNMENT); // To line the items up at the centre of the window
   ques1.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   ques2 = new JLabel(CustInfo.safetyQues[1]);
   ques2.setFont(f);
   ques2.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   ques2.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   ques3 = new JLabel(CustInfo.safetyQues[2]);
   ques3.setFont(f);
   ques3.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   ques3.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   info = new JLabel("Please answer the three safety questions below: ");
   info.setFont(f);
   info.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   info.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   as1 = new JTextField(40);
   as1.setEditable(true); // To allow the textfield to be editted
   as2 = new JTextField(40);
   as2.setEditable(true);
   as3 = new JTextField(40);
   as3.setEditable(true);
   warning = new JLabel("Please provide an unique answer to each question.");
   warning.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   warning.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   nullWarning = new JLabel("The answers should be longer than 3 characters.");
   nullWarning.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   nullWarning.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   finish = new JButton("Save");
   finish.setFont(f);
   finish.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           String ans1 = as1.getText();
           String ans2 = as2.getText();
           String ans3 = as3.getText();
           if (ans1.length() < 3 || ans2.length() < 3 || ans3.length() < 3) {
             frame.setVisible(false);
             frame.remove(warning);
             frame.add(nullWarning);
             frame.setSize(480, 310);
             frame.setVisible(true);
           } else {
             if (ans1.equals(ans2) || ans2.equals(ans3) || ans1.equals(ans3)) {
               frame.setVisible(false);
               frame.remove(nullWarning);
               frame.add(warning);
               frame.setSize(480, 310);
               frame.setVisible(true);
             } else {
               GUIUserOpen.up.addCust(
                   GUIUserOpen.UserID,
                   GUIUserOpen
                       .password); // If the user finished safety questions, add the customer in
               GUIUserOpen.engine.SafetyQuestion(
                   ans1, ans2, ans3); // To write the answers into file
               frame.setVisible(false);
               GUIUserOpen open =
                   new GUIUserOpen(true); // Go to main page to let the user log in
             }
           }
         }
       });
   finish.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   finish.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   setNull = new JButton("Clean");
   setNull.setFont(f);
   setNull.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           frame.setVisible(false); // Close the current window
           GUISafetyQues que =
               new GUISafetyQues(); // Create a new window for enter the answers again
         }
       });
   setNull.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   setNull.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   contentPane.add(info);
   contentPane.add(ques1);
   contentPane.add(as1);
   contentPane.add(ques2);
   contentPane.add(as2);
   contentPane.add(ques3);
   contentPane.add(as3);
   contentPane.add(finish);
   contentPane.add(setNull);
   frame.setContentPane(contentPane);
   frame.pack();
   frame.setVisible(true); // Open the pop-up window
   frame.setLocationRelativeTo(
       null); // Set the location of the pop-up window at the centre of the computer
 }
Exemple #16
0
  public ContextEditor(Context cntxt) {
    super("Edit User Context: " + localFileName(cntxt));
    ctxt = cntxt;
    windowNum = ctxt.languageName + " Context Editor";
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    listener = new CEListener(this);

    JPanel nameBox = new JPanel();
    nameBox.setLayout(new BoxLayout(nameBox, BoxLayout.LINE_AXIS));
    name = new JTextField(ctxt.languageName, 28);
    name.setMaximumSize(new Dimension(225, 22));
    name.addFocusListener(
        new java.awt.event.FocusAdapter() {

          public void focusLost(java.awt.event.FocusEvent evt) {
            nameFocusLost(evt);
          }
        });

    JLabel nameLabel = new JLabel("Language Name: ");
    nameBox.add(nameLabel);
    nameBox.add(name);

    JPanel folderBox = new JPanel();
    folderBox.setLayout(new BoxLayout(folderBox, BoxLayout.LINE_AXIS));
    folder = new JTextField(ctxt.editDirectory);
    folder.setMaximumSize(new Dimension(225, 22));
    //        folder.addActionListener(listener);
    //        folder.setActionCommand("folder edit");
    folder.addFocusListener(
        new java.awt.event.FocusAdapter() {

          public void focusLost(java.awt.event.FocusEvent evt) {
            folderFocusLost(evt);
          }
        });

    JLabel folderLabel = new JLabel("SILK file folder: ");
    folderBox.add(folderLabel);
    folderBox.add(folder);

    JPanel nameFolderBox = new JPanel();
    nameFolderBox.setLayout(new BoxLayout(nameFolderBox, BoxLayout.PAGE_AXIS));
    nameBox.setAlignmentX(0.5f);
    nameFolderBox.add(nameBox);
    nameFolderBox.add(Box.createRigidArea(new Dimension(0, 4)));
    nameFolderBox.add(folderBox);
    nameFolderBox.setAlignmentX(0.5f);

    buildPopulationBox();

    JPanel btnBoxUDPs = new JPanel(), subBoxUDP = new JPanel();
    btnBoxUDPs.setLayout(new BoxLayout(btnBoxUDPs, BoxLayout.PAGE_AXIS));
    subBoxUDP.setLayout(new BoxLayout(subBoxUDP, BoxLayout.LINE_AXIS));
    int numUDPs = 0;
    if (ctxt.userDefinedProperties != null) {
      numUDPs = ctxt.userDefinedProperties.size();
    }
    String plur = "ies";
    if (numUDPs == 1) {
      plur = "y";
    }
    JLabel udpLabel = new JLabel("Has " + numUDPs + " User-Defined Propert" + plur);
    subBoxUDP.add(udpLabel);
    JButton addUDP = new JButton("Add UDP");
    addUDP.setActionCommand("add UDP");
    addUDP.addActionListener(listener);
    subBoxUDP.add(addUDP);
    btnBoxUDPs.add(subBoxUDP);
    if (numUDPs > 0) {
      Dimension sizer = new Dimension(250, 50);
      String[] udpMenu = genUDPMenu();
      UDPick = new JComboBox(udpMenu);
      UDPick.addActionListener(listener);
      UDPick.setActionCommand("view/edit UDP");
      UDPick.setMinimumSize(sizer);
      UDPick.setMaximumSize(sizer);
      UDPick.setBorder(
          BorderFactory.createTitledBorder(
              BorderFactory.createLineBorder(Color.blue), "View/Edit UDPs"));
      btnBoxUDPs.add(UDPick);
    } //  end of if-any-UDPs-exist

    JPanel domThs = new JPanel();
    domThs.setLayout(new BoxLayout(domThs, BoxLayout.PAGE_AXIS));
    domThs.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.blue), "Kinship System Domain Theories"));
    domThs.setAlignmentX(0.5f);
    JPanel dtRefBtnBox = new JPanel();
    dtRefBtnBox.setLayout(new BoxLayout(dtRefBtnBox, BoxLayout.LINE_AXIS));
    dtRefBtnBox.setAlignmentX(0.0f);
    JLabel dtRefLabel = new JLabel("Terms of Reference ");
    dtRefBtnBox.add(dtRefLabel);
    if (ctxt.domTheoryRefExists()) {
      JButton dtRefEdit = new JButton("Edit Theory");
      dtRefEdit.setActionCommand("edit dtRef");
      dtRefEdit.addActionListener(listener);
      dtRefBtnBox.add(dtRefEdit);
      //            JButton dtRefDelete = new JButton("Delete Theory");
      //            dtRefDelete.setActionCommand("dtRef delete");
      //            dtRefDelete.addActionListener(listener);
      //            dtRefBtnBox.add(dtRefDelete);
    } //  end of if-dt-exists
    else { //  if does not exist
      JLabel dtRefNone = new JLabel("< None >");
      dtRefBtnBox.add(dtRefNone);
      //            JButton dtRefAdd = new JButton("Add Theory");
      //            dtRefAdd.setActionCommand("dtRef add");
      //            dtRefAdd.addActionListener(listener);
      //            dtRefBtnBox.add(dtRefAdd);
    } //  end of does-not-exist
    domThs.add(dtRefBtnBox);

    JPanel dtAddrBtnBox = new JPanel();
    dtAddrBtnBox.setLayout(new BoxLayout(dtAddrBtnBox, BoxLayout.LINE_AXIS));
    dtAddrBtnBox.setAlignmentX(0.0f);
    JLabel dtAddrLabel = new JLabel("Terms of Address ");
    dtAddrBtnBox.add(dtAddrLabel);
    if (ctxt.domTheoryAdrExists()) {
      JButton dtAddrEdit = new JButton("Edit Theory");
      dtAddrEdit.setActionCommand("edit dtAddr");
      dtAddrEdit.addActionListener(listener);
      dtAddrBtnBox.add(dtAddrEdit);
      //            JButton dtAddrViewList = new JButton("Delete Theory");
      //            dtAddrViewList.setActionCommand("dtAddr delete");
      //            dtAddrViewList.addActionListener(listener);
      //            dtAddrBtnBox.add(dtAddrViewList);
    } //  end of if-dt-exists
    else { //  if does not exist
      JLabel dtAddrNone = new JLabel("< None >");
      dtAddrBtnBox.add(dtAddrNone);
      //            JButton dtAddrAdd = new JButton("Add Theory");
      //            dtAddrAdd.setActionCommand("dtAddr add");
      //            dtAddrAdd.addActionListener(listener);
      //            dtAddrBtnBox.add(dtAddrAdd);
    } //  end of does-not-exist
    domThs.add(dtAddrBtnBox);
    // End of the left hand portion
    // Right hand portion follows. it is narrower.

    JPanel polyBox = new JPanel();
    polyBox.setLayout(new BoxLayout(polyBox, BoxLayout.PAGE_AXIS));
    polyBox.setAlignmentX(0.5f);
    JLabel polyLabelA = new JLabel("Polygamy");
    JLabel polyLabelB = new JLabel("Permitted?");
    JRadioButton yesPoly = new JRadioButton("Yes");
    yesPoly.setActionCommand("polygamy yes");
    yesPoly.addActionListener(listener);
    JRadioButton noPoly = new JRadioButton("No");
    noPoly.setActionCommand("polygamy no");
    noPoly.addActionListener(listener);
    if (cntxt.polygamyPermit) {
      yesPoly.setSelected(true);
    } else {
      noPoly.setSelected(true);
    }
    ButtonGroup polyBtns = new ButtonGroup();
    polyBtns.add(yesPoly);
    polyBtns.add(noPoly);
    polyBox.add(polyLabelA);
    polyBox.add(polyLabelB);
    polyBox.add(yesPoly);
    polyBox.add(noPoly);

    JPanel matrixBox = new JPanel();
    matrixBox.setLayout(new BoxLayout(matrixBox, BoxLayout.PAGE_AXIS));
    matrixBox.setAlignmentX(0.5f);
    JLabel matrixLabelA = new JLabel("Kin Term Matrix");
    JLabel matrixLabelC = new JLabel(ctxt.indSerNumGen + " rows");
    JLabel matrixLabelD = new JLabel(ctxt.ktm.numberOfKinTerms() + " terms");
    matrixLabelA.setAlignmentX(0.5f);
    matrixLabelC.setAlignmentX(0.5f);
    matrixLabelD.setAlignmentX(0.5f);
    JButton matrixEditBtn = new JButton("Edit Matrix");
    matrixEditBtn.setEnabled(false);
    matrixEditBtn.setActionCommand("edit matrix");
    matrixEditBtn.addActionListener(listener);
    matrixEditBtn.setAlignmentX(0.5f);
    matrixBox.add(matrixLabelA);
    matrixBox.add(matrixLabelC);
    matrixBox.add(matrixLabelD);
    matrixBox.add(matrixEditBtn);

    JPanel distinctBox = new JPanel();
    distinctBox.setLayout(new BoxLayout(distinctBox, BoxLayout.PAGE_AXIS));
    distinctBox.setAlignmentX(0.5f);
    JLabel distinctLabelA = new JLabel("Distinct Terms");
    JLabel distinctLabelB = new JLabel("of Address");
    distinctLabelA.setAlignmentX(0.5f);
    distinctLabelB.setAlignmentX(0.5f);
    JRadioButton yesDistinct = new JRadioButton("Yes");
    yesDistinct.setActionCommand("distinct yes");
    yesDistinct.addActionListener(listener);
    JRadioButton noDistinct = new JRadioButton("No");
    noDistinct.setActionCommand("distinct no");
    noDistinct.addActionListener(listener);
    yesDistinct.setAlignmentX(0.5f);
    noDistinct.setAlignmentX(0.5f);
    if (ctxt.distinctAdrTerms) {
      yesDistinct.setSelected(true);
    } else {
      noDistinct.setSelected(true);
    }
    ButtonGroup distinctBtns = new ButtonGroup();
    distinctBtns.add(yesDistinct);
    distinctBtns.add(noDistinct);
    distinctBox.add(distinctLabelA);
    distinctBox.add(distinctLabelB);
    distinctBox.add(yesDistinct);
    distinctBox.add(noDistinct);

    /*
     * NOTE: It should be possible to put all these elements directly into
     * the ContentPane. But that doesn't work; the layout is truly ugly and
     * stuff gets stacked on top of other stuff. What works is to put
     * everything into a JPanel with BoxLayout. Then put the JPanel into
     * ContentPane.
     */
    JPanel leftCol = new JPanel();
    leftCol.setLayout(new BoxLayout(leftCol, BoxLayout.PAGE_AXIS));
    leftCol.add(nameFolderBox);
    leftCol.add(Box.createRigidArea(new Dimension(0, 4)));
    leftCol.add(populationBox);
    leftCol.add(Box.createRigidArea(new Dimension(0, 8)));
    leftCol.add(btnBoxUDPs);
    leftCol.add(Box.createRigidArea(new Dimension(0, 8)));
    leftCol.add(domThs);
    leftCol.add(new JLabel(" "));

    JPanel rightCol = new JPanel();
    rightCol.setLayout(new BoxLayout(rightCol, BoxLayout.PAGE_AXIS));
    rightCol.setBorder(
        BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue), "Options"));
    rightCol.add(Box.createRigidArea(new Dimension(0, 20)));
    rightCol.add(polyBox);
    rightCol.add(Box.createRigidArea(new Dimension(0, 20)));
    rightCol.add(matrixBox);
    int high = (numUDPs > 0 ? 120 : 20);
    rightCol.add(Box.createRigidArea(new Dimension(0, high)));
    rightCol.add(distinctBox);

    JPanel commentBox = new JPanel();
    commentBox.setLayout(new BoxLayout(commentBox, BoxLayout.PAGE_AXIS));
    commentBox.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.blue), "Notes on this culture:"));
    JScrollPane commentsPane = new JScrollPane();
    comments = new JTextArea();
    comments.setColumns(20);
    comments.setEditable(true);
    comments.setRows(3);
    comments.setText(PersonPanel.restoreLineBreaks(ctxt.comments));
    comments.getDocument().addDocumentListener(new CommentListener());
    commentsPane.setViewportView(comments);
    commentBox.add(commentsPane);

    JPanel guts = new JPanel(); // Holds the guts of this window
    guts.setLayout(new BoxLayout(guts, BoxLayout.LINE_AXIS));
    guts.add(leftCol);
    guts.add(Box.createRigidArea(new Dimension(10, 4)));
    guts.add(rightCol);

    JPanel wholeThing = new JPanel();
    wholeThing.setLayout(new BoxLayout(wholeThing, BoxLayout.PAGE_AXIS));
    wholeThing.add(Box.createRigidArea(new Dimension(0, 4)));
    wholeThing.add(guts);
    wholeThing.add(Box.createRigidArea(new Dimension(0, 8)));
    wholeThing.add(commentBox);
    wholeThing.add(Box.createRigidArea(new Dimension(0, 4)));

    getContentPane().add(wholeThing);

    addInternalFrameListener(this);
    setSize(600, 620);
    setVisible(true);
  } //  end of ContextEditor constructor
 /**
  * Constructor to setup GUI components and event handling; Pre: name, author and theme should not
  * be null, avg and pop should not be 0; Post: the user will successfully rate the book.
  *
  * @param bookName is the name of the book.
  * @param author is the author of the book.
  * @param genre is the genre of the book.
  * @param avg is the average score of the book.
  * @param pop is the population of people that have rated the book.
  */
 public GUIBookRating(String bookName, String author, String genre, int avg, int pop) {
   frame = new JFrame("Book Rating");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   contentPane = new JPanel();
   contentPane.setLayout(
       new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); // To use BoxLayout to keep items in order
   contentPane.setBorder(
       BorderFactory.createEmptyBorder(10, 10, 10, 10)); // To create an empty border around items
   label = new JLabel("Please give rank to the book " + bookName + ":");
   label.setFont(f); // To keep the font of texts on items the same
   label.setAlignmentX(
       JLabel.CENTER_ALIGNMENT); // To line the items up at the centre of the window
   label.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   submit = new JButton("Submit");
   submit.setFont(f);
   submit.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   submit.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   rankStop = new JButton("Not Now");
   rankStop.setFont(f);
   rankStop.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   rankStop.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   String[] list = {
     "1 Awful >_<", "2 Bad T_T", "3 So So -_-", "4 Good ^_^", "5 Perfect ^3^"
   }; // To create a list for user to choose rate from 1 to 5
   ratingList = new JComboBox(list);
   ratingList.setAlignmentX(JComboBox.CENTER_ALIGNMENT);
   ratingList.setSelectedIndex(0); // Set the original rate to be 1
   submit.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           String rankGet = (String) ratingList.getSelectedItem();
           /*To transfer the rate user chosen in the combobox to the number of rankings in the database*/
           if (rankGet.equalsIgnoreCase("1 Awful >_<")) {
             engine.rankGive(bookName, 1);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(1), String.valueOf(avg), engine.customerBasedRec(bookName));
           } else if (rankGet.equalsIgnoreCase("2 Bad T_T")) {
             engine.rankGive(bookName, 2);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(2), String.valueOf(avg), engine.customerBasedRec(bookName));
           } else if (rankGet.equalsIgnoreCase("3 So So -_-")) {
             engine.rankGive(bookName, 3);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(3), String.valueOf(avg), engine.customerBasedRec(bookName));
           } else if (rankGet.equalsIgnoreCase("4 Good ^_^")) {
             engine.rankGive(bookName, 4);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(4), String.valueOf(avg), engine.bookBasedRec(bookName));
           } else {
             engine.rankGive(bookName, 5);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(5), String.valueOf(avg), engine.bookBasedRec(bookName));
           }
           frame.setVisible(false); // Close the window after going to the next step
         }
       });
   rankStop.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           GUIBookInfo info =
               new GUIBookInfo(
                   bookName,
                   author,
                   genre,
                   avg,
                   pop,
                   custrating); // To review the information of the book if the user do not want to
                                // rate the book
           frame.setVisible(false);
         }
       });
   contentPane.add(label);
   contentPane.add(ratingList);
   contentPane.add(submit);
   contentPane.add(rankStop);
   frame.setContentPane(contentPane);
   frame.pack();
   frame.setVisible(true); // Open the pop-up window
   frame.setLocationRelativeTo(
       null); // Set the location of the pop-up window at the centre of the window of computer
 }