Ejemplo n.º 1
0
  /** This method removes the defaults installed by the Look and Feel. */
  protected void uninstallDefaults() {
    toolBar.setBackground(null);
    toolBar.setForeground(null);
    toolBar.setFont(null);

    dockingBorderColor = null;
    dockingColor = null;
    floatingBorderColor = null;
    floatingColor = null;
  }
Ejemplo n.º 2
0
  /** Create the frame. */
  private MainWindows() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 627, 303);
    contentPane = new JPanel();
    contentPane.setBackground(Color.LIGHT_GRAY); // Nice color
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(new GridLayout(0, 2, 0, 0));

    JScrollPane wordScrollPane = new JScrollPane(); // Scroll Pane for Word List
    JScrollPane phraseScrollPane = new JScrollPane(); // Scroll Pane for Phrase List

    contentPane.add(wordScrollPane);
    contentPane.add(phraseScrollPane);

    jl.setBackground(SystemColor.window); // Word list.
    jl.setMinimumSize(new Dimension(100, 100));
    jl.setMaximumSize(new Dimension(1000, 1000));
    phrases.setBackground(SystemColor.window);

    wordScrollPane.setViewportView(jl);
    phraseScrollPane.setViewportView(phrases);

    JToolBar wordToolbar =
        new JToolBar(); // Create and style wordToolbar (ToolBar at top of word list)
    wordToolbar.setFloatable(false);
    wordToolbar.setBackground(Color.GRAY);
    wordToolbar.setForeground(Color.RED);
    wordScrollPane.setColumnHeaderView(wordToolbar);

    JButton wordEditButton = new JButton("Edit Word List");
    wordToolbar.add(wordEditButton);
    wordEditButton.addActionListener(
        new ActionListener() { // Makes "Edit Words List" open the Edit Word Windows
          public void actionPerformed(ActionEvent e) {
            EditWords edit = new EditWords();
            edit.setVisible(true);
          }
        });

    searchFieldBox = new JTextField();
    searchFieldBox.putClientProperty(
        "JTextField.variant",
        "search"); // Makes search box look rounded on a Mac only. There is no windows equivalent
                   // method.

    searchFieldBox.setColumns(10);
    searchFieldBox.addActionListener(
        new ActionListener() { // Makes search box respond to the user clicking enter by jumping to
                               // the value in the word list, and showing asociated phrases in the
                               // phrase list
          public void actionPerformed(ActionEvent e) {
            Set<Phrase> phraseSet = kwic.getPhrases(new Word(searchFieldBox.getText()));
            Object[] labels = phraseSet.toArray();
            jl.setSelectedValue(new Word(searchFieldBox.getText()), true);
            phrases.setListData(labels);
          }
        });
    wordToolbar.add(searchFieldBox);

    JToolBar phrasesToolbar = new JToolBar(); // Create and style
    phrasesToolbar.setBackground(SystemColor.inactiveCaption);
    phrasesToolbar.setFloatable(false);
    phraseScrollPane.setColumnHeaderView(phrasesToolbar);
    Component horizontalGlue =
        Box
            .createHorizontalGlue(); // Horizontal glue is used to move Edit Phrase Box to the right
                                     // side of the window
    phrasesToolbar.add(horizontalGlue);

    JButton editPhrasesButton = new JButton("Edit Phrases");
    phrasesToolbar.add(editPhrasesButton); // Edit phrases is in located within the ToolBar
    editPhrasesButton.addActionListener(
        new ActionListener() { // Makes "Edit Phrases" open the Edit Phrases Windows
          public void actionPerformed(ActionEvent e) {
            if (jl.getSelectedValue()
                != null) { // Makes sure something is selected in the word list before it opens
              PhrasesEditor editPhrase =
                  new PhrasesEditor(
                      new Word(
                          jl.getSelectedValue()
                              .toString())); // Passes selected word associated with set to be
                                             // edited
              editPhrase.setVisible(true);
            }
          }
        });

    kwic.addPhrases(new File("fortunes.txt")); // Load the file
    Set wordset = kwic.getWords();
    Object[] labels = wordset.toArray();
    jl.setListData(labels); // Set the words list to the words in the file

    MouseListener mouseListener =
        new MouseAdapter() { // When user clicks on values in word list, show the associated phrases
                             // in the phrase list
          public void mouseClicked(MouseEvent mouseEvent) {
            Set<Phrase> phraseset = kwic.getPhrases((Word) jl.getSelectedValue());
            Object[] labels = phraseset.toArray();
            phrases.setListData(labels);
          }
        };
    jl.addMouseListener(mouseListener);

    pcs.addPropertyChangeListener(
        "Phrase Added",
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            // react to the list of words changing
          }
        });
  }