public LimitedTextArea() {
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   JTextArea text = new JTextArea(5, 40);
   // Set the customized Document on the text area. Only allow
   // a maximum of ten characters:
   text.setDocument(new LimitedDocument(10));
   getContentPane().add(new JScrollPane(text));
   pack();
   setLocationRelativeTo(null);
 }
Esempio n. 2
0
  private void setupTab() {

    // The chat area
    BorderLayout chatLayout = new BorderLayout();
    JPanel chatWrapper = new JPanel(chatLayout);

    chatLog = new JTextPane();
    chatLog.setEditable(false);
    chatLog.setDocument(new ChatDocument());
    chatLogScrollPane = new JScrollPane(chatLog);
    chatLogScrollPane.addMouseListener(this);

    chatWrapper.add(chatLogScrollPane, BorderLayout.CENTER);

    // The send message panel
    message = new JTextArea();
    message.addMouseListener(this);
    message.addKeyListener(this);
    messageScrollPane = new JScrollPane(message);
    message.setLineWrap(true);
    message.setWrapStyleWord(true);
    message.requestFocus();
    message.setDocument(new JTextFieldLimit(512));

    sendMessage = new JButton("Send", frame.getGui().getUtil().getImage("sendmessage"));
    sendMessage.addMouseListener(this);
    sendMessage.addActionListener(this);

    chatMessagePanel = new JPanel();
    chatMessagePanel.setLayout(new BoxLayout(chatMessagePanel, BoxLayout.X_AXIS));
    chatMessagePanel.add(messageScrollPane);
    chatMessagePanel.add(sendMessage);

    chatWrapper.add(chatMessagePanel, BorderLayout.PAGE_END);

    // Setup the avatars
    avatarTable = new JTable(new AvatarTableModel(indexNode));
    avatarTable.addMouseListener(this);
    avatarTable.setTableHeader(null);
    avatarTable.setDefaultRenderer(Object.class, new AvatarRenderer(frame));
    avatarTable.setRowHeight(70);
    avatarScrollPane = new JScrollPane(avatarTable);
    avatarScrollPane.setMaximumSize(new Dimension(200, -1));
    avatarScrollPane.setPreferredSize(new Dimension(200, -1));

    // Add all to parent
    BorderLayout pageLayout = new BorderLayout();

    this.setLayout(pageLayout);
    this.add(avatarScrollPane, BorderLayout.LINE_END);
    this.add(chatWrapper, BorderLayout.CENTER);

    // Set the status
    active = true;
  }
