Package gui

Source Code of gui.JRClientPanel

package gui;


// TODO: farbig, commands blau text dunkelgrauund ergebnisse schwarz


import java.awt.LayoutManager;

import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

import dao.RCommand;
import java.util.LinkedList;


public class JRClientPanel extends JPanel {

    private static Log log = LogFactory.getLog(JRClientPanel.class);

    private JLabel jLabelRPrefix;
    private JTextField jTextFieldR;
    private static JScrollPane jscrollPaneRlog;
    private static JTextArea rLog;
    private static LinkedList<String> sHistory = new LinkedList<String>();
    private static int iHistory;
   
    private JPopupMenu popup;


 
    public JRClientPanel(LayoutManager arg0, boolean arg1) {
        super(arg0, arg1);
        initComponents();
    }

    public JRClientPanel(LayoutManager arg0) {
        super(arg0);
        initComponents();
    }

    public JRClientPanel(boolean arg0) {
        super(arg0);
        initComponents();
    }

    public JRClientPanel() {
        super();
        initComponents();
    }
 
    private void initComponents() {
        jscrollPaneRlog = new JScrollPane();
        jTextFieldR = new JTextField();
        jLabelRPrefix = new JLabel();
        rLog = new JTextArea();
        // Font tmpfnt = new Font("Monospaced", 0, 12);
        // tmpfnt.
        rLog.setFont(new Font("Monospaced", 0, 12));
        rLog.setBorder(null);
        rLog.setEditable(false);
       
        jscrollPaneRlog.setViewportView(rLog);
        jscrollPaneRlog.setAutoscrolls(true);
       
        jTextFieldR.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent evt) {
                jTextFieldRKeyTyped(evt);
            }
        });
         
        jLabelRPrefix.setText(">");

        GroupLayout jPanelRLayout = new GroupLayout(this);

        this.setLayout(jPanelRLayout);
        jPanelRLayout.setHorizontalGroup(
                jPanelRLayout.createParallelGroup(GroupLayout.LEADING).add(jPanelRLayout.createSequentialGroup().addContainerGap().add(jLabelRPrefix).addPreferredGap(LayoutStyle.RELATED).add(jTextFieldR, GroupLayout.DEFAULT_SIZE, 656, Short.MAX_VALUE).addContainerGap()).add(
                        jscrollPaneRlog, GroupLayout.DEFAULT_SIZE, 702,
                        Short.MAX_VALUE));
        jPanelRLayout.setVerticalGroup(
                jPanelRLayout.createParallelGroup(GroupLayout.LEADING).add(
                        GroupLayout.TRAILING,
                        jPanelRLayout.createSequentialGroup().add(jscrollPaneRlog, GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE).addPreferredGap(LayoutStyle.RELATED).add(jPanelRLayout.createParallelGroup(GroupLayout.BASELINE).add(jLabelRPrefix).add(jTextFieldR, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addContainerGap()));

       
       
        JPopupMenu popup = new JPopupMenu();
               
        JMenuItem menuItemCut = new JMenuItem("Cut");
        menuItemCut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              jTextFieldR.cut();
            }
        });
       
        popup.add(menuItemCut);
       
        JMenuItem menuItemCopy = new JMenuItem("Copy");
        menuItemCopy.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              jTextFieldR.copy();
            }
        });
        popup.add(menuItemCopy);
       
        JMenuItem menuItemPaste = new JMenuItem("Paste");
        menuItemPaste.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              jTextFieldR.paste();
            }
        });
       
        popup.add(menuItemPaste);
       
        jTextFieldR.addMouseListener(new PopupListener (popup));
       
        JPopupMenu popup_rLog = new JPopupMenu();
        JMenuItem menuItemCopy2 = new JMenuItem("Copy");
        menuItemCopy.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              jTextFieldR.copy();
            }
        });
        popup_rLog.add(menuItemCopy2);
       
        rLog.addMouseListener(new PopupListener (popup_rLog));
       

   
    }

    private void jTextFieldRKeyTyped(KeyEvent evt) {
        // log.info(evt.getKeyCode());
        if ((evt.getKeyCode() == 10) || (evt.getKeyCode() == 13)) {
            RCommand.eval(jTextFieldR.getText());

            jTextFieldR.setText("");
        }
        if ((evt.getKeyCode() == 40)) {
            if (iHistory < sHistory.size() - 1) {
                iHistory++;
            }
            jTextFieldR.setText(getCommand());
        }
        if ((evt.getKeyCode() == 38)) {
            if (iHistory > 0) {
                iHistory--;
            }
            jTextFieldR.setText(getCommand());
        }
    }

    public static void writeRLog(String text) {
        log.info("R-Message:\n" + text);
        rLog.append(text);
        rLog.setCaretPosition(rLog.getDocument().getLength());
    }

    public static void clearRLog() {
        rLog.setText("");
    }

    public static void writeHistory(String command) {
        log.info("Putting to History:\n" + command);
        sHistory.add(command);
        iHistory = sHistory.size();
 
        rLog.append("> " + command + "\n");
    }

    private String getCommand() {
        log.info(
                iHistory + "  " + sHistory.size() + "  "
                + sHistory.get(sHistory.size() - iHistory));
        return sHistory.get(iHistory);

    }

}

TOP

Related Classes of gui.JRClientPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.