Esempio n. 3
0
  public NoteView() {
    setLayout(new BorderLayout(5, 5));

    // note.setFont(note.getFont().deriveFont(Font.BOLD, 18));
    note.setWrapStyleWord(true);
    note.setLineWrap(true);
    note.setDocument(new FixedLengthDocument(255));

    TransparentPanel northPanel = new TransparentPanel(new BorderLayout());
    JScrollPane scrollPane = new JScrollPane(note);
    northPanel.setPreferredSize(new Dimension(100, 60));
    northPanel.add(scrollPane);
    add(northPanel, BorderLayout.NORTH);

    TransparentPanel centerPanel = new TransparentPanel(new GridLayout(0, 1, 2, 2));
    centerPanel.add(addButtonsToPanel(s1));
    centerPanel.add(addButtonsToPanel(s2));
    centerPanel.add(addButtonsToPanel(s3));
    centerPanel.add(addButtonsToPanel(s4));
    add(centerPanel, BorderLayout.CENTER);

    JPanel eastPanel = new JPanel(new GridLayout(0, 1, 2, 2));
    PosButton button = new PosButton();
    button.setText(Messages.getString("NoteView.40")); // $NON-NLS-1$
    button.addActionListener(this);
    eastPanel.add(button);

    POSToggleButton toggleButton = new POSToggleButton();
    toggleButton.setText(Messages.getString("NoteView.41")); // $NON-NLS-1$
    toggleButton.addChangeListener(this);
    eastPanel.add(toggleButton);

    button = new PosButton();
    button.setText(com.floreantpos.POSConstants.CLEAR);
    button.addActionListener(this);
    eastPanel.add(button);

    button = new PosButton();
    button.setText(com.floreantpos.POSConstants.CLEAR_ALL);
    button.addActionListener(this);
    eastPanel.add(button);

    eastPanel.setPreferredSize(new Dimension(90, 50));
    add(eastPanel, BorderLayout.EAST);
  }
  public PlayerSideBar(JPanel panel, final PlayerMedia frame) {
    this.contentPane = panel;
    this.frame = frame;
    // ******************** Button for listening to text entered **********
    btnListen = new JButton("Listen");
    btnListen.setEnabled(false);
    btnListen.setBackground(Color.GRAY);
    btnListen.setForeground(Color.WHITE);
    // ActionListener to perform the speaking when pressed
    btnListen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {

            // disable listen button so speak only one thing at a time
            btnListen.setEnabled(false);

            ListenBG ListenWorker = new ListenBG(frame);

            // execute SwingWorker
            ListenWorker.execute();
          }
        });
    btnListen.setBounds(750, 192, 135, 40);
    contentPane.add(btnListen);
    // ******************************************************************

    // ********************** Create mp3 (TTS) *****************************
    btnCreateMp = new JButton("Create mp3");
    btnCreateMp.setEnabled(false);
    btnCreateMp.setBackground(Color.GRAY);
    btnCreateMp.setForeground(Color.WHITE);
    // ActionListener: Creates mp3 from text entered TTS
    btnCreateMp.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            // ask user to enter desired output name
            final String output = JOptionPane.showInputDialog(null, "Enter Mp3 Name: ");
            File f = new File(output + ".mp3");

            if (output != null && output.length() > 0) {
              if (f.exists() && !f.isDirectory()) {
                // ask if user would want to overwrite existing file
                int reply =
                    JOptionPane.showConfirmDialog(
                        null,
                        "File already exists, overwrite?",
                        "Overwrite?",
                        JOptionPane.YES_NO_OPTION);
                if (reply == JOptionPane.YES_OPTION) {
                  CreateMp3BG maker = new CreateMp3BG(frame, output);
                  maker.execute();
                }
              } else {
                CreateMp3BG maker = new CreateMp3BG(frame, output);
                maker.execute();
              }
            }
          }
        });
    btnCreateMp.setBounds(905, 192, 142, 40);
    contentPane.add(btnCreateMp);
    // ******************************************************************

    // *************Button to combined selected audio and video files*************
    btnAddCom = new JButton("Merge Video/Audio\n");
    btnAddCom.setBackground(Color.GRAY);
    btnAddCom.setForeground(Color.WHITE);
    btnAddCom.setFont(new Font("Dialog", Font.BOLD, 22));
    btnAddCom.setBounds(750, 334, 297, 100);
    btnAddCom.setEnabled(false);
    btnAddCom.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            // pick a name for the output file
            final String comOutName = JOptionPane.showInputDialog("Enter New Video Name: ");
            File f = new File(comOutName + ".avi");

            if (comOutName != null && comOutName.length() > 0) {
              if (f.exists() && !f.isDirectory()) {
                // ask if user would want to overwrite existing file
                int reply =
                    JOptionPane.showConfirmDialog(
                        null,
                        "File already exists, overwrite?",
                        "Overwrite?",
                        JOptionPane.YES_NO_OPTION);

                if (reply == JOptionPane.YES_OPTION) {
                  // generate swingworker instance
                  AddCommentaryBG adder = new AddCommentaryBG(frame, comOutName);
                  adder.execute();
                }

              } else {
                // generate swingworker instance
                AddCommentaryBG adder = new AddCommentaryBG(frame, comOutName);
                adder.execute();
              }
            }
          }
        });
    contentPane.add(btnAddCom);

    // Label to indicate how many characters are remaining
    lblChars = new JLabel("200/200");
    lblChars.setForeground(Color.WHITE);
    lblChars.setBounds(980, 170, 70, 15);
    contentPane.add(lblChars);
    // ***************************************************************************

    // *****************simple text area for the user to enter text ******************
    txtArea = new JTextArea();
    txtArea.setText("Add Text Here");
    txtArea.setWrapStyleWord(true);
    txtArea.setRows(5);
    txtArea.setToolTipText("Enter text for text to speech. ");
    txtArea.setFont(new Font("Dialog", Font.PLAIN, 15));
    txtArea.setLineWrap(true);
    txtArea.setBounds(551, 41, 302, 122);
    txtArea.setDocument(docfilt);
    contentPane.add(txtArea);

    // ****** Scroll pane which allow text area to scroll **************************
    scrollPane = new JScrollPane(txtArea);
    scrollPane.setBounds(750, 41, 297, 122);
    contentPane.add(scrollPane);

    JLabel textLabel = new JLabel("Enter text for text-to-speech");
    scrollPane.setColumnHeaderView(textLabel);

    // **************** Document Filter to count characters ************************
    // set the maximum character to 200 so the festival voice doesn't die
    docfilt.setDocumentFilter(new DocumentSizeFilter(200));
    // add a listener to show user how many characters remaining
    docfilt.addDocumentListener(
        new DocumentListener() {
          @Override
          public void changedUpdate(DocumentEvent e) {
            charCount();
          }

          @Override
          public void insertUpdate(DocumentEvent e) {
            charCount();
          }

          @Override
          public void removeUpdate(DocumentEvent e) {
            charCount();
          }
        });
    // ******************************************************************

    // *************** Button to open window for eiditing commentary *****************
    btnEdit = new JButton("Add Audio Files To Merge");
    btnEdit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            edit.setVisible(true);
          }
        });
    btnEdit.setForeground(Color.WHITE);
    btnEdit.setFont(new Font("Dialog", Font.BOLD, 18));
    btnEdit.setBackground(Color.GRAY);
    btnEdit.setBounds(750, 244, 297, 78);
    contentPane.add(btnEdit);
    // *********************************************************************************

  }
Esempio n. 5
0
 public void setNoteLength(int length) {
   note.setDocument(new FixedLengthDocument(length));
 }
  public SeparateFestivalFrame(final MediaPlayerMain frame) {

    setTitle("[Synthesize speech from text]");
    setSize(540, 250);
    getRootPane().setBorder(BorderFactory.createMatteBorder(0, 3, 0, 3, Color.WHITE));

    thisFrame = this;
    JPanel mainPanel = new JPanel(new BorderLayout());
    setContentPane(mainPanel);

    // Create new fonts with modified styles, while retaining the same font
    final Font defaultFONT = new JLabel().getFont();
    String defaultFont = defaultFONT.getName();

    final AudioConverter ac = frame.getAC();
    ac.setFestivalFrame(this);

    // Definition of Main Panels and Layouts

    JPanel corePanel = new JPanel(new BorderLayout(0, 5));
    corePanel.setBorder(new EmptyBorder(0, 5, 5, 5));
    JPanel botPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0));
    botPanel.setBorder(new EmptyBorder(0, 0, 5, 0));

    // Primary label

    JLabel titleLabel2 = new JLabel("Create custom audio using text to speech");
    titleLabel2.setBorder(new EmptyBorder(5, 0, 0, 0));
    titleLabel2.setFont(new Font(defaultFont, Font.BOLD, 18));
    titleLabel2.setHorizontalAlignment(SwingConstants.LEFT);

    // Festival text box
    final JTextArea textBox2 = new JTextArea();
    remainingCharacters = new JLabel();
    remainingCharacters.setHorizontalAlignment(SwingConstants.LEFT);
    remainingCharacters.setFont(new Font(defaultFont, Font.PLAIN, 10));

    // Document used to restrict characters entered into textbox
    customDoc = new DefaultStyledDocument();
    customDoc.setDocumentFilter(new DocumentLimit(250));
    customDoc.addDocumentListener(
        new DocumentListener() {

          @Override
          public void insertUpdate(DocumentEvent e) {
            updateCount();
          }

          @Override
          public void removeUpdate(DocumentEvent e) {
            updateCount();
          }

          @Override
          public void changedUpdate(DocumentEvent e) {
            updateCount();
          }
        });
    textBox2.setDocument(customDoc);
    updateCount();
    textBox2.setLineWrap(true);
    textBox2.setPreferredSize(new Dimension(350, 100));

    // Festival Speed setting
    JPanel festivalPanel = new JPanel(new BorderLayout());
    festivalPanel.add(textBox2, BorderLayout.CENTER);

    // Panel dedicated to voice speed
    JPanel speedRow = new JPanel(new FlowLayout(FlowLayout.TRAILING, 2, 0));
    JLabel newLabel = new JLabel("Speed of audio output:");
    newLabel.setFont(new Font(defaultFont, Font.BOLD, 12));

    // Combo box allows user to select between voice speeds
    String[] combos = {"Fast", "Normal", "Slow"};
    JComboBox<String> speedBox = new JComboBox<String>(combos);
    speedBox.setSelectedItem(combos[1]);
    speedBox.addActionListener(
        new ActionListener() {

          @Override
          // Update scheme files with any change in selection on combobox
          public void actionPerformed(ActionEvent e) {
            @SuppressWarnings("unchecked")
            JComboBox<String> comboBox = (JComboBox<String>) e.getSource();
            String speed = (String) comboBox.getSelectedItem();
            frame.updateScheme(speed);
          }
        });

    speedRow.add(newLabel);
    speedRow.add(speedBox);

    festivalPanel.add(speedRow, BorderLayout.SOUTH);

    // Festival reads out provided text as a preview
    JButton previewBtn = new JButton("Preview Text to Speech");
    previewBtn.setFont(new Font(defaultFont, Font.PLAIN, 11));

    previewBtn.setPreferredSize(new Dimension(180, 25));
    previewBtn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String text = textBox2.getText();

            if (text.isEmpty()) {
              JOptionPane.showMessageDialog(
                  thisFrame, "Text box has been left blank", "Error", JOptionPane.ERROR_MESSAGE);
            } else {
              currentProcess = ac.convertToAudio(text);
            }
          }
        });

    // Button used to kill speaking process
    JButton cancelPreview = new JButton("Stop");
    cancelPreview.setFont(new Font(defaultFont, Font.PLAIN, 11));
    cancelPreview.setPreferredSize(new Dimension(100, 25));
    cancelPreview.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (currentProcess != null) {
              CancelProcess(currentProcess);
              currentProcess = null;
            }
          }
        });

    // Preview Panel includes the preview button and the Character count
    JPanel previewPanel = new JPanel(new BorderLayout());
    JPanel twoButtons = new JPanel(new FlowLayout());
    previewPanel.add(remainingCharacters, BorderLayout.WEST);
    twoButtons.add(previewBtn);
    twoButtons.add(cancelPreview);
    previewPanel.add(twoButtons, BorderLayout.EAST);
    previewPanel.setBorder(new EmptyBorder(3, 0, 0, 0));

    // Centre Panel includes practically all content except the final
    // options
    corePanel.add(titleLabel2, BorderLayout.NORTH);
    corePanel.add(festivalPanel, BorderLayout.CENTER);
    corePanel.add(previewPanel, BorderLayout.SOUTH);

    mainPanel.add(corePanel, BorderLayout.CENTER);

    // Bottom Panel - Contains Confirm/Cancel buttons for frame

    JButton okBtn = new JButton("Save to MP3 file");
    okBtn.setFont(new Font(defaultFont, Font.BOLD, 12));
    okBtn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String festivalText = textBox2.getText();

            if (festivalText.isEmpty()) {
              JOptionPane.showMessageDialog(
                  thisFrame,
                  "Please enter text into the text area",
                  "No text to convert",
                  JOptionPane.ERROR_MESSAGE);
            } else {
              // convert festival text to wav file
              // get wav file path
              if (ac.convertToWav(festivalText)) {
                ac.wavToMp3();
                thisFrame.setVisible(false);
              }
            }
          }
        });
    okBtn.setPreferredSize(new Dimension(175, 25));

    JButton cnclBtn = new JButton("Cancel");
    cnclBtn.setFont(new Font(defaultFont, Font.BOLD, 12));
    cnclBtn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            thisFrame.setVisible(false);
          }
        });
    cnclBtn.setPreferredSize(new Dimension(175, 25));

    botPanel.add(okBtn);
    botPanel.add(cnclBtn);
    mainPanel.add(botPanel, BorderLayout.SOUTH);
  }